diff options
author | 2023-01-31 14:24:02 +0000 | |
---|---|---|
committer | 2023-02-08 22:19:53 +0000 | |
commit | c6cb16f234b8ae9de4aede3ca09a57e6ca177abe (patch) | |
tree | f14c9a73bb1f78a928b6a9d6ffe9cee289be947e /catalog-ui/src/app/ng2/pages/type-workspace/type-workspace-properties/type-workspace-properties.component.ts | |
parent | 442784e34ef8cae76cca559a600f360dfdeee97e (diff) |
Constraints in data type view
Develop all necessary changes in the UI to allow managing data type constraints
Issue-ID: SDC-4331
Signed-off-by: franciscovila <javier.paradela.vila@est.tech>
Change-Id: I337438ba088e4f2f4978a1aff2408eda8157b892
Diffstat (limited to 'catalog-ui/src/app/ng2/pages/type-workspace/type-workspace-properties/type-workspace-properties.component.ts')
-rw-r--r-- | catalog-ui/src/app/ng2/pages/type-workspace/type-workspace-properties/type-workspace-properties.component.ts | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/catalog-ui/src/app/ng2/pages/type-workspace/type-workspace-properties/type-workspace-properties.component.ts b/catalog-ui/src/app/ng2/pages/type-workspace/type-workspace-properties/type-workspace-properties.component.ts index bcc5fe9c28..83651fc73c 100644 --- a/catalog-ui/src/app/ng2/pages/type-workspace/type-workspace-properties/type-workspace-properties.component.ts +++ b/catalog-ui/src/app/ng2/pages/type-workspace/type-workspace-properties/type-workspace-properties.component.ts @@ -32,6 +32,7 @@ import {TranslateService} from "../../../shared/translator/translate.service"; import {AddPropertyComponent, PropertyValidationEvent} from "./add-property/add-property.component"; import {IWorkspaceViewModelScope} from "../../../../view-models/workspace/workspace-view-model"; import {SdcUiServices} from "onap-ui-angular/dist"; +import {ToscaTypeHelper} from "../../../../utils/tosca-type-helper"; @Component({ selector: 'app-type-workspace-properties', @@ -192,14 +193,47 @@ export class TypeWorkspacePropertiesComponent implements OnInit { this.properties = properties.map(value => { const property = new PropertyBEModel(value); if (property.defaultValue) { - property.defaultValue = JSON.parse(property.defaultValue); + if (!this.isTypeSimple(property.type) && typeof property.defaultValue === 'string') { + property.defaultValue = JSON.parse(property.defaultValue); + } else { + property.defaultValue = property.defaultValue; + } } - return property; }); this.filteredProperties = Array.from(this.properties); this.sort(); } + + public isTypeSimple(value:any): boolean { + return ToscaTypeHelper.isTypeSimple(value); + } + + 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; + } + + private serializePropertyConstraints(constraints: any[]): string[] { + if (constraints) { + let stringConstraints = new Array(); + constraints.forEach((constraint) => { + stringConstraints.push(JSON.stringify(constraint)); + }) + return stringConstraints; + } + return null; + } } interface TableHeader { |