From 6896c1b309aaa50dca820169b9f1ae3f8af84294 Mon Sep 17 00:00:00 2001 From: siddharth0905 Date: Wed, 10 Apr 2019 17:49:51 +0530 Subject: Apply Valid Value Constraints validation Apply Valid Value Constraints validation for FE and BE in Property Assignment, Input, Service Consumption screen Change-Id: I01c7523bad702f003cd52fd88bc69fe950b2b4f3 Issue-ID: SDC-2224 Signed-off-by: siddharth0905 --- .../dynamic-element/dynamic-element.component.ts | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'catalog-ui/src/app/ng2/components/ui') diff --git a/catalog-ui/src/app/ng2/components/ui/dynamic-element/dynamic-element.component.ts b/catalog-ui/src/app/ng2/components/ui/dynamic-element/dynamic-element.component.ts index 4f283fb3f1..049d40831a 100644 --- a/catalog-ui/src/app/ng2/components/ui/dynamic-element/dynamic-element.component.ts +++ b/catalog-ui/src/app/ng2/components/ui/dynamic-element/dynamic-element.component.ts @@ -22,7 +22,7 @@ import * as _ from "lodash"; import { Component, Compiler, EventEmitter, ViewContainerRef, ViewChild, Input, Output, ElementRef, ComponentRef, ComponentFactoryResolver } from '@angular/core' -import {ValidationConfiguration} from "app/models"; +import {ValidationConfiguration, PropertyFEModel} from "app/models"; import {IUiElementChangeEvent} from "../form-components/ui-element-base.component"; import {UiElementInputComponent} from "../form-components/input/ui-element-input.component"; import {UiElementPopoverInputComponent} from "../form-components/popover-input/ui-element-popover-input.component"; @@ -36,6 +36,7 @@ enum DynamicElementComponentCreatorIdentifier { FLOAT, BOOLEAN, SUBNETPOOLID, + ENUM, DEFAULT } @@ -58,6 +59,7 @@ export class DynamicElementComponent { @Input() name: string; @Input() testId: string; @Input() readonly:boolean; + @Input() constraints: Array; @Input() path:string;//optional param. used only for for subnetpoolid type @Input() value: any; @@ -86,6 +88,9 @@ export class DynamicElementComponent { case this.path && this.path.toUpperCase().indexOf("SUBNETPOOLID") !== -1: this.elementCreatorIdentifier = DynamicElementComponentCreatorIdentifier.SUBNETPOOLID; break; + case this.getValidValues() !== undefined && this.getValidValues() !== null: + this.elementCreatorIdentifier = DynamicElementComponentCreatorIdentifier.ENUM; + break; case this.type === 'integer': this.elementCreatorIdentifier = DynamicElementComponentCreatorIdentifier.INTEGER; break; @@ -153,6 +158,19 @@ export class DynamicElementComponent { this.createComponent(UiElementPopoverInputComponent); break; + case DynamicElementComponentCreatorIdentifier.ENUM: + this.createComponent(UiElementDropDownComponent); + let validVals:Array = [...this.getValidValues()].map(val => new DropdownValue(val, val)); + if (this.type === 'float' || this.type === 'integer') { + this.value = this.value && Number(this.value); + validVals = _.map( + validVals, + val => new DropdownValue(Number(val.value), val.value) + ); + } + this.cmpRef.instance.values = validVals; + break; + case DynamicElementComponentCreatorIdentifier.INTEGER: this.createComponent(UiElementIntegerInputComponent); this.cmpRef.instance.pattern = this.validation.validationPatterns.integer; @@ -195,6 +213,14 @@ export class DynamicElementComponent { this.cmpRef.instance.valueChange.subscribe((event) => { this.valueChange.emit(event); }); } + getValidValues(): Array { + let validVals; + _.forEach(this.constraints, constraint => { + validVals = validVals || constraint.validValues; + }); + return validVals; + } + createComponent(ComponentToCreate:any):void { let factory = this.componentFactoryResolver.resolveComponentFactory(ComponentToCreate); this.cmpRef = this.target.createComponent(factory); -- cgit 1.2.3-korg