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