Merge changes Ib4430bf2,Icc0bdb9e,I2736b984
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / drawing-board-tree / drawing-board-tree.service.ts
1 import {Injectable} from "@angular/core";
2 import {ITreeNode} from "angular-tree-component/dist/defs/api";
3 import * as _ from 'lodash';
4 import {NgRedux} from "@angular-redux/store";
5 import {AppState} from "../../../shared/store/reducers";
6 import {FeatureFlagsService, Features} from "../../../shared/services/featureFlag/feature-flags.service";
7 import {ServiceInstanceActions} from "../../../shared/models/serviceInstanceActions";
8
9 @Injectable()
10 export class  DrawingBoardTreeService {
11   constructor(private store: NgRedux<AppState>){}
12   isVFModuleMissingData(node: ITreeNode, serviceModelId : string): boolean {
13     if(node.data.type === 'VFmodule' &&!_.isNil(this.store.getState().service.serviceInstance[serviceModelId].vnfs) &&  !_.isNil(this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.parent.data.vnfStoreKey])){
14       if(!_.isNil(this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.parent.data.vnfStoreKey].vfModules)
15         && !_.isNil(this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.parent.data.vnfStoreKey].vfModules[node.data.modelName])
16         && !_.isNil(this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.parent.data.vnfStoreKey].vfModules[node.data.modelName][node.data.dynamicModelName])){
17
18         return this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.parent.data.vnfStoreKey].vfModules[node.data.modelName][node.data.dynamicModelName].isMissingData;
19       }
20     }
21     return false;
22   }
23
24   isVNFMissingData(node : ITreeNode, serviceModelId : string) : boolean {
25     if(node.data.type == 'VF'  && !_.isNil(this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.data.vnfStoreKey])){
26       return  this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.data.vnfStoreKey].isMissingData;
27     }
28   }
29
30   isViewEditFlagTrue():boolean{
31     return FeatureFlagsService.getFlagState(Features.FLAG_1902_NEW_VIEW_EDIT, this.store);
32   }
33
34   /**********************************************
35    return all drawing board context menu options
36    ***********************************************/
37   generateContextMenuOptions() : TreeNodeContextMenuModel[]{
38     return [
39       new TreeNodeContextMenuModel('edit', 'context-menu-edit', 'Edit', 'edit-file-o'),
40       new TreeNodeContextMenuModel('duplicate', 'context-menu-duplicate', 'Duplicate', 'copy-o'),
41       new TreeNodeContextMenuModel('showAuditInfo', 'context-menu-showAuditInfo', 'Show audit info', 'eye-o'),
42       new TreeNodeContextMenuModel('addGroupMember', 'context-menu-addGroupMember', 'Add group members', 'plus'),
43       new TreeNodeContextMenuModel('delete', 'context-menu-delete', 'Delete', 'trash-o'),
44       new TreeNodeContextMenuModel('remove', 'context-menu-remove', 'Remove', 'trash-o'),
45       new TreeNodeContextMenuModel('undoDelete', 'context-menu-undoDelete', 'Undo Delete', 'undo-delete'),
46       new TreeNodeContextMenuModel('changeAssociations', 'context-menu-changeAssociations', 'Change Associations', 'edit-file-o')
47     ];
48   }
49
50
51   /*******************************************************************
52     delete or remove all service child's on delete existing service
53    *******************************************************************/
54   deleteActionService(nodes : ITreeNode[], serviceModelId : string){
55     if(!_.isNil(nodes)){
56       for(let node of nodes){
57         node.data = node;
58         if(!_.isNil(node.children)){
59           node.children.map((child)=>{
60             child.data = child;
61             child.parent = node;
62           });
63         }
64
65         let menuActionsName : string = node.data.action === ServiceInstanceActions.Create ? 'remove' : 'delete';
66         if(!_.isNil(node.data.menuActions) && !_.isNil(node.data.menuActions[menuActionsName])){
67           node.data.menuActions[menuActionsName]['method'](node, serviceModelId)
68         }
69
70       }
71     }
72   }
73   /*******************************************************************
74    undo delete all service child's on undo delete existing service
75    *******************************************************************/
76   undoDeleteActionService(nodes : ITreeNode[], serviceModelId : string){
77     if(!_.isNil(nodes)){
78       for(let node of nodes){
79         node.data = node;
80         if(!_.isNil(node.children)){
81           node.children.map((child)=>{
82             child.data = child;
83             child.parent = node;
84           });
85         }
86
87         if(!_.isNil(node.data.menuActions) && !_.isNil(node.data.menuActions['undoDelete'])){
88           node.data.menuActions['undoDelete']['method'](node, serviceModelId)
89         }
90       }
91     }
92   }
93
94   /***********************************************************
95    return true if should add line hover the instance name
96    ***********************************************************/
97   isTextDecoration(node) : boolean{
98     return !_.isNil(node.data) && !_.isNil(node.data.action) && node.data.action.split('_').pop() === 'Delete';
99   }
100
101
102   /******************************************
103    should create object of instances action
104    ******************************************/
105   generateServiceActionObject(nodes){
106     let obj = {};
107     let index = 0;
108     for(let node of nodes){
109       obj[index] = {};
110       index++;
111     }
112   }
113 }
114
115 export class TreeNodeContextMenuModel {
116   methodName: string;
117   dataTestId: string;
118   label: string;
119   iconClass: string;
120
121   constructor(methodName: string,
122               dataTestId: string,
123               label: string,
124               iconClass: string) {
125     this.methodName = methodName;
126     this.dataTestId = dataTestId;
127     this.label = label;
128     this.iconClass = iconClass;
129   }
130 }