1 import {AfterViewInit, Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core';
2 import { ContextMenuService } from 'ngx-contextmenu';
3 import { Constants } from '../../shared/utils/constants';
4 import {ServicePlanningService} from "../../services/service-planning.service";
5 import {ITreeNode} from "angular-tree-component/dist/defs/api";
6 import {ITreeOptions, TreeComponent} from "angular-tree-component";
7 import {VnfPopupComponent} from "../../components/vnf-popup/vnf-popup.components";
8 import {DialogService} from "ng2-bootstrap-modal";
9 import {ActivatedRoute} from "@angular/router";
10 import {NgRedux} from "@angular-redux/store";
11 import {AppState} from "../../store/reducers";
12 import { MessageBoxData, ModalSize, ModalType } from '../../shared/components/messageBox/messageBox.data';
13 import { MessageBoxService } from '../../shared/components/messageBox/messageBox.service';
14 import { deleteVnfInstance, deleteVfModuleInstance } from '../../service.actions';
15 import { isNullOrUndefined } from 'util';
16 import {IframeService} from "../../shared/utils/iframe.service";
20 selector: 'drawing-board-tree',
21 templateUrl: './drawing-board-tree.html',
22 styleUrls : ['./drawing-board-tree.scss']
26 export class DrawingBoardTreeComponent implements OnInit, AfterViewInit {
27 constructor(private _contextMenuService: ContextMenuService,
28 private _servicePlanningService: ServicePlanningService,
29 private _iframeService : IframeService,
30 private dialogService: DialogService,
31 private store: NgRedux<AppState>,
32 private route: ActivatedRoute) {
35 .subscribe(params => {
36 this.serviceModelId = params['serviceModelId'];
41 highlightNode : EventEmitter<number> = new EventEmitter<number>();
43 @ViewChild('tree') tree: TreeComponent;
44 missingDataTooltip: string = Constants.Error.MISSING_VNF_DETAILS;
45 currentNode: ITreeNode = null; //
47 serviceModelId: string;
48 options: ITreeOptions = {
52 parentElementClassName = 'content';
55 this.store.subscribe(() => {this.updateTree()});
60 const serviceInstance = this.store.getState().service.serviceInstance[this.serviceModelId];
61 this.nodes = this._servicePlanningService.convertServiceInstanceToTreeData(serviceInstance, this.serviceModelId);
64 ngAfterViewInit():void {
65 // Expand drawing tree on init.
66 this.tree.treeModel.expandAll();
69 public onContextMenu($event: MouseEvent, node: ITreeNode): void {
70 this.currentNode = node;
72 node.setActiveAndVisible(false);
73 this.selectNode(node);
74 this._contextMenuService.show.next({
78 $event.preventDefault();
79 $event.stopPropagation();
82 public editItem(node: ITreeNode): void {
83 node = this.currentNode;
84 this._iframeService.addClassOpenModal(this.parentElementClassName);
85 this.dialogService.addDialog(VnfPopupComponent, {
86 serviceModelId: this.serviceModelId,
87 modelName: node.data.modelName,
88 modelType: node.data.type,
89 parentModelName: node.parent.data.modelName,
94 public deleteItem(node: ITreeNode): void {
95 if(this.currentNode.data.type === 'VF'){
96 if(!isNullOrUndefined(this.currentNode.data.children) && this.currentNode.data.children.length === 0){
97 this.store.dispatch(deleteVnfInstance(this.currentNode.data.modelName, this.serviceModelId));
99 let messageBoxData : MessageBoxData = new MessageBoxData(
100 "Remove VNF", // modal title
101 "You are about to remove this VNF and all its children from this service. Are you sure you want to remove it?",
106 {text:"Remove VNF", size:"large", callback: this.removeVnf.bind(this), closeModal:true},
107 {text:"Don’t Remove", size:"medium", closeModal:true}
110 MessageBoxService.openModal.next(messageBoxData);
113 this.store.dispatch(deleteVfModuleInstance(this.currentNode.data.modelName, this.serviceModelId, node.parent.data.modelName));
118 this.store.dispatch(deleteVnfInstance(this.currentNode.data.modelName, this.serviceModelId));
121 public selectNode(node: ITreeNode): void {
123 this.highlightNode.emit(node.data.modelId);
126 isDataMissing(node: ITreeNode) {
127 //todo: currently not showing the alert icon. will be implemented in upcoming story.