refactor(ui): refine connectors table sizing
[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> {
2113b3c6
JB
45 if (state.isLoading === false) {
46 state.isLoading = true
47 state.chargingStations = (await UIClient.listChargingStations())
48 .chargingStations as ChargingStationData[]
49 state.isLoading = false
50 }
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%;
5a010bf0 65 display: flex;
32de5a57 66 flex-direction: column;
5a010bf0
JB
67}
68
69#inputs-container {
70 display: flex;
71 justify-content: space-between;
32de5a57
LM
72}
73
74#reload-button {
5a010bf0 75 flex: auto;
32de5a57 76 color: white;
9dc8b66f 77 background-color: blue;
2f0851f8 78 font-size: 2rem;
32de5a57
LM
79 font-weight: bold;
80}
81
82#reload-button:hover {
9dc8b66f 83 background-color: rgb(0, 0, 225);
32de5a57
LM
84}
85
86#reload-button:active {
9dc8b66f 87 background-color: red;
32de5a57
LM
88}
89
5a010bf0
JB
90#simulator-button {
91 flex: auto;
32de5a57
LM
92}
93
5a010bf0
JB
94#idtag-field {
95 flex: auto;
1d41bc6b 96 text-align: center;
32de5a57
LM
97}
98</style>