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";
11 export class DrawingBoardTreeService {
13 static triggerCheckIsDirty : Subject<string> = new Subject<string>();
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])){
22 return this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.parent.data.vnfStoreKey].vfModules[node.data.modelName][node.data.dynamicModelName].isMissingData;
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;
34 isViewEditFlagTrue():boolean{
35 return FeatureFlagsService.getFlagState(Features.FLAG_1902_NEW_VIEW_EDIT, this.store);
38 isPauseVFMInstantiationCreationFlagTrue() {
39 return FeatureFlagsService.getFlagState(Features.FLAG_2006_PAUSE_VFMODULE_INSTANTIATION_CREATION, this.store);
42 /**********************************************
43 return all drawing board context menu options
44 ***********************************************/
45 generateContextMenuOptions() : TreeNodeContextMenuModel[]{
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')
63 /*******************************************************************
64 delete or remove all service child's on delete existing service
65 *******************************************************************/
66 deleteActionService(nodes : ITreeNode[], serviceModelId : string){
68 for(let node of nodes){
70 if(!_.isNil(node.children)){
71 node.children.map((child)=>{
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)
85 /*******************************************************************
86 undo delete all service child's on undo delete existing service
87 *******************************************************************/
88 undoDeleteActionService(nodes : ITreeNode[], serviceModelId : string){
90 for(let node of nodes){
92 if(!_.isNil(node.children)){
93 node.children.map((child)=>{
99 if(!_.isNil(node.data.menuActions) && !_.isNil(node.data.menuActions['undoDelete'])){
100 node.data.menuActions['undoDelete']['method'](node, serviceModelId)
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';
114 /******************************************
115 should create object of instances action
116 ******************************************/
117 generateServiceActionObject(nodes){
120 for(let node of nodes){
127 export class TreeNodeContextMenuModel {
133 constructor(methodName: string,
137 this.methodName = methodName;
138 this.dataTestId = dataTestId;
140 this.iconClass = iconClass;