summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/view-models
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2022-10-27 12:47:28 +0100
committerMichael Morris <michael.morris@est.tech>2022-11-30 13:26:41 +0000
commit0d708e3bb2502abe50e1ed4069b43536b538ceef (patch)
treea36c57ddeb12207af60c6c5cfc5311246ca4c126 /catalog-ui/src/app/view-models
parent15f3f0bb8e0cec965a9714e3681fbdee4b19b3c4 (diff)
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 <jeff.van.dam@est.tech>
Diffstat (limited to 'catalog-ui/src/app/view-models')
-rw-r--r--catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view-model.ts40
-rw-r--r--catalog-ui/src/app/view-models/forms/property-forms/component-property-form/property-form-view.html3
2 files changed, 37 insertions, 6 deletions
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 @@
<div class="constraints-section i-sdc-form-item" data-ng-if="editPropertyModel.property.constraints || !(isViewOnly || componentMetadata.isService)">
<label class="i-sdc-form-label">Constraints</label>
<ng-container>
- <app-constraints [property]="editPropertyModel.property"
+ <app-constraints [property-constraints]="editPropertyModel.property.constraints"
[is-view-only]="isViewOnly || componentMetadata.isService"
+ [property-type]="editPropertyModel.property.type"
(on-constraint-change)="onConstraintChange($event)">
</app-constraints>
</ng-container>