aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/models/vrf/vrf.model.info.ts
blob: 4c779a313559fe31e742b2ac41bfcb617cc976eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import {ILevelNodeInfo} from "../basic.model.info";
import {ComponentInfoType} from "../../../component-info/component-info-model";
import {ITreeNode} from "angular-tree-component/dist/defs/api";
import {AvailableNodeIcons} from "../../../available-models-tree/available-models-tree.service";
import {ModelInformationItem} from "../../../../../shared/components/model-information/model-information.component";
import {VrfInstance} from "../../../../../shared/models/vrfInstance";
import {VrfTreeNode} from "../../../../../shared/models/vrfTreeNode";
import {VrfModel} from "../../../../../shared/models/vrfModel";
import {NgRedux} from "@angular-redux/store";
import {AppState} from "../../../../../shared/store/reducers";
import {SharedTreeService} from "../../shared.tree.service";
import {DialogService} from 'ng2-bootstrap-modal';
import {SearchElementsModalComponent} from "../../../../../shared/components/searchMembersModal/search-elements-modal.component";
import {IframeService} from "../../../../../shared/utils/iframe.service";
import {NetworkStepService} from "./vrfModal/networkStep/network.step.service";
import {VpnStepService} from "./vrfModal/vpnStep/vpn.step.service";
import {NetworkModelInfo} from "../network/network.model.info";
import {VpnModelInfo} from "../vpn/vpn.model.info";
import {
  clearAllGenericModalhelper,
  updateGenericModalhelper,
  updateGenericModalTableDataHelper
} from "../../../../../shared/storeUtil/utils/global/global.actions";
import {
  deleteActionVrfInstance,
  undoDeleteActionVrfInstance
} from "../../../../../shared/storeUtil/utils/vrf/vrf.actions";
import * as _ from "lodash";

export class VrfModelInfo implements ILevelNodeInfo {
  constructor(private _store: NgRedux<AppState>,
              private _sharedTreeService: SharedTreeService,
              private _dialogService: DialogService,
              private _iframeService: IframeService,
              private _networkStepService: NetworkStepService,
              private _vpnStepService: VpnStepService) {
  }

  name: string = 'vrfs';
  type: string = 'VRF';
  typeName: string = 'VRF';
  childNames: string [] = ["networks", "vpns"];
  componentInfoType = ComponentInfoType.VRF;

  isEcompGeneratedNaming(currentModel): boolean {
    return false;
  }

  updateDynamicInputsDataFromModel = (currentModel): any => [];

  getModel = (vrfModelId: string, instance: VrfInstance, serviceHierarchy): VrfModel => {
    const originalModelName = instance.originalName ? instance.originalName : vrfModelId;
    return new VrfModel(serviceHierarchy[this.name][originalModelName]);
  };


  createInstanceTreeNode = (instance: VrfInstance, model: VrfModel, parentModel, storeKey: string): VrfTreeNode => {
    let node = new VrfTreeNode(instance, model, storeKey);
    node.missingData = this.hasMissingData(instance, node, model.isEcompGeneratedNaming);
    node.typeName = this.typeName;
    node.menuActions = this.getMenuAction(<any>node, model.uuid);
    node.isFailed = _.isNil(instance.isFailed) ? false : instance.isFailed;
    node.statusMessage = !_.isNil(instance.statusMessage) ? instance.statusMessage : "";
    return node;
  };


  getNextLevelObject = (nextLevelType: string): any => {
    if (nextLevelType === 'vpns') {
      return new VpnModelInfo(this._store, this._sharedTreeService);
    } else {
      if (nextLevelType === 'networks') {
        return new NetworkModelInfo(null, this._sharedTreeService, null, null, null, null, null, this._store);
      }
    }
  };

  getTooltip = (): string => 'VRF';

  getType = (): string => 'VRF';

  hasMissingData(instance, dynamicInputs: any, isEcompGeneratedNaming: boolean): boolean {
    return false;
  }

  onClickAdd(node, serviceModelId: string): void {
    this._store.dispatch(clearAllGenericModalhelper());
    this._store.dispatch(updateGenericModalTableDataHelper('currentVRF', {
      model: this._store.getState().service.serviceHierarchy[serviceModelId].vrfs[node.data.name],
      instance: null
    }));
    this._iframeService.addFullScreen();
    let modalSteps = [this._vpnStepService, this._networkStepService];
    const serviceInstance = this._store.getState().service.serviceInstance[serviceModelId];
    this._dialogService.addDialog(SearchElementsModalComponent, {
        modalInformation: this._networkStepService.getNetworkStep(serviceInstance, serviceModelId, ...modalSteps)
      }
    )
  }

