1 import {ILevelNodeInfo} from "../basic.model.info";
2 import {ComponentInfoType} from "../../../component-info/component-info-model";
3 import {ModelInformationItem} from "../../../../../shared/components/model-information/model-information.component";
4 import {ITreeNode} from "angular-tree-component/dist/defs/api";
5 import {AvailableNodeIcons} from "../../../available-models-tree/available-models-tree.service";
6 import {PNFModel} from "../../../../../shared/models/pnfModel";
7 import {SharedTreeService} from "../../shared.tree.service";
8 import * as _ from "lodash";
9 import {FeatureFlagsService} from "../../../../../shared/services/featureFlag/feature-flags.service";
10 import {NgRedux} from "@angular-redux/store";
11 import {AppState} from "../../../../../shared/store/reducers";
13 GenericFormPopupComponent,
15 } from "../../../../../shared/components/genericFormPopup/generic-form-popup.component";
16 import {DialogService} from "ng2-bootstrap-modal";
17 import {PnfPopupService} from "../../../../../shared/components/genericFormPopup/genericFormServices/pnf/pnf.popup.service";
18 import {PnfTreeNode} from "../../../../../shared/models/pnfTreeNode";
19 import {changeInstanceCounter, removeInstance} from "../../../../../shared/storeUtil/utils/general/general.actions";
20 import {MessageBoxData} from "../../../../../shared/components/messageBox/messageBox.data";
21 import {MessageBoxService} from "../../../../../shared/components/messageBox/messageBox.service";
22 import {IframeService} from "../../../../../shared/utils/iframe.service";
23 import {DuplicateService} from "../../../duplicate/duplicate.service";
24 import {ModalService} from "../../../../../shared/components/customModal/services/modal.service";
26 deleteActionPnfInstance,
27 undoDeleteActionPnfInstance,
29 } from "../../../../../shared/storeUtil/utils/pnf/pnf.actions";
30 import {DynamicInputsService} from "../../dynamicInputs.service";
31 import {InputType} from "../../../../../shared/models/inputTypes";
33 export class PnfModelInfoExtended implements ILevelNodeInfo {
36 private _store: NgRedux<AppState>,
37 private _sharedTreeService: SharedTreeService,
38 private _dialogService: DialogService,
39 private _pnfPopupService: PnfPopupService,
40 private _iframeService: IframeService,
41 private _duplicateService: DuplicateService,
42 private modalService: ModalService,
43 private _dynamicInputsService: DynamicInputsService
46 name: string = 'pnfs';
48 typeName: string = 'PNF';
50 componentInfoType = ComponentInfoType.PNF;
52 createInstanceTreeNode = (instance: any, model: any, parentModel: any, storeKey: string, serviceModelId: string): any => {
53 let node = new PnfTreeNode(instance, model, storeKey);
54 node.missingData = this.hasMissingData(instance, node, model.isEcompGeneratedNaming);
55 node.typeName = this.typeName;
56 node.menuActions = this.getMenuAction(<any>node, serviceModelId);
57 node.isFailed = _.isNil(instance.isFailed) ? false : instance.isFailed;
58 node.statusMessage = !_.isNil(instance.statusMessage) ? instance.statusMessage : "";
59 node = this._sharedTreeService.addingStatusProperty(node);
63 getInfo(model, instance): ModelInformationItem[] {
64 const modelInformation = !_.isEmpty(model) ? [
65 ModelInformationItem.createInstance("Min instances", !_.isNil(model.min) ? String(model.min) : null),
66 this._sharedTreeService.createMaximumToInstantiateModelInformationItem(model)
69 const instanceInfo = !_.isEmpty(instance) ? [
70 ModelInformationItem.createInstance("NF type", instance.nfType),
71 ModelInformationItem.createInstance("NF role", instance.nfRole)
74 const result = [modelInformation, instanceInfo];
75 return _.uniq(_.flatten(result));
78 getMenuAction(node: ITreeNode, serviceModelId: string): { [methodName: string]: { method: Function, visible: Function, enable: Function } } {
81 method: (node, serviceModelId) => {
82 this._iframeService.addClassOpenModal('content');
83 this._dialogService.addDialog(GenericFormPopupComponent, {
86 serviceId: serviceModelId,
87 modelName: node.data.modelName,
88 pnfStoreKey: node.data.pnfStoreKey,
89 modelId: node.data.modelId,
91 popupService: this._pnfPopupService
97 visible: (node) => this._sharedTreeService.shouldShowRemoveAndEdit(node),
98 enable: (node) => this._sharedTreeService.shouldShowRemoveAndEdit(node),
101 method: (node, serviceModelId) => {
102 const instance = this._store.getState().service.serviceInstance[serviceModelId].pnfs[node.data.pnfStoreKey];
103 this._sharedTreeService.openAuditInfoModal(node, serviceModelId, instance, 'PNF', this);
105 visible: (node) => this._sharedTreeService.shouldShowAuditInfo(node),
106 enable: (node) => this._sharedTreeService.shouldShowAuditInfo(node)
109 method: (node, serviceModelId) => {
110 if ((!_.isNil(node.data.children) && node.data.children.length === 0) || _.isNil(node.data.children)) {
111 let storeKey: string = node.data.pnfStoreKey;
112 this._store.dispatch(removeInstance(node.data.pnfStoreKey, serviceModelId, storeKey, node));
113 this._store.dispatch(changeInstanceCounter(node.data.modelUniqueId, serviceModelId, -1, node));
114 this._sharedTreeService.selectedNF = null;
116 let messageBoxData: MessageBoxData = new MessageBoxData(
117 "Remove PNF", // modal title
118 "You are about to remove this PNF from this service. Are you sure you want to remove it?",
125 callback: this.removePnf.bind(this, node, serviceModelId),
128 {text: "Don’t Remove", size: "medium", closeModal: true}
131 MessageBoxService.openModal.next(messageBoxData);
134 visible: (node) => this._sharedTreeService.shouldShowRemoveAndEdit(node),
135 enable: (node) => this._sharedTreeService.shouldShowRemoveAndEdit(node),
138 method: (node, serviceModelId) => {
139 if ((!_.isNil(node.data.children) && node.data.children.length === 0) || _.isNil(node.data.children)) {
140 this._store.dispatch(deleteActionPnfInstance(node.data.pnfStoreKey, serviceModelId));
142 this._sharedTreeService.shouldShowDeleteInstanceWithChildrenModal(node, serviceModelId, (node, serviceModelId) => {
143 this._sharedTreeService.removeDeleteAllChild(node, serviceModelId, (node, serviceModelId) => {
144 this._store.dispatch(deleteActionPnfInstance(node.data.pnfStoreKey, serviceModelId));
149 visible: (node) => this._sharedTreeService.shouldShowDelete(node, serviceModelId),
150 enable: (node) => this._sharedTreeService.shouldShowDelete(node, serviceModelId)
153 method: (node, serviceModelId) => {
154 if ((!_.isNil(node.data.children) && node.data.children.length === 0) || _.isNil(node.data.children)) {
155 this._store.dispatch(undoDeleteActionPnfInstance(node.data.pnfStoreKey, serviceModelId));
157 this._sharedTreeService.undoDeleteAllChild(node, serviceModelId, (node, serviceModelId) => {
158 this._store.dispatch(undoDeleteActionPnfInstance(node.data.pnfStoreKey, serviceModelId));
162 visible: (node) => this._sharedTreeService.shouldShowUndoDelete(node),
163 enable: (node, serviceModelId) => this._sharedTreeService.shouldShowUndoDelete(node) && !this._sharedTreeService.isServiceOnDeleteMode(serviceModelId)
168 removePnf(this, node, serviceModelId) {
169 this._store.dispatch(removeInstance(node.data.modelName, serviceModelId, node.data.pnfStoreKey, node));
170 this._store.dispatch(changeInstanceCounter(node.data.modelUniqueId, serviceModelId, -1, node));
171 this._sharedTreeService.selectedNF = null;
174 getModel = (instanceModel: any): PNFModel => {
175 return new PNFModel(instanceModel);
178 getNextLevelObject(): any {
182 getNodeCount(node: ITreeNode, serviceModelId: string): number {
184 if (!_.isNil(this._store.getState().service.serviceInstance[serviceModelId])) {
185 map = this._store.getState().service.serviceInstance[serviceModelId].existingPNFCounterMap || 0;
188 let count = map[node.data.modelUniqueId] || 0;
189 count -= this._sharedTreeService.getExistingInstancesWithDeleteMode(node, serviceModelId, 'pnfs');
196 getNodePosition(instance): number {
197 return !_.isNil(instance) ? instance.position : null;
200 getTooltip = (): string => 'PNF';
202 getType = (): string => 'PNF';
204 hasMissingData(instance, dynamicInputs: any, isEcompGeneratedNaming: boolean): boolean {
205 return this._sharedTreeService.hasMissingData(instance, dynamicInputs, isEcompGeneratedNaming, [InputType.PLATFORM]);
208 /***********************************************************
209 * return if user should provide instance name or not.
210 * @param currentModel - current Model object
211 ************************************************************/
212 isEcompGeneratedNaming = (currentModel): boolean => {
213 const ecompGeneratedNaming = currentModel.properties.ecomp_generated_naming;
214 return ecompGeneratedNaming === "true";
217 onClickAdd(node, serviceModelId: string): void {
218 this._dialogService.addDialog(GenericFormPopupComponent, {
221 serviceId: serviceModelId,
222 modelName: node.data.name,
224 modelId: node.data.modelVersionId,
225 type: node.data.type,
226 popupService: this._pnfPopupService
233 showNodeIcons(node: ITreeNode, serviceModelId: string): AvailableNodeIcons {
234 let counter: number = !_.isNil(this._store.getState().service.serviceInstance[serviceModelId]) ?
235 (this._store.getState().service.serviceInstance[serviceModelId].existingPNFCounterMap[node.data.modelUniqueId] || 0) : 0;
236 counter -= this._sharedTreeService.getExistingInstancesWithDeleteMode(node, serviceModelId, 'pnfs');
238 const properties = this._store.getState().service.serviceHierarchy[serviceModelId].pnfs[node.data.name].properties;
239 const flags = FeatureFlagsService.getAllFlags(this._store);
240 const isReachedLimit: boolean = this._sharedTreeService.isReachedToMaxInstances(properties, counter, flags);
241 const showAddIcon = this._sharedTreeService.shouldShowAddIcon() && !isReachedLimit;
242 return new AvailableNodeIcons(showAddIcon, isReachedLimit)
245 updateDynamicInputsDataFromModel = (currentModel): any => {
246 let displayInputs = _.isNil(currentModel) ? [] : currentModel.inputs;
247 return _.isEmpty(displayInputs) ? [] : this._dynamicInputsService.getArbitraryInputs(displayInputs);
250 updatePosition(that, node, instanceId): void {
251 that.store.dispatch(updatePnfPosition(node, instanceId, node.vnfStoreKey));