feat(ui): add charging stations action support
[e-mobility-charging-stations-simulator.git] / ui / web / src / components / actions / AddChargingStations.vue
CommitLineData
7086aac2
JB
1<template>
2 <h2>Action Add Charging Stations</h2>
878855a2
JB
3 <p>Template:</p>
4 <select v-if="state.ready" v-model="state.template">
5 <option v-for="template in app?.appContext.config.globalProperties.$templates">
6 {{ template }}
7 </option>
8 </select>
9 <p>Number of stations:</p>
10 <input
11 id="number-of-stations"
12 v-model="state.numberOfStations"
13 type="text"
14 name="number-of-station"
15 placeholder="number of stations"
16 />
17 <br />
18 <Button
19 @click="
20 () => {
21 uiClient
22 .addChargingStations(state.template, state.numberOfStations)
23 .catch((error: Error) => {
24 // TODO: add code for UI notifications or other error handling logic
25 console.error('Error at adding charging stations:', error)
26 })
27 .finally(() => {
28 $router.push({ name: 'charging-stations' })
29 })
30 }
31 "
32 >Add Charging Stations</Button
33 >
34 <Button @click="$router.push({ name: 'charging-stations' })">Cancel</Button>
7086aac2
JB
35</template>
36
37<script setup lang="ts">
878855a2
JB
38import { getCurrentInstance, onMounted, reactive } from 'vue'
39import Button from '@/components/buttons/Button.vue'
40
41const state = reactive({
42 ready: false,
43 template: '',
44 numberOfStations: 1
45})
7086aac2
JB
46
47const app = getCurrentInstance()
48const uiClient = app?.appContext.config.globalProperties.$uiClient
49
50onMounted(() => {
b9d447d2
JB
51 uiClient
52 .listTemplates()
53 .then((response: ResponsePayload) => {
54 if (app != null && app.appContext.config.globalProperties.$templates == null) {
55 app.appContext.config.globalProperties.$templates = response.templates
56 }
57 })
58 .catch((error: Error) => {
59 // TODO: add code for UI notifications or other error handling logic
60 console.error('Error at fetching charging station templates:', error)
61 })
878855a2
JB
62 .finally(() => {
63 state.ready = true
64 })
7086aac2
JB
65})
66</script>
67
878855a2
JB
68<style>
69#number-of-stations {
70 text-align: center;
71}
72</style>