  getNodeCount(node: ITreeNode, serviceModelId: string): number {
    //TODO
    return 0;
  }

  showNodeIcons(node: ITreeNode, serviceModelId: string): AvailableNodeIcons {
    const serviceHierarchy = this._store.getState().service.serviceHierarchy[serviceModelId];

    let counter: number = !_.isNil(this._store.getState().service.serviceInstance[serviceModelId]) ?
      (this._store.getState().service.serviceInstance[serviceModelId].existingVRFCounterMap[node.data.modelUniqueId] || 0) : 0;
    counter -= this._sharedTreeService.getExistingInstancesWithDeleteMode(node, serviceModelId, 'vrfs');
    const model = node.data.getModel(node.data.name, node.data, serviceHierarchy);
    const maxInstances: number = model.max;
    const isReachedLimit = !(maxInstances > counter);
    const showAddIcon = this._sharedTreeService.shouldShowAddIcon() && !isReachedLimit;

    return new AvailableNodeIcons(showAddIcon, isReachedLimit)
  }

  getMenuAction(node: ITreeNode, serviceModelId: string): { [methodName: string]: { method: Function, visible: Function, enable: Function } } {
    return <any>{
      changeAssociations: {
        method: (node, serviceModelId) => {
          let modalSteps = [this._vpnStepService, this._networkStepService];
          this._store.dispatch(clearAllGenericModalhelper());
          const vrfInstance = this._store.getState().service.serviceInstance[serviceModelId].vrfs[node.data.vrfStoreKey];
          const vrfModel = this._store.getState().service.serviceHierarchy[serviceModelId].vrfs[node.data.name];
          this._store.dispatch(updateGenericModalTableDataHelper('currentVRF', {
            model: vrfModel,
            instance: vrfInstance,
            vrfStoreKey: node.data.vrfStoreKey
          }));


          for (let networkKey in vrfInstance.networks) {
            this._store.dispatch(updateGenericModalhelper(`selectedNetwork`, vrfInstance.networks[networkKey], modalSteps[1].uniqObjectField));
          }

          for (let networkKey in vrfInstance.vpns) {
            this._store.dispatch(updateGenericModalhelper(`selectedVPN`, vrfInstance.vpns[networkKey], modalSteps[0].uniqObjectField));
          }

          this._iframeService.addFullScreen();

          const serviceInstance = this._store.getState().service.serviceInstance[serviceModelId];
          this._dialogService.addDialog(SearchElementsModalComponent, {
              modalInformation: this._networkStepService.getNetworkStep(serviceInstance, serviceModelId, ...modalSteps)
            }
          )
        },
        visible: (node) => this._sharedTreeService.shouldShowRemoveAndEdit(node),
        enable: (node) => this._sharedTreeService.shouldShowRemoveAndEdit(node),
      },
      delete: {
        method: (node, serviceModelId) => {
          this._store.dispatch(deleteActionVrfInstance(node.data.vrfStoreKey, serviceModelId));
        },
        visible: (node) => this._sharedTreeService.shouldShowDelete(node),
        enable: (node) => this._sharedTreeService.shouldShowDelete(node)
      },
      undoDelete: {
        method: (node, serviceModelId) => {
          this._store.dispatch(undoDeleteActionVrfInstance(node.data.vrfStoreKey, serviceModelId));
        },
        visible: (node) => this._sharedTreeService.shouldShowUndoDelete(node),
        enable: (node, serviceModelId) => this._sharedTreeService.shouldShowUndoDelete(node) && !this._sharedTreeService.isServiceOnDeleteMode(serviceModelId)
      }
    }
  }

  updatePosition(that, node, instanceId): void {
    //TODO
  }

  getNodePosition(instance): number {
    //TODO
    return 0;
  }

  getInfo(model, instance): ModelInformationItem[] {
    const modelInformation = !_.isEmpty(model) ? [
      ModelInformationItem.createInstance("Min instances", "1"),
      ModelInformationItem.createInstance("Max instances", "1"),
      ModelInformationItem.createInstance("Association", "L3-Network - VPN")] : [];
    return modelInformation;
  }
}