| 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"> |
| 20 | import Container from '@/components/Container.vue'; |
| 21 | import ReloadButton from '@/components/buttons/ReloadButton.vue'; |
| 22 | import CSTable from '@/components/charging-stations/CSTable.vue'; |
| 23 | |
| 24 | import { onMounted, reactive } from 'vue'; |
| 25 | import UIClient from '@/composable/UIClient'; |
| 26 | import { ChargingStationData } from '@/type/ChargingStationType'; |
| 27 | |
| 28 | const UIClientInstance = UIClient.instance; |
| 29 | |
| 30 | onMounted(() => { |
| 31 | UIClientInstance.registerWSonOpenListener(load); |
| 32 | }); |
| 33 | |
| 34 | type State = { |
| 35 | isLoading: boolean; |
| 36 | chargingStations: Record<string, ChargingStationData>; |
| 37 | idTag: string; |
| 38 | }; |
| 39 | |
| 40 | const state: State = reactive({ |
| 41 | isLoading: false, |
| 42 | chargingStations: {}, |
| 43 | idTag: '', |
| 44 | }); |
| 45 | |
| 46 | async function load(): Promise<void> { |
| 47 | if (state.isLoading === true) return; |
| 48 | state.isLoading = true; |
| 49 | const chargingStationsList = await UIClientInstance.listChargingStations(); |
| 50 | state.chargingStations = chargingStationsList as unknown as Record<string, ChargingStationData>; |
| 51 | state.isLoading = false; |
| 52 | } |
| 53 | |
| 54 | function startSimulator(): void { |
| 55 | UIClientInstance.startSimulator(); |
| 56 | } |
| 57 | function 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> |