X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=ui%2Fweb%2Fsrc%2Fmain.ts;h=a39c049ba99052c4e48a2898fe3039508f1aab15;hb=276e05aec38f4e8b4a8d5ebd8cbbcb30592b414d;hp=f3c9ef036f6fb46445aa2f06f0c482d632e4e1cc;hpb=0344ad2b24f8b043b5848a0fea8b5a120d6781db;p=e-mobility-charging-stations-simulator.git diff --git a/ui/web/src/main.ts b/ui/web/src/main.ts index f3c9ef03..a39c049b 100644 --- a/ui/web/src/main.ts +++ b/ui/web/src/main.ts @@ -1,10 +1,12 @@ -import { type App as AppType, createApp } from 'vue' +import 'vue-toast-notification/dist/theme-bootstrap.css' + +import { type App as AppType, createApp, ref } from 'vue' import ToastPlugin from 'vue-toast-notification' -import type { ConfigurationData, ResponsePayload } from '@/types' -import { router } from '@/router' -import { UIClient, getFromLocalStorage, setToLocalStorage } from '@/composables' + import App from '@/App.vue' -import 'vue-toast-notification/dist/theme-bootstrap.css' +import { getFromLocalStorage, setToLocalStorage, UIClient } from '@/composables' +import { router } from '@/router' +import type { ChargingStationData, ConfigurationData, UIServerConfigurationSection } from '@/types' const app = createApp(App) @@ -19,39 +21,31 @@ const initializeApp = (app: AppType, config: ConfigurationData) => { config.uiServer = [config.uiServer] } if (app.config.globalProperties.$configuration == null) { - app.config.globalProperties.$configuration = config + app.config.globalProperties.$configuration = ref(config) + } + if (!Array.isArray(app.config.globalProperties.$templates?.value)) { + app.config.globalProperties.$templates = ref([]) } - if (!Array.isArray(app.config.globalProperties.$chargingStations)) { - app.config.globalProperties.$chargingStations = [] + if (!Array.isArray(app.config.globalProperties.$chargingStations?.value)) { + app.config.globalProperties.$chargingStations = ref([]) } if ( getFromLocalStorage('uiServerConfigurationIndex', undefined) == null || getFromLocalStorage('uiServerConfigurationIndex', 0) > - app.config.globalProperties.$configuration.uiServer.length - 1 + (app.config.globalProperties.$configuration.value.uiServer as UIServerConfigurationSection[]) + .length - + 1 ) { setToLocalStorage('uiServerConfigurationIndex', 0) } if (app.config.globalProperties.$uiClient == null) { app.config.globalProperties.$uiClient = UIClient.getInstance( - app.config.globalProperties.$configuration.uiServer[ + (app.config.globalProperties.$configuration.value.uiServer as UIServerConfigurationSection[])[ getFromLocalStorage('uiServerConfigurationIndex', 0) ] ) - app.config.globalProperties.$uiClient.registerWSEventListener('open', () => { - app.config.globalProperties.$uiClient - .listChargingStations() - .then((response: ResponsePayload) => { - app.config.globalProperties.$chargingStations = response.chargingStations - }) - .catch((error: Error) => { - // TODO: add code for UI notifications or other error handling logic - console.error('Error at fetching charging stations:', error) - }) - .finally(() => { - app.use(router).use(ToastPlugin).mount('#app') - }) - }) } + app.use(router).use(ToastPlugin).mount('#app') } fetch('/config.json') @@ -64,12 +58,7 @@ fetch('/config.json') response .json() .then(config => { - try { - initializeApp(app, config) - } catch (error) { - // TODO: add code for UI notifications or other error handling logic - console.error('Error at initializing app:', error) - } + initializeApp(app, config) }) .catch(error => { // TODO: add code for UI notifications or other error handling logic