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