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