From a2d7224b2efc561b7e76b30641d8f9fef02cdc14 Mon Sep 17 00:00:00 2001 From: mkouremetis Date: Wed, 5 Jun 2024 17:47:00 -0400 Subject: [PATCH 1/2] initial --- src/stores/operationStore.js | 9 +++++++++ src/views/OperationsView.vue | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/stores/operationStore.js b/src/stores/operationStore.js index 5d99799..a225902 100644 --- a/src/stores/operationStore.js +++ b/src/stores/operationStore.js @@ -27,6 +27,15 @@ export const useOperationStore = defineStore("operationStore", { console.error("Error fetching operations", error); } }, + async getOperation($api, operationID) { + try { + const response = await $api.get(`/api/v2/operations/${operationID}`); + let operation = response.data; + this.operations[operation.id] = operation; + } catch (error) { + console.error("Error fetching operations", error); + } + }, async createOperation($api, operation) { try { const response = await $api.post("/api/v2/operations", operation); diff --git a/src/views/OperationsView.vue b/src/views/OperationsView.vue index df05c10..85b056c 100644 --- a/src/views/OperationsView.vue +++ b/src/views/OperationsView.vue @@ -196,7 +196,7 @@ function selectOperation() { resetFilter(); updateInterval = setInterval(async () => { if (operationStore.selectedOperationID !== "") { - await operationStore.getOperations($api); + await operationStore.getOperation($api, operationStore.selectedOperationID); } else { clearInterval(updateInterval); } From fd876288458cc0fd47f06599c60d5001b9472d63 Mon Sep 17 00:00:00 2001 From: mkouremetis Date: Thu, 6 Jun 2024 16:24:15 -0400 Subject: [PATCH 2/2] added check to only poll for active operations --- src/views/OperationsView.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/views/OperationsView.vue b/src/views/OperationsView.vue index 85b056c..aa4a225 100644 --- a/src/views/OperationsView.vue +++ b/src/views/OperationsView.vue @@ -190,12 +190,13 @@ const resetFilter = () => { }; function selectOperation() { - //TODO: Stop updating if operation is finished if (updateInterval) clearInterval(updateInterval); if (operationStore.selectedOperationID === "") return; resetFilter(); updateInterval = setInterval(async () => { - if (operationStore.selectedOperationID !== "") { + if (operationStore.selectedOperationID !== "" && + operationStore.operations[operationStore.selectedOperationID].state !== "finished") + { await operationStore.getOperation($api, operationStore.selectedOperationID); } else { clearInterval(updateInterval);