1 import {AfterViewInit, Component, EventEmitter, Input, 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 {VfModulePopupService} from "../../../shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popup.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 {ComponentInfoService} from "../component-info/component-info.service";
28 import {ComponentInfoModel} from "../component-info/component-info-model";
29 import {ObjectToModelTreeService} from "../objectsToTree/objectToModelTree/objectToModelTree.service";
30 import {DrawingBoardModes} from "../drawing-board.modes";
31 import {ServiceInstanceActions} from "../../../shared/models/serviceInstanceActions";
34 selector: 'drawing-board-tree',
35 templateUrl: './drawing-board-tree.html',
36 styleUrls: ['./drawing-board-tree.scss'],
37 providers: [HighlightPipe]
40 export class DrawingBoardTreeComponent implements OnInit, AfterViewInit {
41 _store: NgRedux<AppState>;
42 duplicateService: DuplicateService;
43 drawingBoardTreeService: DrawingBoardTreeService;
44 objectToModelTreeService : ObjectToModelTreeService;
45 objectToInstanceTreeService : ObjectToInstanceTreeService;
46 errorMsgService: ErrorMsgService;
47 isFilterEnabled: boolean = false;
48 filterValue: string = '';
49 contextMenuOptions: TreeNodeContextMenuModel[];
51 @Input() pageMode : DrawingBoardModes;
52 static triggerDeleteActionService: Subject<string> = new Subject<string>();
53 static triggerUndoDeleteActionService: Subject<string> = new Subject<string>();
54 static triggerreCalculateIsDirty: Subject<string> = new Subject<string>();
55 @ViewChild(ContextMenuComponent) public contextMenu: ContextMenuComponent;
57 constructor(private _contextMenuService: ContextMenuService,
58 private _iframeService: IframeService,
59 private dialogService: DialogService,
60 private store: NgRedux<AppState>,
61 private route: ActivatedRoute,
62 private _duplicateService: DuplicateService,
63 private modalService: SdcUiServices.ModalService,
64 private _drawingBoardTreeService: DrawingBoardTreeService,
65 private _networkPopupService: NetworkPopupService,
66 private _vfModulePopuopService: VfModulePopupService,
67 private _vnfPopupService: VnfPopupService,
68 private _vnfGroupPopupService: VnfGroupPopupService,
69 private _errorMsgService: ErrorMsgService,
70 private _highlightPipe: HighlightPipe,
71 private _objectToInstanceTreeService: ObjectToInstanceTreeService,
72 private _sharedTreeService: SharedTreeService,
73 private _dragAndDropService : DragAndDropService,
74 private _objectToModelTreeService : ObjectToModelTreeService,
75 private _componentInfoService: ComponentInfoService) {
77 this.errorMsgService = _errorMsgService;
78 this.duplicateService = _duplicateService;
79 this.drawingBoardTreeService = _drawingBoardTreeService;
80 this.contextMenuOptions = _drawingBoardTreeService.generateContextMenuOptions();
81 this.objectToModelTreeService = _objectToModelTreeService;
82 this.objectToInstanceTreeService = _objectToInstanceTreeService;
83 DrawingBoardTreeComponent.triggerDeleteActionService.subscribe((serviceModelId) => {
84 this._sharedTreeService.shouldShowDeleteInstanceWithChildrenModal(this.nodes, serviceModelId, (node, serviceModelId)=>{
85 this.drawingBoardTreeService.deleteActionService(this.nodes, serviceModelId);
86 this.store.dispatch(changeServiceIsDirty(this.nodes, serviceModelId));
90 DrawingBoardTreeComponent.triggerUndoDeleteActionService.subscribe((serviceModelId) => {
91 this.drawingBoardTreeService.undoDeleteActionService(this.nodes, serviceModelId);
92 this.store.dispatch(changeServiceIsDirty(this.nodes, serviceModelId));
95 DrawingBoardTreeComponent.triggerreCalculateIsDirty.subscribe((serviceModelId) => {
96 this.store.dispatch(changeServiceIsDirty(this.nodes, serviceModelId));
102 .subscribe(params => {
103 this.serviceModelId = params['serviceModelId'];
107 getNodeId(node: ITreeNode): string {
108 return (node.data.parentType !== "" ? (node.data.parentType + "_") : "") + node.data.typeName;
111 updateNodes(updateData: { nodes: any, filterValue: string }): void {
112 this.nodes = updateData.nodes;
113 this.filterValue = updateData.filterValue;
116 isLinkedInstance = (node) : boolean => {
117 return !_.isNil(node) && node.parentType === "VRF" || node.parentType === "VnfGroup";
121 highlightNode: EventEmitter<number> = new EventEmitter<number>();
123 @ViewChild('tree') tree: TreeComponent;
124 missingDataTooltip: string = Constants.Error.MISSING_VNF_DETAILS;
125 currentNode: ITreeNode = null;
128 serviceModelId: string;
130 allowDrag: this._dragAndDropService.isFlagOn(),
133 drop: (tree:TreeModel, node:TreeNode, $event:any, {from, to}) => {
134 this._dragAndDropService.drop(this.store, this.serviceModelId, this.nodes, {from, to});
141 parentElementClassName = 'content';
144 this.store.subscribe(() => {
150 getNodeName(node: ITreeNode, filter: string) {
151 return this._highlightPipe.transform(node.data.name, filter ? filter : '');
155 const serviceInstance = this.store.getState().service.serviceInstance[this.serviceModelId];
156 this.nodes = this._objectToInstanceTreeService.convertServiceInstanceToTreeData(serviceInstance, this.store.getState().service.serviceHierarchy[this.serviceModelId]).filter((item) => item !== null);
157 console.log('right nodes', this.nodes);
162 ngAfterViewInit(): void {
163 this.tree.treeModel.expandAll();
166 public onContextMenu($event: MouseEvent, node: ITreeNode): void {
167 this.flags = this.store.getState().global.flags;
169 this.currentNode = node;
171 node.setActiveAndVisible(false);
172 this.selectNode(node);
174 this._contextMenuService.show.next({
175 contextMenu: this.contextMenu,
179 $event.preventDefault();
180 $event.stopPropagation();
186 executeMenuAction(methodName: string): void {
187 if (!_.isNil(this.currentNode.data.menuActions) && !_.isNil(this.currentNode.data.menuActions[methodName])) {
188 this.currentNode.data.menuActions[methodName]['method'](this.currentNode, this.serviceModelId);
189 this.store.dispatch(changeServiceIsDirty(this.nodes, this.serviceModelId));
193 isEnabled(node: ITreeNode, serviceModelId: string, methodName: string): boolean {
194 if (!_.isNil(this.currentNode) && !_.isNil(this.currentNode.data.menuActions) && !_.isNil(this.currentNode.data.menuActions[methodName])) {
195 return this.currentNode.data.menuActions[methodName]['enable'](this.currentNode, this.serviceModelId);
200 isVisible(node: ITreeNode, methodName: string): boolean {
201 if (!_.isNil(this.currentNode) && !_.isNil(this.currentNode.data.menuActions) && !_.isNil(this.currentNode.data.menuActions[methodName])) {
202 return this.currentNode.data.menuActions[methodName]['visible'](this.currentNode, this.serviceModelId);
209 isUpgraded(node: ITreeNode): boolean {
210 return this.isLabeledAsAction(node, "Upgrade");
213 isDeleted(node: ITreeNode): boolean {
214 return this.isLabeledAsAction(node, "Delete");
217 private isLabeledAsAction(node: ITreeNode, action) {
218 let nodeAction = node.data.action.split('_').pop();
219 if (!_.isNil(nodeAction)) {
220 return nodeAction === action;
225 public selectNode(node: ITreeNode): void {
227 this._sharedTreeService.setSelectedVNF(node);
228 this.highlightNode.emit(node.data.modelUniqueId);
229 if (FeatureFlagsService.getFlagState(Features.FLAG_1906_COMPONENT_INFO, this.store)) {
230 const serviceHierarchy = this._store.getState().service.serviceHierarchy[this.serviceModelId];
231 const model = node.data.getModel(node.data.modelName, node.data, serviceHierarchy);
232 const modelInfoItems = node.data.getInfo(model, node.data);
233 const componentInfoModel: ComponentInfoModel = this._sharedTreeService.addGeneralInfoItems(modelInfoItems, node.data.componentInfoType, model, node.data);
234 ComponentInfoService.triggerComponentInfoChange.next(componentInfoModel);
238 expandParentByNodeId(id: IDType): void {
239 this.tree.treeModel.getNodeById(id).parent.expand();
242 getcontextMenuOptionLabel(contextMenuOption: TreeNodeContextMenuModel): string{
243 let optionLabel = contextMenuOption.label;
244 if(contextMenuOption.label === ServiceInstanceActions.Upgrade) {
245 return optionLabel.concat(" to V" + this._store.getState().service.serviceInstance[this.serviceModelId].latestAvailableVersion);