merge from ecomp a88f0072 - Modern UI
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / drawing-board-tree / drawing-board-tree.component.ts
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";
28
29 @Component({
30   selector: 'drawing-board-tree',
31   templateUrl: './drawing-board-tree.html',
32   styleUrls: ['./drawing-board-tree.scss'],
33   providers: [HighlightPipe]
34 })
35
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;
48
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) {
66
67     this.errorMsgService = _errorMsgService;
68     this.duplicateService = _duplicateService;
69     this.drawingBoardTreeService = _drawingBoardTreeService;
70     this.contextMenuOptions = _drawingBoardTreeService.generateContextMenuOptions();
71
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));
76       });
77     });
78
79     DrawingBoardTreeComponent.triggerUndoDeleteActionService.subscribe((serviceModelId) => {
80       this.drawingBoardTreeService.undoDeleteActionService(this.nodes, serviceModelId);
81       this.store.dispatch(changeServiceIsDirty(this.nodes, serviceModelId));
82     });
83
84     DrawingBoardTreeComponent.triggerreCalculateIsDirty.subscribe((serviceModelId) => {
85       this.store.dispatch(changeServiceIsDirty(this.nodes, serviceModelId));
86     });
87
88     this._store = store;
89     this.route
90       .queryParams
91       .subscribe(params => {
92         this.serviceModelId = params['serviceModelId'];
93       });
94   }
95
96   getNodeId(node: ITreeNode): string {
97     return (node.data.parentType !== "" ? (node.data.parentType + "_") : "") + node.data.typeName;
98   }
99
100   updateNodes(updateData: { nodes: any, filterValue: string }): void {
101     this.nodes = updateData.nodes;
102     this.filterValue = updateData.filterValue;
103   }
104
105   @Output()
106   highlightNode: EventEmitter<number> = new EventEmitter<number>();
107
108   @ViewChild('tree') tree: TreeComponent;
109   missingDataTooltip: string = Constants.Error.MISSING_VNF_DETAILS;
110   currentNode: ITreeNode = null;
111   flags: any;
112   nodes = [];
113   serviceModelId: string;
114   options = {
115     allowDrag: this._dragAndDropService.isAllow(),
116     actionMapping: {
117       mouse: {
118         drop: (tree:TreeModel, node:TreeNode, $event:any, {from, to}) => {
119           this._dragAndDropService.drag(this.store, this.serviceModelId, this.nodes, {from, to});
120         }
121       }
122     },
123     nodeHeight: 45,
124     dropSlotHeight: 1
125   };
126   parentElementClassName = 'content';
127
128   ngOnInit(): void {
129     this.store.subscribe(() => {
130       this.updateTree();
131     });
132     this.updateTree()
133   }
134
135   getNodeName(node: ITreeNode, filter: string) {
136       return this._highlightPipe.transform(node.data.name, filter ? filter : '');
137   }
138
139   updateTree() {
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);
143
144   }
145
146
147   ngAfterViewInit(): void {
148     this.tree.treeModel.expandAll();
149   }
150
151   public onContextMenu($event: MouseEvent, node: ITreeNode): void {
152     this.flags = this.store.getState().global.flags;
153
154     this.currentNode = node;
155     node.focus();
156     node.setActiveAndVisible(false);
157     this.selectNode(node);
158     setTimeout(() => {
159       this._contextMenuService.show.next({
160         contextMenu: this.contextMenu,
161         event: <any>$event,
162         item: node,
163       });
164       $event.preventDefault();
165       $event.stopPropagation();
166     }, 250);
167
168   }
169
170
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));
175     }
176   }
177
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);
181     }
182     return false;
183   }
184
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);
188     }
189     return false;
190   }
191
192   public selectNode(node: ITreeNode): void {
193     node.expand();
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);
198     }
199   }
200
201   expandParentByNodeId(id: IDType): void {
202     this.tree.treeModel.getNodeById(id).parent.expand();
203   }
204
205 }
206
207