<template>
<Container id="charging-stations">
- <Button id="simulator-button" @click="startSimulator()">Start Simulator</Button>
- <Button id="simulator-button" @click="stopSimulator()">Stop Simulator</Button>
- <Container id="inputs-container">
- <input
- id="idtag-field"
- v-model="state.idTag"
- type="text"
- name="idtag-field"
- placeholder="RFID tag"
- />
- <ReloadButton id="reload-button" :loading="state.isLoading" @click="load()" />
+ <Container id="buttons-container">
+ <Button id="simulator-button" @click="startSimulator()">Start Simulator</Button>
+ <Button id="simulator-button" @click="stopSimulator()">Stop Simulator</Button>
+ <ReloadButton id="reload-button" :loading="state.isLoading" @click="loadChargingStations()" />
</Container>
- <CSTable :charging-stations="state.chargingStations" :id-tag="state.idTag" />
+ <CSTable
+ :charging-stations="
+ getCurrentInstance()?.appContext.config.globalProperties.$chargingStations ?? []
+ "
+ />
</Container>
</template>
<script setup lang="ts">
-import { getCurrentInstance, onMounted, reactive } from 'vue'
+import { getCurrentInstance, reactive } from 'vue'
import CSTable from '@/components/charging-stations/CSTable.vue'
-import type { ChargingStationData } from '@/types'
+import type { ResponsePayload } from '@/types'
import Container from '@/components/Container.vue'
import ReloadButton from '@/components/buttons/ReloadButton.vue'
+import Button from '@/components/buttons/Button.vue'
-const UIClient = getCurrentInstance()?.appContext.config.globalProperties.$UIClient
-
-onMounted(() => {
- UIClient.registerWSonOpenListener(load)
+const state = reactive({
+ isLoading: false
})
-type State = {
- isLoading: boolean
- chargingStations: ChargingStationData[]
- idTag: string
-}
-
-const state: State = reactive({
- isLoading: false,
- chargingStations: [],
- idTag: ''
-})
+const app = getCurrentInstance()
+const uiClient = app?.appContext.config.globalProperties.$uiClient
-async function load(): Promise<void> {
- if (state.isLoading === true) return
- state.isLoading = true
- const listChargingStationsPayload = await UIClient.listChargingStations()
- state.chargingStations =
- listChargingStationsPayload.chargingStations as unknown as ChargingStationData[]
- state.isLoading = false
+function loadChargingStations(): void {
+ if (state.isLoading === false) {
+ state.isLoading = true
+ uiClient
+ .listChargingStations()
+ .then((response: ResponsePayload) => {
+ if (app != null) {
+ app.appContext.config.globalProperties.$chargingStations = response.chargingStations
+ }
+ })
+ .catch((error: Error) => {
+ // TODO: add code for UI notifications or other error handling logic
+ console.error('Error at fetching charging stations:', error)
+ })
+ .finally(() => {
+ state.isLoading = false
+ })
+ }
}
function startSimulator(): void {
- UIClient.startSimulator()
+ uiClient.startSimulator()
}
function stopSimulator(): void {
- UIClient.stopSimulator()
+ uiClient.stopSimulator()
}
</script>
#charging-stations {
height: fit-content;
width: 100%;
- background-color: rgb(233, 227, 227);
display: flex;
flex-direction: column;
}
-#inputs-container {
+#buttons-container {
display: flex;
- justify-content: space-between;
+ flex-direction: row;
}
#reload-button {
flex: auto;
- background-color: rgb(25, 118, 210);
color: white;
- font-size: 35px;
+ background-color: blue;
+ font-size: 1.5rem;
font-weight: bold;
+ align-items: center;
+ justify-content: center;
}
#reload-button:hover {
- background-color: rgb(10, 113, 195);
+ background-color: rgb(0, 0, 225);
}
#reload-button:active {
- background-color: rgb(255, 113, 195);
+ background-color: red;
}
#simulator-button {
flex: auto;
}
-
-#idtag-field {
- flex: auto;
- text-align: center;
-}
</style>