Web UI: add and fix missing commands support
[e-mobility-charging-stations-simulator.git] / src / ui / web / src / views / ChargingStationsView.vue
... / ...
CommitLineData
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 type="text"
9 name="idtag-field"
10 placeholder="RFID tag"
11 v-model="state.idTag"
12 />
13 <ReloadButton id="reload-button" :loading="state.isLoading" @click="load()" />
14 </Container>
15 <CSTable :chargingStations="state.chargingStations" :idTag="state.idTag" />
16 </Container>
17</template>
18
19<script setup lang="ts">
20import Container from '@/components/Container.vue';
21import ReloadButton from '@/components/buttons/ReloadButton.vue';
22import CSTable from '@/components/charging-stations/CSTable.vue';
23
24import { onMounted, reactive } from 'vue';
25import UIClient from '@/composable/UIClient';
26import { ChargingStationData } from '@/type/ChargingStationType';
27
28const UIClientInstance = UIClient.instance;
29
30onMounted(() => {
31 UIClientInstance.onOpen(load);
32});
33
34type State = {
35 isLoading: boolean;
36 chargingStations: Record<string, ChargingStationData>;
37 idTag: string;
38};
39
40const state: State = reactive({
41 isLoading: false,
42 chargingStations: {},
43 idTag: '',
44});
45
46async function load(): Promise<void> {
47 if (state.isLoading === true) return;
48 state.isLoading = true;
49 const list = await UIClientInstance.listChargingStations();
50 state.chargingStations = list as unknown as Record<string, ChargingStationData>;
51 state.isLoading = false;
52}
53
54function startSimulator(): void {
55 UIClientInstance.startSimulator();
56}
57function stopSimulator(): void {
58 UIClientInstance.stopSimulator();
59}
60</script>
61
62<style>
63#charging-stations {
64 height: 100%;
65 width: 100%;
66 padding: 30px;
67 background-color: rgb(233, 227, 227);
68 display: flex;
69 flex-direction: column;
70 gap: 0.5%;
71}
72
73#inputs-container {
74 display: flex;
75 justify-content: space-between;
76}
77
78#reload-button {
79 flex: auto;
80 padding: 6px 14px;
81 background-color: rgb(25, 118, 210);
82 border-radius: 5px;
83
84 color: white;
85 font-size: 35px;
86 font-weight: bold;
87}
88
89#reload-button:hover {
90 background-color: rgb(10, 113, 195);
91}
92
93#reload-button:active {
94 background-color: rgb(255, 113, 195);
95}
96
97#simulator-button {
98 flex: auto;
99}
100
101#idtag-field {
102 flex: auto;
103}
104</style>