Skip to content

Commit

Permalink
Merge branch 'release-v1.4.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikitex70 committed Oct 22, 2023
2 parents 0d42bf3 + 681e6b4 commit a247ad7
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 16 deletions.
56 changes: 55 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,61 @@
# Changelog


## 1.4.7 (2023-06-24)
## v1.4.8 (2023-10-22)

### New

* Added support for `drawio` diagram extension (#131) [Michele Tessaro]

### Fix

* Fixes wrong number of arguments exception. [Liane Hampe]

The macro drawio_dmsf will raise an exception when a user applies
the macro to a previously uploaded drawio file (file ending does not
matter).

The error occurs in DmsfFileRevision#disk_file which has changed four
month ago.

* Fixes uncaught type error. [Liane Hampe]

Math support will only be provided if the user has checked the
corresponding box in plugin settings. When no math support is required
the javascript snippet should be ignored.

Since only MathJax will be ignored and not MathJax.Hub, javascript will
raise a type error. This is fixed with a further condition.

### Other

* Adds some unit tests. [Liane Hampe]

Will add some unit tests for drawio macros.

* Extends error message. [Liane Hampe]

The extension drawio is missing in an error message listing supported
diagram formats.

* Changes spelling in heredoc string. [Liane Hampe]

Will remove inverted comma (') from heredoc string since there are
interpreted as the beginning of a normal string
('text between inverted comma') which won't be closed.

The results is an unreadable code in some IDE such that vscode.

* Changes spelling in heredoc string. [Liane Hampe]

Will remove inverted comma (') from heredoc string since there are
interpreted as the beginning of a normal string
('text between inverted comma') which won't be closed.

The results is an unreadable code in some IDE such that vscode.


## v1.4.7 (2023-06-24)

### Fix

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ This macro handles diagrams saved as attachments of issues or wiki pages.

The supported diagrams format are:
* `xml`: normal diagram source in XML format
* `drawio`: an alias for `xml`, used to load exported diagrams from the [online ditor](https://app.diagrams.net/) without changing the file extension
* `png`: PNG image with an embedded XML source of the diagram (PNG+XML)
* `svg`: SVG image with an embedded XML source of the diagram (SVG+XML)

Expand Down
1 change: 1 addition & 0 deletions app/views/redmine_drawio/_macro_dialog.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<input type="radio" name="drawio_diagType" value="svg" style="margin-left:1em"/>SVG
<% end %>
<input type="radio" name="drawio_diagType" value="xml" style="margin-left:1em" id="drawio_diagTypeXml"/>XML
<input type="radio" name="drawio_diagType" value="drawio" style="margin-left:1em" id="drawio_diagTypeXml"/>DRAWIO
</p>
<p>
<label for="drawio_size"><%= l(:drawio_dlg_size) %></label>
Expand Down
96 changes: 94 additions & 2 deletions assets/javascripts/drawioEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ function editDiagram(image, resource, isDmsf, pageName, originalName) {
'<svg preserve_aspect_ratio="xMaxYMax meet" style="max-width:100%" width="$2px" height="$3px" viewBox="0 0 $2 $3" $1');
}

function getLang() {
if(navigator.languages) {
return navigator.languages[0];
}
return navigator.language;
}

var pngMime = 'image/png';
var svgMime = 'image/svg+xml';
var xmlMime = 'application/xml';
Expand Down Expand Up @@ -349,6 +356,90 @@ function editDiagram(image, resource, isDmsf, pageName, originalName) {
return body.match(new RegExp(macroRegExp));
}

/**
* Updates the list of attachments without reloading the page.
* Since some text is language dependente, we get the last attachment in the page
* and replace the the infos with those from the new attachment.
*/
function updateAttachmentList() {
// Re-read the page to retrieve the list of attachments
$.ajax({
url : pageUrl+'.json',
type : 'GET',
dataType: 'json',
headers : { 'X-Redmine-API-Key': getHash() },
data : {include: 'attachments'},
error : showError,
success : function(page) {
page = page.wiki_page? page.wiki_page: page.issue;
if(page && page.attachments) {
var lastAttach = page.attachments[page.attachments.length-1];
var attachTable = $(".attachments table tbody");

if(attachTable.length == 0) {
$("#wiki_add_attachment").before('<div class="attachments"><table><tbody></tbody></table></div>');
attachTable = $(".attachments table tbody");
}

var lastRow = attachTable.find('tr').last();
var hrefCount = 0;
var linkTextCount = 0;
var lastRowHtml = $(lastRow).html();

if(!lastRowHtml) {
lastRowHtml = '<td>'
+ ' <a class="icon icon-attachment" href="/redmine/attachments/00" data-bcup-haslogintext="no">NAME</a> <span class="size">(SIZE KB)</span>'
+ ' <a class="icon-only icon-download" title="Download" href="/redmine/attachments/download/00/NAME" data-bcup-haslogintext="no">NAME</a> </td>'
+ ' <td></td>'
+ ' <td>'
+ ' <span class="author">USER, TIMESTAMP</span>'
+ ' </td>'
+ ' <td>'
+ ' <a data-confirm="Are you sure ?" class="delete icon-only icon-del" title="Delete" rel="nofollow" data-method="delete" href="/redmine/attachments/00" data-bcup-haslogintext="no">Delete</a>'
+ ' </td>';
}
// 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+'</a>';
} 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.
*/
Expand All @@ -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<div id="wiki_extentions_footer">[\S\s]+?\n<\/div>$/gi, '');
Expand Down Expand Up @@ -417,7 +508,8 @@ function editDiagram(image, resource, isDmsf, pageName, originalName) {
dataType: 'text',
headers : { 'X-Redmine-API-Key': getHash() },
data : data,
error : showError
error : showError,
success : updateAttachmentList
});
}

Expand Down
12 changes: 7 additions & 5 deletions assets/javascripts/drawio_jstoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
}
},
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name 'Redmine Drawio plugin'
author 'Michele Tessaro'
description 'Wiki macro plugin for inserting drawio diagrams into Wiki pages and Issues'
version '1.4.7'
version '1.4.8'
url 'https://github.com/mikitex70/redmine_drawio'
author_url 'https://github.com/mikitex70'

Expand Down
16 changes: 9 additions & 7 deletions lib/redmine_drawio/macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ module Macros
{{drawio_attach(myDiagram[, ...options...])}}
The diagram is drawn from the attachment myDiagram.png (diagram esported as png+xml);
if the attachment doesn't exists a default diagram wil be drawn. Double click it to start
if the attachment does not exists a default diagram wil be drawn. Double click it to start
editing.
Supported diagrams format are:
* 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
Expand All @@ -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
Expand Down Expand Up @@ -177,13 +178,14 @@ module Macros
{{drawio_dmsf(myDiagram[, ...options...])}}
The diagram is drawn from the DMSF document myDiagram.png(diagram esported as png+xml);
if the attachment doesn't exists a default diagram wil be drawn. Double click it to start
if the attachment does not exists a default diagram wil be drawn. Double click it to start
editing.
Supported diagrams format are:
* 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:
Expand Down Expand Up @@ -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, xml, and drawio 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
Expand Down Expand Up @@ -266,7 +268,7 @@ module Macros

if file
# Document exists, get the file path
filename = file.last_revision.disk_file project
filename = file.last_revision.disk_file
canEdit = canEdit && User.current && User.current.allowed_to?(:file_manipulation, file.project)
else
# Document does not exists: use a predefined diagram to start editing
Expand Down Expand Up @@ -314,7 +316,7 @@ module Macros
'toolbar' => toolbar,
'xml' => diagram
}
return RedmineDrawio::Macros.encapsulateXml(graphOpts, inlineStyle, diagramName, title, saveName, false)
return RedmineDrawio::Macros.encapsulateXml(graphOpts, inlineStyle, diagramName, title, saveName, true)
end
end
end
Expand Down Expand Up @@ -462,7 +464,7 @@ def svg_enabled?
end

def pdf?(controller)
return false if controller.is_a?(Mailer)
return false if controller.is_a?(Mailer) || controller.nil?

controller.params[:format]
end
Expand Down
2 changes: 2 additions & 0 deletions spec/defaultImage.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<mxfile host="embed.diagrams.net" modified="2021-02-07T16:33:22.634Z" agent="5.0 (X11)" etag="Gs3lb32EfM7dQXgsjgK5" version="14.2.9" type="embed"><diagram name="Page-1" id="0">pZRLb4JAEMc/DXcEX71qq156Mk3PI4yw6bJjllG0n7677CAQ28SkHMjMbx77mD9E6bq6bi2cynfKUUdJnF+j9DVKkuVs7t4e3AKYTpcBFFblAU16sFffKDAWelY51qNEJtKsTmOYkTGY8YiBtdSM046kx6ueoMAHsM9AP9JPlXMpx0rmPd+hKspu5cn8JUQOkH0Vls5G1jNkMEQq6NrIGesScmoGKH2L0rUl4mBV1zVqf6vdjYW6zR/R+5YtGn6mII0XoeQC+iznjpK5dsWrXF2cWXjzo0Z/+yXKDA5gI985JB5sl9cRt+Cg+peGhzMzmbbbP7rUDJa9wiw0yhTPd2qvnm/dpJtSMe5PkHm/cWJ2SSVX2nkTZx7J8AYqpb2Qd6gvyCoDCYhuJ8vOl7a+sNUA5uKBzSR5FkvymjTZdg9p3D6OkwXjhbkqNNS11D7OVUZ9Qct4HSCZ8xapQrY3lyLRqUjuNnabXtpJLKwcyHohDORrKu6Ne1k5Q5TVub2C29jgB5G+/QA=</diagram></mxfile>
13 changes: 13 additions & 0 deletions test/fixtures/files/test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<mxfile host="Electron" modified="2023-10-11T11:00:41.645Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.2.8 Chrome/112.0.5615.165 Electron/24.2.0 Safari/537.36" etag="ULU4UeZiMxyzgYXR3Rwl" version="21.2.8" type="device">
<diagram name="Seite-1" id="rn0qnA-JrJMqG2GYrRrw">
<mxGraphModel dx="2582" dy="1493" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="na-2I6SyCpFPVLIH_ADP-1" value="&lt;h1&gt;Test&lt;/h1&gt;&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.&lt;/p&gt;" style="text;html=1;strokeColor=#82b366;fillColor=#d5e8d4;spacing=5;spacingTop=-20;whiteSpace=wrap;overflow=hidden;rounded=0;" vertex="1" parent="1">
<mxGeometry x="490" y="320" width="190" height="120" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
1 change: 1 addition & 0 deletions test/unit/drawio_settings_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DrawioSettingsHelperTest < ActiveSupport::TestCase

def teardown
Setting.plugin_redmine_drawio = { drawio_svg_enabled: nil }
Setting.clear_cache
end

def test_svg_disabled
Expand Down
Loading

0 comments on commit a247ad7

Please sign in to comment.