From 0d708e3bb2502abe50e1ed4069b43536b538ceef Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Thu, 27 Oct 2022 12:47:28 +0100 Subject: Support addition of scalar type constraints this also supports the addition of the in_range and the valid_values constraints, and supports delete and editing of current and added constraints Issue-ID: SDC-4223 Change-Id: I5ffb4d17d9f8c2730f650153fb4ff89eccfdd474 Signed-off-by: JvD_Ericsson --- .../property-form-view-model.ts | 40 +++++++++++++++++++--- .../property-form-view.html | 3 +- 2 files changed, 37 insertions(+), 6 deletions(-) (limited to 'catalog-ui/src/app/view-models') diff --git a/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view-model.ts b/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view-model.ts index 614f1583cb..eda5efcd49 100644 --- a/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view-model.ts +++ b/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view-model.ts @@ -69,6 +69,7 @@ interface IPropertyFormViewModelScope extends ng.IScope { constraints:string[]; modelNameFilter:string; isGetFunctionValueType: boolean; + invalidMandatoryFields: boolean; validateJson(json:string):boolean; save(doNotCloseModal?:boolean):void; @@ -404,17 +405,21 @@ export class PropertyFormViewModel { this.$scope.$watch("forms.editForm.$invalid", (newVal) => { if (this.$scope.editPropertyModel.hasGetFunctionValue) { - this.$scope.footerButtons[0].disabled = newVal || !this.$scope.editPropertyModel.property.toscaFunction || this.isViewOnly; + this.$scope.invalidMandatoryFields = !newVal || !this.$scope.editPropertyModel.property.toscaFunction || this.isViewOnly; + this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields; } else { - this.$scope.footerButtons[0].disabled = newVal || this.isViewOnly; + this.$scope.invalidMandatoryFields = !newVal || this.isViewOnly; + this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields; } }); this.$scope.$watch("forms.editForm.$valid", (newVal) => { if (this.$scope.editPropertyModel.hasGetFunctionValue) { - this.$scope.footerButtons[0].disabled = !newVal || !this.$scope.editPropertyModel.property.toscaFunction || this.isViewOnly; + this.$scope.invalidMandatoryFields = !newVal || !this.$scope.editPropertyModel.property.toscaFunction || this.isViewOnly; + this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields; } else { - this.$scope.footerButtons[0].disabled = !newVal || this.isViewOnly; + this.$scope.invalidMandatoryFields = !newVal || this.isViewOnly; + this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields; } }); @@ -460,6 +465,21 @@ export class PropertyFormViewModel { } } + this.$scope.onConstraintChange = (constraints: any): void => { + if (!this.$scope.invalidMandatoryFields) { + this.$scope.footerButtons[0].disabled = !constraints.valid; + } else { + this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields; + } + if (!constraints.constraints || constraints.constraints.length == 0) { + this.$scope.editPropertyModel.property.propertyConstraints = null; + this.$scope.editPropertyModel.property.constraints = null; + return; + } + this.$scope.editPropertyModel.property.propertyConstraints = this.serializePropertyConstraints(constraints.constraints); + this.$scope.editPropertyModel.property.constraints = constraints.constraints; + } + this.$scope.onGetFunctionValidFunction = (toscaGetFunction: ToscaGetFunction): void => { this.$scope.editPropertyModel.property.toscaFunction = toscaGetFunction; } @@ -471,9 +491,19 @@ export class PropertyFormViewModel { } this.$scope.editPropertyModel.isGetFunctionValid = undefined; } - }; + private serializePropertyConstraints(constraints: any[]): string[] { + if (constraints) { + let stringConstrsints = new Array(); + constraints.forEach((constraint) => { + stringConstrsints.push(JSON.stringify(constraint)); + }) + return stringConstrsints; + } + return null; + } + private setEmptyValue() { const property1 = this.$scope.editPropertyModel.property; property1.value = undefined; diff --git a/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view.html b/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view.html index 35e3932586..2f67474d4f 100644 --- a/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view.html +++ b/catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view.html @@ -264,8 +264,9 @@
- -- cgit 1.2.3-korg