From d6c5c231a277e68c471aa53d38ccc5e2f2b314c4 Mon Sep 17 00:00:00 2001 From: Philipp Fromme Date: Wed, 12 Sep 2018 15:40:31 +0200 Subject: [PATCH] feat(client): add image export to cmmn and dmn Related to #866 --- client/src/app/tabs/bpmn/BpmnEditor.js | 2 -- .../app/tabs/bpmn/__tests__/BpmnEditorSpec.js | 2 +- client/src/app/tabs/cmmn/CmmnEditor.js | 32 +++++++++++++++++ client/src/app/tabs/dmn/DmnEditor.js | 34 +++++++++++++++++++ 4 files changed, 67 insertions(+), 3 deletions(-) diff --git a/client/src/app/tabs/bpmn/BpmnEditor.js b/client/src/app/tabs/bpmn/BpmnEditor.js index ef828189f5..73159f67a2 100644 --- a/client/src/app/tabs/bpmn/BpmnEditor.js +++ b/client/src/app/tabs/bpmn/BpmnEditor.js @@ -23,8 +23,6 @@ import { getBpmnEditMenu } from './getBpmnEditMenu'; import css from './BpmnEditor.less'; -import { assign } from 'min-dash'; - import generateImage from '../../util/generateImage'; const COLORS = [{ diff --git a/client/src/app/tabs/bpmn/__tests__/BpmnEditorSpec.js b/client/src/app/tabs/bpmn/__tests__/BpmnEditorSpec.js index 592ba3f69e..ba6619567f 100644 --- a/client/src/app/tabs/bpmn/__tests__/BpmnEditorSpec.js +++ b/client/src/app/tabs/bpmn/__tests__/BpmnEditorSpec.js @@ -144,7 +144,7 @@ describe('', function() { expect(xml).to.eql(diagramXML); }); - describe.only('#exportAs', function() { + describe('#exportAs', function() { let bpmnEditor; diff --git a/client/src/app/tabs/cmmn/CmmnEditor.js b/client/src/app/tabs/cmmn/CmmnEditor.js index b7c6eca349..74d7549b0f 100644 --- a/client/src/app/tabs/cmmn/CmmnEditor.js +++ b/client/src/app/tabs/cmmn/CmmnEditor.js @@ -14,6 +14,8 @@ import { active as isInputActive } from '../../../util/dom/is-input'; import { getCmmnEditMenu } from './getCmmnEditMenu'; +import generateImage from '../../util/generateImage'; + export class CmmnEditor extends CachedComponent { @@ -200,6 +202,36 @@ export class CmmnEditor extends CachedComponent { }); } + exportAs(type) { + const { + modeler + } = this.getCached(); + + return new Promise((resolve, reject) => { + + modeler.saveSVG((err, svg) => { + let contents; + + if (err) { + reject(err); + } + + if (type !== 'svg') { + try { + contents = generateImage(type, svg); + } catch (err) { + return reject(err); + } + } else { + contents = svg; + } + + resolve(contents); + }); + + }); + } + triggerAction = (action, context) => { const { modeler diff --git a/client/src/app/tabs/dmn/DmnEditor.js b/client/src/app/tabs/dmn/DmnEditor.js index 6d448e78cc..6c0205376d 100644 --- a/client/src/app/tabs/dmn/DmnEditor.js +++ b/client/src/app/tabs/dmn/DmnEditor.js @@ -25,6 +25,8 @@ import { import css from './DmnEditor.less'; +import generateImage from '../../util/generateImage'; + class DmnEditor extends CachedComponent { @@ -359,6 +361,38 @@ class DmnEditor extends CachedComponent { }); } + exportAs(type) { + const { + modeler + } = this.getCached(); + + const viewer = modeler.getActiveViewer(); + + return new Promise((resolve, reject) => { + + viewer.saveSVG((err, svg) => { + let contents; + + if (err) { + reject(err); + } + + if (type !== 'svg') { + try { + contents = generateImage(type, svg); + } catch (err) { + return reject(err); + } + } else { + contents = svg; + } + + resolve(contents); + }); + + }); + } + render() { return (