From e2a7abb45b953d405fc5aa1917f74e2da9f188c0 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Tue, 18 Feb 2020 16:58:16 +0200 Subject: VNF's LCP regions found by Line-of-business (and owning-entity) Depends on FLAG_2006_LCP_REGIONS_BY_LINE_OF_BUSINESS Issue-ID: VID-758 Change-Id: I7b5a67202a72fc6ea4afe0a5c1c60657c93bf690 Signed-off-by: Alexey Sandler Signed-off-by: Ittay Stern --- .../sharedControlles/shared.controllers.service.ts | 135 ++++++++++++++++++--- .../vnfGenerator/vnf.control.generator.spec.ts | 10 +- .../vnfGenerator/vnf.control.generator.ts | 34 ++++-- 3 files changed, 151 insertions(+), 28 deletions(-) (limited to 'vid-webpack-master/src/app/shared/components') diff --git a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/sharedControlles/shared.controllers.service.ts b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/sharedControlles/shared.controllers.service.ts index 83f722704..4b567328d 100644 --- a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/sharedControlles/shared.controllers.service.ts +++ b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/sharedControlles/shared.controllers.service.ts @@ -16,6 +16,8 @@ import {Constants} from "../../../../utils/constants"; import {CheckboxFormControl} from "../../../../models/formControlModels/checkboxFormControl.model"; import {InputFormControl} from "../../../../models/formControlModels/inputFormControl.model"; import {NodeModel} from "../../../../models/nodeModel"; +import {LcpRegion} from "../../../../models/lcpRegion"; +import {Tenant} from "../../../../models/tenant"; @Injectable() export class SharedControllersService { @@ -25,6 +27,26 @@ export class SharedControllersService { getLineOfBusinessControl = (instance?: any): DropdownFormControl => { + return this.getLineOfBusinessControlInternal(undefined, instance); + }; + + getLineOfBusinessByOwningEntityControl = (instance?: any, serviceId?: string, controls?: FormControlModel[]): DropdownFormControl => { + const service = this._store.getState().service.serviceInstance[serviceId]; + const owningEntityName: string = service.owningEntityName; + + const changeLcpRegionOptionsOnChange = (lineOfBusinessNameParam: string, form: FormGroup) => { + form.controls['lcpCloudRegionId'].enable(); + form.controls['lcpCloudRegionId'].reset(); + this._basicControlGenerator.getSubscribeInitResult( + this._aaiService.getLcpRegionsByOwningEntityAndLineOfBusiness.bind(this, owningEntityName, lineOfBusinessNameParam), + controls.find(item => item.controlName === 'lcpCloudRegionId') as DropdownFormControl, form + ).subscribe() + }; + + return this.getLineOfBusinessControlInternal(changeLcpRegionOptionsOnChange, instance); + }; + + private getLineOfBusinessControlInternal = (onChange: Function, instance?: any): DropdownFormControl => { return new DropdownFormControl({ type: FormControlType.DROPDOWN, controlName: 'lineOfBusiness', @@ -36,6 +58,7 @@ export class SharedControllersService { value: instance ? instance.lineOfBusiness : null, validations: [new ValidatorModel(ValidatorOptions.required, 'is required')], onInitSelectedField: ['lineOfBusinessList'], + onChange, onInit: this._basicControlGenerator.getSubscribeInitResult.bind(null, this._aaiService.getCategoryParameters) }) }; @@ -44,6 +67,20 @@ export class SharedControllersService { const service = this._store.getState().service.serviceInstance[serviceId]; const globalCustomerId: string = service.globalSubscriberId; const serviceType: string = service.subscriptionServiceType; + + const onInit = instance + ? this._basicControlGenerator.getSubscribeInitResult.bind( + this._aaiService, + this._aaiService.getLcpRegionsAndTenants.bind(this, globalCustomerId, serviceType)) + : () => {}; + return this.getTenantControlInternal(onInit, instance); + }; + + getTenantByLcpRegionControl = (serviceId: string, instance?: any): DropdownFormControl => { + return this.getTenantControlInternal(() => {}, instance); + }; + + private getTenantControlInternal = (onInit: Function, instance?: any): DropdownFormControl => { return new DropdownFormControl({ type: FormControlType.DROPDOWN, controlName: 'tenantId', @@ -55,10 +92,7 @@ export class SharedControllersService { onInitSelectedField: instance ? ['lcpRegionsTenantsMap', instance.lcpCloudRegionId] : null, value: instance ? instance.tenantId : null, validations: [new ValidatorModel(ValidatorOptions.required, 'is required')], - onInit: instance ? this._basicControlGenerator.getSubscribeInitResult.bind( - this._aaiService, - this._aaiService.getLcpRegionsAndTenants.bind(this, globalCustomerId, serviceType)) : () => { - } + onInit, }) }; @@ -93,6 +127,70 @@ export class SharedControllersService { const service = this._store.getState().service.serviceInstance[serviceId]; const globalCustomerId: string = service.globalSubscriberId; const serviceType: string = service.subscriptionServiceType; + + const onInit = this._basicControlGenerator.getSubscribeInitResult.bind( + this._aaiService, + this._aaiService.getLcpRegionsAndTenants.bind(this, globalCustomerId, serviceType) + ); + + const changeTenantsOptionsByServiceTypeOnChange = ( + (globalCustomerId, serviceType, lcpCloudRegionIdParam) => { + if (!_.isNil(globalCustomerId) && !_.isNil(serviceType)) { + this._basicControlGenerator.getSubscribeResult.bind(this, + this._aaiService.getLcpRegionsAndTenants(globalCustomerId, serviceType) + .subscribe(res => this.setTenantsOptions(controls, res.lcpRegionsTenantsMap[lcpCloudRegionIdParam]))); + } + + } + ).bind(this, globalCustomerId, serviceType); + + return this.getLcpRegionControlInternal(instance, controls, + false, onInit, ['lcpRegionList'], changeTenantsOptionsByServiceTypeOnChange) + }; + + getLcpRegionByLineOfBusinessControl = (serviceId: string, instance: any, controls: FormControlModel[]): DropdownFormControl => { + const service = this._store.getState().service.serviceInstance[serviceId]; + const owningEntityName: string = service.owningEntityName; + + const changeTenantsOptions = (controls: FormControlModel[], cloudRegionId, lcpRegionList: LcpRegion[]) => { + const lcpRegionOption = (_.isNil(lcpRegionList) || _.isNil(cloudRegionId)) + ? null : lcpRegionList.find(({id}) => id === cloudRegionId); + + if (!_.isNil(lcpRegionOption)) { + this._aaiService.getTenantsByCloudOwnerAndCloudRegionId(lcpRegionOption.cloudOwner, lcpRegionOption.id) + .subscribe(res => this.setTenantsOptions(controls, res)); + } + }; + + const lcpRegionOptionsList = (controls: FormControlModel[]): LcpRegion[] => { + const lcpCloudRegionIdControl = _.isNil(controls) + ? null : controls.find(({controlName}) => controlName === 'lcpCloudRegionId'); + + return _.isNil(lcpCloudRegionIdControl) ? null : lcpCloudRegionIdControl['options$']; + }; + + const loadLcpRegionOptionsOnInit = (_.isNil(instance) || _.isNil(instance.lineOfBusiness)) + ? () => {} + : this._basicControlGenerator.getSubscribeInitResult.bind( + this, () => { + return this._aaiService.getLcpRegionsByOwningEntityAndLineOfBusiness(owningEntityName, instance.lineOfBusiness) + .do(res => changeTenantsOptions(controls, instance.lcpCloudRegionId, res)); + } + ); + + const changeTenantsOptionsByCloudRegionIdOnChange = ( + (controls, lcpCloudRegionIdParam) => changeTenantsOptions(controls, lcpCloudRegionIdParam, lcpRegionOptionsList(controls)) + ).bind(this, controls); + + return this.getLcpRegionControlInternal(instance, controls, + _.isNil(instance) || _.isNil(instance.lineOfBusiness), + loadLcpRegionOptionsOnInit, null, changeTenantsOptionsByCloudRegionIdOnChange + ) + }; + + private getLcpRegionControlInternal = (instance: any, controls: FormControlModel[], isDisabled: boolean, + onInit: Function, onInitSelectedField: string[], changeTenantsOptionsOnChange: Function + ): DropdownFormControl => { return new DropdownFormControl({ type: FormControlType.DROPDOWN, controlName: 'lcpCloudRegionId', @@ -100,26 +198,19 @@ export class SharedControllersService { dataTestId: 'lcpRegion', placeHolder: 'Select LCP Region', name: "lcpRegion", - isDisabled: false, + isDisabled, value: instance ? instance.lcpCloudRegionId : null, validations: [new ValidatorModel(ValidatorOptions.required, 'is required')], - onInitSelectedField: ['lcpRegionList'], - onInit: this._basicControlGenerator.getSubscribeInitResult.bind( - this._aaiService, - this._aaiService.getLcpRegionsAndTenants.bind(this, globalCustomerId, serviceType)), - onChange: (param: string, form: FormGroup) => { + onInitSelectedField, + onInit, + + onChange: (lcpCloudRegionIdParam: string, form: FormGroup) => { form.controls['tenantId'].enable(); form.controls['tenantId'].reset(); - if (!_.isNil(globalCustomerId) && !_.isNil(serviceType)) { - this._basicControlGenerator.getSubscribeResult.bind(this, this._aaiService.getLcpRegionsAndTenants(globalCustomerId, serviceType).subscribe(res => { - controls.find(item => item.controlName === 'tenantId')['options$'] = res.lcpRegionsTenantsMap[param]; - if (res.lcpRegionsTenantsMap[param]) { - controls.find(item => item.controlName === 'tenantId')['hasEmptyOptions'] = res.lcpRegionsTenantsMap[param].length === 0; - } - })); - } - if (Constants.LegacyRegion.MEGA_REGION.indexOf(param) !== -1) { + changeTenantsOptionsOnChange(lcpCloudRegionIdParam); + + if (Constants.LegacyRegion.MEGA_REGION.indexOf(lcpCloudRegionIdParam) !== -1) { form.controls['legacyRegion'].enable(); controls.find(item => item.controlName === 'legacyRegion').isVisible = true; @@ -133,6 +224,12 @@ export class SharedControllersService { }) }; + private setTenantsOptions = (controls: FormControlModel[], tenants: Tenant[]) => { + const tenantsControl = controls.find(item => item.controlName === 'tenantId'); + tenantsControl['options$'] = tenants; + tenantsControl['hasEmptyOptions'] = tenants && tenants.length === 0; + }; + getSDNCControl = (instance: any, extraContents? : object[]): FormControlModel => { return new CheckboxFormControl({ controlName: SDN_C_PRE_LOAD, diff --git a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vnfGenerator/vnf.control.generator.spec.ts b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vnfGenerator/vnf.control.generator.spec.ts index 4572fa443..c7d623671 100644 --- a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vnfGenerator/vnf.control.generator.spec.ts +++ b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vnfGenerator/vnf.control.generator.spec.ts @@ -6,7 +6,11 @@ import {ControlGeneratorUtil} from "../control.generator.util.service"; import {AaiService} from "../../../../services/aaiService/aai.service"; import {GenericFormService} from "../../generic-form.service"; import {FormBuilder} from "@angular/forms"; -import {FormControlModel, ValidatorModel, ValidatorOptions} from "../../../../models/formControlModels/formControl.model"; +import { + FormControlModel, + ValidatorModel, + ValidatorOptions +} from "../../../../models/formControlModels/formControl.model"; import {LogService} from "../../../../utils/log/log.service"; import {VnfControlGenerator} from "./vnf.control.generator"; import {FeatureFlagsService} from "../../../../services/featureFlag/feature-flags.service"; @@ -904,7 +908,9 @@ class MockAppStore { } } -class MockFeatureFlagsService {} +class MockFeatureFlagsService { + getFlagState = () => false; +} describe('VNF Control Generator', () => { let injector; diff --git a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vnfGenerator/vnf.control.generator.ts b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vnfGenerator/vnf.control.generator.ts index 169780b29..ef58bc761 100644 --- a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vnfGenerator/vnf.control.generator.ts +++ b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vnfGenerator/vnf.control.generator.ts @@ -4,7 +4,11 @@ import {AaiService} from "../../../../services/aaiService/aai.service"; import {NgRedux} from "@angular-redux/store"; import {HttpClient} from "@angular/common/http"; import {ControlGeneratorUtil} from "../control.generator.util.service"; -import {FormControlModel, ValidatorModel, ValidatorOptions} from "../../../../models/formControlModels/formControl.model"; +import { + FormControlModel, + ValidatorModel, + ValidatorOptions +} from "../../../../models/formControlModels/formControl.model"; import {LogService} from "../../../../utils/log/log.service"; import {VNFModel} from "../../../../models/vnfModel"; import {AppState} from "../../../../store/reducers"; @@ -14,6 +18,7 @@ import * as _ from 'lodash'; import {MultiselectFormControl} from "../../../../models/formControlModels/multiselectFormControl.model"; import {MultiSelectItem} from "../../../formControls/component/multiselect/multiselect.model"; import {SharedControllersService} from "../sharedControlles/shared.controllers.service"; +import {FeatureFlagsService, Features} from "../../../../services/featureFlag/feature-flags.service"; @Injectable() export class VnfControlGenerator { @@ -21,6 +26,7 @@ export class VnfControlGenerator { constructor(private genericFormService: GenericFormService, private _basicControlGenerator: ControlGeneratorUtil, private _sharedControllersService : SharedControllersService, + private _featureFlagsService: FeatureFlagsService, private store: NgRedux, private http: HttpClient, private _aaiService: AaiService, @@ -72,14 +78,28 @@ export class VnfControlGenerator { const vnfModel = new VNFModel(this.store.getState().service.serviceHierarchy[serviceId].vnfs[vnfName]); if (!_.isNil(vnfModel)) { - const flags = this.store.getState().global.flags; + const isMultiSelected = + this._featureFlagsService.getFlagState(Features.FLAG_2002_VNF_PLATFORM_MULTI_SELECT); + const lcpRegionsByLineOFBusiness = + this._featureFlagsService.getFlagState(Features.FLAG_2006_LCP_REGIONS_BY_LINE_OF_BUSINESS); + result.push(this.getInstanceName(vnfInstance, serviceId, vnfName, vnfModel.isEcompGeneratedNaming)); result.push(this._sharedControllersService.getProductFamilyControl(vnfInstance, result, true)); - result.push(this._sharedControllersService.getLcpRegionControl(serviceId, vnfInstance, result)); - result.push(this._sharedControllersService.getLegacyRegion(vnfInstance)); - result.push(this._sharedControllersService.getTenantControl(serviceId, vnfInstance)); - result.push(this.getPlatformMultiselectControl(vnfInstance, result, flags['FLAG_2002_VNF_PLATFORM_MULTI_SELECT'])); - result.push(this._sharedControllersService.getLineOfBusinessControl(vnfInstance)); + + if (lcpRegionsByLineOFBusiness) { + result.push(this._sharedControllersService.getLineOfBusinessByOwningEntityControl(vnfInstance, serviceId, result)); + result.push(this._sharedControllersService.getLcpRegionByLineOfBusinessControl(serviceId, vnfInstance, result)); + result.push(this._sharedControllersService.getLegacyRegion(vnfInstance)); + result.push(this._sharedControllersService.getTenantByLcpRegionControl(serviceId, vnfInstance)); + result.push(this.getPlatformMultiselectControl(vnfInstance, result, isMultiSelected)); + } else { + result.push(this._sharedControllersService.getLcpRegionControl(serviceId, vnfInstance, result)); + result.push(this._sharedControllersService.getLegacyRegion(vnfInstance)); + result.push(this._sharedControllersService.getTenantControl(serviceId, vnfInstance)); + result.push(this.getPlatformMultiselectControl(vnfInstance, result, isMultiSelected)); + result.push(this._sharedControllersService.getLineOfBusinessControl(vnfInstance)); + } + result.push(this._sharedControllersService.getRollbackOnFailureControl(vnfInstance)); } return result; -- cgit 1.2.3-korg