Fix Bug 2309: VIM update issue
[osm/NG-UI.git] / src / app / vim-accounts / new-vimaccount / NewVimaccountComponent.ts
index 724bef2..05fe4a2 100644 (file)
@@ -171,6 +171,15 @@ export class NewVimaccountComponent implements OnInit {
   // eslint-disable-next-line @typescript-eslint/no-magic-numbers
   private configLength: number = 3;
 
+  /** Contains config length from get api @private */
+  private getConfigLength: number;
+
+  /** Contains config when update @private */
+  private updateConfig: object;
+
+  /** Contains config length when update @private */
+  private updateConfigLength: number;
+
   /** Instance of the rest service @private */
   private restService: RestService;
 
@@ -266,6 +275,7 @@ export class NewVimaccountComponent implements OnInit {
         }
       }
       delete this.details.config.location;
+      this.getConfigLength = Object.keys(this.details.config).length;
       this.getFormControl('schema_type').disable();
       this.getFormControl('vim_url').disable();
       this.getFormControl('vim_type').disable();
@@ -332,9 +342,23 @@ export class NewVimaccountComponent implements OnInit {
           delete this.vimNewAccountForm.value.config[res];
         }
       });
-      if (!isNullOrUndefined(this.vimID)) {
+      delete this.vimNewAccountForm.value.config.location;
+      if (!isNullOrUndefined(this.data)) {
+        this.updateConfig = jsyaml.load(this.data, { json: true });
+        if (!isNullOrUndefined(this.updateConfig)) {
+          this.updateConfigLength = Object.keys(this.updateConfig).length;
+        }
+      }
+      if (this.updateConfig === undefined) {
+        this.notifierService.notify('warning', this.translateService.instant('PAGE.VIMDETAILS.VIMDELETE'));
+        this.isLocationLoadingResults = false;
+      } else if (this.getConfigLength > this.updateConfigLength) {
+        this.notifierService.notify('warning', this.translateService.instant('PAGE.VIMDETAILS.VIMEMPTY'));
+        this.isLocationLoadingResults = false;
+      }
+      if (!isNullOrUndefined(this.vimID) && ((this.getConfigLength <= this.updateConfigLength))) {
         this.editVIM();
-      } else {
+      } else if (isNullOrUndefined(this.vimID)) {
         this.createNewVIM();
       }
     }