refactor(ui): refine action container styling
[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>
2610da71 5 <select v-model="state.template">
b221407f 6 <option disabled value="">Please select a template</option>
2610da71
JB
7 <option
8 v-for="template in app?.appContext.config.globalProperties.$templates"
9 v-show="
10 Array.isArray(app?.appContext.config.globalProperties.$templates) &&
3eea3ebc 11 app.appContext.config.globalProperties.$templates.length > 0
2610da71
JB
12 "
13 >
878855a2
JB
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>
ef2b2d03 27 <ul id="template-options">
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>
7086aac2
JB
98</template>
99
100<script setup lang="ts">
3b0c6e17 101import { getCurrentInstance, ref } from 'vue'
cea23fa0 102import { useToast } from 'vue-toast-notification'
878855a2 103import Button from '@/components/buttons/Button.vue'
093ca832 104import { convertToBoolean } from '@/composables'
878855a2 105
cf959670
JB
106const state = ref<{
107 template: string
108 numberOfStations: number
109 supervisionUrl: string
110 autoStart: boolean
111 persistentConfiguration: boolean
112 ocppStrictCompliance: boolean
113 enableStatistics: boolean
114}>({
878855a2 115 template: '',
093ca832 116 numberOfStations: 1,
2293fadc 117 supervisionUrl: '',
3d9f3741
JB
118 autoStart: false,
119 persistentConfiguration: true,
120 ocppStrictCompliance: true,
121 enableStatistics: false
878855a2 122})
7086aac2
JB
123
124const app = getCurrentInstance()
125const uiClient = app?.appContext.config.globalProperties.$uiClient
126
cea23fa0 127const $toast = useToast()
7086aac2
JB
128</script>
129
878855a2
JB
130<style>
131#number-of-stations {
d18fc1e3 132 width: 15%;
878855a2
JB
133 text-align: center;
134}
427a4970
JB
135
136#supervision-url {
137 width: 90%;
138 text-align: left;
139}
ef2b2d03
JB
140
141#template-options {
142 list-style: circle inside;
143 text-align: left;
144}
878855a2 145</style>