From 0544a3dfde41a1ff063a0eb7a06d237c7216a5f1 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Fri, 5 Dec 2025 14:13:14 +0100 Subject: [PATCH] Add transport and inventory update handling in BranchView component - Implemented socket event listeners for 'transport_arrived' and 'inventory_updated' to manage real-time updates in the BranchView component. - Enhanced event handling logic to refresh vehicle and inventory data based on the selected branch, improving user experience and data accuracy. - Updated the component to ensure proper cleanup of socket listeners on component destruction, maintaining optimal performance. --- frontend/src/views/falukant/BranchView.vue | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/frontend/src/views/falukant/BranchView.vue b/frontend/src/views/falukant/BranchView.vue index d38b974..f0bf722 100644 --- a/frontend/src/views/falukant/BranchView.vue +++ b/frontend/src/views/falukant/BranchView.vue @@ -283,6 +283,8 @@ export default { if (this.socket) { this.socket.on('falukantUpdateStatus', (data) => this.handleEvent({ event: 'falukantUpdateStatus', ...data })); this.socket.on('falukantBranchUpdate', (data) => this.handleEvent({ event: 'falukantBranchUpdate', ...data })); + this.socket.on('transport_arrived', (data) => this.handleEvent({ event: 'transport_arrived', ...data })); + this.socket.on('inventory_updated', (data) => this.handleEvent({ event: 'inventory_updated', ...data })); } }, @@ -294,6 +296,8 @@ export default { if (this.socket) { this.socket.off('falukantUpdateStatus'); this.socket.off('falukantBranchUpdate'); + this.socket.off('transport_arrived'); + this.socket.off('inventory_updated'); } }, @@ -549,6 +553,40 @@ export default { this.$refs.revenueSection.refresh && this.$refs.revenueSection.refresh(); } break; + case 'transport_arrived': + // Leerer Transport angekommen - Fahrzeug wurde zurückgeholt + if (eventData.empty && eventData.branch_id) { + // Nur aktualisieren, wenn der betroffene Branch ausgewählt ist + if (this.selectedBranch && this.selectedBranch.id === eventData.branch_id) { + // Fahrzeuge im Transport-Tab aktualisieren + this.loadVehicles(); + // Laufende Transporte im Inventar-Tab aktualisieren + if (this.$refs.saleSection) { + this.$refs.saleSection.loadTransports(); + } + } + } + break; + case 'inventory_updated': + // Inventar wurde aktualisiert (durch Transporte) + if (eventData.branch_id) { + // Nur aktualisieren, wenn der betroffene Branch ausgewählt ist + if (this.selectedBranch && this.selectedBranch.id === eventData.branch_id) { + // Inventar im Inventar-Tab aktualisieren + if (this.$refs.saleSection) { + this.$refs.saleSection.loadInventory(); + this.$refs.saleSection.loadTransports(); + } + // Lager aktualisieren + if (this.$refs.storageSection) { + this.$refs.storageSection.loadStorageData(); + } + if (this.$refs.productionSection) { + this.$refs.productionSection.loadStorage(); + } + } + } + break; default: console.log('Unhandled event:', eventData); }