Advanced Cluster Enhancements

	- Added edit cluster, profile type in OKA
	- State to Git State in all pages
	- Changed mandatory fields of edit profile
	- Changed api in cluster page

Change-Id: I8a3239f83eb58a3997e4550fc030694c0a2a6c72
Signed-off-by: SANDHYA.JS <sandhya.j@tataelxsi.co.in>
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.html b/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.html
index 3d623ae..e8b57b6 100644
--- a/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.html
+++ b/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.html
@@ -26,6 +26,9 @@
     <h4 *ngIf="profileType === 'upgrade'" class="modal-title" id="modal-basic-title">{{'PAGE.K8S.UPGRADECLUSTER' |
       translate}}
     </h4>
+    <h4 *ngIf="profileType === 'update'" class="modal-title" id="modal-basic-title">{{'PAGE.K8S.UPDATECLUSTER' |
+      translate}}
+    </h4>
     <h4 *ngIf="profileType === 'vertical'" class="modal-title" id="modal-basic-title">{{'PAGE.K8S.VERTICALSCALING' |
       translate}}
     </h4>
@@ -59,6 +62,13 @@
           formControlName="name" id="name" [ngClass]="{ 'is-invalid': submitted && f.name.errors }" required>
       </div>
     </div>
+    <div class="form-group row mb-3" *ngIf="profileType === 'update'">
+      <label class="col-sm-4 col-form-label" for="name">{{'PAGE.K8S.NAME' | translate}}</label>
+      <div class="col-sm-8">
+        <input autocomplete="off" class="form-control" placeholder="{{'PAGE.K8S.NAME' | translate}}" type="text"
+          formControlName="update" id="name" [ngClass]="{ 'is-invalid': submitted && f.update.errors }">
+      </div>
+    </div>
     <div class="form-group row mb-3" *ngIf="profileType === 'Manage'|| !isChecked">
       <label class="col-sm-4 col-form-label" for="k8s_version">{{'PAGE.K8S.K8SVERSION' | translate}}*</label>
       <div class="col-sm-8">
@@ -88,7 +98,7 @@
         </ng-select>
       </div>
     </div>
-    <div class="form-group row mb-3" *ngIf="profileType === 'Manage' || profileType === 'Register' || !isChecked">
+    <div class="form-group row mb-3" *ngIf="profileType === 'Manage' || profileType === 'Register' || !isChecked || profileType === 'update'">
       <label class="col-sm-4 col-form-label" for="description">{{'PAGE.K8S.DESCRIPTION' | translate}}</label>
       <div class="col-sm-8">
         <textarea class="form-control" placeholder="{{'PAGE.K8S.DESCRIPTION' | translate}}" type="text"
@@ -179,7 +189,7 @@
     <button type="button" class="btn btn-danger" (click)="activeModal.close()">{{'CANCEL' | translate}}</button>
     <button *ngIf="profileType === 'Manage'" type="submit" class="btn btn-primary">{{'CREATE' | translate}}</button>
     <button *ngIf="profileType === 'Register'" type="submit" class="btn btn-primary">{{'REGISTER' | translate}}</button>
-    <button *ngIf="profileType === 'upgrade' || profileType === 'vertical' || profileType === 'horizontal'"
+    <button *ngIf="profileType === 'upgrade' || profileType === 'vertical' || profileType === 'horizontal' || profileType === 'update'"
       type="submit" class="btn btn-primary">{{'APPLY'
       | translate}}</button>
   </div>
diff --git a/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts b/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts
index cf03f0f..37ddc13 100644
--- a/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts
+++ b/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts
@@ -27,7 +27,7 @@
 import { APIURLHEADER, ERRORDATA, MODALCLOSERESPONSEDATA, TYPESECTION } from 'CommonModel';
 import { environment } from 'environment';
 import * as jsyaml from 'js-yaml';
-import { K8SPayload } from 'K8sModel';
+import { K8SCLUSTERDATA, K8SPayload } from 'K8sModel';
 import { RestService } from 'RestService';
 import { isNullOrUndefined, SharedService } from 'SharedService';
 import { VimAccountDetails } from 'VimAccountModel';
@@ -66,6 +66,9 @@
   /** Contains all deployment methods selected */
   public selectedDeploymentMethods: string[] = ['helm-chart-v3', 'juju-bundle'];
 
+  /** Contains all action types */
+  public actionTypes: string[] = ['update', 'upgrade', 'horizontal', 'vertical'];
+
   /** Instance for active modal service @public */
   public activeModal: NgbActiveModal;
 
@@ -149,6 +152,11 @@
       'Content-Type': 'application/json',
       'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
     });
+    this.actionTypes.forEach((type: string): void => {
+      if (type === this.profileType) {
+        this.k8sClusterDetail();
+      }
+    });
   }
 
   /** On modal initializing forms  @public */
@@ -168,7 +176,8 @@
       bootstrap: [true],
       k8sVersion: ['', [Validators.required]],
       nodeCount: ['', [Validators.required]],
-      nodeSize: ['', [Validators.required]]
+      nodeSize: ['', [Validators.required]],
+      update: ['']
     });
   }
 
@@ -187,6 +196,26 @@
     });
   }
 
