b88086396c2fb7faa53391ef5f777a3da7b7920d
[e-mobility-charging-stations-simulator.git] / ui / web / src / components / charging-stations / CSData.vue
1 <template>
2 <tr class="cs-table__row">
3 <td class="cs-table__column">
4 {{ props.chargingStation.stationInfo.chargingStationId }}
5 </td>
6 <td class="cs-table__column">{{ props.chargingStation.started === true ? 'Yes' : 'No' }}</td>
7 <td class="cs-table__column">
8 {{ getSupervisionUrl() }}
9 </td>
10 <td class="cs-table__column">{{ getWSState() }}</td>
11 <td class="cs-table__column">
12 {{ props.chargingStation?.bootNotificationResponse?.status ?? 'Ø' }}
13 </td>
14 <td class="cs-table__column">
15 {{ props.chargingStation.stationInfo.templateName }}
16 </td>
17 <td class="cs-table__column">{{ props.chargingStation.stationInfo.chargePointVendor }}</td>
18 <td class="cs-table__column">{{ props.chargingStation.stationInfo.chargePointModel }}</td>
19 <td class="cs-table__column">
20 {{ props.chargingStation.stationInfo.firmwareVersion ?? 'Ø' }}
21 </td>
22 <td class="cs-table__column">
23 <Button @click="startChargingStation()">Start Charging Station</Button>
24 <Button @click="stopChargingStation()">Stop Charging Station</Button>
25 <Button
26 @click="
27 $router.push({
28 name: 'set-supervision-url',
29 params: {
30 hashId: props.chargingStation.stationInfo.hashId,
31 chargingStationId: props.chargingStation.stationInfo.chargingStationId
32 }
33 })
34 "
35 >
36 Set Supervision Url
37 </Button>
38 <Button @click="openConnection()">Open Connection</Button>
39 <Button @click="closeConnection()">Close Connection</Button>
40 <Button @click="deleteChargingStation()">Delete Charging Station</Button>
41 </td>
42 <td class="cs-table__connectors-column">
43 <table id="connectors-table">
44 <thead id="connectors-table__head">
45 <tr class="connectors-table__row">
46 <th scope="col" class="connectors-table__column">Identifier</th>
47 <th scope="col" class="connectors-table__column">Status</th>
48 <th scope="col" class="connectors-table__column">Transaction</th>
49 <th scope="col" class="connectors-table__column">ATG Started</th>
50 <th scope="col" class="connectors-table__column">Actions</th>
51 </tr>
52 </thead>
53 <tbody id="connectors-table__body">
54 <!-- eslint-disable-next-line vue/valid-v-for -->
55 <CSConnector
56 v-for="(connector, index) in getConnectorStatuses()"
57 :hash-id="props.chargingStation.stationInfo.hashId"
58 :charging-station-id="props.chargingStation.stationInfo.chargingStationId"
59 :connector-id="index + 1"
60 :connector="connector"
61 :atg-status="getATGStatus(index + 1)"
62 />
63 </tbody>
64 </table>
65 </td>
66 </tr>
67 </template>
68
69 <script setup lang="ts">
70 import { getCurrentInstance } from 'vue'
71 import { useToast } from 'vue-toast-notification'
72 import CSConnector from '@/components/charging-stations/CSConnector.vue'
73 import Button from '@/components/buttons/Button.vue'
74 import type { ChargingStationData, ConnectorStatus, Status } from '@/types'
75
76 const props = defineProps<{
77 chargingStation: ChargingStationData
78 }>()
79
80 const getConnectorStatuses = (): ConnectorStatus[] => {
81 if (Array.isArray(props.chargingStation.evses) && props.chargingStation.evses.length > 0) {
82 const connectorsStatus: ConnectorStatus[] = []
83 for (const [evseId, evseStatus] of props.chargingStation.evses.entries()) {
84 if (evseId > 0 && Array.isArray(evseStatus.connectors) && evseStatus.connectors.length > 0) {
85 for (const connectorStatus of evseStatus.connectors) {
86 connectorsStatus.push(connectorStatus)
87 }
88 }
89 }
90 return connectorsStatus
91 }
92 return props.chargingStation.connectors?.slice(1)
93 }
94 const getATGStatus = (connectorId: number): Status | undefined => {
95 return props.chargingStation.automaticTransactionGenerator
96 ?.automaticTransactionGeneratorStatuses?.[connectorId - 1]
97 }
98 const getSupervisionUrl = (): string => {
99 const supervisionUrl = new URL(props.chargingStation.supervisionUrl)
100 return `${supervisionUrl.protocol}//${supervisionUrl.host.split('.').join('.\u200b')}`
101 }
102 const getWSState = (): string => {
103 switch (props.chargingStation?.wsState) {
104 case WebSocket.CONNECTING:
105 return 'Connecting'
106 case WebSocket.OPEN:
107 return 'Open'
108 case WebSocket.CLOSING:
109 return 'Closing'
110 case WebSocket.CLOSED:
111 return 'Closed'
112 default:
113 return 'Ø'
114 }
115 }
116
117 const uiClient = getCurrentInstance()?.appContext.config.globalProperties.$uiClient
118
119 const $toast = useToast()
120
121 const startChargingStation = (): void => {
122 uiClient
123 .startChargingStation(props.chargingStation.stationInfo.hashId)
124 .then(() => {
125 $toast.success('Charging station successfully started')
126 })
127 .catch((error: Error) => {
128 $toast.error('Error at starting charging station')
129 console.error('Error at starting charging station', error)
130 })
131 }
132 const stopChargingStation = (): void => {
133 uiClient
134 .stopChargingStation(props.chargingStation.stationInfo.hashId)
135 .then(() => {
136 $toast.success('Charging station successfully stopped')
137 })
138 .catch((error: Error) => {
139 $toast.error('Error at stopping charging station')
140 console.error('Error at stopping charging station', error)
141 })
142 }
143 const openConnection = (): void => {
144 uiClient
145 .openConnection(props.chargingStation.stationInfo.hashId)
146 .then(() => {
147 $toast.success('Connection successfully opened')
148 })
149 .catch((error: Error) => {
150 $toast.error('Error at opening connection')
151 console.error('Error at opening connection', error)
152 })
153 }
154 const closeConnection = (): void => {
155 uiClient
156 .closeConnection(props.chargingStation.stationInfo.hashId)
157 .then(() => {
158 $toast.success('Connection successfully closed')
159 })
160 .catch((error: Error) => {
161 $toast.error('Error at closing connection')
162 console.error('Error at closing connection', error)
163 })
164 }
165 const deleteChargingStation = (): void => {
166 uiClient
167 .deleteChargingStation(props.chargingStation.stationInfo.hashId)
168 .then(() => {
169 $toast.success('Charging station successfully deleted')
170 })
171 .catch((error: Error) => {
172 $toast.error('Error at deleting charging station')
173 console.error('Error at deleting charging station', error)
174 })
175 }
176 </script>
177
178 <style>
179 #connectors-table {
180 display: flex;
181 flex-direction: column;
182 background-color: white;
183 overflow: auto hidden;
184 border-collapse: collapse;
185 empty-cells: show;
186 }
187
188 #connectors-table__body {
189 display: flex;
190 flex-direction: column;
191 }
192
193 .connectors-table__row {
194 display: flex;
195 flex-direction: row;
196 justify-content: center;
197 align-items: center;
198 }
199
200 .connectors-table__row:nth-of-type(even) {
201 background-color: whitesmoke;
202 }
203
204 #connectors-table__head .connectors-table__row {
205 background-color: lightgrey;
206 }
207
208 .connectors-table__column {
209 width: calc(100% / 5);
210 text-align: center;
211 }
212 </style>