Feature: 11055 Support of several node groups in clusters created by OSM

	- Added control plane support in managed post
	- When aws vim account is selected paylaod will get differed
	- Added details page in clusters to view node and ksu for
	  specified cluster
	- Fixed Bug 2402 - Unable to create Ns Config template from Ui
	  bug by chnaging api

Change-Id: I4eb327fd86b0c4a706b05a8ed10524e4d2c5bc95
Signed-off-by: SANDHYA.JS <sandhya.j@tataelxsi.co.in>
diff --git a/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts b/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts
index 34ceeab..69fe54f 100644
--- a/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts
+++ b/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts
@@ -20,7 +20,7 @@
  */
 import { HttpHeaders } from '@angular/common/http';
 import { Component, ElementRef, Injector, Input, OnInit, ViewChild } from '@angular/core';
-import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
+import { AbstractControl, FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
 import { TranslateService } from '@ngx-translate/core';
 import { NotifierService } from 'angular-notifier';
@@ -51,6 +51,9 @@
   /** Contains all vim account collections */
   public vimAccountSelect: VimAccountDetails;
 
+  /** Contains selected vim */
+  public vimType: string;
+
   /** Input contains Modal dialog component Instance @public */
   @Input() public profileType: string;
 
@@ -163,7 +166,7 @@
   public k8sclusterFormAction(): void {
     this.k8sclusterForm = this.formBuilder.group({
       name: ['', [Validators.required]],
-      k8s_version: ['', [Validators.required]],
+      k8s_version: [''],
       vim_account: [null, [Validators.required]],
       description: [''],
       nets: ['', [Validators.required]],
@@ -175,6 +178,9 @@
       node_size: ['', [Validators.required]],
       bootstrap: [true],
       k8sVersion: ['', [Validators.required]],
+      iam_role: [''],
+      private_subnet: this.formBuilder.array([]),
+      public_subnet: this.formBuilder.array([]),
       update: ['']
     });
   }
@@ -182,6 +188,65 @@
   /** convenience getter for easy access to form fields */
   get f(): FormGroup['controls'] { return this.k8sclusterForm.controls; }
 
+  /** convenience getter for easy access to form array privatesubnet */
+  get chipsprivateArray(): FormArray {
+    return this.k8sclusterForm.get('private_subnet') as FormArray;
+  }
+
+  /** To add privatesubnet chips */
+  public addprivateChips() {
+    const input = document.getElementById('private_subnet') as HTMLInputElement;
+    const value = input.value.trim();
+
+    if (value) {
+      this.chipsprivateArray.push(new FormControl(value));
+      input.value = '';
+    }
+  }
+  /** convenience getter for easy access to form array publicsubnet */
+  get chipspublicArray(): FormArray {
+    return this.k8sclusterForm.get('public_subnet') as FormArray;
+  }
+
+  /** To add publicsubnet chips */
+  public addpublicChips() {
+    const input = document.getElementById('public_subnet') as HTMLInputElement;
+    const value = input.value.trim();
+
+    if (value) {
+      this.chipspublicArray.push(new FormControl(value));
+      input.value = '';
+    }
+  }
+
+  /** To remove privatesubnet chips */
+  public removeprivateChip(index: number) {
+    this.chipsprivateArray.removeAt(index);
+  }
+
+  /** To remove privatesubnet last chip */
+  public removeprivateLastChip(event: KeyboardEvent) {
+    const input = event.target as HTMLInputElement;
+    if (event.key === 'Backspace' && input.value === '' && this.chipsprivateArray.length > 0) {
+      this.chipsprivateArray.removeAt(this.chipsprivateArray.length - 1); // Remove last chip if input is empty
+      event.preventDefault();
+    }
+  }
+  /** To remove publicsubnet chips */
+  public removepublicChip(index: number) {
+    this.chipspublicArray.removeAt(index);
+  }
+
+  /** To remove publicsubnet last chip */
+  public removepublicLastChip(event: KeyboardEvent) {
+    const input = event.target as HTMLInputElement;
+    if (event.key === 'Backspace' && input.value === '' && this.chipspublicArray.length > 0) {
+      this.chipspublicArray.removeAt(this.chipspublicArray.length - 1); // Remove last chip if input is empty
+      event.preventDefault();
+    }
+  }
+
+
   /** Call the vimAccount details in the selection options @public */
   public getDetailsvimAccount(): void {
     this.isLoadingResults = true;
@@ -219,6 +284,7 @@
   /** Contain selected vimAccount details @public */
   public getDetailsvim(event: VimAccountDetails): void {
     this.vimAccountId = event._id;
+    this.vimType = event.vim_type;
   }
 
   /** On modal submit k8sAddClusterSubmit will called @public */
@@ -229,6 +295,23 @@
       this.getFormControl('deployment_methods').disable();
       this.getFormControl('k8sVersion').disable();
       this.getFormControl('update').disable();
+      this.clusterUrl = environment.K8SCREATECLUSTER_URL;
+      if (this.vimType === 'aws') {
+        this.getFormControl('resource_group').disable();
+        this.getFormControl('k8sVersion').disable();
+        this.getFormControl('node_size').disable();
+        this.getFormControl('node_count').disable();
+        this.getFormControl('nets').disable();
+        this.getFormControl('credentials').disable();
+        this.getFormControl('update').disable();
+        this.getFormControl('deployment_methods').disable();
+      } else if (this.vimType !== 'aws') {
+        this.getFormControl('nets').disable();
+        this.getFormControl('credentials').disable();
+        this.getFormControl('deployment_methods').disable();
+        this.getFormControl('k8sVersion').disable();
+        this.getFormControl('update').disable();
+      }
       this.manageCluster();
     } else if (this.profileType === 'Register' && this.isChecked === true) {
       this.clusterUrl = environment.K8SCREATECLUSTER_URL + '/register';
@@ -240,6 +323,9 @@
       this.getFormControl('nets').disable();
       this.getFormControl('deployment_methods').disable();
       this.getFormControl('k8sVersion').disable();
+      this.getFormControl('iam_role').disable();
+      this.getFormControl('private_subnet').disable();
+      this.getFormControl('public_subnet').disable();
       this.getFormControl('update').disable();
       this.registerCluster();
     } if (this.isChecked === false && this.profileType === 'Register') {
@@ -250,6 +336,9 @@
       this.getFormControl('node_count').disable();
       this.getFormControl('node_size').disable();
       this.getFormControl('k8sVersion').disable();
+      this.getFormControl('iam_role').disable();
+      this.getFormControl('private_subnet').disable();
+      this.getFormControl('public_subnet').disable();
       this.getFormControl('update').disable();
       this.oldregisterCluster();
     } else if (this.profileType === 'upgrade') {
@@ -265,7 +354,9 @@
       this.getFormControl('bootstrap').disable();
       this.getFormControl('node_count').disable();
       this.getFormControl('node_size').disable();
-      this.getFormControl('k8s_version').disable();
+      this.getFormControl('iam_role').disable();
+      this.getFormControl('private_subnet').disable();
+      this.getFormControl('public_subnet').disable();
       this.getFormControl('update').disable();
       this.updateCluster();
     } else if (this.profileType === 'update') {
@@ -281,8 +372,10 @@
       this.getFormControl('node_size').disable();
       this.getFormControl('k8s_version').disable();
       this.getFormControl('k8sVersion').disable();
+      this.getFormControl('iam_role').disable();
+      this.getFormControl('private_subnet').disable();
+      this.getFormControl('public_subnet').disable();
       this.getFormControl('name').disable();
-
       this.editCluster();
     }
   }
