From 0a95f8cb5f9e122b2bb28495fd918923c3840e6e Mon Sep 17 00:00:00 2001 From: Michele Tessaro Date: Sat, 16 Sep 2023 11:00:52 +0200 Subject: [PATCH 1/8] new: usr: added support for `drawio` diagram extension (#131) --- app/views/redmine_drawio/_macro_dialog.html.erb | 1 + assets/javascripts/drawio_jstoolbar.js | 12 +++++++----- lib/redmine_drawio/macros.rb | 6 ++++-- spec/defaultImage.drawio | 2 ++ 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 spec/defaultImage.drawio diff --git a/app/views/redmine_drawio/_macro_dialog.html.erb b/app/views/redmine_drawio/_macro_dialog.html.erb index fbf369f4..3e1e2d71 100644 --- a/app/views/redmine_drawio/_macro_dialog.html.erb +++ b/app/views/redmine_drawio/_macro_dialog.html.erb @@ -15,6 +15,7 @@ SVG <% end %> XML + DRAWIO

diff --git a/assets/javascripts/drawio_jstoolbar.js b/assets/javascripts/drawio_jstoolbar.js index 18883ad6..b085b1f7 100644 --- a/assets/javascripts/drawio_jstoolbar.js +++ b/assets/javascripts/drawio_jstoolbar.js @@ -210,14 +210,14 @@ if(diagName != '' && size.match(/^\d*$/)) { // Add/replace file extension - diagName = diagName.replace(/^(.*?)(?:\.\w{3})?$/, '$1.'+diagType); - + diagName = diagName.replace(/^(.*?)(?:\.\w{3,6})?$/, '$1.'+diagType); + var options = [diagName]; if(/^\d+$/.test(size)) options.push('size='+size); - if(diagType === 'xml') { + if(diagType === 'xml' || diagType === 'drawio') { var tbAutoHide = $("#drawio_tbautohide").is(":checked"); var lightbox = $("#drawio_lightbox").is(":checked"); var zoom = $("#drawio_zoom").is(":checked"); @@ -290,7 +290,9 @@ } } - if($('input:radio[name=drawio_diagType]:checked').val() === 'xml') + var selectedType = $('input:radio[name=drawio_diagType]:checked').val(); + + if(selectedType === 'xml' || selectedType === 'drawio') $("#drawio_xml_params").show(); } }, @@ -313,7 +315,7 @@ $("input[name=drawio__P1]").val(filename.replace(/\.[^/.]+$/, "")+"."+this.value); } - if(this.value === 'xml') + if(this.value === 'xml' || this.value === 'drawio') $("#drawio_xml_params").show(); else $("#drawio_xml_params").hide(); diff --git a/lib/redmine_drawio/macros.rb b/lib/redmine_drawio/macros.rb index 6fa45dca..1b6f50bf 100644 --- a/lib/redmine_drawio/macros.rb +++ b/lib/redmine_drawio/macros.rb @@ -30,6 +30,7 @@ module Macros * png: diagram exported as png+xml (embedded source diagram) * svg: diagram exported as svg+xml (embedded source diagram) * xml: classic diagram xml source +* drawio: same ax xml Every time a diagram is saved, a new attachment will be created; for now you must manually delete old attachments (missing Redmine API; version 3.3.0 seems to have included @@ -55,7 +56,7 @@ module Macros diagramName = RedmineDrawio::Macros.strip_non_filename_chars(args.first) return "«Please set a diagram name»".html_safe unless diagramName - return "«Only png, svg and xml diagram formats are supported»".html_safe unless diagramName =~ /.*(\.(png|svg|xml))?$/i + return "«Only png, svg and xml diagram formats are supported»".html_safe unless diagramName =~ /.*(\.(png|svg|xml|drawio))?$/i return "svg diagrams are disabled by the administrator" unless RedmineDrawio::Macros.svg_enabled? || not(diagramName =~ /.*\.svg$/i) # defalts @@ -184,6 +185,7 @@ module Macros * png: diagram exported as png+xml (embedded source diagram) * svg: diagram exported as svg+xml (embedded source diagram) * xml: classic diagram xml source +* drawio: same ax xml The diagram name can contain a path. For example: @@ -212,7 +214,7 @@ module Macros diagramName = RedmineDrawio::Macros.strip_non_filename_chars(args.first).force_encoding("UTF-8") return "«Please set a diagram name»".html_safe unless diagramName - return "«Only png and svg diagram formats are supported»".html_safe unless diagramName =~ /.*(\.(png|svg))?$/i + return "«Only png, svg and xml diagram formats are supported»".html_safe unless diagramName =~ /.*(\.(png|svg|xml|drawio))?$/i return "svg diagrams are disabled by the administrator" unless RedmineDrawio::Macros.svg_enabled? || not(diagramName =~ /.*\.svg$/i) # Add an extension, if missing diff --git a/spec/defaultImage.drawio b/spec/defaultImage.drawio new file mode 100644 index 00000000..af1acccb --- /dev/null +++ b/spec/defaultImage.drawio @@ -0,0 +1,2 @@ + +pZRLb4JAEMc/DXcEX71qq156Mk3PI4yw6bJjllG0n7677CAQ28SkHMjMbx77mD9E6bq6bi2cynfKUUdJnF+j9DVKkuVs7t4e3AKYTpcBFFblAU16sFffKDAWelY51qNEJtKsTmOYkTGY8YiBtdSM046kx6ueoMAHsM9AP9JPlXMpx0rmPd+hKspu5cn8JUQOkH0Vls5G1jNkMEQq6NrIGesScmoGKH2L0rUl4mBV1zVqf6vdjYW6zR/R+5YtGn6mII0XoeQC+iznjpK5dsWrXF2cWXjzo0Z/+yXKDA5gI985JB5sl9cRt+Cg+peGhzMzmbbbP7rUDJa9wiw0yhTPd2qvnm/dpJtSMe5PkHm/cWJ2SSVX2nkTZx7J8AYqpb2Qd6gvyCoDCYhuJ8vOl7a+sNUA5uKBzSR5FkvymjTZdg9p3D6OkwXjhbkqNNS11D7OVUZ9Qct4HSCZ8xapQrY3lyLRqUjuNnabXtpJLKwcyHohDORrKu6Ne1k5Q5TVub2C29jgB5G+/QA= \ No newline at end of file From 9fae814ab345cc45b0c237c922c90d7b685452fc Mon Sep 17 00:00:00 2001 From: Michele Tessaro Date: Mon, 18 Sep 2023 07:43:19 +0200 Subject: [PATCH 2/8] fix: dev: fixed attachments list after editing (#131) The list of attachments is now refreshed after every edit. The refresh is done without refreshing the whole page, some text may not be in the correct language, but reloading the page fixes the issue. --- assets/javascripts/drawioEditor.js | 96 +++++++++++++++++++++++++++++- lib/redmine_drawio/macros.rb | 2 +- 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/drawioEditor.js b/assets/javascripts/drawioEditor.js index f2a643af..47ae6a40 100644 --- a/assets/javascripts/drawioEditor.js +++ b/assets/javascripts/drawioEditor.js @@ -45,6 +45,13 @@ function editDiagram(image, resource, isDmsf, pageName, originalName) { '
'); + attachTable = $(".attachments table tbody"); + } + + var lastRow = attachTable.find('tr').last(); + var hrefCount = 0; + var linkTextCount = 0; + var lastRowHtml = $(lastRow).html(); + + if(!lastRowHtml) { + lastRowHtml = '' + + ' NAME (SIZE KB)' + + ' NAME ' + + ' ' + + ' ' + + ' USER, TIMESTAMP' + + ' ' + + ' ' + + ' Delete' + + ' '; + } + // replace icon link + lastRowHtml = lastRowHtml.replace(/href="[^"]+"/g, function(match) { + var path = lastAttach.content_url.substring(0, lastAttach.content_url.indexOf('/attachments/download/')+'/attachments'.length); + + //var path = lastAttach.content_url.substring(0, lastAttach.content_url.lastIndexOf('/')); + + //path = path.substring(0, path.lastIndexOf('/')); + + switch(hrefCount++) { + case 0: + case 2: return 'href="'+path+'/'+lastAttach.id+'"'; + case 1: return 'href="'+lastAttach.content_url+'"'; + default: return match; + } + }); + // replace file size + lastRowHtml = lastRowHtml.replace(/\((.*?) KB\)/, '('+(lastAttach.filesize/1024).toFixed(2)+' KB)'); + // replace file name + lastRowHtml = lastRowHtml.replace(/>[^<]+<\/a>/g, function(match) { + if(linkTextCount++ < 2) { + return '>'+lastAttach.filename+''; + } else { + return match; + } + }); + // replace author and date + var attachDate = new Date(lastAttach.created_on).toLocaleString(); + lastRowHtml = lastRowHtml.replace(/author">[^<]+/, 'author">'+lastAttach.author.name+', '+ + attachDate.replaceAll('/', '-').substring(0, attachDate.lastIndexOf(':')) + ); + // add the new attachment to the attachments list + attachTable.append(lastRowHtml); + // increment the number of attachments + var numAttachs = $("fieldset legend"); + numAttachs.text(numAttachs.text().replace(/\d+/, function(match) { + return Number(match)+1; + })); + } + } + }); + } + /** * Fix for `{{fnlist}}` duplication with the `redmine_wiki_extensions` plugin. */ @@ -364,7 +455,7 @@ function editDiagram(image, resource, isDmsf, pageName, originalName) { } /** - * Fix for Wiki Extensions header page. + * Fix for Wiki Extensions footer page. */ function fixWikiExtensionsFooter(value) { return value.replace(/\n\n