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