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 | /> | |
2293fadc | 20 | <p>Template options overrides:</p> |
093ca832 | 21 | <ul> |
2293fadc JB |
22 | <li> |
23 | Supervision url: | |
24 | <input | |
25 | id="supervision-url" | |
26 | v-model.trim="state.supervisionUrl" | |
27 | type="url" | |
28 | name="supervision-url" | |
29 | placeholder="wss://" | |
30 | /> | |
31 | </li> | |
093ca832 JB |
32 | <li> |
33 | Auto start: | |
34 | <input v-model="state.autoStart" type="checkbox" true-value="true" false-value="false" /> | |
35 | </li> | |
3d9f3741 JB |
36 | <li> |
37 | Persistent configuration: | |
38 | <input | |
39 | v-model="state.persistentConfiguration" | |
40 | type="checkbox" | |
41 | true-value="true" | |
42 | false-value="false" | |
43 | /> | |
44 | </li> | |
45 | <li> | |
46 | OCPP strict compliance: | |
47 | <input | |
48 | v-model="state.ocppStrictCompliance" | |
49 | type="checkbox" | |
50 | true-value="true" | |
51 | false-value="false" | |
52 | /> | |
53 | </li> | |
54 | <li> | |
55 | Performance statistics: | |
56 | <input | |
57 | v-model="state.enableStatistics" | |
58 | type="checkbox" | |
59 | true-value="true" | |
60 | false-value="false" | |
61 | /> | |
62 | </li> | |
093ca832 | 63 | </ul> |
878855a2 JB |
64 | <br /> |
65 | <Button | |
14ee627a | 66 | id="action-button" |
878855a2 JB |
67 | @click=" |
68 | () => { | |
69 | uiClient | |
093ca832 | 70 | .addChargingStations(state.template, state.numberOfStations, { |
2293fadc | 71 | supervisionUrls: state.supervisionUrl.length > 0 ? state.supervisionUrl : undefined, |
3d9f3741 JB |
72 | autoStart: convertToBoolean(state.autoStart), |
73 | persistentConfiguration: convertToBoolean(state.persistentConfiguration), | |
74 | ocppStrictCompliance: convertToBoolean(state.ocppStrictCompliance), | |
75 | enableStatistics: convertToBoolean(state.enableStatistics) | |
093ca832 | 76 | }) |
cea23fa0 JB |
77 | .then(() => { |
78 | $toast.success('Charging stations successfully added') | |
79 | }) | |
878855a2 | 80 | .catch((error: Error) => { |
cea23fa0 | 81 | $toast.error('Error at adding charging stations') |
878855a2 JB |
82 | console.error('Error at adding charging stations:', error) |
83 | }) | |
84 | .finally(() => { | |
85 | $router.push({ name: 'charging-stations' }) | |
86 | }) | |
87 | } | |
88 | " | |
878855a2 | 89 | > |
1eb5f592 JB |
90 | Add Charging Stations |
91 | </Button> | |
14ee627a | 92 | <Button id="action-button" @click="$router.push({ name: 'charging-stations' })">Cancel</Button> |
7086aac2 JB |
93 | </template> |
94 | ||
95 | <script setup lang="ts"> | |
878855a2 | 96 | import { getCurrentInstance, onMounted, reactive } from 'vue' |
cea23fa0 | 97 | import { useToast } from 'vue-toast-notification' |
878855a2 | 98 | import Button from '@/components/buttons/Button.vue' |
3a3ba0a2 | 99 | import type { ResponsePayload } from '@/types' |
093ca832 | 100 | import { convertToBoolean } from '@/composables' |
878855a2 JB |
101 | |
102 | const state = reactive({ | |
103 | ready: false, | |
104 | template: '', | |
093ca832 | 105 | numberOfStations: 1, |
2293fadc | 106 | supervisionUrl: '', |
3d9f3741 JB |
107 | autoStart: false, |
108 | persistentConfiguration: true, | |
109 | ocppStrictCompliance: true, | |
110 | enableStatistics: false | |
878855a2 | 111 | }) |
7086aac2 JB |
112 | |
113 | const app = getCurrentInstance() | |
114 | const uiClient = app?.appContext.config.globalProperties.$uiClient | |
115 | ||
cea23fa0 JB |
116 | const $toast = useToast() |
117 | ||
7086aac2 | 118 | onMounted(() => { |
b9d447d2 JB |
119 | uiClient |
120 | .listTemplates() | |
121 | .then((response: ResponsePayload) => { | |
122 | if (app != null && app.appContext.config.globalProperties.$templates == null) { | |
123 | app.appContext.config.globalProperties.$templates = response.templates | |
124 | } | |
125 | }) | |
126 | .catch((error: Error) => { | |
cea23fa0 | 127 | $toast.error('Error at fetching charging station templates') |
b9d447d2 JB |
128 | console.error('Error at fetching charging station templates:', error) |
129 | }) | |
878855a2 JB |
130 | .finally(() => { |
131 | state.ready = true | |
132 | }) | |
7086aac2 JB |
133 | }) |
134 | </script> | |
135 | ||
878855a2 JB |
136 | <style> |
137 | #number-of-stations { | |
d18fc1e3 | 138 | width: 15%; |
878855a2 JB |
139 | text-align: center; |
140 | } | |
427a4970 JB |
141 | |
142 | #supervision-url { | |
143 | width: 90%; | |
144 | text-align: left; | |
145 | } | |
878855a2 | 146 | </style> |