fix(ui): fix charging stations refresh
[e-mobility-charging-stations-simulator.git] / ui / web / src / components / charging-stations / CSData.vue
CommitLineData
32de5a57 1<template>
9dc8b66f 2 <tr class="cs-table__row">
f1df3177 3 <td class="cs-table__column">
c317ae3e 4 {{ props.chargingStation.stationInfo.chargingStationId }}
f1df3177
JB
5 </td>
6 <td class="cs-table__column">{{ props.chargingStation.started === true ? 'Yes' : 'No' }}</td>
9dc8b66f
JB
7 <td class="cs-table__column">
8 {{ getSupervisionUrl() }}
9 </td>
1d41bc6b 10 <td class="cs-table__column">{{ getWsState() }}</td>
9dc8b66f 11 <td class="cs-table__column">
f1df3177 12 {{ props.chargingStation?.bootNotificationResponse?.status ?? 'Ø' }}
9dc8b66f
JB
13 </td>
14 <td class="cs-table__column">
f1df3177 15 {{ props.chargingStation.stationInfo.templateName }}
9dc8b66f 16 </td>
f1df3177
JB
17 <td class="cs-table__column">{{ props.chargingStation.stationInfo.chargePointVendor }}</td>
18 <td class="cs-table__column">{{ props.chargingStation.stationInfo.chargePointModel }}</td>
9dc8b66f 19 <td class="cs-table__column">
f1df3177 20 {{ props.chargingStation.stationInfo.firmwareVersion ?? 'Ø' }}
9dc8b66f
JB
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 @click="openConnection()">Open Connection</Button>
26 <Button @click="closeConnection()">Close Connection</Button>
a64b9a64 27 <Button @click="deleteChargingStation()">Delete Charging Station</Button>
9dc8b66f
JB
28 </td>
29 <td class="cs-table__connectors-column">
30 <table id="connectors-table">
31 <thead id="connectors-table__head">
32 <tr class="connectors-table__row">
33 <th scope="col" class="connectors-table__column">Identifier</th>
34 <th scope="col" class="connectors-table__column">Status</th>
35 <th scope="col" class="connectors-table__column">Transaction</th>
36 <th scope="col" class="connectors-table__column">ATG Started</th>
37 <th scope="col" class="connectors-table__column">Actions</th>
38 </tr>
39 </thead>
40 <tbody id="connectors-table__body">
41 <!-- eslint-disable-next-line vue/valid-v-for -->
42 <CSConnector
43 v-for="(connector, index) in getConnectors()"
f1df3177 44 :hash-id="props.chargingStation.stationInfo.hashId"
c317ae3e 45 :charging-station-id="props.chargingStation.stationInfo.chargingStationId"
9dc8b66f
JB
46 :connector-id="index + 1"
47 :connector="connector"
48 :atg-status="getATGStatus(index + 1)"
9dc8b66f
JB
49 />
50 </tbody>
51 </table>
52 </td>
32de5a57
LM
53 </tr>
54</template>
55
56<script setup lang="ts">
9dc8b66f 57import { getCurrentInstance } from 'vue'
9d76f5ec 58import CSConnector from '@/components/charging-stations/CSConnector.vue'
13c19b7b 59import Button from '@/components/buttons/Button.vue'
f1df3177 60import type { ChargingStationData, ConnectorStatus, Status } from '@/types'
32de5a57
LM
61
62const props = defineProps<{
66a7748d 63 chargingStation: ChargingStationData
66a7748d 64}>()
32de5a57 65
f1df3177
JB
66function getConnectors(): ConnectorStatus[] {
67 if (Array.isArray(props.chargingStation.evses) && props.chargingStation.evses.length > 0) {
68 const connectorsStatus: ConnectorStatus[] = []
69 for (const [evseId, evseStatus] of props.chargingStation.evses.entries()) {
70 if (evseId > 0 && Array.isArray(evseStatus.connectors) && evseStatus.connectors.length > 0) {
71 for (const connectorStatus of evseStatus.connectors) {
72 connectorsStatus.push(connectorStatus)
73 }
74 }
75 }
76 return connectorsStatus
77 }
78 return props.chargingStation.connectors?.slice(1)
9dc8b66f
JB
79}
80function getATGStatus(connectorId: number): Status | undefined {
81 return props.chargingStation.automaticTransactionGenerator
82 ?.automaticTransactionGeneratorStatuses?.[connectorId - 1]
32de5a57 83}
1d41bc6b
JB
84function getSupervisionUrl(): string {
85 const supervisionUrl = new URL(props.chargingStation.supervisionUrl)
86 return `${supervisionUrl.protocol}//${supervisionUrl.host.split('.').join('.\u200b')}`
87}
5e3cb728
JB
88function getWsState(): string {
89 switch (props.chargingStation?.wsState) {
90 case WebSocket.CONNECTING:
66a7748d 91 return 'Connecting'
5e3cb728 92 case WebSocket.OPEN:
66a7748d 93 return 'Open'
5e3cb728 94 case WebSocket.CLOSING:
66a7748d 95 return 'Closing'
5e3cb728 96 case WebSocket.CLOSED:
66a7748d 97 return 'Closed'
5e3cb728 98 default:
66a7748d 99 return 'Ø'
5e3cb728
JB
100 }
101}
9dc8b66f 102
57c0ba05 103const uiClient = getCurrentInstance()?.appContext.config.globalProperties.$uiClient
9dc8b66f
JB
104
105function startChargingStation(): void {
57c0ba05 106 uiClient.startChargingStation(props.chargingStation.stationInfo.hashId)
9dc8b66f
JB
107}
108function stopChargingStation(): void {
57c0ba05 109 uiClient.stopChargingStation(props.chargingStation.stationInfo.hashId)
9dc8b66f
JB
110}
111function openConnection(): void {
57c0ba05 112 uiClient.openConnection(props.chargingStation.stationInfo.hashId)
9dc8b66f
JB
113}
114function closeConnection(): void {
57c0ba05 115 uiClient.closeConnection(props.chargingStation.stationInfo.hashId)
9dc8b66f 116}
a64b9a64 117function deleteChargingStation(): void {
57c0ba05 118 uiClient.deleteChargingStation(props.chargingStation.stationInfo.hashId)
a64b9a64 119}
32de5a57 120</script>
9dc8b66f
JB
121
122<style>
123#connectors-table {
124 display: flex;
9dc8b66f 125 flex-direction: column;
b002bbab 126 background-color: white;
9dc8b66f
JB
127 overflow: auto hidden;
128 border-collapse: collapse;
129 empty-cells: show;
130}
131
9dc8b66f
JB
132#connectors-table__body {
133 display: flex;
134 flex-direction: column;
135}
136
137.connectors-table__row {
138 display: flex;
b002bbab 139 flex-direction: row;
9dc8b66f
JB
140 justify-content: center;
141 align-items: center;
142}
143
9dc8b66f
JB
144.connectors-table__row:nth-of-type(even) {
145 background-color: whitesmoke;
146}
147
b002bbab
JB
148#connectors-table__head .connectors-table__row {
149 background-color: lightgrey;
150}
151
9dc8b66f
JB
152.connectors-table__column {
153 width: calc(100% / 5);
154 text-align: center;
155}
156</style>