1 import {ILevelNodeInfo} from "../basic.model.info";
2 import {ComponentInfoType} from "../../../component-info/component-info-model";
3 import {ITreeNode} from "angular-tree-component/dist/defs/api";
4 import {AvailableNodeIcons} from "../../../available-models-tree/available-models-tree.service";
5 import {ModelInformationItem} from "../../../../../shared/components/model-information/model-information.component";
6 import {VrfInstance} from "../../../../../shared/models/vrfInstance";
7 import {VrfTreeNode} from "../../../../../shared/models/vrfTreeNode";
8 import {VrfModel} from "../../../../../shared/models/vrfModel";
9 import {NgRedux} from "@angular-redux/store";
10 import {AppState} from "../../../../../shared/store/reducers";
11 import {SharedTreeService} from "../../shared.tree.service";
12 import {DialogService} from 'ng2-bootstrap-modal';
13 import {SearchElementsModalComponent} from "../../../../../shared/components/searchMembersModal/search-elements-modal.component";
14 import {IframeService} from "../../../../../shared/utils/iframe.service";
15 import {NetworkStepService} from "./vrfModal/networkStep/network.step.service";
16 import {VpnStepService} from "./vrfModal/vpnStep/vpn.step.service";
17 import {NetworkModelInfo} from "../network/network.model.info";
18 import {VpnModelInfo} from "../vpn/vpn.model.info";
20 clearAllGenericModalhelper,
21 updateGenericModalhelper,
22 updateGenericModalTableDataHelper
23 } from "../../../../../shared/storeUtil/utils/global/global.actions";
25 deleteActionVrfInstance,
26 undoDeleteActionVrfInstance
27 } from "../../../../../shared/storeUtil/utils/vrf/vrf.actions";
28 import * as _ from "lodash";
30 export class VrfModelInfo implements ILevelNodeInfo {
31 constructor(private _store: NgRedux<AppState>,
32 private _sharedTreeService: SharedTreeService,
33 private _dialogService: DialogService,
34 private _iframeService: IframeService,
35 private _networkStepService: NetworkStepService,
36 private _vpnStepService: VpnStepService) {
39 name: string = 'vrfs';
41 typeName: string = 'VRF';
42 childNames: string [] = ["networks", "vpns"];
43 componentInfoType = ComponentInfoType.VRF;
45 isEcompGeneratedNaming(currentModel): boolean {
49 updateDynamicInputsDataFromModel = (currentModel): any => [];
51 getModel = (vrfModelId: string, instance: VrfInstance, serviceHierarchy): VrfModel => {
52 const originalModelName = instance.originalName ? instance.originalName : vrfModelId;
53 return new VrfModel(serviceHierarchy[this.name][originalModelName]);
57 createInstanceTreeNode = (instance: VrfInstance, model: VrfModel, parentModel, storeKey: string): VrfTreeNode => {
58 let node = new VrfTreeNode(instance, model, storeKey);
59 node.missingData = this.hasMissingData(instance, node, model.isEcompGeneratedNaming);
60 node.typeName = this.typeName;
61 node.menuActions = this.getMenuAction(<any>node, model.uuid);
62 node.isFailed = _.isNil(instance.isFailed) ? false : instance.isFailed;
63 node.statusMessage = !_.isNil(instance.statusMessage) ? instance.statusMessage : "";
68 getNextLevelObject = (nextLevelType: string): any => {
69 if (nextLevelType === 'vpns') {
70 return new VpnModelInfo(this._store, this._sharedTreeService);
72 if (nextLevelType === 'networks') {
73 return new NetworkModelInfo(null, this._sharedTreeService, null, null, null, null, null, this._store);
78 getTooltip = (): string => 'VRF';
80 getType = (): string => 'VRF';
82 hasMissingData(instance, dynamicInputs: any, isEcompGeneratedNaming: boolean): boolean {
86 onClickAdd(node, serviceModelId: string): void {
87 this._store.dispatch(clearAllGenericModalhelper());
88 this._store.dispatch(updateGenericModalTableDataHelper('currentVRF', {
89 model: this._store.getState().service.serviceHierarchy[serviceModelId].vrfs[node.data.name],
92 this._iframeService.addFullScreen();
93 let modalSteps = [this._vpnStepService, this._networkStepService];
94 const serviceInstance = this._store.getState().service.serviceInstance[serviceModelId];
95 this._dialogService.addDialog(SearchElementsModalComponent, {
96 modalInformation: this._networkStepService.getNetworkStep(serviceInstance, serviceModelId, ...modalSteps)
101 getNodeCount(node: ITreeNode, serviceModelId: string): number {
106 showNodeIcons(node: ITreeNode, serviceModelId: string): AvailableNodeIcons {
107 const serviceHierarchy = this._store.getState().service.serviceHierarchy[serviceModelId];
109 let counter: number = !_.isNil(this._store.getState().service.serviceInstance[serviceModelId]) ?
110 (this._store.getState().service.serviceInstance[serviceModelId].existingVRFCounterMap[node.data.modelUniqueId] || 0) : 0;
111 counter -= this._sharedTreeService.getExistingInstancesWithDeleteMode(node, serviceModelId, 'vrfs');
112 const model = node.data.getModel(node.data.name, node.data, serviceHierarchy);
113 const maxInstances: number = model.max;
114 const isReachedLimit = !(maxInstances > counter);
115 const showAddIcon = this._sharedTreeService.shouldShowAddIcon() && !isReachedLimit;
117 return new AvailableNodeIcons(showAddIcon, isReachedLimit)
120 getMenuAction(node: ITreeNode, serviceModelId: string): { [methodName: string]: { method: Function, visible: Function, enable: Function } } {
122 changeAssociations: {
123 method: (node, serviceModelId) => {
124 let modalSteps = [this._vpnStepService, this._networkStepService];
125 this._store.dispatch(clearAllGenericModalhelper());
126 const vrfInstance = this._store.getState().service.serviceInstance[serviceModelId].vrfs[node.data.vrfStoreKey];
127 const vrfModel = this._store.getState().service.serviceHierarchy[serviceModelId].vrfs[node.data.name];
128 this._store.dispatch(updateGenericModalTableDataHelper('currentVRF', {
130 instance: vrfInstance,
131 vrfStoreKey: node.data.vrfStoreKey
135 for (let networkKey in vrfInstance.networks) {
136 this._store.dispatch(updateGenericModalhelper(`selectedNetwork`, vrfInstance.networks[networkKey], modalSteps[1].uniqObjectField));
139 for (let networkKey in vrfInstance.vpns) {
140 this._store.dispatch(updateGenericModalhelper(`selectedVPN`, vrfInstance.vpns[networkKey], modalSteps[0].uniqObjectField));
143 this._iframeService.addFullScreen();
145 const serviceInstance = this._store.getState().service.serviceInstance[serviceModelId];
146 this._dialogService.addDialog(SearchElementsModalComponent, {
147 modalInformation: this._networkStepService.getNetworkStep(serviceInstance, serviceModelId, ...modalSteps)
151 visible: (node) => this._sharedTreeService.shouldShowRemoveAndEdit(node),
152 enable: (node) => this._sharedTreeService.shouldShowRemoveAndEdit(node),
155 method: (node, serviceModelId) => {
156 this._store.dispatch(deleteActionVrfInstance(node.data.vrfStoreKey, serviceModelId));
158 visible: (node) => this._sharedTreeService.shouldShowDelete(node),
159 enable: (node) => this._sharedTreeService.shouldShowDelete(node)
162 method: (node, serviceModelId) => {
163 this._store.dispatch(undoDeleteActionVrfInstance(node.data.vrfStoreKey, serviceModelId));
165 visible: (node) => this._sharedTreeService.shouldShowUndoDelete(node),
166 enable: (node, serviceModelId) => this._sharedTreeService.shouldShowUndoDelete(node) && !this._sharedTreeService.isServiceOnDeleteMode(serviceModelId)
171 updatePosition(that, node, instanceId): void {
175 getNodePosition(instance): number {
180 getInfo(model, instance): ModelInformationItem[] {
181 const modelInformation = !_.isEmpty(model) ? [
182 ModelInformationItem.createInstance("Min instances", "1"),
183 ModelInformationItem.createInstance("Max instances", "1"),
184 ModelInformationItem.createInstance("Association", "L3-Network - VPN")] : [];
185 return modelInformation;