diff --git a/src/lib/editor/editor.component.ts b/src/lib/editor/editor.component.ts index 05b40f9..283850a 100644 --- a/src/lib/editor/editor.component.ts +++ b/src/lib/editor/editor.component.ts @@ -875,8 +875,10 @@ export class EditorComponent implements OnInit, OnDestroy { } markElement(cell: dia.Cell, markers: Array) { - let errorMessages = markers.map(m => m.message); + cell.set('markers', markers); + // Old legacy code below consider removing + let errorMessages = markers.map(m => m.message); let errorCell = cell.getEmbeddedCells().find((e: dia.Cell) => e.attr('./kind') === Constants.ERROR_DECORATION_KIND); if (errorCell) { if (errorMessages.length === 0) { @@ -893,14 +895,12 @@ export class EditorComponent implements OnInit, OnDestroy { kind: Constants.ERROR_DECORATION_KIND, messages: errorMessages }); - const view = this.paper.findViewByModel(error); - view.setInteractivity(false); + if (error) { + const view = this.paper.findViewByModel(error); + view.setInteractivity(false); + } } - const cellView = this.paper.findViewByModel(cell); - if (cellView) { - joint.V(cellView.el).toggleClass('marker-error', errorMessages.length); - } } doLayout(): Promise { @@ -1018,6 +1018,13 @@ export class EditorComponent implements OnInit, OnDestroy { } }); } + + node.on('change:markers', () => { + if (this.renderer && this.renderer.markersChanged) { + this.renderer.markersChanged(node, this.paper); + } + }); + } /** diff --git a/src/lib/shared/flo-common.ts b/src/lib/shared/flo-common.ts index 7383add..4477c49 100644 --- a/src/lib/shared/flo-common.ts +++ b/src/lib/shared/flo-common.ts @@ -123,6 +123,7 @@ export namespace Flo { isSemanticProperty?(propertyPath: string, element: dia.Cell): boolean; refreshVisuals?(cell: dia.Cell, propertyPath: string, paper: dia.Paper): void; getLinkAnchorPoint?(linkView: dia.LinkView, view: dia.ElementView, port: SVGElement, reference: dia.Point): dia.Point; + markersChanged?(cell: dia.Cell, paper: dia.Paper): void; } export interface EditorContext { diff --git a/src/lib/shared/shapes.ts b/src/lib/shared/shapes.ts index 14af41d..b72abd2 100644 --- a/src/lib/shared/shapes.ts +++ b/src/lib/shared/shapes.ts @@ -654,37 +654,28 @@ export namespace Shapes { let decoration: dia.Element; if (renderer && _.isFunction(renderer.createDecoration)) { decoration = renderer.createDecoration(kind, parent); - } else { - decoration = new joint.shapes.flo.ErrorDecoration({ - attrs: { - image: { 'xlink:href': DECORATION_ICON_MAP.get(kind) }, - } - }); - if (parent instanceof joint.dia.Element) { - const pt = location || ( parent).getBBox().topRight().offset(-decoration.size().width, 0); - decoration.position(pt.x, pt.y); - } else { - // TODO: do something for the link perhaps? + } + if (decoration) { + decoration.set('type', joint.shapes.flo.DECORATION_TYPE); + if ((isChrome || isFF) && parent && typeof parent.get('z') === 'number') { + decoration.set('z', parent.get('z') + 1); } + decoration.attr('./kind', kind); + decoration.attr('messages', messages); + if (graph) { + graph.addCell(decoration); + } + parent.embed(decoration); + if (renderer && _.isFunction(renderer.initializeNewDecoration)) { + let descriptor: Flo.ViewerDescriptor = { + paper: paper, + graph: graph + }; + renderer.initializeNewDecoration(decoration, descriptor); + } + return decoration; } - decoration.set('type', joint.shapes.flo.DECORATION_TYPE); - if ((isChrome || isFF) && parent && typeof parent.get('z') === 'number') { - decoration.set('z', parent.get('z') + 1); - } - decoration.attr('./kind', kind); - decoration.attr('messages', messages); - if (graph) { - graph.addCell(decoration); - } - parent.embed(decoration); - if (renderer && _.isFunction(renderer.initializeNewDecoration)) { - let descriptor: Flo.ViewerDescriptor = { - paper: paper, - graph: graph - }; - renderer.initializeNewDecoration(decoration, descriptor); - } - return decoration; + } static createHandle(params: HandleCreationParams): dia.Element {