From ddde283fb5ca941052928770c66ebfdc4dd462fa Mon Sep 17 00:00:00 2001
From: kbeyro <121854496+kbeyro@users.noreply.github.com>
Date: Mon, 26 May 2025 12:31:02 +0200
Subject: [PATCH] update webhooks & clusters

---
 .../webhook-details.component.html            | 16 ++--
 .../webhook-details.component.ts              |  4 +
 .../webhook-list/webhook-list.component.html  |  2 +-
 .../domains/domain/domain.component.html      | 74 ++++++++++---------
 src/app/service/cluster-manager.service.ts    |  4 +
 .../clusters/manager/manager.component.html   |  4 +
 .../clusters/manager/manager.component.ts     | 13 +++-
 .../appinstall/appinstallmodal.component.html |  2 +-
 8 files changed, 78 insertions(+), 41 deletions(-)

diff --git a/src/app/appmarket/admin/webhook/webhook-details/webhook-details.component.html b/src/app/appmarket/admin/webhook/webhook-details/webhook-details.component.html
index 6508c441..bd62085c 100644
--- a/src/app/appmarket/admin/webhook/webhook-details/webhook-details.component.html
+++ b/src/app/appmarket/admin/webhook/webhook-details/webhook-details.component.html
@@ -42,27 +42,33 @@
                     <div class="col-sm-10">
                         <div class="col-sm-10">
                             <input type="text" class="form-control" id="clusterDescription" name="clusterDescription"
-                                   placeholder="{{webhook.eventType | translate}}" [disabled]="true">
+                                   placeholder="{{'WEBHOOKS.' +webhook.eventType | translate}}" [disabled]="true">
                         </div>
                     </div>
                 </div>
-
                 <div class="form-group">
+                    <label for="assignDomain" class="col-sm-2 control-label">Auth required</label>
+                     <div class="col-sm-10">
+                    <input class="ml-5 mt-2" type="checkbox" [(ngModel)]="authRequired" [ngModelOptions]="{standalone: true}"  id="authRequired"/>
+                     </div>
+                </div>
+
+                <div *ngIf="authRequired" class="form-group">
                     <label for="token" class="col-sm-2 control-label">{{ 'WEBHOOKS.TOKEN' | translate }}</label>
                     <div class="col-sm-10">
                         <div class="col-sm-10">
-                            <input type="text" class="form-control" id="token" name="token"
+                            <input type="text" class="form-control" id="token" name="token" [ngModelOptions]="{standalone: true}"
                                    [(ngModel)]="webhook.tokenValue" [disabled]="false">
                         </div>
                     </div>
                 </div>
 
 
-                <div class="form-group">
+                <div *ngIf="authRequired" class="form-group">
                     <label for="auth" class="col-sm-2 control-label">{{ 'WEBHOOKS.AUTH' | translate }}</label>
                     <div class="col-sm-10">
                         <div class="col-sm-10">
-                            <input type="text" class="form-control" id="auth" name="auth"
+                            <input type="text" class="form-control" id="auth" name="auth" [ngModelOptions]="{standalone: true}"
                                    [(ngModel)]="webhook.authorizationHeader" [disabled]="false">
                         </div>
                     </div>
diff --git a/src/app/appmarket/admin/webhook/webhook-details/webhook-details.component.ts b/src/app/appmarket/admin/webhook/webhook-details/webhook-details.component.ts
index ef3ae89e..9c64e1db 100644
--- a/src/app/appmarket/admin/webhook/webhook-details/webhook-details.component.ts
+++ b/src/app/appmarket/admin/webhook/webhook-details/webhook-details.component.ts
@@ -13,6 +13,7 @@ export class WebhookDetailsComponent extends BaseComponent implements OnInit {
 
   public webhooksId: number;
   public webhook: Webhook;
+  public authRequired: boolean = false;
 
   constructor(private service: WebhookService,
       public router: Router,
@@ -28,6 +29,9 @@ export class WebhookDetailsComponent extends BaseComponent implements OnInit {
         this.service.getOne(this.webhooksId).subscribe(result => {
           console.log(result);
           this.webhook = result;
+          if(this.webhook.tokenValue !== null ) {
+            this.authRequired = true;
+          }
         } )
     })
       }
diff --git a/src/app/appmarket/admin/webhook/webhook-list/webhook-list.component.html b/src/app/appmarket/admin/webhook/webhook-list/webhook-list.component.html
index 39080066..6f59c32b 100644
--- a/src/app/appmarket/admin/webhook/webhook-list/webhook-list.component.html
+++ b/src/app/appmarket/admin/webhook/webhook-list/webhook-list.component.html
@@ -108,7 +108,7 @@
     </div>
     <div class="nmaas-modal-footer">
       <button type="button" class="btn btn-primary" [disabled]=" addedWebhook?.name === null "(click)="closeModalAndSaveWebhook()" 
