a0661a08d083060058d8546bdebcec9e77a860f7
[e-mobility-charging-stations-simulator.git] / ui / web / src / components / actions / AddChargingStations.vue
1 <template>
2 <h1 id="action">Action</h1>
3 <h2>Add Charging Stations</h2>
4 <p>Template:</p>
5 <select v-model="state.template">
6 <option disabled value="">Please select a template</option>
7 <option
8 v-for="template in app?.appContext.config.globalProperties.$templates"
9 v-show="
10 Array.isArray(app?.appContext.config.globalProperties.$templates) &&
11 app?.appContext.config.globalProperties.$templates.length > 0
12 "
13 >
14 {{ template }}
15 </option>
16 </select>
17 <p>Number of stations:</p>
18 <input
19 id="number-of-stations"
20 v-model="state.numberOfStations"
21 type="number"
22 min="1"
23 name="number-of-stations"
24 placeholder="number of stations"
25 />
26 <p>Template options overrides:</p>
27 <ul>
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>
38 <li>
39 Auto start:
40 <input v-model="state.autoStart" type="checkbox" true-value="true" false-value="false" />
41 </li>
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>
69 </ul>
70 <br />
71 <Button
72 id="action-button"
73 @click="
74 () => {
75 uiClient
76 .addChargingStations(state.template, state.numberOfStations, {
77 supervisionUrls: state.supervisionUrl.length > 0 ? state.supervisionUrl : undefined,
78 autoStart: convertToBoolean(state.autoStart),
79 persistentConfiguration: convertToBoolean(state.persistentConfiguration),
80 ocppStrictCompliance: convertToBoolean(state.ocppStrictCompliance),
81 enableStatistics: convertToBoolean(state.enableStatistics)
82 })
83 .then(() => {
84 $toast.success('Charging stations successfully added')
85 })
86 .catch((error: Error) => {
87 $toast.error('Error at adding charging stations')
88 console.error('Error at adding charging stations:', error)
89 })
90 .finally(() => {
91 $router.push({ name: 'charging-stations' })
92 })
93 }
94 "
95 >
96 Add Charging Stations
97 </Button>
98 </template>
99
100 <script setup lang="ts">
101 import { getCurrentInstance, ref } from 'vue'
102 import { useToast } from 'vue-toast-notification'
103 import Button from '@/components/buttons/Button.vue'
104 import { convertToBoolean } from '@/composables'
105
106 const state = ref({
107 template: '',
108 numberOfStations: 1,
109 supervisionUrl: '',
110 autoStart: false,
111 persistentConfiguration: true,
112 ocppStrictCompliance: true,
113 enableStatistics: false
114 })
115
116 const app = getCurrentInstance()
117 const uiClient = app?.appContext.config.globalProperties.$uiClient
118
119 const $toast = useToast()
120 </script>
121
122 <style>
123 #number-of-stations {
124 width: 15%;
125 text-align: center;
126 }
127
128 #supervision-url {
129 width: 90%;
130 text-align: left;
131 }
132 </style>