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