28b6e51b1d3d49736261180f5409f09fb7cf9879
[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('upgrade', 'context-menu-upgrade', 'Upgrade', 'upgrade'),
46       new TreeNodeContextMenuModel('undoDelete', 'context-menu-undoDelete', 'Undo Delete', 'undo-delete'),
47       new TreeNodeContextMenuModel('undoUpgrade', 'context-menu-undoUpgrade', 'Undo Upgrade', 'undo-delete'),
48       new TreeNodeContextMenuModel('changeAssociations', 'context-menu-changeAssociations', 'Change Associations', 'edit-file-o')
49     ];
50   }
51
52
53   /*******************************************************************
54     delete or remove all service child's on delete existing service
55    *******************************************************************/
56   deleteActionService(nodes : ITreeNode[], serviceModelId : string){
57     if(!_.isNil(nodes)){
58       for(let node of nodes){
59         node.data = node;
60         if(!_.isNil(node.children)){
61           node.children.map((child)=>{
62             child.data = child;
63             child.parent = node;
64           });
65         }
66
67         let menuActionsName : string = node.data.action === ServiceInstanceActions.Create ? 'remove' : 'delete';
68         if(!_.isNil(node.data.menuActions) && !_.isNil(node.data.menuActions[menuActionsName])){
69           node.data.menuActions[menuActionsName]['method'](node, serviceModelId)
70         }
71
72       }
73     }
74   }
75   /*******************************************************************
76    undo delete all service child's on undo delete existing service
77    *******************************************************************/
78   undoDeleteActionService(nodes : ITreeNode[], serviceModelId : string){
79     if(!_.isNil(nodes)){
80       for(let node of nodes){
81         node.data = node;
82         if(!_.isNil(node.children)){
83           node.children.map((child)=>{
84             child.data = child;
85             child.parent = node;
86           });
87         }
88
89         if(!_.isNil(node.data.menuActions) && !_.isNil(node.data.menuActions['undoDelete'])){
90           node.data.menuActions['undoDelete']['method'](node, serviceModelId)
91         }
92       }
93     }
94   }
95
96   /***********************************************************
97    return true if should add line hover the instance name
98    ***********************************************************/
99   isTextDecoration(node) : boolean{
100     return !_.isNil(node.data) && !_.isNil(node.data.action) && node.data.action.split('_').pop() === 'Delete';
101   }
102
103
104   /******************************************
105    should create object of instances action
106    ******************************************/
107   generateServiceActionObject(nodes){
108     let obj = {};
109     let index = 0;
110     for(let node of nodes){
111       obj[index] = {};
112       index++;
113     }
114   }
115 }
116
117 export class TreeNodeContextMenuModel {
118   methodName: string;
119   dataTestId: string;
120   label: string;
121   iconClass: string;
122
123   constructor(methodName: string,
124               dataTestId: string,
125               label: string,
126               iconClass: string) {
127     this.methodName = methodName;
128     this.dataTestId = dataTestId;
129     this.label = label;
130     this.iconClass = iconClass;
131   }
132 }