From ebcd50e9a2ab34eecfed553fd4a76966a697a78a Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 26 Sep 2025 17:46:03 +0200 Subject: [PATCH] - Fixed issue #5 - resetting assistant store after creating premisses. --- .../src/pages/CalculationAssistant.vue | 2 +- src/frontend/src/store/assistant.js | 49 ++++++++++++++----- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/frontend/src/pages/CalculationAssistant.vue b/src/frontend/src/pages/CalculationAssistant.vue index 71d79e0..76531bf 100644 --- a/src/frontend/src/pages/CalculationAssistant.vue +++ b/src/frontend/src/pages/CalculationAssistant.vue @@ -115,7 +115,7 @@ export default { } else { this.$router.push({name: "bulk", params: {ids: new UrlSafeBase64().encodeIds(ids)}}); } - + this.assistantStore.reset(); }, selectedSupplier(supplier) { this.assistantStore.addSupplier(supplier); diff --git a/src/frontend/src/store/assistant.js b/src/frontend/src/store/assistant.js index 595a8b8..f8f1b67 100644 --- a/src/frontend/src/store/assistant.js +++ b/src/frontend/src/store/assistant.js @@ -27,7 +27,12 @@ export const useAssistantStore = defineStore('assistant', { const materialIds = this.materials.map((material) => material.id); const supplierIds = this.suppliers.filter(s => s.id.startsWith('s')).map((supplier) => supplier.origId); const userSupplierIds = this.suppliers.filter(s => s.id.startsWith('u')).map((supplier) => supplier.origId); - const jsonBody = JSON.stringify({ material: materialIds, supplier: supplierIds, user_supplier: userSupplierIds, from_scratch: this.createEmpty }); + const jsonBody = JSON.stringify({ + material: materialIds, + supplier: supplierIds, + user_supplier: userSupplierIds, + from_scratch: this.createEmpty + }); console.log(`Creation body: ${jsonBody}`); @@ -36,9 +41,10 @@ export const useAssistantStore = defineStore('assistant', { headers: { 'Content-Type': 'application/json' }, - body: jsonBody}; + body: jsonBody + }; - const request = { url: url, params: params}; + const request = {url: url, params: params}; const response = await fetch(url, params).catch(e => { this.error = {code: 'Network error.', message: "Please check your internet connection.", trace: null} @@ -47,7 +53,7 @@ export const useAssistantStore = defineStore('assistant', { console.error(this.error); const errorStore = useErrorStore(); - void errorStore.addError(this.error, { store: this, request: request}); + void errorStore.addError(this.error, {store: this, request: request}); throw e; }); @@ -63,18 +69,23 @@ export const useAssistantStore = defineStore('assistant', { console.error(this.error); const errorStore = useErrorStore(); - void errorStore.addError(this.error, { store: this, request: request}); + void errorStore.addError(this.error, {store: this, request: request}); throw e; }); if (!response.ok) { - this.error = {code: data.error.code, title: data.error.title, message: data.error.message, trace: data.error.trace }; + this.error = { + code: data.error.code, + title: data.error.title, + message: data.error.message, + trace: data.error.trace + }; this.loading = false; console.error(this.error); const errorStore = useErrorStore(); - void errorStore.addError(this.error, { store: this, request: request}); + void errorStore.addError(this.error, {store: this, request: request}); return; } @@ -83,6 +94,15 @@ export const useAssistantStore = defineStore('assistant', { return data.map(p => p.id); + }, + reset() { + this.materials = []; + this.suppliers = []; + this.createEmpty = false; + this.loading = false; + this.error = null; + this.pagination = {}; + this.query = {}; }, addSupplier(supplier) { const uid = `${supplier.is_user_node ? 'u' : 's'}${supplier.id}` @@ -128,7 +148,7 @@ export const useAssistantStore = defineStore('assistant', { const headers = new Headers(); headers.append('search', encodeURIComponent(query)); - const request = { url: url, params: {method: 'GET'}}; + const request = {url: url, params: {method: 'GET'}}; const response = await fetch(url, { method: 'GET', @@ -139,7 +159,7 @@ export const useAssistantStore = defineStore('assistant', { console.error(this.error); const errorStore = useErrorStore(); - void errorStore.addError(this.error, { store: this, request: request}); + void errorStore.addError(this.error, {store: this, request: request}); throw e; }); @@ -154,18 +174,23 @@ export const useAssistantStore = defineStore('assistant', { console.error(this.error); const errorStore = useErrorStore(); - void errorStore.addError(this.error, { store: this, request: request}); + void errorStore.addError(this.error, {store: this, request: request}); throw e; }); if (!response.ok) { - this.error = {code: data.error.code, title: data.error.title, message: data.error.message, trace: data.error.trace }; + this.error = { + code: data.error.code, + title: data.error.title, + message: data.error.message, + trace: data.error.trace + }; this.loading = false; console.error(this.error); const errorStore = useErrorStore(); - void errorStore.addError(this.error, { store: this, request: request}); + void errorStore.addError(this.error, {store: this, request: request}); return; }