From 6461dfc82c2f6cf637ca0dd8ec3fcc9944b371da Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 14 Feb 2023 18:16:03 +0100 Subject: [PATCH] wait #5731 @0.75 --- .../FluidbookPublication/EditOperation.php | 33 +++++++++++++++++++ resources/linkeditor/js/linkeditor.links.js | 30 +++++++++++++++-- .../link_editor.blade.php | 1 + 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/EditOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/EditOperation.php index cf6798be9..ace3aa60e 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/EditOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/EditOperation.php @@ -22,6 +22,7 @@ trait EditOperation Route::match(['post'], $segment . '/{id}/edit/links/import/replace', $controller . '@importLinks'); Route::match(['post'], $segment . '/{id}/edit/links/move', $controller . '@moveLinks'); Route::match(['get'], $segment . '/{id}/edit/links/versions/restore/{version}', $controller . '@restoreLinks'); + Route::match(['get'], $segment . '/{id}/edit/links/fixdriftedlinks', $controller . '@fixDriftedLinks'); Route::match(['get'], $segment . '/{id}/edit/links/assets/{file}', $controller . '@getLinkAsset'); Route::put($segment . '/{id}/save/links', $controller . '@saveLinks'); @@ -245,4 +246,36 @@ trait EditOperation } return view('fluidbook_publication.link_editor', ['id' => $id, 'fluidbook' => FluidbookPublication::find($id)]); } + + + protected function fixDriftedLinks($fluidbook_id) + { + if (!FluidbookPublication::hasPermission($fluidbook_id)) { + abort(401); + } + /** @var FluidbookPublication $book */ + $book = FluidbookPublication::find($fluidbook_id); + $w = $book->getPageWidth(); + $w2 = $w * 2; + Links::getLinksAndRulers($fluidbook_id, $links, $rulers); + foreach ($links as $i => $link) { + $change = false; + while (true) { + if ($link['page'] % 2 === 0) { + $diff = $link['left'] - $w2; + } else { + $diff = $link['left'] - $w; + } + if ($diff < 0) { + break; + } + $change = true; + $link['left'] -= $w; + } + if ($change) { + $links[$i] = $link; + } + } + Links::saveLinksInFile($fluidbook_id, backpack_user()->id, __("Corriger la dérive des liens"), $links, $rulers, [], []); + } } diff --git a/resources/linkeditor/js/linkeditor.links.js b/resources/linkeditor/js/linkeditor.links.js index 2a7d20b56..fd2dc66df 100644 --- a/resources/linkeditor/js/linkeditor.links.js +++ b/resources/linkeditor/js/linkeditor.links.js @@ -48,8 +48,12 @@ LinkeditorLinks.prototype = { return false; }); - this.key('ctrl+a', function () { + this.key('ctrl+alt+shift+f', function () { + $this.fixDriftedLinks(); + }); + + this.key('ctrl+a', function () { $this.selectAll(); return false; }); @@ -183,6 +187,27 @@ LinkeditorLinks.prototype = { }) }, + + fixDriftedLinks: function () { + var $this = this; + var callback = function () { + $this._fixDriftedLinks(); + } + + //Restore links from 2022-12-07 13:37:15 + this.linkeditor.save.saveIfUnsavedChanges(TRANSLATIONS.before_fix_drifted, false, callback); + }, + + _fixDriftedLinks: function () { + $.ajax({ + url: '/fluidbook-publication/' + FLUIDBOOK_DATA.id + '/edit/links/fixdriftedlinks', + success: function (data) { + window.location.reload(); + }, + }); + }, + + allowsKeyboardShortcut: function (shortcut) { if (shortcut === 'pageup' || shortcut === 'pagedown' || shortcut === 'enter') { return true; @@ -541,7 +566,7 @@ LinkeditorLinks.prototype = { loadLinks: function (page, side) { let $this = this; $.each(LINKS, function (uid, link) { - if ($this.linkeditor.single && page % 2 === 1 && link.page % 2 === 0 && link.left > $this.linkeditor.pw) { + if (!$this.linkeditor.single && page % 2 === 1 && link.page % 2 === 0 && link.left > $this.linkeditor.pw) { link.page++; link.left -= $this.linkeditor.pw; } @@ -549,6 +574,7 @@ LinkeditorLinks.prototype = { return; } if (side === 'right') { + link.page--; link.left = parseInt(link.left) + $this.linkeditor.pw; } $this.addLink(link, side); diff --git a/resources/views/fluidbook_publication/link_editor.blade.php b/resources/views/fluidbook_publication/link_editor.blade.php index ec0e8108c..9fd7f4299 100644 --- a/resources/views/fluidbook_publication/link_editor.blade.php +++ b/resources/views/fluidbook_publication/link_editor.blade.php @@ -50,6 +50,7 @@ 'empty'=>__('Vide'), 'copy_link_id'=>__('Copier l\'identifiant unique'), 'level'=>__('Niveau'), + 'before_fix_drifted'=>__('Sauvegarde avant la correction de la dérive des liens'), ]; $rulers=!count($rulers)?'{}':json_encode($rulers); -- 2.39.5