mikitex70 / redmine_drawio

Macro plugin to embed draw.io diagrams into Redmine wiki pages
MIT License
125 stars 51 forks source link

Diagram is attached as Name_1.png and so not shown after page reload #19

Closed amenk closed 7 years ago

amenk commented 7 years ago

Easyredmine / EasyredmineCompat Branch

Steps to reproduce

  1. Go to an issue
  2. insert {{drawio_attach(test.png)}}
  3. save
  4. click to draw and draw
  5. save in drawio
  6. all fine so far, diagram is shown
  7. reload the page

See:

Want to see:

amenk commented 7 years ago

For wiki pages something similar, but different happens. It is attached as _test.png_

mikitex70 commented 7 years ago

The behaviour of saving the diagram as test_1.png is normal: Readmine (at least until 3.2.0) does not have the API to delete attachments, and for new releases I need to try and implement the code. So I needed a way to "version" the diagram and so the diagram is saved with a numeric suffix that will be incremented every time the diagram is saved. At the same time the body is updated changing the reference from test.png to test_1.png. I've just tested the drawio_attach macro with Redmine 3.3.1, png diagram format, and with issue and wiki pages and it works fine.

For the issue, it seems that the issue body is not update; maybe there is a difference for the APIs between Redmine and EasyRedmine. Try another time but with the browser console open and check if there are javascript errors.

For the Wiki... at this time I have no idea. I will try to reproduce the proble.

amenk commented 7 years ago

But there is a versioning - if you upload a file with the same name, it is replaced with a new version (or is this only in ER) ? The body updating does not seem to work though ...

amenk commented 7 years ago

Is it possible to put an option to always save under the same name ? (if only for ER - but I believe stock redmine has this as well)

mikitex70 commented 7 years ago

With attachments (at least in standard Redmine) will not replace an attachment you upload two files with the same name. You can try with two different images using the same name, both will appear in the attachment list. For the body updating... what is your version of EasyRedmine? Maybe I can match a similar version of Redmine and reproduce the issue.

amenk commented 7 years ago

Interesting. In ER it is definitely the case that images get replaced by a new version. But I do not know if the API is the same. Maybe you can try in the ER branch to disable the file-renaming or give me a hint where it is done. This would magically solve the need for the body updating :-)

But now it seems to save also with foo.png for {{drawio_attach("foo.png")}} in issues - no clue why.

amenk commented 7 years ago

The are coming because I use " ... I found the versioning code and will see what happens if I disable i

https://github.com/mikitex70/redmine_drawio/blob/feature/easyredmineCompat/lib/redmine_drawio/macros.rb#L137

amenk commented 7 years ago

works

    --- a/lib/redmine_drawio/macros.rb
+++ b/lib/redmine_drawio/macros.rb
@@ -136,11 +136,12 @@ EOF

     if canEdit
         # Diagram and document are editable
-            if diagramName =~ /_\d+\./
-                saveName = diagramName.sub(/_(\d+)/) {|v| v.next } # increment version
-            else
-                saveName = diagramName.sub(/(\.\w+)$/, '_1\1') # set version to _1
-            end
+#            if diagramName =~ /_\d+\./
+#                saveName = diagramName.sub(/_(\d+)/) {|v| v.next } # increment version
+#            else
+#                saveName = diagramName.sub(/(\.\w+)$/, '_1\1') # set version to _1
+#            end
+            saveName = diagramName
     else
         # Diagram cannot be saved, it wil become not editable
         saveName = nil
amenk commented 7 years ago

Can we put a detection for easyredmine (if a easy Plugin is present?) and include that code? Where to disable the modification of the body? Even it is not working, it should be disabled I think..

mikitex70 commented 7 years ago

This is what happens when I modify a diagram without the "versioning" suffix: not_replaced The green image is the first editing attempt, the red (it looks pinker than red) is the second. As you can see the image is not replaced, and as the attachment is requested by name, it is not guaranteed to pick the latest image. Can you confirm that with EasyRedmine this doesn't happen, that when saving the image in the attachment list is replaced and not appended to list? If so than it is needed some code to disable the "versioning" (I would prefer to remove it completely, i would simplify the javascript too). A sort of detection is also needed for the EasyRedmine toolbar covering the iframe of the editor, so the detection is already necessary. But I'm not sure on the detection by testing the presence of a EasyRedmine plugin, there are plugins that can be used for free (with limitations) on the standard Redmine. I need to investigate.

amenk commented 7 years ago

Yes I can confirm it is not like on your screenshot but with proper replacing and automatic versioning by easyredmine with my small change above.

mikitex70 commented 7 years ago

Hi amenk, can you try again from the easredmineCompat branch? I've introduced an EasyRedmine detection, so I hope the code will work fine with both ER and Redmine. The code need to be cleaned but if this works I can go on with the changes.

amenk commented 7 years ago

Works well.

mikitex70 commented 7 years ago

Good, now I can clean the code and handle the toolbar covering the iframe.

mikitex70 commented 7 years ago

Plugin is almost complete, I would try to implement request #21 before release a new version. If you want you can try the current version for EasyRedmine from the develop branch.

amenk commented 7 years ago

fixed in develop