Commit | Line | Data |
---|---|---|
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" | |
3a3ba0a2 | 14 | name="number-of-stations" |
878855a2 JB |
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 |
38 | import { getCurrentInstance, onMounted, reactive } from 'vue' |
39 | import Button from '@/components/buttons/Button.vue' | |
3a3ba0a2 | 40 | import type { ResponsePayload } from '@/types' |
878855a2 JB |
41 | |
42 | const state = reactive({ | |
43 | ready: false, | |
44 | template: '', | |
45 | numberOfStations: 1 | |
46 | }) | |
7086aac2 JB |
47 | |
48 | const app = getCurrentInstance() | |
49 | const uiClient = app?.appContext.config.globalProperties.$uiClient | |
50 | ||
51 | onMounted(() => { | |
b9d447d2 JB |
52 | uiClient |
53 | .listTemplates() | |
54 | .then((response: ResponsePayload) => { | |
55 | if (app != null && app.appContext.config.globalProperties.$templates == null) { | |
56 | app.appContext.config.globalProperties.$templates = response.templates | |
57 | } | |
58 | }) | |
59 | .catch((error: Error) => { | |
60 | // TODO: add code for UI notifications or other error handling logic | |
61 | console.error('Error at fetching charging station templates:', error) | |
62 | }) | |
878855a2 JB |
63 | .finally(() => { |
64 | state.ready = true | |
65 | }) | |
7086aac2 JB |
66 | }) |
67 | </script> | |
68 | ||
878855a2 JB |
69 | <style> |
70 | #number-of-stations { | |
71 | text-align: center; | |
72 | } | |
73 | </style> |