Skip to content

Conversation

@cmeier76
Copy link
Member

@cmeier76 cmeier76 commented Feb 18, 2023

Find enclosed an initial rough draft to proof the concept of web-based tooling for Diagrams and Charts in ZMS.

Feb-18-2023 18-12-36

See example files for XML-Import and BPMN-Upload.

This approach utilizes Mermaid.js for rendering Markdown-inspired text definitions to create and modify diagrams dynamically.

https://github.com/mermaid-js/mermaid

In addition, the viewer of BPMN.io is used to display BPMN 2.0 (Business Process Model and Notation) and DMN 1.3 (Decision Model and Notation) diagrams in the browser.

https://github.com/bpmn-io

At the moment the ZMI preview rendering lacks due to

  • interferences with Turbolinks and jQuery

Furthermore, the user interface of the ZMSDiagram should be optimized

@cmeier76 cmeier76 requested review from drfho and zmsdev February 18, 2023 19:13
@drfho
Copy link
Contributor

drfho commented Feb 19, 2023

turbolinks seems to be a blocker; even this solution
https://stackoverflow.com/questions/50120824/turbolinks-load-event-doesnt-work-on-page-load
does not work, of the ZMI page is loaded via turbolinks. Blocking turbolinks "ex-post" makes mermaid work more constantly:

<script type="module"
tal:define="dgrm_load python:request.set('dgrm_load',request.get('dgrm_load',0)+1)"
tal:condition="python:request.get('dgrm_load',0)==1">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.esm.min.mjs';
$(document).on('ready turbolinks:load', function() {
$('body').attr('data-turbolinks','false');
mermaid.initialize({ startOnLoad: true });
});
</script>

@cmeier76 cmeier76 changed the title zms.diagrams ZMSDiagrams Feb 19, 2023
@cmeier76 cmeier76 changed the title ZMSDiagrams ZMSDiagrams Mermaid BPMN Feb 19, 2023
@cmeier76 cmeier76 changed the title ZMSDiagrams Mermaid BPMN ZMSDiagrams / Mermaid BPMN Feb 19, 2023
@drfho
Copy link
Contributor

drfho commented Feb 22, 2023

Now on code-change the mermaid chart will be re-rendered in the ZMI:

ZMSDiagram

Hint: the JS code for the re-rendering basically is inspirated by
https://mermaid.js.org/config/usage.html#api-usage
Actually the jquery context tends to provoke callback errors, so the code looks like this:

<script type="module">
//<!--
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.esm.min.mjs';
$(document).on('ready turbolinks:load', function() {
$('body').attr('data-turbolinks','false');
mermaid.initialize({ startOnLoad: true });
$('textarea[id^="diagram_code"]').on('keydown',function(){
let dgrm_code = $('textarea[id^="diagram_code"]').prop('value').trim();
let dgrm_html = `<pre class="mermaid" id="diagram_code_rendered">${dgrm_code}</pre>`;
$('#diagram_code_preview').html(dgrm_html);
//debugger;
let test = mermaid.parse(dgrm_code);
$('#diagram_code_preview').html('<pre>Mermaid Parsing = ' + test + '</pre>');
let svg = mermaid.render("diagram_code_rendered", dgrm_code);
$('#diagram_code_preview').html(svg);
});
});
//-->
</script>

@drfho
Copy link
Contributor

drfho commented Feb 22, 2023

ACE Editor on Dblclick
image

@drfho
Copy link
Contributor

drfho commented Feb 23, 2023

added error handling: 0bc023f
image

@cmeier76 cmeier76 marked this pull request as ready for review February 23, 2023 15:28
cmeier76 and others added 16 commits March 6, 2023 08:23
This approach utilizes Mermaid.js for rendering Markdown-inspired text definitions to create and modify diagrams dynamically.
https://github.com/mermaid-js/mermaid

In addition, the viewer of BPMN.io is used to display BPMN 2.0 (Business Process Model and Notation) and DMN 1.3 (Decision Model and Notation) diagrams in the browser.
https://github.com/bpmn-io
avoids any turbo-linking on content obj ZMI if attr turbolinks=false
- based on https://github.com/bpmn-io/bpmn-js-examples/tree/master/url-viewer
- jQuery is required - in ZMI preview available by default - in WEB theme this must be ensured
Caveat: Unfortunately the html comment for the javascript block had to be removed to insert the unique e-id using tal blocks for the viewer variable name.

<tal:block tal:condition="python:is_bpmn and diagram_file">
<script tal:attributes="src python:zmscontext.breadcrumbs_obj_path()[0].metaobj_manager.absolute_url()+'/ZMSDiagram.bpmn-viewer.js'"></script>
<script tal:content="python:'var canvas_id = \'js-canvas_%s\''%(id)"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errror case: multiple canvas elements on a page.
solution: a global var for each canvas id based on it's ZMS id

@drfho drfho merged commit 6f01d65 into main Mar 6, 2023
@drfho drfho deleted the zms_diagrams branch June 26, 2023 08:50
@drfho drfho mentioned this pull request Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants