+const getSimulatorState = (): void => {
+ uiClient
+ .simulatorState()
+ .then((response: ResponsePayload) => {
+ state.value.simulatorState = response.state as { started: boolean }
+ })
+ .catch((error: Error) => {
+ $toast.error('Error at fetching simulator state')
+ console.error('Error at fetching simulator state:', error)
+ })
+ .finally(() => {
+ state.value.renderSimulator = randomUUID()
+ })
+}
+
+const initializeWSEventListeners = () => {
+ app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('open', () => {
+ getSimulatorState()
+ uiClient
+ .listTemplates()
+ .then((response: ResponsePayload) => {
+ if (app != null) {
+ app.appContext.config.globalProperties.$templates = response.templates
+ }
+ })
+ .catch((error: Error) => {
+ if (app != null) {
+ app.appContext.config.globalProperties.$templates = []
+ }
+ $toast.error('Error at fetching charging station templates')
+ console.error('Error at fetching charging station templates:', error)
+ })
+ .finally(() => {
+ state.value.renderAddChargingStations = randomUUID()
+ })
+ loadChargingStations(() => {
+ state.value.renderChargingStations = randomUUID()
+ })
+ })
+ app?.appContext.config.globalProperties.$uiClient.registerWSEventListener(
+ 'error',
+ clearChargingStations
+ )
+ app?.appContext.config.globalProperties.$uiClient.registerWSEventListener(
+ 'close',
+ clearChargingStations
+ )
+}
+
+onMounted(() => {
+ initializeWSEventListeners()
+})
+
+const uiServerConfigurations: { configuration: UIServerConfigurationSection; index: number }[] =
+ app?.appContext.config.globalProperties.$configuration.uiServer.map(
+ (configuration: UIServerConfigurationSection, index: number) => ({
+ configuration,
+ index
+ })
+ )
+
+const $toast = useToast()
+
+const loadChargingStations = (renderCallback?: () => void): void => {
+ if (state.value.loading === false) {
+ state.value.loading = true