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