]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5731 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 14 Feb 2023 17:16:03 +0000 (18:16 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 14 Feb 2023 17:16:03 +0000 (18:16 +0100)
app/Http/Controllers/Admin/Operations/FluidbookPublication/EditOperation.php
resources/linkeditor/js/linkeditor.links.js
resources/views/fluidbook_publication/link_editor.blade.php

index cf6798be9baa1945cd906ed2bdc05f98387df43b..ace3aa60e532e75ba68b2bb7c48f35d1a9728160 100644 (file)
@@ -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, [], []);
+    }
 }
index 2a7d20b5614363c176e409c6f301e2e13d352e1c..fd2dc66df986d7e745b22b92893563f309747eb9 100644 (file)
@@ -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);
index ec0e8108c3ffd5d2f768987e4a493f4df3752701..9fd7f4299f031127c08364f6252e0abadefca292 100644 (file)
@@ -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);