-      pTooltip="Upload file is required before save" showDelay="2000" >{{'CLUSTERS.SAVE' | translate}}</button>
+      pTooltip="Upload file is required before save" showDelay="2000" >{{'WEBHOOKS.SAVE' | translate}}</button>
       <button type="button" class="btn btn-secondary"
                     (click)="this.modal.hide()">{{'UNDEPLOY_MODAL.CANCEL_BUTTON' | translate}}</button>
     
diff --git a/src/app/appmarket/domains/domain/domain.component.html b/src/app/appmarket/domains/domain/domain.component.html
index c2a98386..6064793e 100644
--- a/src/app/appmarket/domains/domain/domain.component.html
+++ b/src/app/appmarket/domains/domain/domain.component.html
@@ -270,50 +270,58 @@
 
 
 			<!-- CLUSTER CONFIGURATION READ ONLY PRESENTATION  -->
-		<div class="background-section" *ngIf="isInMode(ComponentMode.VIEW) && !authService.hasRole('ROLE_OPERATOR')">
+		 <div class="background-section" *ngIf="isInMode(ComponentMode.VIEW) && !authService.hasRole('ROLE_OPERATOR')">
 			<h4 style="font-size:15px; font-weight: bold">{{ 'CLUSTERS.CONFIGURATION' | translate  }}</h4>
 			<div class="panel-body" *ngIf="domain.clusters.length === 0" >
 				<p>None</p>
 			</div>
 
 			<div class="form-group panel-body" *ngIf="domain.clusters.length >0">
-				<label for="clusterId" class="col-sm-2 control-label">{{ 'CLUSTERS.ID' | translate }}</label>
-				<div class="col-sm-10">
-					<input type="text" class="form-control" [disabled]="true" id="clusterId "
-						   name="clusterId " [(ngModel)]="cluster.id">
-				</div>
-			</div>
+					<p-table
+    [value]="domain.clusters"
+    [paginator]="true"
+    [rows]="10"
+    [responsiveLayout]="'scroll'">
+        <ng-template pTemplate="header">
+            <tr>
+                <th  pSortableColumn="id" id="id"> {{ 'CLUSTERS.ID' | translate }}
+                    <p-sortIcon field="id"></p-sortIcon>
+                </th>
+                <th pSortableColumn="name" id="name"> {{ 'CLUSTERS.NAME' | translate }}
+                    <p-sortIcon field="name"></p-sortIcon>
+                </th>
+                <th pSortableColumn="codename" id="codename"> {{ 'CLUSTERS.CODENAME' | translate }}
+                    <p-sortIcon field="codename"></p-sortIcon>
+                </th>
+                <th pSortableColumn="state" id="state"> {{ 'CLUSTERS.STATE' | translate }}
+                    <p-sortIcon field="state"></p-sortIcon>
+                </th>
+                <th pSortableColumn="creationDate" id="creationDate"> {{ 'CLUSTERS.CREATION_DATE' | translate }}
+                    <p-sortIcon field="creationDate"></p-sortIcon>
+                </th>
+                <th pSortableColumn="modificationDate" id="modificationDate"> {{ 'CLUSTERS.MODIFICATION_DATE' | translate }}
+                    <p-sortIcon field="modificationDate"></p-sortIcon>
+                </th>
+            </tr>
+        </ng-template>
+        <ng-template pTemplate="body" let-cluster>
+            <tr>
+                <td [routerLink]="['/admin/manage/clusters/',cluster.id]">{{cluster.id}}</td>
+                <td [routerLink]="['/admin/manage/clusters/',cluster.id]">{{cluster.name}}</td>
+                <td [routerLink]="['/admin/manage/clusters/',cluster.id]">{{cluster.codename}}</td>
+                <td [routerLink]="['/admin/manage/clusters/',cluster.id]">{{('CLUSTERS.'+cluster.state.toString().toUpperCase() ) | translate}}</td>
+                <td [routerLink]="['/admin/manage/clusters/',cluster.id]">{{cluster.creationDate | date: 'dd-MM-yyyy HH:mm'}}</td>
+                <td [routerLink]="['/admin/manage/clusters/',cluster.id]">{{cluster.modificationDate | date: 'dd-MM-yyyy HH:mm'}}</td>
+                
+            </tr>
+        </ng-template>
+    </p-table>
 
-			<div class="form-group panel-body" *ngIf="domain.clusters.length >0">
-				<label for="clusterName" class="col-sm-2 control-label">{{ 'CLUSTERS.NAME' | translate }}</label>
-				<div class="col-sm-10">
-					<input type="text" class="form-control" [disabled]="true" id="clusterName "
-						   name="clusterName " [(ngModel)]="cluster.name">
-				</div>
-			</div>
 
