2 <Container id="charging-stations-container">
4 v-show="Array.isArray(uiServerConfigurations) && uiServerConfigurations.length > 1"
5 id="ui-server-container"
8 id="ui-server-selector"
9 v-model="state.uiServerIndex"
13 getFromLocalStorage<number>('uiServerConfigurationIndex', 0) !== state.uiServerIndex
15 app?.appContext.config.globalProperties.$uiClient.setConfiguration(
16 app?.appContext.config.globalProperties.$configuration.uiServer[state.uiServerIndex]
18 initializeWSEventListeners()
19 app?.appContext.config.globalProperties.$uiClient.registerWSEventListener(
22 setToLocalStorage<number>('uiServerConfigurationIndex', state.uiServerIndex)
23 delete app?.appContext.config.globalProperties.$templates
27 app?.appContext.config.globalProperties.$uiClient.registerWSEventListener(
30 state.uiServerIndex = getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
31 app?.appContext.config.globalProperties.$uiClient.setConfiguration(
32 app?.appContext.config.globalProperties.$configuration.uiServer[
33 getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
36 initializeWSEventListeners()
45 v-for="uiServerConfiguration in uiServerConfigurations"
46 :value="uiServerConfiguration.index"
48 {{ uiServerConfiguration.configuration.name ?? uiServerConfiguration.configuration.host }}
52 <Container id="buttons-container">
53 <Button @click="startSimulator()">Start Simulator</Button>
54 <Button @click="stopSimulator()">Stop Simulator</Button>
55 <Button @click="$router.push({ name: 'add-charging-stations' })">
60 :loading="state.loading"
61 @click="loadChargingStations(() => (state.renderChargingStationsList = randomUUID()))"
66 Array.isArray(app?.appContext.config.globalProperties.$chargingStations) &&
67 app?.appContext.config.globalProperties.$chargingStations.length > 0
69 :key="state.renderChargingStationsList"
70 :charging-stations="app?.appContext.config.globalProperties.$chargingStations"
75 <script setup lang="ts">
76 import { getCurrentInstance, onMounted, reactive } from 'vue'
77 import { useToast } from 'vue-toast-notification'
78 import CSTable from '@/components/charging-stations/CSTable.vue'
79 import type { ResponsePayload, UIServerConfigurationSection } from '@/types'
80 import Container from '@/components/Container.vue'
81 import ReloadButton from '@/components/buttons/ReloadButton.vue'
82 import Button from '@/components/buttons/Button.vue'
83 import { getFromLocalStorage, setToLocalStorage } from '@/composables'
85 const randomUUID = (): `${string}-${string}-${string}-${string}-${string}` => {
86 return crypto.randomUUID()
89 const app = getCurrentInstance()
91 const initializeWSEventListeners = () => {
92 app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('open', () => {
93 loadChargingStations(() => (state.renderChargingStationsList = randomUUID()))
95 app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('error', () => {
96 app.appContext.config.globalProperties.$chargingStations = []
97 state.renderChargingStationsList = randomUUID()
99 app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('close', () => {
100 app.appContext.config.globalProperties.$chargingStations = []
101 state.renderChargingStationsList = randomUUID()
106 initializeWSEventListeners()
109 const state = reactive({
110 renderChargingStationsList: randomUUID(),
112 uiServerIndex: getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
115 const uiClient = app?.appContext.config.globalProperties.$uiClient
116 const uiServerConfigurations: { configuration: UIServerConfigurationSection; index: number }[] =
117 app?.appContext.config.globalProperties.$configuration.uiServer.map(
118 (configuration: UIServerConfigurationSection, index: number) => ({
124 const $toast = useToast()
126 const loadChargingStations = (renderCallback?: () => void): void => {
127 if (state.loading === false) {
130 .listChargingStations()
131 .then((response: ResponsePayload) => {
133 app.appContext.config.globalProperties.$chargingStations = response.chargingStations
136 .catch((error: Error) => {
138 app.appContext.config.globalProperties.$chargingStations = []
140 $toast.error('Error at fetching charging stations')
141 console.error('Error at fetching charging stations:', error)
144 if (renderCallback != null) {
147 state.loading = false
152 const startSimulator = (): void => {
156 $toast.success('Simulator successfully started')
158 .catch((error: Error) => {
159 $toast.error('Error at starting simulator')
160 console.error('Error at starting simulator:', error)
163 const stopSimulator = (): void => {
168 app.appContext.config.globalProperties.$chargingStations = []
170 $toast.success('Simulator successfully stopped')
172 .catch((error: Error) => {
173 $toast.error('Error at stopping simulator')
174 console.error('Error at stopping simulator:', error)
180 #charging-stations-container {
184 flex-direction: column;
187 #ui-server-container {
192 #ui-server-selector {
209 background-color: blue;
213 justify-content: center;
216 #reload-button:hover {
217 background-color: rgb(0, 0, 225);
220 #reload-button:active {
221 background-color: red;
226 background-color: black;