From: Jérôme Benoit Date: Sat, 17 Feb 2024 13:12:24 +0000 (+0100) Subject: refactor(ui): cleanup vue.js app initialization code and logic X-Git-Tag: v1.2.37~32 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a64b9a64f0cb3b2b9b07ec38ec4001dcc7024a60;p=e-mobility-charging-stations-simulator.git refactor(ui): cleanup vue.js app initialization code and logic Signed-off-by: Jérôme Benoit --- diff --git a/ui/web/src/App.vue b/ui/web/src/App.vue index 203fb47f..b3fc6d1c 100644 --- a/ui/web/src/App.vue +++ b/ui/web/src/App.vue @@ -16,7 +16,7 @@ body { height: fit-content; width: fit-content; - margin: 0.001%; - padding: 0.001%; + margin: 0.005%; + padding: 0.005%; } diff --git a/ui/web/src/components/charging-stations/CSData.vue b/ui/web/src/components/charging-stations/CSData.vue index c0f07792..b11ad0fe 100644 --- a/ui/web/src/components/charging-stations/CSData.vue +++ b/ui/web/src/components/charging-stations/CSData.vue @@ -22,6 +22,7 @@ + @@ -147,6 +148,9 @@ function openConnection(): void { function closeConnection(): void { UIClient.closeConnection(getHashId()) } +function deleteChargingStation(): void { + UIClient.deleteChargingStation(getHashId()) +} // function showTagModal(): void { // state.isTagModalVisible = true // } @@ -172,7 +176,6 @@ function closeConnection(): void { } .connectors-table__row { - min-height: 4rem; display: flex; justify-content: center; align-items: center; diff --git a/ui/web/src/composables/UIClient.ts b/ui/web/src/composables/UIClient.ts index 4e7fb249..572dc5d4 100644 --- a/ui/web/src/composables/UIClient.ts +++ b/ui/web/src/composables/UIClient.ts @@ -45,6 +45,10 @@ export class UIClient { return this.sendRequest(ProcedureName.STOP_SIMULATOR, {}) } + public async deleteChargingStation(hashId: string): Promise { + return this.sendRequest(ProcedureName.DELETE_CHARGING_STATIONS, { hashIds: [hashId] }) + } + public async listChargingStations(): Promise { return this.sendRequest(ProcedureName.LIST_CHARGING_STATIONS, {}) } @@ -111,7 +115,7 @@ export class UIClient { }) } - private openWS(): void { + public openWS(): void { const protocols = this.configuration.uiServer.authentication?.enabled === true && this.configuration.uiServer.authentication?.type === AuthenticationType.PROTOCOL_BASIC_AUTH @@ -141,9 +145,6 @@ export class UIClient { payload: RequestPayload ): Promise { return new Promise((resolve, reject) => { - if (this.ws.readyState !== WebSocket.OPEN) { - this.openWS() - } if (this.ws.readyState === WebSocket.OPEN) { const uuid = crypto.randomUUID() const msg = JSON.stringify([uuid, procedureName, payload]) diff --git a/ui/web/src/main.ts b/ui/web/src/main.ts index ac9c9e82..1c213741 100644 --- a/ui/web/src/main.ts +++ b/ui/web/src/main.ts @@ -1,19 +1,31 @@ import { createApp } from 'vue' +import type { ConfigurationData } from './types' import router from '@/router' import { UIClient } from '@/composables' import App from '@/App.vue' -const app = createApp(App) +const initializeApp = async (config: ConfigurationData) => { + const app = createApp(App) + app.config.errorHandler = (error, instance, info) => { + console.error('Error:', error) + console.info('Vue instance:', instance) + console.info('Error info:', info) + // TODO: Add code for UI notifications or other error handling logic + } + app.config.globalProperties.$UIClient = UIClient.getInstance(config) + app.config.globalProperties.$UIClient.openWS() + app.use(router).mount('#app') +} fetch('/config.json') .then(response => response.json()) + .catch(error => { + console.error('Error at fetching app configuration:', error) + throw error + }) .then(config => { - app.config.errorHandler = (error, instance, info) => { - console.error('Error:', error) - console.info('Vue instance:', instance) - console.info('Error info:', info) - // TODO: Add code for UI notifications or other error handling logic - } - app.config.globalProperties.$UIClient = UIClient.getInstance(config) - app.use(router).mount('#app') + initializeApp(config) + }) + .catch(error => { + console.error('Error at initializing app:', error) }) diff --git a/ui/web/src/types/UIProtocol.ts b/ui/web/src/types/UIProtocol.ts index 6883cf8b..a431540b 100644 --- a/ui/web/src/types/UIProtocol.ts +++ b/ui/web/src/types/UIProtocol.ts @@ -27,6 +27,7 @@ export type ProtocolRequestHandler = ( export enum ProcedureName { START_SIMULATOR = 'startSimulator', STOP_SIMULATOR = 'stopSimulator', + DELETE_CHARGING_STATIONS = 'deleteChargingStations', LIST_CHARGING_STATIONS = 'listChargingStations', START_CHARGING_STATION = 'startChargingStation', STOP_CHARGING_STATION = 'stopChargingStation',