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
24 $router.currentRoute.value.name !== 'charging-stations' &&
25 $router.push({ name: 'charging-stations' })
29 app?.appContext.config.globalProperties.$uiClient.registerWSEventListener(
32 state.uiServerIndex = getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
33 app?.appContext.config.globalProperties.$uiClient.setConfiguration(
34 app?.appContext.config.globalProperties.$configuration.uiServer[
35 getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
38 initializeWSEventListeners()
47 v-for="uiServerConfiguration in uiServerConfigurations"
48 :value="uiServerConfiguration.index"
50 {{ uiServerConfiguration.configuration.name ?? uiServerConfiguration.configuration.host }}
54 <Container id="buttons-container">
55 <Button @click="startSimulator()">Start Simulator</Button>
56 <Button @click="stopSimulator()">Stop Simulator</Button>
57 <Button @click="$router.push({ name: 'add-charging-stations' })">
62 :loading="state.loading"
63 @click="loadChargingStations(() => (state.renderChargingStationsList = randomUUID()))"
68 Array.isArray(app?.appContext.config.globalProperties.$chargingStations) &&
69 app?.appContext.config.globalProperties.$chargingStations.length > 0
71 :key="state.renderChargingStationsList"
72 :charging-stations="app?.appContext.config.globalProperties.$chargingStations"
77 <script setup lang="ts">
78 import { getCurrentInstance, onMounted, reactive } from 'vue'
79 import { useToast } from 'vue-toast-notification'
80 import CSTable from '@/components/charging-stations/CSTable.vue'
81 import type { ResponsePayload, UIServerConfigurationSection } from '@/types'
82 import Container from '@/components/Container.vue'
83 import ReloadButton from '@/components/buttons/ReloadButton.vue'
84 import Button from '@/components/buttons/Button.vue'
85 import { getFromLocalStorage, setToLocalStorage } from '@/composables'
87 const randomUUID = (): `${string}-${string}-${string}-${string}-${string}` => {
88 return crypto.randomUUID()
91 const app = getCurrentInstance()
93 const initializeWSEventListeners = () => {
94 app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('open', () => {
95 loadChargingStations(() => (state.renderChargingStationsList = randomUUID()))
97 app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('error', () => {
98 app.appContext.config.globalProperties.$chargingStations = []
99 state.renderChargingStationsList = randomUUID()
101 app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('close', () => {
102 app.appContext.config.globalProperties.$chargingStations = []
103 state.renderChargingStationsList = randomUUID()
108 initializeWSEventListeners()
111 const state = reactive({
112 renderChargingStationsList: randomUUID(),
114 uiServerIndex: getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
117 const uiClient = app?.appContext.config.globalProperties.$uiClient
118 const uiServerConfigurations: { configuration: UIServerConfigurationSection; index: number }[] =
119 app?.appContext.config.globalProperties.$configuration.uiServer.map(
120 (configuration: UIServerConfigurationSection, index: number) => ({
126 const $toast = useToast()
128 const loadChargingStations = (renderCallback?: () => void): void => {
129 if (state.loading === false) {
132 .listChargingStations()
133 .then((response: ResponsePayload) => {
135 app.appContext.config.globalProperties.$chargingStations = response.chargingStations
138 .catch((error: Error) => {
140 app.appContext.config.globalProperties.$chargingStations = []
142 $toast.error('Error at fetching charging stations')
143 console.error('Error at fetching charging stations:', error)
146 if (renderCallback != null) {
149 state.loading = false
154 const startSimulator = (): void => {
158 $toast.success('Simulator successfully started')
160 .catch((error: Error) => {
161 $toast.error('Error at starting simulator')
162 console.error('Error at starting simulator:', error)
165 const stopSimulator = (): void => {
170 app.appContext.config.globalProperties.$chargingStations = []
172 $toast.success('Simulator successfully stopped')
174 .catch((error: Error) => {
175 $toast.error('Error at stopping simulator')
176 console.error('Error at stopping simulator:', error)
182 #charging-stations-container {
186 flex-direction: column;
189 #ui-server-container {
194 #ui-server-selector {
211 background-color: blue;
215 justify-content: center;
218 #reload-button:hover {
219 background-color: rgb(0, 0, 225);
222 #reload-button:active {
223 background-color: red;
228 background-color: black;