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