Skip to content

Commit

Permalink
feat(client): add image export to cmmn and dmn
Browse files Browse the repository at this point in the history
Related to #866
  • Loading branch information
philippfromme committed Sep 12, 2018
1 parent 7dc7d1f commit d6c5c23
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
2 changes: 0 additions & 2 deletions client/src/app/tabs/bpmn/BpmnEditor.js
Expand Up @@ -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 = [{
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/tabs/bpmn/__tests__/BpmnEditorSpec.js
Expand Up @@ -144,7 +144,7 @@ describe('<BpmnEditor>', function() {
expect(xml).to.eql(diagramXML);
});

describe.only('#exportAs', function() {
describe('#exportAs', function() {

let bpmnEditor;

Expand Down
32 changes: 32 additions & 0 deletions client/src/app/tabs/cmmn/CmmnEditor.js
Expand Up @@ -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 {

Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions client/src/app/tabs/dmn/DmnEditor.js
Expand Up @@ -25,6 +25,8 @@ import {

import css from './DmnEditor.less';

import generateImage from '../../util/generateImage';


class DmnEditor extends CachedComponent {

Expand Down Expand Up @@ -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 (
<div className={ css.DmnEditor }>
Expand Down

0 comments on commit d6c5c23

Please sign in to comment.