Découvrez les nouveautés de cette version : Fonctionnalités, améliorations et évolutions vous attendent ! 👉 Cliquez ici pour en savoir plus

Modifications pour le document DiagramEditSheet

Modifié par Admin le 19/03/2025 - 19:24

Depuis la version 9.1
modifié par Admin
sur 19/03/2025 - 19:24
Commentaire de modification : Install extension [com.xwiki.diagram:application-diagram/1.22.1]
À la version 8.1
modifié par Admin
sur 10/02/2025 - 13:05
Commentaire de modification : Install extension [com.xwiki.diagram:application-diagram/1.22.0]

Résumé

Détails

XWiki.JavaScriptExtension[1]
Code
... ... @@ -105,19 +105,18 @@
105 105   var attachmentReference = new XWiki.AttachmentReference(fileName, documentReference);
106 106   var uploadMethod = (diagramConfig.isTemporaryUploadSupported) ? xutils.temporaryUploadAttachment : xutils.uploadAttachment;
107 107   var uploadAttachment = $.proxy(uploadMethod, null, blob, attachmentReference);
108 - return uploadAttachment();
108 + // Avoid creating too many versions of the attachment. Upload the attachment even if we failed to delete it first.
109 + return xutils.deleteAttachment(attachmentReference).then(uploadAttachment, uploadAttachment);
109 109   };
110 110  
111 111   var imageCache = {};
112 - var saveFileAsPNGImageAttachment = function(file, index, originalPage) {
113 + var saveFileAsPNGImageAttachment = function(file) {
113 113   var deferred = $.Deferred();
114 - let page = file.ui.pages[index];
115 - file.ui.selectPage(page, true, null);
116 - file.getUi().exportToCanvas(/* callback */ function (canvas) {
115 + file.getUi().exportToCanvas(/* callback */ function(canvas) {
117 117   if (canvas) {
118 118   try {
119 - canvas.toBlob(function (blob) {
120 - pipeDeferred(saveBlobAsImageAttachment(blob, `${getXWikiAttachmentName(index)}.png`, file.documentReference), deferred);
118 + canvas.toBlob(function(blob) {
119 + pipeDeferred(saveBlobAsImageAttachment(blob, 'diagram.png', file.documentReference), deferred);
121 121   });
122 122   } catch(err) {
123 123   deferred.reject();
... ... @@ -130,17 +130,13 @@
130 130   $jsontool.serialize($services.localization.render('diagram.editor.saveAsImageAttachmentError')), 'error');
131 131   deferred.reject();
132 132   }, /* limitHeight */ null, /* ignoreSelection */ true, /* scale */ diagramConfig.pdfImageExportZoom);
133 - file.ui.selectPage(originalPage, true, null);
134 134   return deferred.promise();
135 135   };
136 136  
137 - var saveFileAsSVGImageAttachment = function(file, index, originalPage) {
138 - var deferred = $.Deferred()
139 - let page = file.ui.pages[index];
140 - file.ui.selectPage(page, true, null);
135 + var saveFileAsSVGImageAttachment = function(file) {
136 + var deferred = $.Deferred();
141 141   var svgRoot = file.ui.editor.graph.getSvg(/* background: */ '#ffffff', /* scale: */ null, /* border: */ null,
142 142   /* nocrop: */ true, /* crisp: */ null, /* ignoreSelection: */ true);
143 - file.ui.selectPage(originalPage, true, null);
144 144   // Embed the images because the PDF exporter might not be able to access them.
145 145   file.ui.convertImages(svgRoot, function() {
146 146   var svg = '<?xml version="1.0" encoding="UTF-8"?>\n' +
... ... @@ -147,62 +147,28 @@
147 147   '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
148 148   mxUtils.getXml(svgRoot);
149 149   var blob = new Blob([svg], {type: 'image/svg+xml'});
150 - pipeDeferred(saveBlobAsImageAttachment(blob, `${getXWikiAttachmentName(index)}.svg`, file.documentReference),
151 - deferred);
145 + pipeDeferred(saveBlobAsImageAttachment(blob, 'diagram.svg', file.documentReference), deferred);
152 152   }, imageCache);
153 153   return deferred.promise();
154 154   };
155 155  
156 - var saveFileAsImageAttachments = function(file, index, originalPage) {
150 + var saveFileAsImageAttachments = function(file) {
157 157   // This is a workaround for https://github.com/jgraph/drawio/issues/490
158 158   // Stop editing for getting the latest content from diagram
159 159   file.ui.editor.graph.stopEditing(false);
160 160   // We upload the PNG image even if the SVG upload has failed.
161 - var pngUpload = $.proxy(saveFileAsPNGImageAttachment, null, file, index, originalPage);
162 - return saveFileAsSVGImageAttachment(file, index, originalPage).then(pngUpload, pngUpload);
155 + var pngUpload = $.proxy(saveFileAsPNGImageAttachment, null, file);
156 + return saveFileAsSVGImageAttachment(file).then(pngUpload, pngUpload);
163 163   };
164 164  
165 - var getXWikiAttachmentName = function (index) {
166 - if (index == 0)
167 - {
168 - // If is the first page we keep the old naming strategy -> diagram.png / diagram.svg
169 - return "diagram";
170 - }
171 - return `diagram${index+1}`;
172 - };
173 -
174 - var deleteAllDiagrams = function() {
175 - let baseUrl = `/xwiki/rest/diagram/${xm.documentReference.toString()}`;
176 - let queryString = $.param({"form_token": xm.form_token});
177 - return $.post(`${baseUrl}?${queryString}`);
178 - };
179 -
180 180   var saveFilesAsImageAttachments = function() {
181 - var uploadDeferredList = []
182 -
183 - forEachOpenedFile(function (file) {
184 - var uploadDeferred = $.Deferred().resolve();
185 - // Get the current page so we know where to return after saving.
186 - let originalPage = file.ui.currentPage;
187 -
188 - file.ui.pages.forEach(function (page, index) {
189 - // We do the next upload even if the previous uploads have failed.
190 - var nextUpload = $.proxy(saveFileAsImageAttachments, null, file, index,originalPage);
191 - uploadDeferred = uploadDeferred.then(nextUpload, nextUpload);
192 - uploadDeferredList.push(uploadDeferred.promise());
193 - });
160 + var uploadDeferred = $.Deferred().resolve();
161 + forEachOpenedFile(function(file) {
162 + // We do the next upload even if the previous uploads have failed.
163 + var nextUpload = $.proxy(saveFileAsImageAttachments, null, file);
164 + uploadDeferred = uploadDeferred.then(nextUpload, nextUpload);
194 194   });
195 - // Wait for all deferreds to complete.
196 - return $.when.apply($, uploadDeferredList).then(
197 - function () {
198 - // Resolve the overall promise if all succeeded.
199 - return { status: 'success' };
200 - },
201 - function () {
202 - // Reject the overall promise if any failed.
203 - return $.Deferred().reject({ status: 'fail' });
204 - }
205 - ).promise();
166 + return uploadDeferred.promise();
206 206   };
207 207  
208 208   var uploadInProgress = false;
... ... @@ -214,13 +214,10 @@
214 214   event.stopPropagation();
215 215   var saveButton = $(event.target);
216 216   saveButton.prop('disabled', true);
217 - deleteAllDiagrams()
218 - .then(saveFilesAsImageAttachments)
219 - .catch(function(e) {
178 + saveFilesAsImageAttachments().fail(function(e) {
220 220   new XWiki.widgets.Notification(
221 221   $jsontool.serialize($services.localization.render('diagram.editor.saveAsImageAttachmentError')), 'error');
222 - })
223 - .always(function() {
181 + }).always(function() {
224 224   saveButton.prop('disabled', false).click();
225 225   });
226 226   } else {
Parser le contenu
... ... @@ -1,1 +1,1 @@
1 -Non
1 +Oui
XWiki.JavaScriptExtension[2]
Code
... ... @@ -18,29 +18,6 @@
18 18   a.nodeName.toLowerCase() != b.toLowerCase() ? !1 : null == c || a.getAttribute(c) == d;
19 19   };
20 20  
21 -/**
22 - * TODO: When upgrading, make sure to check if this method has changed.
23 - * This method was copied directly from draw.io, and the only change made was the call to this.showDialog.
24 - * Both the width and height were modified to fit better within the XWiki UI.
25 - */
26 -EditorUi.prototype.showBackgroundImageDialog = function (apply, img, color, showColor) {
27 - apply = (apply != null) ? apply : mxUtils.bind(this, function (image, failed, color, shadowVisible) {
28 - if (!failed) {
29 - var change = new ChangePageSetup(this, (showColor) ? color : null, image);
30 - change.ignoreColor = !showColor;
31 - if (shadowVisible != null && showColor) {
32 - change.shadowVisible = shadowVisible;
33 - }
34 - this.editor.graph.model.execute(change);
35 - }
36 - });
37 -
38 - var dlg = new BackgroundImageDialog(this, apply, img, color, showColor);
39 - this.showDialog(dlg.container, 420, (showColor) ? 260 : 240, true, true);
40 - dlg.init();
41 -};
42 -
43 -
44 44   EditorUi.prototype.showLinkDialog = function(value, selectLabel, callback, showNewWindowOption, linkTarget) {
45 45   var resourceReference = diagramLinkHandler.getResourceReferenceFromCustomLink(value);
46 46   // We append the modal to the body element in order to fix Issue #108: "Inserting a link in full screen mode is not
... ... @@ -394,7 +394,8 @@
394 394   //
395 395   // Change the service name in order to disable notifications.
396 396   //
397 - EditorUi.prototype.getServiceName = function() {
374 + EditorUi.prototype.getServiceName = function()
375 + {
398 398   return 'xwiki.com';
399 399   };
400 400