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)
26 app?.appContext.config.globalProperties.$uiClient.registerWSEventListener(
29 state.uiServerIndex = getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
30 app?.appContext.config.globalProperties.$uiClient.setConfiguration(
31 app?.appContext.config.globalProperties.$configuration.uiServer[
32 getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
35 initializeWSEventListeners()
44 v-for="uiServerConfiguration in uiServerConfigurations"
45 :value="uiServerConfiguration.index"
47 {{ uiServerConfiguration.configuration.name ?? uiServerConfiguration.configuration.host }}
51 <Container id="buttons-container">
52 <Button @click="startSimulator()">Start Simulator</Button>
53 <Button @click="stopSimulator()">Stop Simulator</Button>
54 <Button @click="$router.push({ name: 'add-charging-stations' })">
59 :loading="state.loading"
60 @click="loadChargingStations(() => (state.renderChargingStationsList = randomUUID()))"
65 Array.isArray(app?.appContext.config.globalProperties.$chargingStations) &&
66 app?.appContext.config.globalProperties.$chargingStations.length > 0
68 :key="state.renderChargingStationsList"
69 :charging-stations="app?.appContext.config.globalProperties.$chargingStations"
74 <script setup lang="ts">
75 import { getCurrentInstance, onMounted, reactive } from 'vue'
76 import { useToast } from 'vue-toast-notification'
77 import CSTable from '@/components/charging-stations/CSTable.vue'
78 import type { ResponsePayload, UIServerConfigurationSection } from '@/types'
79 import Container from '@/components/Container.vue'
80 import ReloadButton from '@/components/buttons/ReloadButton.vue'
81 import Button from '@/components/buttons/Button.vue'
82 import { getFromLocalStorage, setToLocalStorage } from '@/composables'
84 const randomUUID = (): `${string}-${string}-${string}-${string}-${string}` => {
85 return crypto.randomUUID()
88 const app = getCurrentInstance()
90 const initializeWSEventListeners = () => {
91 app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('open', () => {
92 loadChargingStations(() => (state.renderChargingStationsList = randomUUID()))
94 app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('error', () => {
95 app.appContext.config.globalProperties.$chargingStations = []
96 state.renderChargingStationsList = randomUUID()
98 app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('close', () => {
99 app.appContext.config.globalProperties.$chargingStations = []
100 state.renderChargingStationsList = randomUUID()
105 initializeWSEventListeners()
108 const state = reactive({
109 renderChargingStationsList: randomUUID(),
111 uiServerIndex: getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
114 const uiClient = app?.appContext.config.globalProperties.$uiClient
115 const uiServerConfigurations: { configuration: UIServerConfigurationSection; index: number }[] =
116 app?.appContext.config.globalProperties.$configuration.uiServer.map(
117 (configuration: UIServerConfigurationSection, index: number) => ({
123 const $toast = useToast()
125 const loadChargingStations = (renderCallback?: () => void): void => {
126 if (state.loading === false) {
129 .listChargingStations()
130 .then((response: ResponsePayload) => {
132 app.appContext.config.globalProperties.$chargingStations = response.chargingStations
135 .catch((error: Error) => {
137 app.appContext.config.globalProperties.$chargingStations = []
139 $toast.error('Error at fetching charging stations')
140 console.error('Error at fetching charging stations:', error)
143 if (renderCallback != null) {
146 state.loading = false
151 const startSimulator = (): void => {
155 $toast.success('Simulator successfully started')
157 .catch((error: Error) => {
158 $toast.error('Error at starting simulator')
159 console.error('Error at starting simulator:', error)
162 const stopSimulator = (): void => {
167 app.appContext.config.globalProperties.$chargingStations = []
169 $toast.success('Simulator successfully stopped')
171 .catch((error: Error) => {
172 $toast.error('Error at stopping simulator')
173 console.error('Error at stopping simulator:', error)
179 #charging-stations-container {
183 flex-direction: column;
186 #ui-server-container {
191 #ui-server-selector {
208 background-color: blue;
212 justify-content: center;
215 #reload-button:hover {
216 background-color: rgb(0, 0, 225);
219 #reload-button:active {
220 background-color: red;
225 background-color: black;