From 54f0bb9e852d47248677ed071c3c69790c1e82cb Mon Sep 17 00:00:00 2001 From: "mtarrade.sap@gmail.com" Date: Fri, 13 Dec 2024 16:00:28 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20instant=20state=20update=20in?= =?UTF-8?q?=20decoy=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../list-decoy/list-decoy.component.html | 2 +- .../pages/list-decoy/list-decoy.component.ts | 19 +++++++++++-------- .../src/app/services/api/decoy-api.service.ts | 3 +++ .../cad/src/app/services/decoy.service.ts | 8 ++++++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/controlpanel/cad/src/app/pages/list-decoy/list-decoy.component.html b/controlpanel/cad/src/app/pages/list-decoy/list-decoy.component.html index 5303f92..685671a 100644 --- a/controlpanel/cad/src/app/pages/list-decoy/list-decoy.component.html +++ b/controlpanel/cad/src/app/pages/list-decoy/list-decoy.component.html @@ -64,6 +64,6 @@

Decoys list 🗒️

- +
\ No newline at end of file diff --git a/controlpanel/cad/src/app/pages/list-decoy/list-decoy.component.ts b/controlpanel/cad/src/app/pages/list-decoy/list-decoy.component.ts index 5ee5be5..1cecc1a 100644 --- a/controlpanel/cad/src/app/pages/list-decoy/list-decoy.component.ts +++ b/controlpanel/cad/src/app/pages/list-decoy/list-decoy.component.ts @@ -33,7 +33,7 @@ export class ListDecoyComponent implements OnInit, OnDestroy { ngOnDestroy(): void { this.globalStateSubscription?.unsubscribe(); - this.save(); + // this.save(); } async getDecoyList() { @@ -52,9 +52,12 @@ export class ListDecoyComponent implements OnInit, OnDestroy { if (state == 'active') return true; else return false; } - setDeployed(decoyData: DecoyData) { + async setDeployed(decoyData: DecoyData) { if (decoyData.state == 'active') decoyData.state = 'inactive'; else decoyData.state = 'active'; + const updateResponse = await this.decoyService.updateDecoyState(decoyData); + if (updateResponse.type == 'error') this.toastr.error(updateResponse.message, "Error updating state"); + else this.toastr.success("Successfully updated decoy state", "Saved"); } async deleteDecoy(decoyId: UUID) { const saveResponse = await this.decoyService.deleteDecoy(decoyId); @@ -65,10 +68,10 @@ export class ListDecoyComponent implements OnInit, OnDestroy { } } - async save() { - if (!this.decoys.length) return; - const saveResponse = await this.decoyService.updateDecoysState(this.decoys); - if (saveResponse.type == 'error') this.toastr.error(saveResponse.message, "Error saving"); - else this.toastr.success("Successfully saved decoys states", "Saved"); - } + // async save() { + // if (!this.decoys.length) return; + // const saveResponse = await this.decoyService.updateDecoysState(this.decoys); + // if (saveResponse.type == 'error') this.toastr.error(saveResponse.message, "Error saving"); + // else this.toastr.success("Successfully saved decoys states", "Saved"); + // } } diff --git a/controlpanel/cad/src/app/services/api/decoy-api.service.ts b/controlpanel/cad/src/app/services/api/decoy-api.service.ts index a986632..396a4aa 100644 --- a/controlpanel/cad/src/app/services/api/decoy-api.service.ts +++ b/controlpanel/cad/src/app/services/api/decoy-api.service.ts @@ -33,4 +33,7 @@ export class DecoyApiService { deleteDecoy(id: UUID) { return this.http.delete(`${this.globalState.API_URL}/decoy/${id}`); } + patchDecoyState(decoy: DecoyData) { + return this.http.patch(`${this.globalState.API_URL}/decoy/state`, decoy); + } } diff --git a/controlpanel/cad/src/app/services/decoy.service.ts b/controlpanel/cad/src/app/services/decoy.service.ts index 67bc9d4..432e85d 100644 --- a/controlpanel/cad/src/app/services/decoy.service.ts +++ b/controlpanel/cad/src/app/services/decoy.service.ts @@ -65,6 +65,14 @@ export class DecoyService { return { message: "Error when saving decoy", type: 'error' }; } } + async updateDecoyState(decoy: DecoyData): Promise { + try { + const apiResponse = await lastValueFrom(this.decoyApi.patchDecoyState(decoy)); + return apiResponse; + } catch(e) { + return { message: "Error when saving decoy", type: 'error' }; + } + } async getDecoys(): Promise { try {