Fix for Penetration test _ Session and cookie management
[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 import {Subject} from "rxjs";
9
10 @Injectable()
11 export class  DrawingBoardTreeService {
12
13   static triggerCheckIsDirty : Subject<string> = new Subject<string>();
14
15   constructor(private store: NgRedux<AppState>){}
16   isVFModuleMissingData(node: ITreeNode, serviceModelId : string): boolean {
17     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])){
18       if(!_.isNil(this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.parent.data.vnfStoreKey].vfModules)
19         && !_.isNil(this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.parent.data.vnfStoreKey].vfModules[node.data.modelName])
20         && !_.isNil(this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.parent.data.vnfStoreKey].vfModules[node.data.modelName][node.data.dynamicModelName])){
21
22         return this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.parent.data.vnfStoreKey].vfModules[node.data.modelName][node.data.dynamicModelName].isMissingData;
23       }
24     }
25     return false;
26   }
27
28   isVNFMissingData(node : ITreeNode, serviceModelId : string) : boolean {
29     if(node.data.type == 'VF'  && !_.isNil(this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.data.vnfStoreKey])){
30       return  this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.data.vnfStoreKey].isMissingData;
31     }
32   }
33
34   isViewEditFlagTrue():boolean{
35     return FeatureFlagsService.getFlagState(Features.FLAG_1902_NEW_VIEW_EDIT, this.store);
36   }
37
38   isPauseVFMInstantiationCreationFlagTrue() {
39     return FeatureFlagsService.getFlagState(Features.FLAG_2006_PAUSE_VFMODULE_INSTANTIATION_CREATION, this.store);
40   }
41
42   /**********************************************
43    return all drawing board context menu options
44    ***********************************************/
45   generateContextMenuOptions() : TreeNodeContextMenuModel[]{
46     return [
47       new TreeNodeContextMenuModel('edit', 'context-menu-edit', 'Edit', 'edit-file-o'),
48       new TreeNodeContextMenuModel('duplicate', 'context-menu-duplicate', 'Duplicate', 'copy-o'),
49       new TreeNodeContextMenuModel('addGroupMember', 'context-menu-addGroupMember', 'Add group members', 'plus'),
50       new TreeNodeContextMenuModel('delete', 'context-menu-delete', 'Delete', 'trash-o'),
51       new TreeNodeContextMenuModel('remove', 'context-menu-remove', 'Remove', 'trash-o'),
52       new TreeNodeContextMenuModel('upgrade', 'context-menu-upgrade', 'Upgrade', 'upgrade'),
53       new TreeNodeContextMenuModel('undoDelete', 'context-menu-undoDelete', 'Undo Delete', 'undo-delete'),
54       new TreeNodeContextMenuModel('undoUpgrade', 'context-menu-undoUpgrade', 'Undo Upgrade', 'undo-delete'),
55       new TreeNodeContextMenuModel('changeAssociations', 'context-menu-changeAssociations', 'Change Associations', 'edit-file-o'),
56       new TreeNodeContextMenuModel('pauseInstantiation', 'context-menu-pause', 'Add pause upon completion', 'pause-upon-completion'),
57       new TreeNodeContextMenuModel('removePause', 'context-menu-removePause', 'Remove Pause', 'pause-upon-completion')
58     ];
59   }
60
61
62   /*******************************************************************
63     delete or remove all service child's on delete existing service
64    *******************************************************************/
65   deleteActionService(nodes : ITreeNode[], serviceModelId : string){
66     if(!_.isNil(nodes)){
67       for(let node of nodes){
68         node.data = node;
69         if(!_.isNil(node.children)){
70           node.children.map((child)=>{
71             child.data = child;
72             child.parent = node;
73           });
74         }
75
76         let menuActionsName : string = node.data.action === ServiceInstanceActions.Create ? 'remove' : 'delete';
77         if(!_.isNil(node.data.menuActions) && !_.isNil(node.data.menuActions[menuActionsName])){
78           node.data.menuActions[menuActionsName]['method'](node, serviceModelId)
79         }
80
81       }
82     }
83   }
84   /*******************************************************************
85    undo delete all service child's on undo delete existing service
86    *******************************************************************/
87   undoDeleteActionService(nodes : ITreeNode[], serviceModelId : string){
88     if(!_.isNil(nodes)){
89       for(let node of nodes){
90         node.data = node;
91         if(!_.isNil(node.children)){
92           node.children.map((child)=>{
93             child.data = child;
94             child.parent = node;
95           });
96         }
97
98         if(!_.isNil(node.data.menuActions) && !_.isNil(node.data.menuActions['undoDelete'])){
99           node.data.menuActions['undoDelete']['method'](node, serviceModelId)
100         }
101       }
102     }
103   }
104
105   /***********************************************************
106    return true if should add line hover the instance name
107    ***********************************************************/
108   isTextDecoration(node) : boolean{
109     return !_.isNil(node.data) && !_.isNil(node.data.action) && node.data.action.split('_').pop() === 'Delete';
110   }
111
112
113   /******************************************
114    should create object of instances action
115    ******************************************/
116   generateServiceActionObject(nodes){
117     let obj = {};
118     let index = 0;
119     for(let node of nodes){
120       obj[index] = {};
121       index++;
122     }
123   }
124 }
125
126 export class TreeNodeContextMenuModel {
127   methodName: string;
128   dataTestId: string;
129   label: string;
130   iconClass: string;
131
132   constructor(methodName: string,
133               dataTestId: string,
134               label: string,
135               iconClass: string) {
136     this.methodName = methodName;
137     this.dataTestId = dataTestId;
138     this.label = label;
139     this.iconClass = iconClass;
140   }
141 }