From: Jérôme Benoit Date: Tue, 20 Feb 2024 16:37:38 +0000 (+0100) Subject: fix: clear UI server cache at simulator stop X-Git-Tag: v1.2.38~69 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5c0e9352ee4e933387ae3a20ac814bda7e43b72a;p=e-mobility-charging-stations-simulator.git fix: clear UI server cache at simulator stop Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 3993ae1f..5ee1f2c0 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -261,6 +261,7 @@ export class Bootstrap extends EventEmitter { await this.workerImplementation?.stop() delete this.workerImplementation this.removeAllListeners() + this.uiServer?.chargingStations.clear() await this.storage?.close() delete this.storage this.started = false diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 11098648..4ee9ff67 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1832,6 +1832,7 @@ export class ChargingStation extends EventEmitter { private async onOpen (): Promise { if (this.isWebSocketConnectionOpened()) { + this.emit(ChargingStationEvents.updated) logger.info( `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.href} succeeded` ) @@ -1894,6 +1895,7 @@ export class ChargingStation extends EventEmitter { private onClose (code: WebSocketCloseEventStatusCode, reason: Buffer): void { this.emit(ChargingStationEvents.disconnected) + this.emit(ChargingStationEvents.updated) switch (code) { // Normal close case WebSocketCloseEventStatusCode.CLOSE_NORMAL: @@ -1913,12 +1915,13 @@ export class ChargingStation extends EventEmitter { )}' and reason '${reason.toString()}'` ) this.started && - this.reconnect().catch(error => - logger.error(`${this.logPrefix()} Error while reconnecting:`, error) - ) + this.reconnect() + .then(() => { + this.emit(ChargingStationEvents.updated) + }) + .catch(error => logger.error(`${this.logPrefix()} Error while reconnecting:`, error)) break } - this.emit(ChargingStationEvents.updated) } private getCachedRequest ( diff --git a/src/charging-station/ui-server/AbstractUIServer.ts b/src/charging-station/ui-server/AbstractUIServer.ts index b17dec30..e24a5769 100644 --- a/src/charging-station/ui-server/AbstractUIServer.ts +++ b/src/charging-station/ui-server/AbstractUIServer.ts @@ -63,6 +63,10 @@ export abstract class AbstractUIServer { for (const uiService of this.uiServices.values()) { uiService.stop() } + this.clearCaches() + } + + private clearCaches (): void { this.chargingStations.clear() this.chargingStationTemplates.clear() } diff --git a/ui/web/src/views/ChargingStationsView.vue b/ui/web/src/views/ChargingStationsView.vue index 8df77d92..50851055 100644 --- a/ui/web/src/views/ChargingStationsView.vue +++ b/ui/web/src/views/ChargingStationsView.vue @@ -12,7 +12,13 @@ @click="loadChargingStations(() => $router.go(0))" /> - + @@ -72,6 +78,9 @@ const stopSimulator = (): void => { uiClient .stopSimulator() .then(() => { + if (app != null) { + app.appContext.config.globalProperties.$chargingStations = [] + } $toast.success('Simulator successfully stopped') }) .catch((error: Error) => { @@ -85,6 +94,7 @@ const stopSimulator = (): void => { #charging-stations-container { height: fit-content; width: 100%; + position: absolute; display: flex; flex-direction: column; }