refactor(ui): factor out app initialization
[e-mobility-charging-stations-simulator.git] / ui / web / src / components / actions / AddChargingStations.vue
CommitLineData
7086aac2 1<template>
229d8c34
JB
2 <h1 id="action">Action</h1>
3 <h2>Add Charging Stations</h2>
878855a2 4 <p>Template:</p>
3b0c6e17
JB
5 <select
6 v-show="
7 Array.isArray(app?.appContext.config.globalProperties.$templates) &&
8 app?.appContext.config.globalProperties.$templates.length > 0
9 "
10 v-model="state.template"
11 >
b221407f 12 <option disabled value="">Please select a template</option>
878855a2
JB
13 <option v-for="template in app?.appContext.config.globalProperties.$templates">
14 {{ template }}
15 </option>
16 </select>
17 <p>Number of stations:</p>
18 <input
19 id="number-of-stations"
20 v-model="state.numberOfStations"
d18fc1e3
JB
21 type="number"
22 min="1"
3a3ba0a2 23 name="number-of-stations"
878855a2
JB
24 placeholder="number of stations"
25 />
2293fadc 26 <p>Template options overrides:</p>
093ca832 27 <ul>
2293fadc
JB
28 <li>
29 Supervision url:
30 <input
31 id="supervision-url"
32 v-model.trim="state.supervisionUrl"
33 type="url"
34 name="supervision-url"
35 placeholder="wss://"
36 />
37 </li>
093ca832
JB
38 <li>
39 Auto start:
40 <input v-model="state.autoStart" type="checkbox" true-value="true" false-value="false" />
41 </li>
3d9f3741
JB
42 <li>
43 Persistent configuration:
44 <input
45 v-model="state.persistentConfiguration"
46 type="checkbox"
47 true-value="true"
48 false-value="false"
49 />
50 </li>
51 <li>
52 OCPP strict compliance:
53 <input
54 v-model="state.ocppStrictCompliance"
55 type="checkbox"
56 true-value="true"
57 false-value="false"
58 />
59 </li>
60 <li>
61 Performance statistics:
62 <input
63 v-model="state.enableStatistics"
64 type="checkbox"
65 true-value="true"
66 false-value="false"
67 />
68 </li>
093ca832 69 </ul>
878855a2
JB
70 <br />
71 <Button
14ee627a 72 id="action-button"
878855a2
JB
73 @click="
74 () => {
75 uiClient
093ca832 76 .addChargingStations(state.template, state.numberOfStations, {
2293fadc 77 supervisionUrls: state.supervisionUrl.length > 0 ? state.supervisionUrl : undefined,
3d9f3741
JB
78 autoStart: convertToBoolean(state.autoStart),
79 persistentConfiguration: convertToBoolean(state.persistentConfiguration),
80 ocppStrictCompliance: convertToBoolean(state.ocppStrictCompliance),
81 enableStatistics: convertToBoolean(state.enableStatistics)
093ca832 82 })
cea23fa0
JB
83 .then(() => {
84 $toast.success('Charging stations successfully added')
85 })
878855a2 86 .catch((error: Error) => {
cea23fa0 87 $toast.error('Error at adding charging stations')
878855a2
JB
88 console.error('Error at adding charging stations:', error)
89 })
90 .finally(() => {
91 $router.push({ name: 'charging-stations' })
92 })
93 }
94 "
878855a2 95 >
1eb5f592
JB
96 Add Charging Stations
97 </Button>
14ee627a 98 <Button id="action-button" @click="$router.push({ name: 'charging-stations' })">Cancel</Button>
7086aac2
JB
99</template>
100
101<script setup lang="ts">
3b0c6e17 102import { getCurrentInstance, ref } from 'vue'
cea23fa0 103import { useToast } from 'vue-toast-notification'
878855a2 104import Button from '@/components/buttons/Button.vue'
093ca832 105import { convertToBoolean } from '@/composables'
878855a2 106
3b0c6e17 107const state = ref({
878855a2 108 template: '',
093ca832 109 numberOfStations: 1,
2293fadc 110 supervisionUrl: '',
3d9f3741
JB
111 autoStart: false,
112 persistentConfiguration: true,
113 ocppStrictCompliance: true,
114 enableStatistics: false
878855a2 115})
7086aac2
JB
116
117const app = getCurrentInstance()
118const uiClient = app?.appContext.config.globalProperties.$uiClient
119
cea23fa0 120const $toast = useToast()
7086aac2
JB
121</script>
122
878855a2
JB
123<style>
124#number-of-stations {
d18fc1e3 125 width: 15%;
878855a2
JB
126 text-align: center;
127}
427a4970
JB
128
129#supervision-url {
130 width: 90%;
131 text-align: left;
132}
878855a2 133</style>