From: Jérôme Benoit Date: Sun, 18 Feb 2024 14:36:11 +0000 (+0100) Subject: refactor(ui): cleanup casing style X-Git-Tag: v1.2.37~11 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f292861c82c819c87719364485f5bba141eb51fa;p=e-mobility-charging-stations-simulator.git refactor(ui): cleanup casing style Signed-off-by: Jérôme Benoit --- diff --git a/ui/web/src/components/charging-stations/CSData.vue b/ui/web/src/components/charging-stations/CSData.vue index 300cfa44..b8fb0662 100644 --- a/ui/web/src/components/charging-stations/CSData.vue +++ b/ui/web/src/components/charging-stations/CSData.vue @@ -7,7 +7,7 @@ {{ getSupervisionUrl() }} - {{ getWsState() }} + {{ getWSState() }} {{ props.chargingStation?.bootNotificationResponse?.status ?? 'Ø' }} @@ -98,7 +98,7 @@ const getSupervisionUrl = (): string => { const supervisionUrl = new URL(props.chargingStation.supervisionUrl) return `${supervisionUrl.protocol}//${supervisionUrl.host.split('.').join('.\u200b')}` } -const getWsState = (): string => { +const getWSState = (): string => { switch (props.chargingStation?.wsState) { case WebSocket.CONNECTING: return 'Connecting' diff --git a/ui/web/src/composables/UIClient.ts b/ui/web/src/composables/UIClient.ts index ce459f1b..81a322d3 100644 --- a/ui/web/src/composables/UIClient.ts +++ b/ui/web/src/composables/UIClient.ts @@ -1,12 +1,12 @@ import { ApplicationProtocol, AuthenticationType, - type ConfigurationData, ProcedureName, type ProtocolResponse, type RequestPayload, type ResponsePayload, - ResponseStatus + ResponseStatus, + type UIServerConfigurationSection } from '@/types' type ResponseHandler = { @@ -16,21 +16,26 @@ type ResponseHandler = { } export class UIClient { - private static instance: UIClient | null = null + private static readonly instances: Map = new Map() private ws!: WebSocket private responseHandlers: Map - private constructor(private configuration: ConfigurationData) { + private constructor(private uiServerConfiguration: UIServerConfigurationSection) { this.openWS() this.responseHandlers = new Map() } - public static getInstance(configuration: ConfigurationData) { - if (UIClient.instance === null) { - UIClient.instance = new UIClient(configuration) + public static getInstance( + serverId: number, + uiServerConfiguration?: UIServerConfigurationSection + ): UIClient { + if (!UIClient.instances.has(serverId) && uiServerConfiguration != null) { + UIClient.instances.set(serverId, new UIClient(uiServerConfiguration)) + } else if (!UIClient.instances.has(serverId)) { + throw new Error(`UI client instance not found for server id: ${serverId}`) } - return UIClient.instance + return UIClient.instances.get(serverId)! } public registerWSEventListener( @@ -138,15 +143,15 @@ export class UIClient { private openWS(): void { const protocols = - this.configuration.uiServer.authentication?.enabled === true && - this.configuration.uiServer.authentication?.type === AuthenticationType.PROTOCOL_BASIC_AUTH + this.uiServerConfiguration.authentication?.enabled === true && + this.uiServerConfiguration.authentication?.type === AuthenticationType.PROTOCOL_BASIC_AUTH ? [ - `${this.configuration.uiServer.protocol}${this.configuration.uiServer.version}`, - `authorization.basic.${btoa(`${this.configuration.uiServer.authentication.username}:${this.configuration.uiServer.authentication.password}`).replace(/={1,2}$/, '')}` + `${this.uiServerConfiguration.protocol}${this.uiServerConfiguration.version}`, + `authorization.basic.${btoa(`${this.uiServerConfiguration.authentication.username}:${this.uiServerConfiguration.authentication.password}`).replace(/={1,2}$/, '')}` ] - : `${this.configuration.uiServer.protocol}${this.configuration.uiServer.version}` + : `${this.uiServerConfiguration.protocol}${this.uiServerConfiguration.version}` this.ws = new WebSocket( - `${this.configuration.uiServer.secure === true ? ApplicationProtocol.WSS : ApplicationProtocol.WS}://${this.configuration.uiServer.host}:${this.configuration.uiServer.port}`, + `${this.uiServerConfiguration.secure === true ? ApplicationProtocol.WSS : ApplicationProtocol.WS}://${this.uiServerConfiguration.host}:${this.uiServerConfiguration.port}`, protocols ) this.ws.onopen = openEvent => { diff --git a/ui/web/src/main.ts b/ui/web/src/main.ts index bb42f576..8c993f79 100644 --- a/ui/web/src/main.ts +++ b/ui/web/src/main.ts @@ -14,7 +14,10 @@ const initializeApp = (config: ConfigurationData) => { console.info('Error info:', info) // TODO: add code for UI notifications or other error handling logic } - app.config.globalProperties.$uiClient = UIClient.getInstance(config) + if (Array.isArray(config.uiServer)) { + throw new Error('Multiple UI server configurations is not yet supported') + } + app.config.globalProperties.$uiClient = UIClient.getInstance(0, config.uiServer) app.config.globalProperties.$uiClient.registerWSEventListener('open', () => { app.config.globalProperties.$uiClient .listChargingStations() diff --git a/ui/web/src/types/ConfigurationType.ts b/ui/web/src/types/ConfigurationType.ts index 93cfe86e..51bd2138 100644 --- a/ui/web/src/types/ConfigurationType.ts +++ b/ui/web/src/types/ConfigurationType.ts @@ -1,10 +1,10 @@ import type { AuthenticationType, Protocol, ProtocolVersion } from './UIProtocol' export type ConfigurationData = { - uiServer: UIServerConfigurationSection + uiServer: UIServerConfigurationSection | UIServerConfigurationSection[] } -type UIServerConfigurationSection = { +export type UIServerConfigurationSection = { host: string port: number secure?: boolean diff --git a/ui/web/src/types/index.ts b/ui/web/src/types/index.ts index 3e38d5c2..596cc933 100644 --- a/ui/web/src/types/index.ts +++ b/ui/web/src/types/index.ts @@ -4,7 +4,7 @@ export type { ConnectorStatus, Status } from './ChargingStationType' -export type { ConfigurationData } from './ConfigurationType' +export type { ConfigurationData, UIServerConfigurationSection } from './ConfigurationType' export { ApplicationProtocol, AuthenticationType,