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(
17 ($configuration.value.uiServer as UIServerConfigurationSection[])[
21 registerWSEventListeners()
22 $uiClient.registerWSEventListener(
25 setToLocalStorage<number>('uiServerConfigurationIndex', state.uiServerIndex)
27 $route.name !== 'charging-stations' &&
28 $router.push({ name: 'charging-stations' })
32 $uiClient.registerWSEventListener(
35 state.uiServerIndex = getFromLocalStorage<number>(
36 'uiServerConfigurationIndex',
39 $uiClient.setConfiguration(
40 ($configuration.value.uiServer as UIServerConfigurationSection[])[
41 getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
44 registerWSEventListeners()
53 v-for="uiServerConfiguration in uiServerConfigurations"
54 :value="uiServerConfiguration.index"
57 uiServerConfiguration.configuration.name ?? uiServerConfiguration.configuration.host
64 :key="state.renderSimulator"
65 :status="simulatorState?.started"
66 :on="() => startSimulator()"
67 :off="() => stopSimulator()"
68 :class="simulatorButtonClass"
70 {{ simulatorButtonMessage }}
73 :id="'add-charging-stations'"
74 :key="state.renderAddChargingStations"
78 $router.push({ name: 'add-charging-stations' })
83 $router.push({ name: 'charging-stations' })
88 state.renderChargingStations = randomUUID()
96 :loading="state.gettingChargingStations"
97 @click="getChargingStations()"
101 v-show="Array.isArray($chargingStations.value) && $chargingStations.value.length > 0"
102 :key="state.renderChargingStations"
103 :charging-stations="$chargingStations.value"
106 state.renderAddChargingStations = randomUUID()
107 state.renderChargingStations = randomUUID()
114 <script setup lang="ts">
115 import { computed, getCurrentInstance, onMounted, onUnmounted, ref, watch } from 'vue'
116 import { useToast } from 'vue-toast-notification'
117 import CSTable from '@/components/charging-stations/CSTable.vue'
122 UIServerConfigurationSection
124 import Container from '@/components/Container.vue'
125 import ReloadButton from '@/components/buttons/ReloadButton.vue'
127 deleteFromLocalStorage,
133 } from '@/composables'
134 import ToggleButton from '@/components/buttons/ToggleButton.vue'
136 const simulatorState = ref<SimulatorState | undefined>(undefined)
138 const simulatorButtonClass = computed<string>(() =>
139 simulatorState.value?.started === true ? 'simulator-stop-button' : 'simulator-start-button'
141 const simulatorButtonMessage = computed<string>(
143 `${simulatorState.value?.started === true ? 'Stop' : 'Start'} Simulator${simulatorState.value?.version != null ? ` (${simulatorState.value.version})` : ''}`
147 renderSimulator: `${string}-${string}-${string}-${string}-${string}`
148 renderAddChargingStations: `${string}-${string}-${string}-${string}-${string}`
149 renderChargingStations: `${string}-${string}-${string}-${string}-${string}`
150 gettingSimulatorState: boolean
151 gettingTemplates: boolean
152 gettingChargingStations: boolean
153 uiServerIndex: number
155 renderSimulator: randomUUID(),
156 renderAddChargingStations: randomUUID(),
157 renderChargingStations: randomUUID(),
158 gettingSimulatorState: false,
159 gettingTemplates: false,
160 gettingChargingStations: false,
161 uiServerIndex: getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
164 const clearToggleButtons = (): void => {
165 for (const key in getLocalStorage()) {
166 if (key.includes('toggle-button')) {
167 deleteFromLocalStorage(key)
170 state.value.renderChargingStations = randomUUID()
171 state.value.renderAddChargingStations = randomUUID()
174 const app = getCurrentInstance()
176 watch(app!.appContext.config.globalProperties.$chargingStations, () => {
177 state.value.renderChargingStations = randomUUID()
180 watch(simulatorState, () => {
181 state.value.renderSimulator = randomUUID()
184 const clearTemplates = (): void => {
186 app.appContext.config.globalProperties.$templates.value = []
190 const clearChargingStations = (): void => {
192 app.appContext.config.globalProperties.$chargingStations.value = []
196 const uiClient = useUIClient()
198 const $toast = useToast()
200 const getSimulatorState = (): void => {
201 if (state.value.gettingSimulatorState === false) {
202 state.value.gettingSimulatorState = true
205 .then((response: ResponsePayload) => {
206 simulatorState.value = response.state as SimulatorState
208 .catch((error: Error) => {
209 $toast.error('Error at fetching simulator state')
210 console.error('Error at fetching simulator state:', error)
213 state.value.gettingSimulatorState = false
218 const getTemplates = (): void => {
219 if (state.value.gettingTemplates === false) {
220 state.value.gettingTemplates = true
223 .then((response: ResponsePayload) => {
225 app.appContext.config.globalProperties.$templates.value = response.templates as string[]
228 .catch((error: Error) => {
230 $toast.error('Error at fetching charging station templates')
231 console.error('Error at fetching charging station templates:', error)
234 state.value.gettingTemplates = false
239 const getChargingStations = (): void => {
240 if (state.value.gettingChargingStations === false) {
241 state.value.gettingChargingStations = true
243 .listChargingStations()
244 .then((response: ResponsePayload) => {
246 app.appContext.config.globalProperties.$chargingStations.value =
247 response.chargingStations as ChargingStationData[]
250 .catch((error: Error) => {
251 clearChargingStations()
252 $toast.error('Error at fetching charging stations')
253 console.error('Error at fetching charging stations:', error)
256 state.value.gettingChargingStations = false
261 const getData = (): void => {
264 getChargingStations()
267 const registerWSEventListeners = () => {
268 uiClient.registerWSEventListener('open', getData)
269 uiClient.registerWSEventListener('error', clearChargingStations)
270 uiClient.registerWSEventListener('close', clearChargingStations)
273 const unregisterWSEventListeners = () => {
274 uiClient.unregisterWSEventListener('open', getData)
275 uiClient.unregisterWSEventListener('error', clearChargingStations)
276 uiClient.unregisterWSEventListener('close', clearChargingStations)
280 registerWSEventListeners()
284 unregisterWSEventListeners()
287 const uiServerConfigurations: { index: number; configuration: UIServerConfigurationSection }[] = (
288 app?.appContext.config.globalProperties.$configuration.value
289 .uiServer as UIServerConfigurationSection[]
290 ).map((configuration: UIServerConfigurationSection, index: number) => ({
295 const startSimulator = (): void => {
299 $toast.success('Simulator successfully started')
301 .catch((error: Error) => {
302 $toast.error('Error at starting simulator')
303 console.error('Error at starting simulator:', error)
309 const stopSimulator = (): void => {
313 clearChargingStations()
314 $toast.success('Simulator successfully stopped')
316 .catch((error: Error) => {
317 $toast.error('Error at stopping simulator')
318 console.error('Error at stopping simulator:', error)
327 #charging-stations-container {
331 flex-direction: column;
334 #ui-server-container {
336 justify-content: center;
337 border-style: outset;
340 #ui-server-selector {
342 background-color: rgb(239, 239, 239);
347 #ui-server-selector:hover {
348 background-color: rgb(229, 229, 229);
356 .simulator-start-button {
358 background-color: green;
361 .simulator-start-button:hover {
362 background-color: rgb(0, 98, 0);
365 .simulator-stop-button {
367 background-color: red;
370 .simulator-stop-button:hover {
371 background-color: rgb(225, 0, 0);
380 background-color: blue;
384 #reload-button:hover {
385 background-color: rgb(0, 0, 225);
388 #reload-button:active {
389 background-color: darkblue;
393 min-width: max-content;
395 background-color: black;