New error marker support via model only
This commit is contained in:
@@ -875,8 +875,10 @@ export class EditorComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
markElement(cell: dia.Cell, markers: Array<Flo.Marker>) {
|
||||
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<void> {
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 || (<dia.Element> 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 {
|
||||
|
||||
Reference in New Issue
Block a user