refactor: cleanup vue.js global properties usage
[e-mobility-charging-stations-simulator.git] / ui / web / src / components / actions / AddChargingStations.vue
CommitLineData
7086aac2 1<template>
916f0920 2 <h1 id="action">Add Charging Stations</h1>
878855a2 3 <p>Template:</p>
2610da71 4 <select v-model="state.template">
b221407f 5 <option disabled value="">Please select a template</option>
2610da71 6 <option
7e315430
JB
7 v-for="template in $templates.value"
8 v-show="Array.isArray($templates.value) && $templates.value.length > 0"
2610da71 9 >
878855a2
JB
10 {{ template }}
11 </option>
12 </select>
13 <p>Number of stations:</p>
14 <input
15 id="number-of-stations"
16 v-model="state.numberOfStations"
d18fc1e3
JB
17 type="number"
18 min="1"
3a3ba0a2 19 name="number-of-stations"
878855a2
JB
20 placeholder="number of stations"
21 />
2293fadc 22 <p>Template options overrides:</p>
ef2b2d03 23 <ul id="template-options">
2293fadc
JB
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>
093ca832
JB
34 <li>
35 Auto start:
36 <input v-model="state.autoStart" type="checkbox" true-value="true" false-value="false" />
37 </li>
3d9f3741
JB
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>
093ca832 65 </ul>
878855a2
JB
66 <br />
67 <Button
14ee627a 68 id="action-button"
878855a2
JB
69 @click="
70 () => {
7e315430 71 $uiClient
093ca832 72 .addChargingStations(state.template, state.numberOfStations, {
2293fadc 73 supervisionUrls: state.supervisionUrl.length > 0 ? state.supervisionUrl : undefined,
3d9f3741
JB
74 autoStart: convertToBoolean(state.autoStart),
75 persistentConfiguration: convertToBoolean(state.persistentConfiguration),
76 ocppStrictCompliance: convertToBoolean(state.ocppStrictCompliance),
77 enableStatistics: convertToBoolean(state.enableStatistics)
093ca832 78 })
cea23fa0
JB
79 .then(() => {
80 $toast.success('Charging stations successfully added')
81 })
878855a2 82 .catch((error: Error) => {
cea23fa0 83 $toast.error('Error at adding charging stations')
878855a2
JB
84 console.error('Error at adding charging stations:', error)
85 })
86 .finally(() => {
87 $router.push({ name: 'charging-stations' })
88 })
89 }
90 "
878855a2 91 >
1eb5f592
JB
92 Add Charging Stations
93 </Button>
7086aac2
JB
94</template>
95
96<script setup lang="ts">
7e315430 97import { ref } from 'vue'
878855a2 98import Button from '@/components/buttons/Button.vue'
093ca832 99import { convertToBoolean } from '@/composables'
878855a2 100
cf959670
JB
101const state = ref<{
102 template: string
103 numberOfStations: number
104 supervisionUrl: string
105 autoStart: boolean
106 persistentConfiguration: boolean
107 ocppStrictCompliance: boolean
108 enableStatistics: boolean
109}>({
878855a2 110 template: '',
093ca832 111 numberOfStations: 1,
2293fadc 112 supervisionUrl: '',
3d9f3741
JB
113 autoStart: false,
114 persistentConfiguration: true,
115 ocppStrictCompliance: true,
116 enableStatistics: false
878855a2 117})
7086aac2
JB
118</script>
119
878855a2
JB
120<style>
121#number-of-stations {
d18fc1e3 122 width: 15%;
878855a2
JB
123 text-align: center;
124}
427a4970
JB
125
126#supervision-url {
127 width: 90%;
128 text-align: left;
129}
ef2b2d03
JB
130
131#template-options {
132 list-style: circle inside;
133 text-align: left;
134}
878855a2 135</style>