@@ -375,7 +468,6 @@
     if (this.k8sclusterForm.value.description === '') {
       delete this.k8sclusterForm.value.description;
     }
-
     const apiURLHeader: APIURLHEADER = {
       url: this.clusterUrl,
       httpOptions: { headers: this.headers }
@@ -393,7 +485,7 @@
     });
   }
 
-  /** Manage cluster @public */
+  /** controlplane cluster flow @public */
   public manageCluster(): void {
     this.submitted = true;
     this.sharedService.cleanForm(this.k8sclusterForm);
@@ -404,36 +496,51 @@
       message: 'Done'
     };
     const apiURLHeader: APIURLHEADER = {
-      url: environment.K8SCREATECLUSTER_URL,
+      url: this.clusterUrl,
       httpOptions: { headers: this.headers }
     };
 
     this.isLoadingResults = true;
-    const payload: K8SPayload = {
-      name: this.k8sclusterForm.value.name,
-      vim_account: this.k8sclusterForm.value.vim_account,
-      location: this.k8sclusterForm.value.location,
-      region_name: this.k8sclusterForm.value.region_name,
-      resource_group: this.k8sclusterForm.value.resource_group,
-      k8s_version: this.k8sclusterForm.value.k8s_version,
-      node_size: this.k8sclusterForm.value.node_size,
-      node_count: Number(this.k8sclusterForm.value.node_count),
-      description: this.k8sclusterForm.value.description,
-      bootstrap: Boolean(this.k8sclusterForm.value.bootstrap)
-    };
-    if (this.k8sclusterForm.value.region_name === '') {
-      delete payload.region_name;
-    } else if (this.k8sclusterForm.value.resource_group === '') {
-      delete payload.resource_group;
-    } else if (this.k8sclusterForm.value.description === '') {
-      delete payload.description;
+    const formData = this.k8sclusterForm.value;
+    if (this.k8sclusterForm.value.private_subnet.length <= 0) {
+      delete this.k8sclusterForm.value.private_subnet;
     }
-    if (this.k8sclusterForm.value.region_name === '' && this.k8sclusterForm.value.resource_group === '' && this.k8sclusterForm.value.description === '') {
-      delete payload.region_name;
-      delete payload.resource_group;
-      delete payload.description;
+    if (this.k8sclusterForm.value.public_subnet.length <= 0) {
+      delete this.k8sclusterForm.value.public_subnet;
     }
-    this.restService.postResource(apiURLHeader, payload).subscribe((result: {}) => {
+    if (this.vimType !== 'aws') {
+      this.payload = {
+        name: this.k8sclusterForm.value.name,
+        vim_account: this.k8sclusterForm.value.vim_account,
+        location: this.k8sclusterForm.value.location,
+        region_name: this.k8sclusterForm.value.region_name,
+        resource_group: this.k8sclusterForm.value.resource_group,
+        k8s_version: this.k8sclusterForm.value.k8s_version,
+        node_size: this.k8sclusterForm.value.node_size,
+        node_count: Number(this.k8sclusterForm.value.node_count),
+        description: this.k8sclusterForm.value.description,
+        bootstrap: Boolean(this.k8sclusterForm.value.bootstrap)
+      };
+      if (this.k8sclusterForm.value.region_name === '') {
+        delete this.payload.region_name;
+      }
+      if (this.k8sclusterForm.value.resource_group === '') {
+        delete this.payload.resource_group;
+      }
+      if (this.k8sclusterForm.value.description === '') {
+        delete this.payload.description;
+      }
+    } else {
+      this.payload = Object.keys(formData).reduce((acc, key) => {
+        // eslint-disable-next-line security/detect-object-injection
+        if (formData[key] !== null && formData[key] !== undefined && formData[key] !== '') {
+          // eslint-disable-next-line security/detect-object-injection
+          acc[key] = formData[key];
+        }
+        return acc;
+      }, {});
+    }
+    this.restService.postResource(apiURLHeader, this.payload).subscribe((result: {}) => {
       this.activeModal.close(modalData);
       this.isLoadingResults = false;
       this.notifierService.notify('success', this.k8sclusterForm.value.name +
@@ -475,8 +582,7 @@
     });
   }
 
-
-  /** Update cluster @public */
+  /** Edit cluster @public */
   public editCluster(): void {
     this.submitted = true;
     this.sharedService.cleanForm(this.k8sclusterForm);