From bbe143b701bddef6ad1ddbc85e2cc8122f2d1319 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 9 Dec 2022 17:00:54 +0100 Subject: [PATCH] wait #5463 @2.5 --- .../FluidbookPublication/EditOperation.php | 24 ++++++++++++------- app/Util/FluidbookLinks.php | 1 + resources/linkeditor/js/linkeditor.js | 2 +- resources/linkeditor/js/linkeditor.links.js | 5 ++++ resources/linkeditor/js/linkeditor.save.js | 8 ++++++- resources/linkeditor/js/linkeditor.toolbar.js | 14 +++++++++-- .../linkeditor/js/linkeditor.versions.js | 6 ++--- .../link_editor.blade.php | 7 +++++- 8 files changed, 50 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/EditOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/EditOperation.php index a03aa2508..5b71fe68f 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/EditOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/EditOperation.php @@ -7,6 +7,7 @@ use App\Models\FluidbookPublication; use App\Util\FluidbookLinks; use Cubist\Backpack\Http\Controllers\Base\XSendFileController; use Cubist\Util\Files\Files; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Route; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; @@ -34,11 +35,12 @@ trait EditOperation if (!FluidbookPublication::hasPermission($fluidbook_id)) { abort(401); } + FluidbookLinks::saveLinksInFile($fluidbook_id, backpack_user()->id, request('message'), - request('links', []), - request('rulers', []) + json_decode(request('links', '[]'), true), + json_decode(request('rulers', '[]'), true), ); } @@ -95,11 +97,9 @@ trait EditOperation if (!FluidbookPublication::hasPermission($fluidbook_id)) { abort(401); } - $comments = 'Restore links from ' . date('Y-m-d H:i:s', $version); - // New way FluidbookLinks::getLinksAndRulers($fluidbook_id, $links, $rulers, $version); - FluidbookLinks::saveLinksInFile($fluidbook_id, backpack_user()->id, $comments, $links, $rulers, [], []); + FluidbookLinks::saveLinksInFile($fluidbook_id, backpack_user()->id, __('Restaurer la sauvegarde des liens :date', ['date' => date('Y-m-d H:i:s', $version)]), $links, $rulers, [], []); } @@ -108,8 +108,11 @@ trait EditOperation if (!FluidbookPublication::hasPermission($fluidbook_id)) { abort(401); } - FluidbookLinks::getLinksAndRulersFromExcelFile(request()->file('file')->getPathname(), $links, $rulers); - FluidbookLinks::saveLinksInFile($fluidbook_id, backpack_user()->id, 'Replace links from excel', $links, $rulers, [], []); + /** @var UploadedFile $uploadedFile */ + $uploadedFile = request()->file('file'); + + FluidbookLinks::getLinksAndRulersFromExcelFile($uploadedFile->getPathname(), $links, $rulers); + FluidbookLinks::saveLinksInFile($fluidbook_id, backpack_user()->id, __("Remplacer les liens à partir du fichier :file", ['file' => $uploadedFile->getClientOriginalName()]), $links, $rulers, [], []); } protected function importLinksMerge($fluidbook_id) @@ -118,8 +121,11 @@ trait EditOperation abort(401); } + /** @var UploadedFile $uploadedFile */ + $uploadedFile = request()->file('file'); + FluidbookLinks::getLinksAndRulers($fluidbook_id, $merged_links, $merged_rulers); - FluidbookLinks::getLinksAndRulersFromExcelFile(request()->file('file')->getPathname(), $links, $rulers); + FluidbookLinks::getLinksAndRulersFromExcelFile($uploadedFile->getPathname(), $links, $rulers); $existing_uids = []; foreach ($merged_links as $merged_link) { $existing_uids[$merged_link['uid']] = true; @@ -135,7 +141,7 @@ trait EditOperation $merged_rulers = array_merge($merged_rulers, $rulers); - FluidbookLinks::saveLinksInFile($fluidbook_id, backpack_user()->id, 'Merge existing links with excel', $merged_links, $merged_rulers, [], []); + FluidbookLinks::saveLinksInFile($fluidbook_id, backpack_user()->id, __("Ajouter les liens à partir du fichier :file", ['file' => $uploadedFile->getClientOriginalName()]) . ' ', $merged_links, $merged_rulers, [], []); } // protected function getThumb($doc_id, $doc_page) diff --git a/app/Util/FluidbookLinks.php b/app/Util/FluidbookLinks.php index 430f99223..9cc37eb8d 100644 --- a/app/Util/FluidbookLinks.php +++ b/app/Util/FluidbookLinks.php @@ -440,6 +440,7 @@ class FluidbookLinks { $finalLinks = []; $l = array_merge(self::_getAsArray($links), self::_getAsArray($specialLinks)); + $k = 0; foreach ($l as $item) { $item['id'] = $k + 1; diff --git a/resources/linkeditor/js/linkeditor.js b/resources/linkeditor/js/linkeditor.js index d28d242c6..7e1b5bdb9 100644 --- a/resources/linkeditor/js/linkeditor.js +++ b/resources/linkeditor/js/linkeditor.js @@ -129,7 +129,7 @@ LinkEditor.prototype = { $this.rulers.moveRuler(); }); - $(document).on('mousedown', "#linkeditor-main", function (e) { + $(document).on('mousedown', "#linkeditor-editor", function (e) { var deselectAll = true; $this.setMouseCoordinates(e); if ($(this).hasClass('duplicate')) { diff --git a/resources/linkeditor/js/linkeditor.links.js b/resources/linkeditor/js/linkeditor.links.js index 6bdcb4780..862f239f7 100644 --- a/resources/linkeditor/js/linkeditor.links.js +++ b/resources/linkeditor/js/linkeditor.links.js @@ -279,6 +279,10 @@ LinkeditorLinks.prototype = { }, updateLinkData: function (id, data) { + if (LINKS[id] === undefined) { + console.warn('Link ' + id + ' not found'); + return; + } $.each(data, function (k, v) { LINKS[id][k] = v; }); @@ -482,6 +486,7 @@ LinkeditorLinks.prototype = { deleteSelection: function () { var $this = this; + this.linkeditor.form.emptyForm(); $(".link.selected").each(function () { $this.deleteLink(this, false); }); diff --git a/resources/linkeditor/js/linkeditor.save.js b/resources/linkeditor/js/linkeditor.save.js index 07e7d3b8e..4989fd017 100644 --- a/resources/linkeditor/js/linkeditor.save.js +++ b/resources/linkeditor/js/linkeditor.save.js @@ -32,8 +32,11 @@ LinkeditorSave.prototype = { saveIfUnsavedChanges: function (message, notify, callback) { if (this.unsavedChanges) { + console.log('unsaved changes', this.unsavedChanges); this.save(message, false, function () { + console.log('saved'); setTimeout(function () { + console.log('callback ok'); callback(); }, 1000); }); @@ -58,7 +61,10 @@ LinkeditorSave.prototype = { var notificationTimeout = 5000; $.ajax({ url: '/fluidbook-publication/' + FLUIDBOOK_DATA.id + '/save/links', method: 'post', data: { - _method: 'put', 'message': message, rulers: window.RULERS, links: window.LINKS, + _method: 'put', + message: message, + rulers: JSON.stringify(window.RULERS), + links: JSON.stringify(window.LINKS), }, success: function (data) { if (notify) { diff --git a/resources/linkeditor/js/linkeditor.toolbar.js b/resources/linkeditor/js/linkeditor.toolbar.js index 38deaf197..3c80f79c8 100644 --- a/resources/linkeditor/js/linkeditor.toolbar.js +++ b/resources/linkeditor/js/linkeditor.toolbar.js @@ -37,14 +37,24 @@ LinkeditorToolbar.prototype = { var xhr = f.data('jqxhr'); xhr.done(function (data) { setTimeout(function () { - console.log('reload'); window.location.reload(); }, 1000); }); } - $this.linkeditor.save.saveIfUnsavedChanges('Sauvegarde before excel import', false, callback); + $this.linkeditor.save.saveIfUnsavedChanges(TRANSLATIONS.before_restore_message, false, callback); }); + $(document).on('click', '#linkeditor-export-latest', function () { + var e = $(this); + if ($this.linkeditor.save.unsavedChanges) { + $this.linkeditor.save.save(TRANSLATIONS.before_export_save_message, false, function () { + $(e).get(0).click(); + }); + return false; + } + return true; + }) + this.linkeditor.initTooltips(); }, }; diff --git a/resources/linkeditor/js/linkeditor.versions.js b/resources/linkeditor/js/linkeditor.versions.js index 1050ddc23..d0b0696eb 100644 --- a/resources/linkeditor/js/linkeditor.versions.js +++ b/resources/linkeditor/js/linkeditor.versions.js @@ -34,8 +34,8 @@ LinkeditorVersions.prototype = { item += '
' + version.rulers + ' rulers
'; item += '' item += '
'; - item += '
' + - '
'; + item += '
' + + '
'; item += '
' item += '' list.append(item); @@ -52,7 +52,7 @@ LinkeditorVersions.prototype = { } //Restore links from 2022-12-07 13:37:15 - this.linkeditor.save.saveIfUnsavedChanges('Save before restoring links',false,callback); + this.linkeditor.save.saveIfUnsavedChanges(TRANSLATIONS.before_restore_message,false,callback); }, _restoreVersion(timestamp) { diff --git a/resources/views/fluidbook_publication/link_editor.blade.php b/resources/views/fluidbook_publication/link_editor.blade.php index 0e62a435e..62db0f8b1 100644 --- a/resources/views/fluidbook_publication/link_editor.blade.php +++ b/resources/views/fluidbook_publication/link_editor.blade.php @@ -12,6 +12,11 @@ 'manual_save_message'=>__('Sauvegarde manuelle'), 'automatic_save_message'=>__('Sauvegarde automatique'), 'warning_unsaved_changes'=>__('Des données n\'ont pas été sauvegardées'), + 'before_import_save_message'=>__("Sauvegarde avant l'import d'un fichier excel"), + 'before_export_save_message'=>__("Sauvegarde avant export"), + 'before_restore_message'=>__("Sauvegarde avant la restauration des liens"), + 'restore_version_tooltip'=>__('Restaurer cette version'), + 'export_version_tooltip'=>__('Exporter les liens au format xlsx'), ]; $rulers=!count($rulers)?'{}':json_encode($rulers); @@ -91,7 +96,7 @@ name="file"/> -