2 <Container id="charging-stations-container">
3 <Container id="buttons-container">
5 v-show="Array.isArray(uiServerConfigurations) && uiServerConfigurations.length > 1"
6 id="ui-server-container"
9 id="ui-server-selector"
10 v-model="state.uiServerIndex"
14 getFromLocalStorage<number>('uiServerConfigurationIndex', 0) !== state.uiServerIndex
16 $uiClient.setConfiguration($configuration.value.uiServer[state.uiServerIndex])
17 registerWSEventListeners()
18 $uiClient.registerWSEventListener(
21 setToLocalStorage<number>('uiServerConfigurationIndex', state.uiServerIndex)
23 $router.currentRoute.value.name !== 'charging-stations' &&
24 $router.push({ name: 'charging-stations' })
28 $uiClient.registerWSEventListener(
31 state.uiServerIndex = getFromLocalStorage<number>(
32 'uiServerConfigurationIndex',
35 $uiClient.setConfiguration(
36 $configuration.value.uiServer[
37 getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
40 registerWSEventListeners()
49 v-for="uiServerConfiguration in uiServerConfigurations"
50 :value="uiServerConfiguration.index"
53 uiServerConfiguration.configuration.name ?? uiServerConfiguration.configuration.host
60 :key="state.renderSimulator"
61 :status="state.simulatorState?.started"
62 :on="() => startSimulator()"
63 :off="() => stopSimulator()"
64 :class="simulatorButtonClass"
66 {{ simulatorButtonMessage }}
69 :id="'add-charging-stations'"
70 :key="state.renderAddChargingStations"
74 $router.push({ name: 'add-charging-stations' })
79 $router.push({ name: 'charging-stations' })
84 state.renderChargingStations = randomUUID()
92 :loading="state.gettingChargingStations"
93 @click="getChargingStations()"
97 v-show="Array.isArray($chargingStations.value) && $chargingStations.value.length > 0"
98 :key="state.renderChargingStations"
99 :charging-stations="$chargingStations.value"
102 state.renderAddChargingStations = randomUUID()
103 state.renderChargingStations = randomUUID()
110 <script setup lang="ts">
111 import { computed, getCurrentInstance, onMounted, onUnmounted, ref } from 'vue'
112 import { useToast } from 'vue-toast-notification'
113 import CSTable from '@/components/charging-stations/CSTable.vue'
114 import type { ResponsePayload, SimulatorState, UIServerConfigurationSection } from '@/types'
115 import Container from '@/components/Container.vue'
116 import ReloadButton from '@/components/buttons/ReloadButton.vue'
118 deleteFromLocalStorage,
123 } from '@/composables'
124 import ToggleButton from '@/components/buttons/ToggleButton.vue'
127 renderSimulator: `${string}-${string}-${string}-${string}-${string}`
128 renderAddChargingStations: `${string}-${string}-${string}-${string}-${string}`
129 renderChargingStations: `${string}-${string}-${string}-${string}-${string}`
130 gettingSimulatorState: boolean
131 gettingTemplates: boolean
132 gettingChargingStations: boolean
133 simulatorState?: SimulatorState
134 uiServerIndex: number
136 renderSimulator: randomUUID(),
137 renderAddChargingStations: randomUUID(),
138 renderChargingStations: randomUUID(),
139 gettingSimulatorState: false,
140 gettingTemplates: false,
141 gettingChargingStations: false,
142 uiServerIndex: getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
145 const simulatorButtonClass = computed<string>(() =>
146 state.value.simulatorState?.started === true ? 'simulator-stop-button' : 'simulator-start-button'
148 const simulatorButtonMessage = computed<string>(
150 `${state.value.simulatorState?.started === true ? 'Stop' : 'Start'} Simulator${state.value.simulatorState?.version != null ? ` (${state.value.simulatorState.version})` : ''}`
153 const clearToggleButtons = (): void => {
154 for (const key in getLocalStorage()) {
155 if (key.includes('toggle-button')) {
156 deleteFromLocalStorage(key)
159 state.value.renderChargingStations = randomUUID()
160 state.value.renderAddChargingStations = randomUUID()
163 const app = getCurrentInstance()
165 const clearChargingStations = (): void => {
167 app.appContext.config.globalProperties.$chargingStations.value = []
169 state.value.renderChargingStations = randomUUID()
172 const uiClient = app?.appContext.config.globalProperties.$uiClient
174 const $toast = useToast()
176 const getSimulatorState = (): void => {
177 if (state.value.gettingSimulatorState === false) {
178 state.value.gettingSimulatorState = true
181 .then((response: ResponsePayload) => {
182 state.value.simulatorState = response.state as SimulatorState
184 .catch((error: Error) => {
185 $toast.error('Error at fetching simulator state')
186 console.error('Error at fetching simulator state:', error)
189 state.value.renderSimulator = randomUUID()
190 state.value.gettingSimulatorState = false
195 const getTemplates = (): void => {
196 if (state.value.gettingTemplates === false) {
197 state.value.gettingTemplates = true
200 .then((response: ResponsePayload) => {
202 app.appContext.config.globalProperties.$templates.value = response.templates
205 .catch((error: Error) => {
207 app.appContext.config.globalProperties.$templates.value = []
209 $toast.error('Error at fetching charging station templates')
210 console.error('Error at fetching charging station templates:', error)
213 state.value.gettingTemplates = false
218 const getChargingStations = (): void => {
219 if (state.value.gettingChargingStations === false) {
220 state.value.gettingChargingStations = true
222 .listChargingStations()
223 .then((response: ResponsePayload) => {
225 app.appContext.config.globalProperties.$chargingStations.value = response.chargingStations
228 .catch((error: Error) => {
230 app.appContext.config.globalProperties.$chargingStations.value = []
232 $toast.error('Error at fetching charging stations')
233 console.error('Error at fetching charging stations:', error)
236 state.value.renderChargingStations = randomUUID()
237 state.value.gettingChargingStations = false
242 const getData = (): void => {
245 getChargingStations()
248 const registerWSEventListeners = () => {
249 uiClient.registerWSEventListener('open', getData)
250 uiClient.registerWSEventListener('error', clearChargingStations)
251 uiClient.registerWSEventListener('close', clearChargingStations)
254 const unregisterWSEventListeners = () => {
255 uiClient.unregisterWSEventListener('open', getData)
256 uiClient.unregisterWSEventListener('error', clearChargingStations)
257 uiClient.unregisterWSEventListener('close', clearChargingStations)
261 registerWSEventListeners()
265 unregisterWSEventListeners()
268 const uiServerConfigurations: { index: number; configuration: UIServerConfigurationSection }[] =
269 app?.appContext.config.globalProperties.$configuration.value.uiServer.map(
270 (configuration: UIServerConfigurationSection, index: number) => ({
276 const startSimulator = (): void => {
280 $toast.success('Simulator successfully started')
282 .catch((error: Error) => {
283 $toast.error('Error at starting simulator')
284 console.error('Error at starting simulator:', error)
290 const stopSimulator = (): void => {
295 app.appContext.config.globalProperties.$chargingStations.value = []
297 $toast.success('Simulator successfully stopped')
299 .catch((error: Error) => {
300 $toast.error('Error at stopping simulator')
301 console.error('Error at stopping simulator:', error)
310 #charging-stations-container {
314 flex-direction: column;
317 #ui-server-container {
319 justify-content: center;
320 border-style: outset;
323 #ui-server-selector {
325 background-color: rgb(239, 239, 239);
330 #ui-server-selector:hover {
331 background-color: rgb(229, 229, 229);
339 .simulator-start-button {
341 background-color: green;
344 .simulator-start-button:hover {
345 background-color: rgb(0, 98, 0);
348 .simulator-stop-button {
350 background-color: red;
353 .simulator-stop-button:hover {
354 background-color: rgb(225, 0, 0);
363 background-color: blue;
367 #reload-button:hover {
368 background-color: rgb(0, 0, 225);
371 #reload-button:active {
372 background-color: darkblue;
376 min-width: max-content;
378 background-color: black;