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 /**********************************************
39 return all drawing board context menu options
40 ***********************************************/
41 generateContextMenuOptions() : TreeNodeContextMenuModel[]{
43 new TreeNodeContextMenuModel('edit', 'context-menu-edit', 'Edit', 'edit-file-o'),
44 new TreeNodeContextMenuModel('duplicate', 'context-menu-duplicate', 'Duplicate', 'copy-o'),
45 new TreeNodeContextMenuModel('showAuditInfo', 'context-menu-showAuditInfo', 'Show audit info', 'eye-o'),
46 new TreeNodeContextMenuModel('addGroupMember', 'context-menu-addGroupMember', 'Add group members', 'plus'),
47 new TreeNodeContextMenuModel('delete', 'context-menu-delete', 'Delete', 'trash-o'),
48 new TreeNodeContextMenuModel('remove', 'context-menu-remove', 'Remove', 'trash-o'),
49 new TreeNodeContextMenuModel('upgrade', 'context-menu-upgrade', 'Upgrade', 'upgrade'),
50 new TreeNodeContextMenuModel('undoDelete', 'context-menu-undoDelete', 'Undo Delete', 'undo-delete'),
51 new TreeNodeContextMenuModel('undoUpgrade', 'context-menu-undoUpgrade', 'Undo Upgrade', 'undo-delete'),
52 new TreeNodeContextMenuModel('changeAssociations', 'context-menu-changeAssociations', 'Change Associations', 'edit-file-o')
57 /*******************************************************************
58 delete or remove all service child's on delete existing service
59 *******************************************************************/
60 deleteActionService(nodes : ITreeNode[], serviceModelId : string){
62 for(let node of nodes){
64 if(!_.isNil(node.children)){
65 node.children.map((child)=>{
71 let menuActionsName : string = node.data.action === ServiceInstanceActions.Create ? 'remove' : 'delete';
72 if(!_.isNil(node.data.menuActions) && !_.isNil(node.data.menuActions[menuActionsName])){
73 node.data.menuActions[menuActionsName]['method'](node, serviceModelId)
79 /*******************************************************************
80 undo delete all service child's on undo delete existing service
81 *******************************************************************/
82 undoDeleteActionService(nodes : ITreeNode[], serviceModelId : string){
84 for(let node of nodes){
86 if(!_.isNil(node.children)){
87 node.children.map((child)=>{
93 if(!_.isNil(node.data.menuActions) && !_.isNil(node.data.menuActions['undoDelete'])){
94 node.data.menuActions['undoDelete']['method'](node, serviceModelId)
100 /***********************************************************
101 return true if should add line hover the instance name
102 ***********************************************************/
103 isTextDecoration(node) : boolean{
104 return !_.isNil(node.data) && !_.isNil(node.data.action) && node.data.action.split('_').pop() === 'Delete';
108 /******************************************
109 should create object of instances action
110 ******************************************/
111 generateServiceActionObject(nodes){
114 for(let node of nodes){
121 export class TreeNodeContextMenuModel {
127 constructor(methodName: string,
131 this.methodName = methodName;
132 this.dataTestId = dataTestId;
134 this.iconClass = iconClass;