1 import {AfterViewInit, Component, EventEmitter, OnInit, Output, ViewChild,} from '@angular/core';
2 import {ContextMenuComponent, ContextMenuService} from 'ngx-contextmenu';
3 import {Constants} from '../../../shared/utils/constants';
4 import {IDType, ITreeNode} from "angular-tree-component/dist/defs/api";
5 import {TreeComponent, TreeModel, TreeNode} from "angular-tree-component";
6 import {DialogService} from "ng2-bootstrap-modal";
7 import {ActivatedRoute} from "@angular/router";
8 import {NgRedux} from "@angular-redux/store";
9 import {AppState} from "../../../shared/store/reducers";
10 import {IframeService} from "../../../shared/utils/iframe.service";
11 import {DuplicateService} from '../duplicate/duplicate.service';
12 import {DrawingBoardTreeService, TreeNodeContextMenuModel} from "./drawing-board-tree.service";
13 import {NetworkPopupService} from "../../../shared/components/genericFormPopup/genericFormServices/network/network.popup.service";
14 import {VfModulePopuopService} from "../../../shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service";
15 import {VnfPopupService} from "../../../shared/components/genericFormPopup/genericFormServices/vnf/vnf.popup.service";
16 import {SdcUiServices} from "onap-ui-angular";
17 import {HighlightPipe} from "../../../shared/pipes/highlight/highlight-filter.pipe";
18 import {VnfGroupPopupService} from "../../../shared/components/genericFormPopup/genericFormServices/vnfGroup/vnfGroup.popup.service";
19 import {ObjectToInstanceTreeService} from "../objectsToTree/objectToInstanceTree/objectToInstanceTree.service";
20 import {SharedTreeService} from "../objectsToTree/shared.tree.service";
21 import {Subject} from "rxjs/Subject";
22 import {changeServiceIsDirty} from "../../../shared/storeUtil/utils/service/service.actions";
23 import * as _ from 'lodash';
24 import {ErrorMsgService} from "../../../shared/components/error-msg/error-msg.service";
25 import {DragAndDropService} from "./dragAndDrop/dragAndDrop.service";
26 import {FeatureFlagsService, Features} from "../../../shared/services/featureFlag/feature-flags.service";
27 import {PopoverPlacement} from "../../../shared/components/popover/popover.component";
30 selector: 'drawing-board-tree',
31 templateUrl: './drawing-board-tree.html',
32 styleUrls: ['./drawing-board-tree.scss'],
33 providers: [HighlightPipe]
36 export class DrawingBoardTreeComponent implements OnInit, AfterViewInit {
37 _store: NgRedux<AppState>;
38 duplicateService: DuplicateService;
39 drawingBoardTreeService: DrawingBoardTreeService;
40 errorMsgService: ErrorMsgService;
41 isFilterEnabled: boolean = false;
42 filterValue: string = '';
43 contextMenuOptions: TreeNodeContextMenuModel[];
44 static triggerDeleteActionService: Subject<string> = new Subject<string>();
45 static triggerUndoDeleteActionService: Subject<string> = new Subject<string>();
46 static triggerreCalculateIsDirty: Subject<string> = new Subject<string>();
47 @ViewChild(ContextMenuComponent) public contextMenu: ContextMenuComponent;
49 constructor(private _contextMenuService: ContextMenuService,
50 private _iframeService: IframeService,
51 private dialogService: DialogService,
52 private store: NgRedux<AppState>,
53 private route: ActivatedRoute,
54 private _duplicateService: DuplicateService,
55 private modalService: SdcUiServices.ModalService,
56 private _drawingBoardTreeService: DrawingBoardTreeService,
57 private _networkPopupService: NetworkPopupService,
58 private _vfModulePopuopService: VfModulePopuopService,
59 private _vnfPopupService: VnfPopupService,
60 private _vnfGroupPopupService: VnfGroupPopupService,
61 private _errorMsgService: ErrorMsgService,
62 private _highlightPipe: HighlightPipe,
63 private _objectToInstanceTreeService: ObjectToInstanceTreeService,
64 private _sharedTreeService: SharedTreeService,
65 private _dragAndDropService : DragAndDropService) {
67 this.errorMsgService = _errorMsgService;
68 this.duplicateService = _duplicateService;
69 this.drawingBoardTreeService = _drawingBoardTreeService;
70 this.contextMenuOptions = _drawingBoardTreeService.generateContextMenuOptions();
72 DrawingBoardTreeComponent.triggerDeleteActionService.subscribe((serviceModelId) => {
73 this._sharedTreeService.shouldShowDeleteInstanceWithChildrenModal(this.nodes, serviceModelId, (node, serviceModelId)=>{
74 this.drawingBoardTreeService.deleteActionService(this.nodes, serviceModelId);
75 this.store.dispatch(changeServiceIsDirty(this.nodes, serviceModelId));
79 DrawingBoardTreeComponent.triggerUndoDeleteActionService.subscribe((serviceModelId) => {
80 this.drawingBoardTreeService.undoDeleteActionService(this.nodes, serviceModelId);
81 this.store.dispatch(changeServiceIsDirty(this.nodes, serviceModelId));
84 DrawingBoardTreeComponent.triggerreCalculateIsDirty.subscribe((serviceModelId) => {
85 this.store.dispatch(changeServiceIsDirty(this.nodes, serviceModelId));
91 .subscribe(params => {
92 this.serviceModelId = params['serviceModelId'];
96 getNodeId(node: ITreeNode): string {
97 return (node.data.parentType !== "" ? (node.data.parentType + "_") : "") + node.data.typeName;
100 updateNodes(updateData: { nodes: any, filterValue: string }): void {
101 this.nodes = updateData.nodes;
102 this.filterValue = updateData.filterValue;
106 highlightNode: EventEmitter<number> = new EventEmitter<number>();
108 @ViewChild('tree') tree: TreeComponent;
109 missingDataTooltip: string = Constants.Error.MISSING_VNF_DETAILS;
110 currentNode: ITreeNode = null;
113 serviceModelId: string;
115 allowDrag: this._dragAndDropService.isAllow(),
118 drop: (tree:TreeModel, node:TreeNode, $event:any, {from, to}) => {
119 this._dragAndDropService.drag(this.store, this.serviceModelId, this.nodes, {from, to});
126 parentElementClassName = 'content';
129 this.store.subscribe(() => {
135 getNodeName(node: ITreeNode, filter: string) {
136 return this._highlightPipe.transform(node.data.name, filter ? filter : '');
140 const serviceInstance = this.store.getState().service.serviceInstance[this.serviceModelId];
141 this.nodes = this._objectToInstanceTreeService.convertServiceInstanceToTreeData(serviceInstance, this.store.getState().service.serviceHierarchy[this.serviceModelId]);
142 console.log('right nodes', this.nodes);
147 ngAfterViewInit(): void {
148 this.tree.treeModel.expandAll();
151 public onContextMenu($event: MouseEvent, node: ITreeNode): void {
152 this.flags = this.store.getState().global.flags;
154 this.currentNode = node;
156 node.setActiveAndVisible(false);
157 this.selectNode(node);
159 this._contextMenuService.show.next({
160 contextMenu: this.contextMenu,
164 $event.preventDefault();
165 $event.stopPropagation();
171 executeMenuAction(methodName: string): void {
172 if (!_.isNil(this.currentNode.data.menuActions) && !_.isNil(this.currentNode.data.menuActions[methodName])) {
173 this.currentNode.data.menuActions[methodName]['method'](this.currentNode, this.serviceModelId);
174 this.store.dispatch(changeServiceIsDirty(this.nodes, this.serviceModelId));
178 isEnabled(node: ITreeNode, serviceModelId: string, methodName: string): boolean {
179 if (!_.isNil(this.currentNode) && !_.isNil(this.currentNode.data.menuActions) && !_.isNil(this.currentNode.data.menuActions[methodName])) {
180 return this.currentNode.data.menuActions[methodName]['enable'](this.currentNode, this.serviceModelId);
185 isVisible(node: ITreeNode, methodName: string): boolean {
186 if (!_.isNil(this.currentNode) && !_.isNil(this.currentNode.data.menuActions) && !_.isNil(this.currentNode.data.menuActions[methodName])) {
187 return this.currentNode.data.menuActions[methodName]['visible'](this.currentNode, this.serviceModelId);
192 public selectNode(node: ITreeNode): void {
194 this._sharedTreeService.setSelectedVNF(node);
195 this.highlightNode.emit(node.data.modelUniqueId);
196 if (FeatureFlagsService.getFlagState(Features.FLAG_1906_COMPONENT_INFO, this.store)) {
197 node.data.onSelectedNode(node);
201 expandParentByNodeId(id: IDType): void {
202 this.tree.treeModel.getNodeById(id).parent.expand();