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 :key="uiServerConfiguration.index"
55 :value="uiServerConfiguration.index"
58 uiServerConfiguration.configuration.name ?? uiServerConfiguration.configuration.host
65 :key="state.renderSimulator"
66 :status="simulatorState?.started"
67 :on="() => startSimulator()"
68 :off="() => stopSimulator()"
69 :class="simulatorButtonClass"
71 {{ simulatorButtonMessage }}
74 :id="'add-charging-stations'"
75 :key="state.renderAddChargingStations"
79 $router.push({ name: 'add-charging-stations' })
84 $router.push({ name: 'charging-stations' })
89 state.renderChargingStations = randomUUID()
97 :loading="state.gettingChargingStations"
98 @click="getChargingStations()"
102 v-show="Array.isArray($chargingStations.value) && $chargingStations.value.length > 0"
103 :key="state.renderChargingStations"
104 :charging-stations="$chargingStations.value"
107 state.renderAddChargingStations = randomUUID()
108 state.renderChargingStations = randomUUID()
115 <script setup lang="ts">
116 import { computed, getCurrentInstance, onMounted, onUnmounted, ref, watch } from 'vue'
117 import { useToast } from 'vue-toast-notification'
119 import ReloadButton from '@/components/buttons/ReloadButton.vue'
120 import ToggleButton from '@/components/buttons/ToggleButton.vue'
121 import CSTable from '@/components/charging-stations/CSTable.vue'
122 import Container from '@/components/Container.vue'
124 deleteFromLocalStorage,
130 } from '@/composables'
135 UIServerConfigurationSection
138 const simulatorState = ref<SimulatorState | undefined>(undefined)
140 const simulatorButtonClass = computed<string>(() =>
141 simulatorState.value?.started === true ? 'simulator-stop-button' : 'simulator-start-button'
143 const simulatorButtonMessage = computed<string>(
145 `${simulatorState.value?.started === true ? 'Stop' : 'Start'} Simulator${simulatorState.value?.version != null ? ` (${simulatorState.value.version})` : ''}`
149 renderSimulator: `${string}-${string}-${string}-${string}-${string}`
150 renderAddChargingStations: `${string}-${string}-${string}-${string}-${string}`
151 renderChargingStations: `${string}-${string}-${string}-${string}-${string}`
152 gettingSimulatorState: boolean
153 gettingTemplates: boolean
154 gettingChargingStations: boolean
155 uiServerIndex: number
157 renderSimulator: randomUUID(),
158 renderAddChargingStations: randomUUID(),
159 renderChargingStations: randomUUID(),
160 gettingSimulatorState: false,
161 gettingTemplates: false,
162 gettingChargingStations: false,
163 uiServerIndex: getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
166 const clearToggleButtons = (): void => {
167 for (const key in getLocalStorage()) {
168 if (key.includes('toggle-button')) {
169 deleteFromLocalStorage(key)
172 state.value.renderChargingStations = randomUUID()
173 state.value.renderAddChargingStations = randomUUID()
176 const app = getCurrentInstance()
178 watch(app!.appContext.config.globalProperties.$chargingStations, () => {
179 state.value.renderChargingStations = randomUUID()
182 watch(simulatorState, () => {
183 state.value.renderSimulator = randomUUID()
186 const clearTemplates = (): void => {
188 app.appContext.config.globalProperties.$templates.value = []
192 const clearChargingStations = (): void => {
194 app.appContext.config.globalProperties.$chargingStations.value = []
198 const uiClient = useUIClient()
200 const $toast = useToast()
202 const getSimulatorState = (): void => {
203 if (state.value.gettingSimulatorState === false) {
204 state.value.gettingSimulatorState = true
207 .then((response: ResponsePayload) => {
208 simulatorState.value = response.state as SimulatorState
210 .catch((error: Error) => {
211 $toast.error('Error at fetching simulator state')
212 console.error('Error at fetching simulator state:', error)
215 state.value.gettingSimulatorState = false
220 const getTemplates = (): void => {
221 if (state.value.gettingTemplates === false) {
222 state.value.gettingTemplates = true
225 .then((response: ResponsePayload) => {
227 app.appContext.config.globalProperties.$templates.value = response.templates as string[]
230 .catch((error: Error) => {
232 $toast.error('Error at fetching charging station templates')
233 console.error('Error at fetching charging station templates:', error)
236 state.value.gettingTemplates = false
241 const getChargingStations = (): void => {
242 if (state.value.gettingChargingStations === false) {
243 state.value.gettingChargingStations = true
245 .listChargingStations()
246 .then((response: ResponsePayload) => {
248 app.appContext.config.globalProperties.$chargingStations.value =
249 response.chargingStations as ChargingStationData[]
252 .catch((error: Error) => {
253 clearChargingStations()
254 $toast.error('Error at fetching charging stations')
255 console.error('Error at fetching charging stations:', error)
258 state.value.gettingChargingStations = false
263 const getData = (): void => {
266 getChargingStations()
269 const registerWSEventListeners = () => {
270 uiClient.registerWSEventListener('open', getData)
271 uiClient.registerWSEventListener('error', clearChargingStations)
272 uiClient.registerWSEventListener('close', clearChargingStations)
275 const unregisterWSEventListeners = () => {
276 uiClient.unregisterWSEventListener('open', getData)
277 uiClient.unregisterWSEventListener('error', clearChargingStations)
278 uiClient.unregisterWSEventListener('close', clearChargingStations)
282 registerWSEventListeners()
286 unregisterWSEventListeners()
289 const uiServerConfigurations: { index: number; configuration: UIServerConfigurationSection }[] = (
290 app?.appContext.config.globalProperties.$configuration.value
291 .uiServer as UIServerConfigurationSection[]
292 ).map((configuration: UIServerConfigurationSection, index: number) => ({
297 const startSimulator = (): void => {
301 $toast.success('Simulator successfully started')
303 .catch((error: Error) => {
304 $toast.error('Error at starting simulator')
305 console.error('Error at starting simulator:', error)
311 const stopSimulator = (): void => {
315 clearChargingStations()
316 $toast.success('Simulator successfully stopped')
318 .catch((error: Error) => {
319 $toast.error('Error at stopping simulator')
320 console.error('Error at stopping simulator:', error)
329 #charging-stations-container {
333 flex-direction: column;
336 #ui-server-container {
338 justify-content: center;
339 border-style: outset;
342 #ui-server-selector {
344 background-color: rgb(239, 239, 239);
349 #ui-server-selector:hover {
350 background-color: rgb(229, 229, 229);
358 .simulator-start-button {
360 background-color: green;
363 .simulator-start-button:hover {
364 background-color: rgb(0, 98, 0);
367 .simulator-stop-button {
369 background-color: red;
372 .simulator-stop-button:hover {
373 background-color: rgb(225, 0, 0);
382 background-color: blue;
386 #reload-button:hover {
387 background-color: rgb(0, 0, 225);
390 #reload-button:active {
391 background-color: darkblue;
395 min-width: max-content;
397 background-color: black;