Commit | Line | Data |
---|---|---|
7086aac2 | 1 | <template> |
229d8c34 JB |
2 | <h1 id="action">Action</h1> |
3 | <h2>Add Charging Stations</h2> | |
878855a2 | 4 | <p>Template:</p> |
7378b34a | 5 | <select v-show="state.ready" v-model="state.template"> |
b221407f | 6 | <option disabled value="">Please select a template</option> |
878855a2 JB |
7 | <option v-for="template in app?.appContext.config.globalProperties.$templates"> |
8 | {{ template }} | |
9 | </option> | |
10 | </select> | |
11 | <p>Number of stations:</p> | |
12 | <input | |
13 | id="number-of-stations" | |
14 | v-model="state.numberOfStations" | |
d18fc1e3 JB |
15 | type="number" |
16 | min="1" | |
3a3ba0a2 | 17 | name="number-of-stations" |
878855a2 JB |
18 | placeholder="number of stations" |
19 | /> | |
093ca832 JB |
20 | <p>Options:</p> |
21 | <ul> | |
22 | <li> | |
23 | Auto start: | |
24 | <input v-model="state.autoStart" type="checkbox" true-value="true" false-value="false" /> | |
25 | </li> | |
26 | </ul> | |
878855a2 JB |
27 | <br /> |
28 | <Button | |
14ee627a | 29 | id="action-button" |
878855a2 JB |
30 | @click=" |
31 | () => { | |
32 | uiClient | |
093ca832 JB |
33 | .addChargingStations(state.template, state.numberOfStations, { |
34 | autoStart: convertToBoolean(state.autoStart) | |
35 | }) | |
cea23fa0 JB |
36 | .then(() => { |
37 | $toast.success('Charging stations successfully added') | |
38 | }) | |
878855a2 | 39 | .catch((error: Error) => { |
cea23fa0 | 40 | $toast.error('Error at adding charging stations') |
878855a2 JB |
41 | console.error('Error at adding charging stations:', error) |
42 | }) | |
43 | .finally(() => { | |
44 | $router.push({ name: 'charging-stations' }) | |
45 | }) | |
46 | } | |
47 | " | |
878855a2 | 48 | > |
1eb5f592 JB |
49 | Add Charging Stations |
50 | </Button> | |
14ee627a | 51 | <Button id="action-button" @click="$router.push({ name: 'charging-stations' })">Cancel</Button> |
7086aac2 JB |
52 | </template> |
53 | ||
54 | <script setup lang="ts"> | |
878855a2 | 55 | import { getCurrentInstance, onMounted, reactive } from 'vue' |
cea23fa0 | 56 | import { useToast } from 'vue-toast-notification' |
878855a2 | 57 | import Button from '@/components/buttons/Button.vue' |
3a3ba0a2 | 58 | import type { ResponsePayload } from '@/types' |
093ca832 | 59 | import { convertToBoolean } from '@/composables' |
878855a2 JB |
60 | |
61 | const state = reactive({ | |
62 | ready: false, | |
63 | template: '', | |
093ca832 JB |
64 | numberOfStations: 1, |
65 | autoStart: false | |
878855a2 | 66 | }) |
7086aac2 JB |
67 | |
68 | const app = getCurrentInstance() | |
69 | const uiClient = app?.appContext.config.globalProperties.$uiClient | |
70 | ||
cea23fa0 JB |
71 | const $toast = useToast() |
72 | ||
7086aac2 | 73 | onMounted(() => { |
b9d447d2 JB |
74 | uiClient |
75 | .listTemplates() | |
76 | .then((response: ResponsePayload) => { | |
77 | if (app != null && app.appContext.config.globalProperties.$templates == null) { | |
78 | app.appContext.config.globalProperties.$templates = response.templates | |
79 | } | |
80 | }) | |
81 | .catch((error: Error) => { | |
cea23fa0 | 82 | $toast.error('Error at fetching charging station templates') |
b9d447d2 JB |
83 | console.error('Error at fetching charging station templates:', error) |
84 | }) | |
878855a2 JB |
85 | .finally(() => { |
86 | state.ready = true | |
87 | }) | |
7086aac2 JB |
88 | }) |
89 | </script> | |
90 | ||
878855a2 JB |
91 | <style> |
92 | #number-of-stations { | |
d18fc1e3 | 93 | width: 15%; |
878855a2 JB |
94 | text-align: center; |
95 | } | |
96 | </style> |