From 82ee153edbf6ffca0d69bd450b48037ee0465191 Mon Sep 17 00:00:00 2001 From: vasraz Date: Thu, 15 Apr 2021 10:03:58 +0100 Subject: Fix 'Unable to save changed attributes default value' Implements missing functionality to save changed attribute Change-Id: I1bc828ef133c8a2bf2fd6333a51fb46fc41b6547 Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3562 --- .../attributes-outputs.page.component.ts | 60 ++++++++++++++-------- 1 file changed, 40 insertions(+), 20 deletions(-) (limited to 'catalog-ui') diff --git a/catalog-ui/src/app/ng2/pages/attributes-outputs/attributes-outputs.page.component.ts b/catalog-ui/src/app/ng2/pages/attributes-outputs/attributes-outputs.page.component.ts index d7db8f3c82..f97f8499ea 100644 --- a/catalog-ui/src/app/ng2/pages/attributes-outputs/attributes-outputs.page.component.ts +++ b/catalog-ui/src/app/ng2/pages/attributes-outputs/attributes-outputs.page.component.ts @@ -198,7 +198,6 @@ export class AttributesOutputsComponent { event.preventDefault(); this.showUnsavedChangesAlert().then(() => { this.$state.go(toState, toParams); - }, () => { }); } }); @@ -390,7 +389,6 @@ export class AttributesOutputsComponent { this.attributeOutputTabs.triggerTabChange(this.currentMainTab.title); this.showUnsavedChangesAlert().then(() => { this.attributeOutputTabs.selectTab(this.attributeOutputTabs.tabs.find((tab) => tab.title === event.title)); - }, () => { }); return; } @@ -451,7 +449,7 @@ export class AttributesOutputsComponent { let request; let handleSuccess, handleError; if (this.isAttributesTabSelected) { - this.changedData.map((changedAttrib) => { + const changedAttribs = this.changedData.map((changedAttrib) => { changedAttrib = changedAttrib; const attribBE = new AttributeBEModel(changedAttrib); attribBE.toscaPresentation = new ToscaPresentationData(); @@ -461,6 +459,28 @@ export class AttributesOutputsComponent { delete attribBE.origName; return attribBE; }); + + if (this.selectedInstanceData instanceof ComponentInstance) { + if (this.isSelf()) { + console.log("changedAttribs", changedAttribs); + request = this.topologyTemplateService.updateServiceAttributes(this.component.uniqueId, _.map(changedAttribs, cp => { + delete cp.constraints; + return cp; + })); + } else { + request = this.componentInstanceServiceNg2 + .updateInstanceAttributes(this.component.componentType, this.component.uniqueId, this.selectedInstanceData.uniqueId, changedAttribs); + } + handleSuccess = (response) => { + // reset each changed attribute with new value and remove it from changed attributes list + response.forEach((resAttrib) => { + const changedAttrib = this.changedData.shift(); + this.attributesUtils.resetAttributeValue(changedAttrib, resAttrib.value); + }); + resolve(response); + console.log("updated instance attributes: ", response); + }; + } } else if (this.isOutputsTabSelected) { const changedOutputs: OutputBEModel[] = this.changedData.map((changedOutput) => { changedOutput = changedOutput; @@ -468,8 +488,7 @@ export class AttributesOutputsComponent { outputBE.defaultValue = changedOutput.getJSONDefaultValue(); return outputBE; }); - request = this.componentServiceNg2 - .updateComponentOutputs(this.component, changedOutputs); + request = this.componentServiceNg2.updateComponentOutputs(this.component, changedOutputs); handleSuccess = (response) => { // reset each changed attribute with new value and remove it from changed attributes list response.forEach((resOutput) => { @@ -478,23 +497,24 @@ export class AttributesOutputsComponent { changedOutput.required = resOutput.required; }); } - this.savingChangedData = true; - request.subscribe( - (response) => { - this.savingChangedData = false; - handleSuccess && handleSuccess(response); - this.updateHasChangedData(); - resolve(response); - }, - (error) => { - this.savingChangedData = false; - handleError && handleError(error); - this.updateHasChangedData(); - reject(error); - } - ); } + this.savingChangedData = true; + request.subscribe( + (response) => { + this.savingChangedData = false; + handleSuccess && handleSuccess(response); + this.updateHasChangedData(); + resolve(response); + }, + (error) => { + this.savingChangedData = false; + handleError && handleError(error); + this.updateHasChangedData(); + reject(error); + } + ); + }); }; -- cgit 1.2.3-korg