Commit | Line | Data |
---|---|---|
32de5a57 | 1 | <template> |
ca1e5439 | 2 | <Container id="charging-stations-container"> |
13c19b7b | 3 | <Container id="buttons-container"> |
878855a2 JB |
4 | <Button id="button" @click="startSimulator()">Start Simulator</Button> |
5 | <Button id="button" @click="stopSimulator()">Stop Simulator</Button> | |
1eb5f592 JB |
6 | <Button id="button" @click="$router.push({ name: 'add-charging-stations' })"> |
7 | Add Charging Stations | |
8 | </Button> | |
b9d447d2 JB |
9 | <ReloadButton |
10 | id="reload-button" | |
11 | :loading="state.isLoading" | |
12 | @click="loadChargingStations(() => $router.go(0))" | |
13 | /> | |
13c19b7b | 14 | </Container> |
30fc5f08 | 15 | <CSTable :charging-stations="app?.appContext.config.globalProperties.$chargingStations" /> |
32de5a57 LM |
16 | </Container> |
17 | </template> | |
18 | ||
19 | <script setup lang="ts"> | |
57c0ba05 | 20 | import { getCurrentInstance, reactive } from 'vue' |
cea23fa0 | 21 | import { useToast } from 'vue-toast-notification' |
66a7748d | 22 | import CSTable from '@/components/charging-stations/CSTable.vue' |
57c0ba05 | 23 | import type { ResponsePayload } from '@/types' |
66a7748d JB |
24 | import Container from '@/components/Container.vue' |
25 | import ReloadButton from '@/components/buttons/ReloadButton.vue' | |
13c19b7b | 26 | import Button from '@/components/buttons/Button.vue' |
32de5a57 | 27 | |
57c0ba05 | 28 | const state = reactive({ |
c317ae3e | 29 | isLoading: false |
66a7748d | 30 | }) |
32de5a57 | 31 | |
57c0ba05 JB |
32 | const app = getCurrentInstance() |
33 | const uiClient = app?.appContext.config.globalProperties.$uiClient | |
34 | ||
cea23fa0 JB |
35 | const $toast = useToast() |
36 | ||
fa5d129a | 37 | const loadChargingStations = (reloadCallback?: () => void): void => { |
2113b3c6 JB |
38 | if (state.isLoading === false) { |
39 | state.isLoading = true | |
57c0ba05 JB |
40 | uiClient |
41 | .listChargingStations() | |
42 | .then((response: ResponsePayload) => { | |
43 | if (app != null) { | |
44 | app.appContext.config.globalProperties.$chargingStations = response.chargingStations | |
45 | } | |
46 | }) | |
47 | .catch((error: Error) => { | |
cea23fa0 | 48 | $toast.error('Error at fetching charging stations') |
57c0ba05 JB |
49 | console.error('Error at fetching charging stations:', error) |
50 | }) | |
51 | .finally(() => { | |
b9d447d2 JB |
52 | if (reloadCallback != null) { |
53 | reloadCallback() | |
54 | } | |
57c0ba05 JB |
55 | state.isLoading = false |
56 | }) | |
2113b3c6 | 57 | } |
32de5a57 | 58 | } |
5a010bf0 | 59 | |
fa5d129a | 60 | const startSimulator = (): void => { |
cea23fa0 JB |
61 | uiClient |
62 | .startSimulator() | |
63 | .then(() => { | |
64 | $toast.success('Simulator successfully started') | |
65 | }) | |
66 | .catch((error: Error) => { | |
67 | $toast.error('Error at starting simulator') | |
68 | console.error('Error at starting simulator:', error) | |
69 | }) | |
5a010bf0 | 70 | } |
fa5d129a | 71 | const stopSimulator = (): void => { |
cea23fa0 JB |
72 | uiClient |
73 | .stopSimulator() | |
74 | .then(() => { | |
75 | $toast.success('Simulator successfully stopped') | |
76 | }) | |
77 | .catch((error: Error) => { | |
78 | $toast.error('Error at stopping simulator') | |
79 | console.error('Error at stopping simulator:', error) | |
80 | }) | |
5a010bf0 | 81 | } |
32de5a57 LM |
82 | </script> |
83 | ||
84 | <style> | |
ca1e5439 | 85 | #charging-stations-container { |
1d41bc6b | 86 | height: fit-content; |
32de5a57 | 87 | width: 100%; |
5a010bf0 | 88 | display: flex; |
32de5a57 | 89 | flex-direction: column; |
5a010bf0 JB |
90 | } |
91 | ||
13c19b7b JB |
92 | #buttons-container { |
93 | display: flex; | |
94 | flex-direction: row; | |
95 | } | |
96 | ||
878855a2 JB |
97 | #button { |
98 | flex: auto; | |
99 | } | |
100 | ||
32de5a57 | 101 | #reload-button { |
5a010bf0 | 102 | flex: auto; |
32de5a57 | 103 | color: white; |
9dc8b66f | 104 | background-color: blue; |
13c19b7b | 105 | font-size: 1.5rem; |
32de5a57 | 106 | font-weight: bold; |
aee67dee JB |
107 | align-items: center; |
108 | justify-content: center; | |
32de5a57 LM |
109 | } |
110 | ||
111 | #reload-button:hover { | |
9dc8b66f | 112 | background-color: rgb(0, 0, 225); |
32de5a57 LM |
113 | } |
114 | ||
115 | #reload-button:active { | |
9dc8b66f | 116 | background-color: red; |
32de5a57 | 117 | } |
32de5a57 | 118 | </style> |