refactor(ui): use JSON format as runtime configuration
[e-mobility-charging-stations-simulator.git] / ui / web / src / views / ChargingStationsView.vue
CommitLineData
32de5a57
LM
1<template>
2 <Container id="charging-stations">
5a010bf0
JB
3 <Button id="simulator-button" @click="startSimulator()">Start Simulator</Button>
4 <Button id="simulator-button" @click="stopSimulator()">Stop Simulator</Button>
5 <Container id="inputs-container">
32de5a57 6 <input
5a010bf0 7 id="idtag-field"
01ff4231 8 v-model="state.idTag"
32de5a57 9 type="text"
5a010bf0
JB
10 name="idtag-field"
11 placeholder="RFID tag"
32de5a57
LM
12 />
13 <ReloadButton id="reload-button" :loading="state.isLoading" @click="load()" />
14 </Container>
01ff4231 15 <CSTable :charging-stations="state.chargingStations" :id-tag="state.idTag" />
32de5a57
LM
16 </Container>
17</template>
18
19<script setup lang="ts">
9d76f5ec 20import { getCurrentInstance, onMounted, reactive } from 'vue'
66a7748d
JB
21import CSTable from '@/components/charging-stations/CSTable.vue'
22import type { ChargingStationData } from '@/types'
23import Container from '@/components/Container.vue'
24import ReloadButton from '@/components/buttons/ReloadButton.vue'
32de5a57 25
9d76f5ec 26const UIClient = getCurrentInstance()?.appContext.config.globalProperties.$UIClient
32de5a57
LM
27
28onMounted(() => {
9d76f5ec 29 UIClient.registerWSonOpenListener(load)
66a7748d 30})
32de5a57
LM
31
32type State = {
66a7748d
JB
33 isLoading: boolean
34 chargingStations: ChargingStationData[]
35 idTag: string
36}
32de5a57
LM
37
38const state: State = reactive({
39 isLoading: false,
5e3cb728 40 chargingStations: [],
a974c8e4 41 idTag: ''
66a7748d 42})
32de5a57
LM
43
44async function load(): Promise<void> {
66a7748d
JB
45 if (state.isLoading === true) return
46 state.isLoading = true
9d76f5ec 47 const listChargingStationsPayload = await UIClient.listChargingStations()
5e3cb728 48 state.chargingStations =
66a7748d
JB
49 listChargingStationsPayload.chargingStations as unknown as ChargingStationData[]
50 state.isLoading = false
32de5a57 51}
5a010bf0
JB
52
53function startSimulator(): void {
9d76f5ec 54 UIClient.startSimulator()
5a010bf0
JB
55}
56function stopSimulator(): void {
9d76f5ec 57 UIClient.stopSimulator()
5a010bf0 58}
32de5a57
LM
59</script>
60
61<style>
62#charging-stations {
1d41bc6b 63 height: fit-content;
32de5a57 64 width: 100%;
32de5a57 65 background-color: rgb(233, 227, 227);
5a010bf0 66 display: flex;
32de5a57 67 flex-direction: column;
5a010bf0
JB
68}
69
70#inputs-container {
71 display: flex;
72 justify-content: space-between;
32de5a57
LM
73}
74
75#reload-button {
5a010bf0 76 flex: auto;
32de5a57 77 background-color: rgb(25, 118, 210);
32de5a57
LM
78 color: white;
79 font-size: 35px;
80 font-weight: bold;
81}
82
83#reload-button:hover {
84 background-color: rgb(10, 113, 195);
85}
86
87#reload-button:active {
88 background-color: rgb(255, 113, 195);
89}
90
5a010bf0
JB
91#simulator-button {
92 flex: auto;
32de5a57
LM
93}
94
5a010bf0
JB
95#idtag-field {
96 flex: auto;
1d41bc6b 97 text-align: center;
32de5a57
LM
98}
99</style>