2 * Copyright (c) 2017 ZTE Corporation.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * and the Apache License 2.0 which both accompany this distribution,
\r
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
\r
7 * and http://www.apache.org/licenses/LICENSE-2.0
\r
10 * ZTE - initial API and implementation and/or initial documentation
\r
13 import { Injectable } from '@angular/core';
\r
14 import * as jsp from 'jsplumb';
\r
15 import { WorkflowService } from "./workflow.service";
\r
19 * provides all of the operations about jsplumb plugin.
\r
22 export class JsPlumbService {
\r
23 public jsplumbInstance;
\r
25 constructor(private workflowService: WorkflowService) {
\r
26 this.initJsPlumbInstance();
\r
30 public initJsPlumbInstance() {
\r
31 this.jsplumbInstance = jsp.jsPlumb.getInstance({
\r
35 this.jsplumbInstance.importDefaults({
\r
36 Anchor: ['Top', 'RightMiddle', 'LeftMiddle', 'Bottom'],
\r
39 { cornerRadius: 0, stub: 0, gap: 3 },
\r
41 ConnectionOverlays: [
\r
44 { direction: 1, foldback: 1, location: 1, width: 10, length: 10 },
\r
46 ['Label', { label: '', id: 'label', cssClass: 'aLabel' }],
\r
59 // add connection to model data while a new connection is build
\r
60 this.jsplumbInstance.bind('connection', info => {
\r
61 info.connection.bind('click', connection => {
\r
62 this.jsplumbInstance.select({ connections: [connection] }).delete();
\r
68 public initNode(selectorString: string) {
\r
69 const selector = this.jsplumbInstance.getSelector(selectorString);
\r
71 this.jsplumbInstance.draggable(selector, {
\r
73 // node.position.left = event.pos[0];
\r
74 // node.position.top = event.pos[1];
\r
78 this.jsplumbInstance.makeTarget(selector, {
\r
84 this.jsplumbInstance.makeSource(selector, {
\r
85 filter: '.anchor, .anchor *',
\r
93 public remove(nodeId: string) {
\r
94 this.jsplumbInstance.remove(nodeId);
\r
97 public buttonDraggable() {
\r
98 const selector = this.jsplumbInstance.getSelector('.toolbar .item');
\r
99 this.jsplumbInstance.draggable(selector,
\r
106 public buttonDroppable() {
\r
107 console.log('buttonDroppable');
\r
108 const selector = this.jsplumbInstance.getSelector('.canvas');
\r
109 this.jsplumbInstance.droppable(selector, {
\r
112 const el = this.jsplumbInstance.getSelector(event.drag.el);
\r
113 const type = el.attributes.nodeType.value;
\r
114 const left = event.e.clientX - event.drop.position[0];
\r
115 const top = event.e.clientY - event.drop.position[1];
\r
117 this.workflowService.addNode(type, type, top, left);
\r