Refactor trigger creation logic: Update the created_at and updated_at fields to use the election date instead of the current timestamp, ensuring accurate term end calculations. Enhance socket event handling in StatusBar component by implementing setup and teardown methods for improved event management and user notifications.
This commit is contained in:
@@ -64,6 +64,17 @@ export default {
|
||||
this.preloadQuickAccessImages();
|
||||
},
|
||||
deep: true
|
||||
},
|
||||
socket(newVal, oldVal) {
|
||||
if (oldVal) this.teardownSocketListeners();
|
||||
if (newVal) this.setupSocketListeners();
|
||||
},
|
||||
daemonSocket(newVal, oldVal) {
|
||||
if (oldVal && this._daemonHandler) {
|
||||
oldVal.removeEventListener('message', this._daemonHandler);
|
||||
this._daemonHandler = null;
|
||||
}
|
||||
if (newVal) this.setupDaemonListeners();
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
@@ -72,24 +83,13 @@ export default {
|
||||
// Bilder für Schnellzugriff vorladen und cachen
|
||||
this.preloadQuickAccessImages();
|
||||
|
||||
// Live-Socket-Events
|
||||
["falukantUpdateStatus", "stock_change", "familychanged"].forEach(eventName => {
|
||||
if (this.daemonSocket) {
|
||||
this.daemonSocket.addEventListener('message', (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.event === eventName) {
|
||||
this.handleEvent(data);
|
||||
}
|
||||
} catch (error) {
|
||||
// Ignore non-JSON messages like ping/pong
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// Socket.IO (Backend notifyUser) – Hauptkanal für Falukant-Events
|
||||
this.setupSocketListeners();
|
||||
this.setupDaemonListeners();
|
||||
},
|
||||
beforeUnmount() {
|
||||
// Daemon WebSocket wird automatisch beim Logout geschlossen
|
||||
this.teardownSocketListeners();
|
||||
this.teardownDaemonListeners();
|
||||
},
|
||||
methods: {
|
||||
preloadQuickAccessImages() {
|
||||
@@ -155,6 +155,40 @@ export default {
|
||||
// Error fetching status
|
||||
}
|
||||
},
|
||||
setupSocketListeners() {
|
||||
this.teardownSocketListeners();
|
||||
if (!this.socket) return;
|
||||
this.socket.on('falukantUpdateStatus', (data) => this.handleEvent({ event: 'falukantUpdateStatus', ...data }));
|
||||
this.socket.on('stock_change', (data) => this.handleEvent({ event: 'stock_change', ...data }));
|
||||
this.socket.on('familychanged', (data) => this.handleEvent({ event: 'familychanged', ...data }));
|
||||
},
|
||||
teardownSocketListeners() {
|
||||
if (this.socket) {
|
||||
this.socket.off('falukantUpdateStatus');
|
||||
this.socket.off('stock_change');
|
||||
this.socket.off('familychanged');
|
||||
}
|
||||
},
|
||||
setupDaemonListeners() {
|
||||
this.teardownDaemonListeners();
|
||||
if (!this.daemonSocket) return;
|
||||
this._daemonHandler = (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
if (['falukantUpdateStatus', 'stock_change', 'familychanged'].includes(data.event)) {
|
||||
this.handleEvent(data);
|
||||
}
|
||||
} catch (_) {}
|
||||
};
|
||||
this.daemonSocket.addEventListener('message', this._daemonHandler);
|
||||
},
|
||||
teardownDaemonListeners() {
|
||||
const sock = this.daemonSocket;
|
||||
if (sock && this._daemonHandler) {
|
||||
sock.removeEventListener('message', this._daemonHandler);
|
||||
this._daemonHandler = null;
|
||||
}
|
||||
},
|
||||
handleEvent(eventData) {
|
||||
switch (eventData.event) {
|
||||
case 'falukantUpdateStatus':
|
||||
|
||||
Reference in New Issue
Block a user