+  /** patch the form values for edit @public */
+  public k8sClusterDetail(): void {
+    this.isLoadingResults = true;
+    this.restService.getResource(environment.K8SCREATECLUSTER_URL + '/' + this.profileID).subscribe((k8sData: K8SCLUSTERDATA) => {
+      if (this.profileType === 'update') {
+        this.k8sclusterForm.patchValue({ update: k8sData.name, description: !isNullOrUndefined(k8sData.description) ? k8sData.description : '' });
+      } else if (this.profileType === 'upgrade') {
+        this.k8sclusterForm.patchValue({ k8sVersion: !isNullOrUndefined(k8sData.k8s_version) ? k8sData.k8s_version : '' });
+      } else if (this.profileType === 'horizontal') {
+        this.k8sclusterForm.patchValue({ nodeCount: !isNullOrUndefined(k8sData.node_count) ? k8sData.node_count : '' });
+      } else if (this.profileType === 'vertical') {
+        this.k8sclusterForm.patchValue({ nodeSize: !isNullOrUndefined(k8sData.node_size) ? k8sData.node_size : '' });
+      }
+      this.isLoadingResults = false;
+    }, (error: ERRORDATA) => {
+      this.restService.handleError(error, 'get');
+      this.isLoadingResults = false;
+    });
+  }
+
   /** Call the event when checkbox is checked @public */
   public getValue(event: Event): void {
     this.isChecked = (event.target as HTMLInputElement).checked;
@@ -207,6 +236,7 @@
       this.getFormControl('k8sVersion').disable();
       this.getFormControl('nodeSize').disable();
       this.getFormControl('nodeCount').disable();
+      this.getFormControl('update').disable();
       this.manageCluster();
     } else if (this.profileType === 'Register' && this.isChecked === true) {
       this.clusterUrl = environment.K8SCREATECLUSTER_URL + '/register';
@@ -220,6 +250,7 @@
       this.getFormControl('k8sVersion').disable();
       this.getFormControl('nodeSize').disable();
       this.getFormControl('nodeCount').disable();
+      this.getFormControl('update').disable();
       this.registerCluster();
     } if (this.isChecked === false && this.profileType === 'Register') {
       this.clusterUrl = environment.K8SCLUSTER_URL;
@@ -231,6 +262,7 @@
       this.getFormControl('k8sVersion').disable();
       this.getFormControl('nodeSize').disable();
       this.getFormControl('nodeCount').disable();
+      this.getFormControl('update').disable();
       this.oldregisterCluster();
     } else if (this.profileType === 'upgrade' || this.profileType === 'horizontal' || this.profileType === 'vertical') {
       this.clusterUrl = environment.K8SCREATECLUSTER_URL + '/' + this.profileID + '/' + 'update';
@@ -246,6 +278,7 @@
       this.getFormControl('node_count').disable();
       this.getFormControl('node_size').disable();
       this.getFormControl('k8s_version').disable();
+      this.getFormControl('update').disable();
       if (this.profileType === 'upgrade') {
         this.getFormControl('nodeCount').disable();
         this.getFormControl('nodeSize').disable();
@@ -257,6 +290,24 @@
         this.getFormControl('k8sVersion').disable();
       }
       this.updateCluster();
+    } else if (this.profileType === 'update') {
+      this.clusterUrl = environment.K8SCREATECLUSTER_URL + '/' + this.profileID;
+      this.getFormControl('bootstrap').disable();
+      this.getFormControl('region_name').disable();
+      this.getFormControl('resource_group').disable();
+      this.getFormControl('nets').disable();
+      this.getFormControl('credentials').disable();
+      this.getFormControl('deployment_methods').disable();
+      this.getFormControl('vim_account').disable();
+      this.getFormControl('node_count').disable();
+      this.getFormControl('node_size').disable();
+      this.getFormControl('k8s_version').disable();
+      this.getFormControl('nodeCount').disable();
+      this.getFormControl('k8sVersion').disable();
+      this.getFormControl('nodeSize').disable();
+      this.getFormControl('name').disable();
+
+      this.editCluster();
     }
   }
 
@@ -456,6 +507,51 @@
     });
   }
 
+
+  /** Update cluster @public */
+  public editCluster(): void {
+    this.submitted = true;
+    this.sharedService.cleanForm(this.k8sclusterForm);
+    if (this.k8sclusterForm.invalid) {
+      return;
+    }
+    const modalData: MODALCLOSERESPONSEDATA = {
+      message: 'Done'
+    };
+    const apiURLHeader: APIURLHEADER = {
+      url: this.clusterUrl,
+      httpOptions: { headers: this.headers }
+    };
+    this.isLoadingResults = true;
+    if (this.k8sclusterForm.value.description === '') {
+      delete this.k8sclusterForm.value.description;
+      this.payload = {
+        name: this.k8sclusterForm.value.update
+      };
+    }
+    if (this.k8sclusterForm.value.update === '') {
+      delete this.k8sclusterForm.value.update;
+      this.payload = {
+        description: this.k8sclusterForm.value.description
+      };
+    }
+    if (this.k8sclusterForm.value.update !== '' && this.k8sclusterForm.value.description !== '') {
+      this.payload = {
+        name: this.k8sclusterForm.value.update,
+        description: this.k8sclusterForm.value.description
+      };
+    }
+    this.restService.patchResource(apiURLHeader, this.payload).subscribe((result: {}) => {
+      this.activeModal.close(modalData);
+      this.isLoadingResults = false;
+      this.notifierService.notify('success',
+        this.translateService.instant('PAGE.K8S.UPDATEDSUCCESSFULLY'));
+    }, (error: ERRORDATA) => {
+      this.restService.handleError(error, 'post');
+      this.isLoadingResults = false;
+    });
+  }
+
   /** Nets file process @private */
   public netsFile(files: FileList): void {
     if (files && files.length === 1) {