diff options
author | 2019-07-07 19:23:03 +0300 | |
---|---|---|
committer | 2019-07-08 16:13:43 +0300 | |
commit | f792671ae247a931f34d902e9276202b5016ef9a (patch) | |
tree | 6104971e8074c9a3d720836276ff18619719ec02 /vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/models/vrf/vrfModal/vpnStep/vpn.step.service.ts | |
parent | fc62274e8d15964d63c62bf0e2f4abc040252ee9 (diff) |
Merge from ecomp 718fd196 - Modern UI
Issue-ID: VID-378
Change-Id: I2736b98426e324ec3aa233b034229ba84d99839f
Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/models/vrf/vrfModal/vpnStep/vpn.step.service.ts')
-rw-r--r-- | vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/models/vrf/vrfModal/vpnStep/vpn.step.service.ts | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/models/vrf/vrfModal/vpnStep/vpn.step.service.ts b/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/models/vrf/vrfModal/vpnStep/vpn.step.service.ts new file mode 100644 index 000000000..5523cf1ff --- /dev/null +++ b/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/models/vrf/vrfModal/vpnStep/vpn.step.service.ts @@ -0,0 +1,195 @@ +import {Injectable} from "@angular/core"; +import {NgRedux} from "@angular-redux/store"; +import {AppState} from "../../../../../../../shared/store/reducers"; +import {AaiService} from "../../../../../../../shared/services/aaiService/aai.service"; +import { + ISearchField, + ITableContent, + ModalInformation +} from "../../../../../../../shared/components/searchMembersModal/members-table/element-table-row.model"; +import {ElementsTableService} from "../../../../../../../shared/components/searchMembersModal/members-table/elements-table.service"; +import { + clearAllGenericModalhelper, + updateGenericModalhelper +} from "../../../../../../../shared/storeUtil/utils/global/global.actions"; +import {Observable} from "rxjs"; +import {CustomTableColumnDefinition} from "../../../../../../../shared/components/searchMembersModal/members-table/elements-table.component"; +import {VPNModalRow} from "./vpn.step.model"; +import {NetworkStepService} from "../networkStep/network.step.service"; +import * as _ from "lodash"; +import { + associateVRFMember, + clearAssociateVRFMemberInstance, + createVrfInstance +} from "../../../../../../../shared/storeUtil/utils/vrf/vrf.actions"; +import {calculateNextUniqueModelName} from "../../../../../../../shared/storeUtil/utils/vnf/vnf.reducers"; + +@Injectable() +export class VpnStepService { + constructor(private _store: NgRedux<AppState>, private _aaiService: AaiService, private _networkStepService: NetworkStepService) { + } + + uniqObjectField: string = "instanceId"; + type: string = "VPN"; + + getVpnStep = (serviceInstance, serviceModelId, ...otherSteps): ModalInformation => { + return { + type: this.type, + serviceModelId: serviceModelId, + title: 'Associate VPN', + description: 'Select a VPN to associate to the VRF Entry', + noElementsMsg: 'No VPN instances were found.', + maxSelectRow: 1, + uniqObjectField: this.uniqObjectField, + backAction: (searchElementsModalComponent) => { + ElementsTableService.changeModalInformationDataTrigger.next({ + modalInformation: otherSteps[1].getNetworkStep(serviceInstance, searchElementsModalComponent.modalInformation.serviceModelId, ...otherSteps), + selectedRowsIds: [this._store.getState().global.genericModalHelper.selectedNetwork.instanceUUID] + }); + }, + topButton: { + text: 'SET VPN', + action: (searchElementsModalComponent) => { + let currentVRF = this._store.getState().global.genericModalHelper['currentVRF']; + const vrfStoreKey: string = _.isNil(currentVRF['vrfStoreKey']) + ? calculateNextUniqueModelName(currentVRF['model']['name'], searchElementsModalComponent.modalInformation.serviceModelId, this._store.getState().service, 'vrfs') + : currentVRF['vrfStoreKey']; + + + if (_.isNil(currentVRF['vrfStoreKey'])) { + this._store.dispatch(createVrfInstance(currentVRF['model'], serviceModelId, vrfStoreKey)); + } else { + this._store.dispatch(clearAssociateVRFMemberInstance(vrfStoreKey, serviceModelId, 'networks')); + this._store.dispatch(clearAssociateVRFMemberInstance(vrfStoreKey, serviceModelId, 'vpns')); + } + + this.associateVrfVPNMember(searchElementsModalComponent, vrfStoreKey); + this.associateVrfNetworkMember(searchElementsModalComponent, vrfStoreKey); + + this._store.dispatch(clearAllGenericModalhelper()); + searchElementsModalComponent.closeDialog(); + } + }, + getElements: () => this.getVPNs(), + criteria: [], + searchFields: this.getsVPNStepSearchFields(), + tableHeaders: this.getVPNStepHeaders(), + tableContent: this.getVPNTableContent() + }; + }; + + getVPNs = (): Observable<any[]> => { + return this._aaiService.retrieveActiveVPNs().map((vpns: VPNModalRow[]) => { + return this.sortElementsResultByField(vpns, "instanceName"); + }); + }; + + sortElementsResultByField = (elements, fieldName): any[] => { + return _.sortBy(elements, o => o[fieldName]); + }; + + associateVrfVPNMember = (searchElementsModalComponent, vrfStoreKey): void => { + let tmpMembers = searchElementsModalComponent._membersTableService.allElementsStatusMap; + for (let key in tmpMembers) { + if (tmpMembers[key].isSelected) { + this._store.dispatch(updateGenericModalhelper(`selected${this.type}`, tmpMembers[key], this.uniqObjectField)); + this._store.dispatch(associateVRFMember(vrfStoreKey, searchElementsModalComponent.modalInformation.serviceModelId, tmpMembers[key], 'vpns')); + } + } + }; + + associateVrfNetworkMember = (searchElementsModalComponent, vrfStoreKey): void => { + let selectedNetworks = this._store.getState().global.genericModalHelper['selectedNetwork']; + for (let key in selectedNetworks) { + this._store.dispatch(associateVRFMember(vrfStoreKey, searchElementsModalComponent.modalInformation.serviceModelId, selectedNetworks[key], 'networks')); + } + }; + + getsVPNStepSearchFields = (): ISearchField[] => { + return [ + { + title: 'Type ', + dataTestId: 'Type', + value: "SERVICE-INFRASTRUCTURE", + type: "LABEL" + } + ] + }; + + getVPNStepHeaders = (): CustomTableColumnDefinition[] => { + return [ + {displayName: `VPN instance name`, key: ['instanceName']}, + {displayName: `Version`, key: ['modelInfo', 'modelVersionId']}, + {displayName: `Instance ID`, key: ['instanceId']}, + {displayName: `Platform`, key: ['platformName']}, + {displayName: 'Region', key: ['region']}, + {displayName: 'Route target', key: ['routeTargets', 'globalRouteTarget'], type: 'LIST'}, + {displayName: 'Route target role', key: ['routeTargets', 'routeTargetRole'], type: 'LIST'}, + {displayName: 'Customer VPN ID', key: ['customerId']}, + ]; + }; + + getVPNTableContent = (): ITableContent[] => { + return [ + { + id: 'vpn-name', + contents: [{ + id: ['vpn-name'], + value: ['instanceName'] + }] + }, + { + id: 'model-version-id', + contents: [{ + id: ['model-version-id'], + value: ['modelInfo', 'modelVersionId'] + }] + }, + { + id: 'vpn-id', + contents: [{ + id: ['vpn-id'], + value: ['instanceId'] + }] + }, + { + id: 'vpn-platform', + contents: [{ + id: ['vpn-platform'], + value: ['platformName'] + }] + }, + { + id: 'vpn-region', + contents: [{ + id: ['vpn-region'], + value: ['region'] + }] + }, + { + id: 'global-route-target', + contents: [{ + id: ['global-route-target'], + value: ['routeTargets', 'globalRouteTarget'], + type: 'LIST' + }] + }, + { + id: 'route-target-role', + contents: [{ + id: ['route-target-role'], + value: ['routeTargets', 'routeTargetRole'], + type: 'LIST' + }] + }, + { + id: 'customer-vpn-id', + contents: [{ + id: ['customer-vpn-id'], + value: ['customerId'] + }] + } + ]; + }; + +} |