From 2f74a4ac81f228bdb0bf0f509e9c0ef296d28d82 Mon Sep 17 00:00:00 2001 From: aribeiro Date: Tue, 17 Nov 2020 10:52:41 +0000 Subject: Fix import VFC with attributes Fix import VFC with default attribute value Fix Update, create and delete attribute action Make attribute definition tosca compliant Issue-ID: SDC-3381 Signed-off-by: aribeiro Change-Id: Ibbd36b105b8c86d1e750f3b6d55752d63fe6530e --- catalog-ui/src/app/models/attributes.ts | 30 ++++++++++------------ .../attributes/attribute-modal.component.html | 24 +++++------------ .../attributes/attribute-modal.component.ts | 16 +++++------- .../attributes/attributes-modal.component.spec.ts | 20 ++++----------- .../workspace/attributes/attributes.component.html | 4 +-- 5 files changed, 33 insertions(+), 61 deletions(-) (limited to 'catalog-ui/src/app') diff --git a/catalog-ui/src/app/models/attributes.ts b/catalog-ui/src/app/models/attributes.ts index 80af540ef3..a51358cdc4 100644 --- a/catalog-ui/src/app/models/attributes.ts +++ b/catalog-ui/src/app/models/attributes.ts @@ -41,13 +41,12 @@ export interface IAttributeModel { //server data uniqueId:string; name:string; - defaultValue:string; + _default:string; description:string; type:string; schema:SchemaAttributeGroupModel; status:string; value:string; - hidden:boolean; parentUniqueId:string; //custom data resourceInstanceUniqueId:string; @@ -60,13 +59,12 @@ export class AttributeModel implements IAttributeModel { //server data uniqueId:string; name:string; - defaultValue:string; + _default:string; description:string; type:string; schema:SchemaAttributeGroupModel; status:string; value:string; - hidden:boolean; parentUniqueId:string; //custom data resourceInstanceUniqueId:string; @@ -77,20 +75,18 @@ export class AttributeModel implements IAttributeModel { if (attribute) { this.uniqueId = attribute.uniqueId; this.name = attribute.name; - this.defaultValue = attribute.defaultValue; + this._default = attribute._default; this.description = attribute.description; this.type = attribute.type; this.status = attribute.status; this.schema = attribute.schema; this.value = attribute.value; - this.hidden = attribute.hidden; this.parentUniqueId = attribute.parentUniqueId; this.resourceInstanceUniqueId = attribute.resourceInstanceUniqueId; this.readonly = attribute.readonly; this.valueUniqueUid = attribute.valueUniqueUid; } else { - this.defaultValue = ''; - this.hidden = false; + this._default = ''; } if (!this.schema || !this.schema.property) { @@ -104,13 +100,13 @@ export class AttributeModel implements IAttributeModel { } public convertToServerObject():string { - if (this.defaultValue && this.type === 'map') { - this.defaultValue = '{' + this.defaultValue + '}'; + if (this._default && this.type === 'map') { + this._default = '{' + this._default + '}'; } - if (this.defaultValue && this.type === 'list') { - this.defaultValue = '[' + this.defaultValue + ']'; + if (this._default && this.type === 'list') { + this._default = '[' + this._default + ']'; } - this.defaultValue = this.defaultValue != "" && this.defaultValue != "[]" && this.defaultValue != "{}" ? this.defaultValue : null; + this._default = this._default != "" && this._default != "[]" && this._default != "{}" ? this._default : null; return JSON.stringify(this); }; @@ -118,10 +114,10 @@ export class AttributeModel implements IAttributeModel { public convertValueToView() { //unwrapping value {} or [] if type is complex - if (this.defaultValue && (this.type === 'map' || this.type === 'list') && - ['[', '{'].indexOf(this.defaultValue.charAt(0)) > -1 && - [']', '}'].indexOf(this.defaultValue.slice(-1)) > -1) { - this.defaultValue = this.defaultValue.slice(1, -1); + if (this._default && (this.type === 'map' || this.type === 'list') && + ['[', '{'].indexOf(this._default.charAt(0)) > -1 && + [']', '}'].indexOf(this._default.slice(-1)) > -1) { + this._default = this._default.slice(1, -1); } //also for value - for the modal in canvas diff --git a/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.html b/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.html index bd30a469e0..094045e8b4 100644 --- a/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.html +++ b/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.html @@ -48,19 +48,19 @@
- - + @@ -71,7 +71,7 @@
@@ -88,17 +88,7 @@
- - - -
- \ No newline at end of file + diff --git a/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.ts b/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.ts index c703869ad2..b0a7651809 100644 --- a/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.ts +++ b/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.ts @@ -15,7 +15,7 @@ import { AttributeOptions } from './attributes-options'; }) export class AttributeModalComponent implements OnInit { - @ViewChild('defaultValue') validatedInput: InputComponent; + @ViewChild('_default') validatedInput: InputComponent; public readonly types = AttributeOptions.types; // integer, string, boolean etc. @@ -44,13 +44,9 @@ export class AttributeModalComponent implements OnInit { this.revalidateDefaultValue(); } - onHiddenCheckboxClicked(event: boolean) { - this.attributeToEdit.hidden = event; - } - onTypeSelected(selectedElement: IDropDownOption) { if (this.attributeToEdit.type !== selectedElement.value && selectedElement.value === 'boolean') { - this.attributeToEdit.defaultValue = ''; // Clean old value in case we choose change type to boolean + this.attributeToEdit._default = ''; // Clean old value in case we choose change type to boolean } this.attributeToEdit.type = selectedElement.value; this.revalidateDefaultValue(); @@ -58,7 +54,7 @@ export class AttributeModalComponent implements OnInit { onBooleanDefaultValueSelected(selectedElement: IDropDownOption) { if (this.attributeToEdit.type === 'boolean') { - this.attributeToEdit.defaultValue = selectedElement.value; + this.attributeToEdit._default = selectedElement.value; } } @@ -92,8 +88,8 @@ export class AttributeModalComponent implements OnInit { } public isMapUnique = () => { - if (this.attributeToEdit && this.attributeToEdit.type === 'map' && this.attributeToEdit.defaultValue) { - return ValidationUtils.validateUniqueKeys(this.attributeToEdit.defaultValue); + if (this.attributeToEdit && this.attributeToEdit.type === 'map' && this.attributeToEdit._default) { + return ValidationUtils.validateUniqueKeys(this.attributeToEdit._default); } return true; } @@ -102,7 +98,7 @@ export class AttributeModalComponent implements OnInit { this.setDefaultValuePattern(this.attributeToEdit.type); setTimeout(() => { if (this.validatedInput) { - this.validatedInput.onKeyPress(this.attributeToEdit.defaultValue); + this.validatedInput.onKeyPress(this.attributeToEdit._default); } }, 250); } diff --git a/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes-modal.component.spec.ts b/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes-modal.component.spec.ts index 99aa140dd1..2eed2311bb 100644 --- a/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes-modal.component.spec.ts +++ b/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes-modal.component.spec.ts @@ -56,28 +56,18 @@ describe('attributes modal component', () => { }) ); - it('test that when hidden is clicked, hidden attribute is set', async () => { - fixture.componentInstance.attributeToEdit = new AttributeModel(); - const hidden = fixture.componentInstance.attributeToEdit.hidden; - fixture.componentInstance.ngOnInit(); - - expect(hidden).toBe(false); - fixture.componentInstance.onHiddenCheckboxClicked(true); - expect(fixture.componentInstance.attributeToEdit.hidden).toBe(true); - }); - it('test that when type is set to boolean default value is cleared', async () => { const component = fixture.componentInstance; component.attributeToEdit = new AttributeModel(); component.ngOnInit(); component.onTypeSelected({ value : 'string', label : 'string'}); - component.attributeToEdit.defaultValue = 'some_value'; + component.attributeToEdit._default = 'some_value'; component.onTypeSelected({ value : 'boolean', label : 'boolean'}); - expect(component.attributeToEdit.defaultValue).toBe(''); + expect(component.attributeToEdit._default).toBe(''); component.onBooleanDefaultValueSelected({ value : 'true', label : 'true'}); - expect(component.attributeToEdit.defaultValue).toBe('true'); + expect(component.attributeToEdit._default).toBe('true'); }); it('test that when certain type is selected, the correct regex pattern is chosen', async () => { @@ -120,9 +110,9 @@ describe('attributes modal component', () => { expect(component.isMapUnique()).toBe(true); // map is not selected so return true by default component.onTypeSelected({ value : 'map', label : 'map'}); component.onEntrySchemaTypeSelected({ value : 'boolean', label : 'boolean' }); - component.attributeToEdit.defaultValue = '"1":true,"2":false'; + component.attributeToEdit._default = '"1":true,"2":false'; expect(component.isMapUnique()).toBe(true); - component.attributeToEdit.defaultValue = '"1":true,"1":false'; + component.attributeToEdit._default = '"1":true,"1":false'; expect(component.isMapUnique()).toBe(false); }); }); diff --git a/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes.component.html b/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes.component.html index 00a7a5cec0..6d50bbe11b 100644 --- a/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes.component.html +++ b/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes.component.html @@ -66,7 +66,7 @@ - {{row.defaultValue}} + {{row._default}} @@ -90,4 +90,4 @@ - \ No newline at end of file + -- cgit 1.2.3-korg