2 * Copyright (c) 2017 ZTE Corporation.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * ZTE - initial API and implementation and/or initial documentation
12 import { Component, OnInit } from "@angular/core";
13 import { TranslateService } from "@ngx-translate/core";
14 import { NodeTypeService } from "../../../services/node-type.service";
15 import { DisplayInfoService } from "../../../services/display-info.service";
16 import { NodeDataType } from "../../../model/node-data-type/node-data-type";
17 import { NodeType } from "../../../model/workflow/node-type.enum";
18 import { JsPlumbService } from "../../../services/jsplumb.service";
19 import { SettingService } from "../../../services/setting.service";
20 import { WorkflowUtil } from "../../../util/workflow-util";
23 selector: 'wfm-toolbar-node',
24 templateUrl: 'toolbar-node.component.html',
25 styleUrls: ['../toolbar.component.css']
27 export class ToolbarNodeComponent implements OnInit {
28 public nodeCategories: any[] = [];
29 public nodeTypeEnum = NodeType;
30 public supportRest: boolean;
32 private needInitButton = false;
34 constructor(private nodeTypeService: NodeTypeService,
35 private displayInfoService: DisplayInfoService,
36 private jsPlumbService: JsPlumbService,
37 private settingService: SettingService,
38 public translate: TranslateService) {
42 public ngOnInit(): void {
43 this.settingService.getSetting().subscribe(setting => {
44 this.initSetting(setting);
45 this.displayInfoService.getDisplayInfo().subscribe(resp => {
46 this.initNodeCategories(resp);
47 this.needInitButton = true;
52 public ngAfterViewChecked(): void {
53 if (this.needInitButton) {
54 console.log('initJsPlumb');
56 this.needInitButton = false;
60 private initSetting(setting: any): void {
61 this.supportRest = setting.supportRestNode;
64 private initJsPlumb(): void {
65 this.jsPlumbService.buttonDraggable();
66 this.jsPlumbService.buttonDroppable();
69 private initNodeCategories(displayInfo: any): void {
70 const defaultCategory = this.insertDefaultCategory();
72 const categoryData = displayInfo['categoryData'] || {};
73 for (let key in categoryData) {
76 displayName: categoryData[key].displayName,
77 collapse: categoryData[key].collapse || false,
80 this.nodeCategories.push(group);
83 const defaultNodes = displayInfo['nodes'] || {};
84 for (let nodeId in defaultNodes) {
85 const nodeType = this.nodeTypeService.getNodeDataTypeById(nodeId);
86 const node = defaultNodes[nodeId];
87 if (node && node.category) {
88 const nodeCategory = this.nodeCategories.find(category => category.id === node.category);
90 nodeCategory.nodes.push(nodeType);
92 defaultCategory.nodes.push(nodeType);
95 defaultCategory.nodes.push(nodeType);
100 private insertDefaultCategory(): any {
101 this.nodeCategories = [];
102 const defaultCategory = {
111 this.nodeCategories.push(defaultCategory);
113 return defaultCategory;
116 public getDisplayName(data: any): string {
117 let language = 'zh_CN';
118 if (this.translate.currentLang.indexOf('en') > -1) {
121 return data.displayName ? data.displayName[language] : data.id;
124 public getImageUrl(nodeType: NodeDataType): string {
125 const name = nodeType && nodeType.icon ? nodeType.icon.name : '';
126 return WorkflowUtil.GetIconFullPath(name);