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";
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])){
18 return this.store.getState().service.serviceInstance[serviceModelId].vnfs[node.parent.data.vnfStoreKey].vfModules[node.data.modelName][node.data.dynamicModelName].isMissingData;
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;
30 isViewEditFlagTrue():boolean{
31 return FeatureFlagsService.getFlagState(Features.FLAG_1902_NEW_VIEW_EDIT, this.store);
34 /**********************************************
35 return all drawing board context menu options
36 ***********************************************/
37 generateContextMenuOptions() : TreeNodeContextMenuModel[]{
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')
53 /*******************************************************************
54 delete or remove all service child's on delete existing service
55 *******************************************************************/
56 deleteActionService(nodes : ITreeNode[], serviceModelId : string){
58 for(let node of nodes){
60 if(!_.isNil(node.children)){
61 node.children.map((child)=>{
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)
75 /*******************************************************************
76 undo delete all service child's on undo delete existing service
77 *******************************************************************/
78 undoDeleteActionService(nodes : ITreeNode[], serviceModelId : string){
80 for(let node of nodes){
82 if(!_.isNil(node.children)){
83 node.children.map((child)=>{
89 if(!_.isNil(node.data.menuActions) && !_.isNil(node.data.menuActions['undoDelete'])){
90 node.data.menuActions['undoDelete']['method'](node, serviceModelId)
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';
104 /******************************************
105 should create object of instances action
106 ******************************************/
107 generateServiceActionObject(nodes){
110 for(let node of nodes){
117 export class TreeNodeContextMenuModel {
123 constructor(methodName: string,
127 this.methodName = methodName;
128 this.dataTestId = dataTestId;
130 this.iconClass = iconClass;