diff --git a/src/frontend/src/pages/CalculationMassEdit.vue b/src/frontend/src/pages/CalculationMassEdit.vue index e63fe54..9e5cf82 100644 --- a/src/frontend/src/pages/CalculationMassEdit.vue +++ b/src/frontend/src/pages/CalculationMassEdit.vue @@ -267,7 +267,7 @@ export default { return this.premiseEditStore.showProcessingModal || this.destinationEditStore.showProcessingModal; }, shownProcessingMessage() { - if(this.premiseEditStore.showProcessingModal) + if (this.premiseEditStore.showProcessingModal) return "Please wait. Prepare calculation ..." return this.processingMessage; @@ -444,6 +444,7 @@ export default { async closeEditModalAction(action) { let massUpdate = false; + let success = true; if (this.modalType === 'amount' || this.modalType === 'routes' || this.modalType === "destinations") { @@ -453,18 +454,21 @@ export default { const setMatrix = this.$refs.modalComponent?.destMatrix; if (setMatrix) { - await this.destinationEditStore.massSetDestinations(setMatrix); + success = await this.destinationEditStore.massSetDestinations(setMatrix); } } else { massUpdate = true } } - // Clear data - this.fillData(this.modalType); - this.modalType = null; - if(massUpdate) { + if (success) { + // Clear data + this.fillData(this.modalType); + this.modalType = null; + } else return; + + if (massUpdate) { await this.destinationEditStore.massUpdateDestinations(this.editIds); } diff --git a/src/frontend/src/store/destinationEdit.js b/src/frontend/src/store/destinationEdit.js index e15fc31..eb160a8 100644 --- a/src/frontend/src/store/destinationEdit.js +++ b/src/frontend/src/store/destinationEdit.js @@ -1,6 +1,8 @@ import {defineStore} from 'pinia' import performRequest from "@/backend.js"; import {config} from '@/config' +import logger from "@/logger.js"; +import {useNotificationStore} from "@/store/notification.js"; export const useDestinationEditStore = defineStore('destinationEdit', { state: () => ({ @@ -83,30 +85,44 @@ export const useDestinationEditStore = defineStore('destinationEdit', { async massSetDestinations(updateMatrix) { this.loading = true; - const toBeAdded = {}; - const toBeDeletedMap = new Map(); + try { - updateMatrix.forEach(row => { - toBeAdded[row.id] = row.destinations.filter(d => d.selected).map(d => d.id); - toBeDeletedMap.set(row.id, row.destinations.filter(d => !d.selected).map(d => d.id)); - }); + const toBeAdded = {}; + const toBeDeletedMap = new Map(); - const url = `${config.backendUrl}/calculation/destination`; - const { - data: data, - headers: headers - } = await performRequest(this, 'POST', url, {'destination_node_ids': toBeAdded}); + updateMatrix.forEach(row => { + toBeAdded[row.id] = row.destinations.filter(d => d.selected).map(d => d.id); + toBeDeletedMap.set(row.id, row.destinations.filter(d => !d.selected).map(d => d.id)); + }); - this.destinations.forEach((destinations, premiseId) => { - const toBeDeleted = toBeDeletedMap.get(premiseId); + const url = `${config.backendUrl}/calculation/destination`; + const { + data: data, + headers: headers + } = await performRequest(this, 'POST', url, {'destination_node_ids': toBeAdded}); - const filtered = destinations !== null ? destinations.filter(d => !toBeDeleted?.includes(d.destination_node.id)) : []; + this.destinations.forEach((destinations, premiseId) => { + const toBeDeleted = toBeDeletedMap.get(premiseId); - this.destinations.set(premiseId, [...filtered, ...data[premiseId]]); - }); + const filtered = destinations !== null ? destinations.filter(d => !toBeDeleted?.includes(d.destination_node.id)) : []; + this.destinations.set(premiseId, [...filtered, ...data[premiseId]]); + }); - this.loading = false; + } catch (error) { + logger.error('Error in massSetDestinations:', error); + useNotificationStore().addNotification({ + title: 'Unable to set destinations', + message: error.message ?? error.toString(), + variant: 'exception', + icon: 'bug', + }) + return false; + } finally { + this.loading = false; + } + + return true; }, async massUpdateDestinations(premiseIds) { this.loading = true;