-			<div class="form-group panel-body" *ngIf="domain.clusters.length >0">
-				<label for="clusterCodeName" class="col-sm-2 control-label">{{ 'CLUSTERS.CODENAME' | translate }}</label>
-				<div class="col-sm-10">
-					<input type="text" class="form-control" [disabled]="true" id="clusterCodeName "
-						   name="clusterCodeName " [(ngModel)]="cluster.codename">
 				</div>
-			</div>
-
-			<div class="form-group panel-body" *ngIf="domain.clusters.length >0">
-				<label for="clusterDescription" class="col-sm-2 control-label">{{ 'CLUSTERS.DESCRIPTION' | translate }}</label>
-				<div class="col-sm-10">
-					<input type="text" class="form-control" [disabled]="true" id="clusterDescription "
-						   name="clusterDescription " [(ngModel)]="cluster.description">
 				</div>
-			</div>
-
-
-
-
-
-		</div>
 
+		 
 		<div class="flex justify-content-end">
 			<button *ngIf="!isInMode(ComponentMode.VIEW)" type="submit" class="btn btn-primary" [disabled]="!domainForm.form.valid">{{ 'DOMAIN_DETAILS.SUBMIT_BUTTON' | translate }}</button>
 		</div>
diff --git a/src/app/service/cluster-manager.service.ts b/src/app/service/cluster-manager.service.ts
index a298dfe9..1a6c6b89 100644
--- a/src/app/service/cluster-manager.service.ts
+++ b/src/app/service/cluster-manager.service.ts
@@ -36,4 +36,8 @@ export class ClusterManagerService {
         return this.http.put<ClusterManager>(`${this.url}/${cluster.id}`, cluster);
     }
 
+     public deleteCluster(id: number): Observable<void> {
+        return this.http.delete<void>(this.url + '/' + id);
+    }
+
 }
\ No newline at end of file
diff --git a/src/app/shared/admin/clusters/manager/manager.component.html b/src/app/shared/admin/clusters/manager/manager.component.html
index fbced4c7..785c7ebb 100644
--- a/src/app/shared/admin/clusters/manager/manager.component.html
+++ b/src/app/shared/admin/clusters/manager/manager.component.html
@@ -61,7 +61,11 @@
                                 <li><a [routerLink]="[ cluster.id]" class="">
                                     {{ 'CLUSTERS.DETAILS' | translate }}</a>
                                 </li>
+                                <li><a (click)="deleteCluster(cluster)" class="">
+                                    {{ 'CLUSTERS.REMOVE' | translate }}</a>
+                                </li>
                             </ul>
+
                     </span>
                 </td>
             </tr>
diff --git a/src/app/shared/admin/clusters/manager/manager.component.ts b/src/app/shared/admin/clusters/manager/manager.component.ts
index 1e8c8938..f077af8c 100644
--- a/src/app/shared/admin/clusters/manager/manager.component.ts
+++ b/src/app/shared/admin/clusters/manager/manager.component.ts
@@ -72,8 +72,19 @@ public openModal() {
   this.modal.show();
 }
 
+public deleteCluster(cluster: ClusterManager) {
+  this.clusterService.deleteCluster(cluster.id).subscribe(() => { 
+    console.log('Cluster deleted successfully');
+    this.getAllClusters();
+  }, error => {
+    console.error('Error deleting cluster:', error);   
+  }
+  );
+}
+
 public onDomainChange(event: any) {
-console.log(event);
+  console.log(event);
+  this.addedCluster.domainNames = [this.domains[0].name];
 }
 
     filterClusters() {
diff --git a/src/app/shared/modal/appinstall/appinstallmodal.component.html b/src/app/shared/modal/appinstall/appinstallmodal.component.html
index 83c1876c..47e02a01 100644
--- a/src/app/shared/modal/appinstall/appinstallmodal.component.html
+++ b/src/app/shared/modal/appinstall/appinstallmodal.component.html
@@ -27,7 +27,7 @@
 				<p><strong>{{'INSTALL_MODAL.DOMAIN' | translate}}: </strong>{{domainName}}</p>
 			</div>
 
-			<div class="form-group" style="padding-top: 15px">
+			<div *ngIf="isRemoteClusterAvailable" class="form-group" style="padding-top: 15px">
 				<label for="showCluster" style="padding-left: 0px" class="col-sm-10 control-label">{{ 'INSTALL_MODAL.REMOTE_CLUSTER' | translate }}:</label>
 				<div class="col-sm-2">
 					<input type="checkbox" id="showCluster" name="showCluster"
-- 
GitLab