fix(ui): fix charging stations refresh
[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 @click="openConnection()">Open Connection</Button>
26 <Button @click="closeConnection()">Close Connection</Button>
27 <Button @click="deleteChargingStation()">Delete Charging Station</Button>
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()"
44 :hash-id="props.chargingStation.stationInfo.hashId"
45 :charging-station-id="props.chargingStation.stationInfo.chargingStationId"
46 :connector-id="index + 1"
47 :connector="connector"
48 :atg-status="getATGStatus(index + 1)"
49 />
50 </tbody>
51 </table>
52 </td>
53 </tr>
54 </template>
55
56 <script setup lang="ts">
57 import { getCurrentInstance } from 'vue'
58 import CSConnector from '@/components/charging-stations/CSConnector.vue'
59 import Button from '@/components/buttons/Button.vue'
60 import type { ChargingStationData, ConnectorStatus, Status } from '@/types'
61
62 const props = defineProps<{
63 chargingStation: ChargingStationData
64 }>()
65
66 function 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)
79 }
80 function getATGStatus(connectorId: number): Status | undefined {
81 return props.chargingStation.automaticTransactionGenerator
82 ?.automaticTransactionGeneratorStatuses?.[connectorId - 1]
83 }
84 function getSupervisionUrl(): string {
85 const supervisionUrl = new URL(props.chargingStation.supervisionUrl)
86 return `${supervisionUrl.protocol}//${supervisionUrl.host.split('.').join('.\u200b')}`
87 }
88 function getWsState(): string {
89 switch (props.chargingStation?.wsState) {
90 case WebSocket.CONNECTING:
91 return 'Connecting'
92 case WebSocket.OPEN:
93 return 'Open'
94 case WebSocket.CLOSING:
95 return 'Closing'
96 case WebSocket.CLOSED:
97 return 'Closed'
98 default:
99 return 'Ø'
100 }
101 }
102
103 const uiClient = getCurrentInstance()?.appContext.config.globalProperties.$uiClient
104
105 function startChargingStation(): void {
106 uiClient.startChargingStation(props.chargingStation.stationInfo.hashId)
107 }
108 function stopChargingStation(): void {
109 uiClient.stopChargingStation(props.chargingStation.stationInfo.hashId)
110 }
111 function openConnection(): void {
112 uiClient.openConnection(props.chargingStation.stationInfo.hashId)
113 }
114 function closeConnection(): void {
115 uiClient.closeConnection(props.chargingStation.stationInfo.hashId)
116 }
117 function deleteChargingStation(): void {
118 uiClient.deleteChargingStation(props.chargingStation.stationInfo.hashId)
119 }
120 </script>
121
122 <style>
123 #connectors-table {
124 display: flex;
125 flex-direction: column;
126 background-color: white;
127 overflow: auto hidden;
128 border-collapse: collapse;
129 empty-cells: show;
130 }
131
132 #connectors-table__body {
133 display: flex;
134 flex-direction: column;
135 }
136
137 .connectors-table__row {
138 display: flex;
139 flex-direction: row;
140 justify-content: center;
141 align-items: center;
142 }
143
144 .connectors-table__row:nth-of-type(even) {
145 background-color: whitesmoke;
146 }
147
148 #connectors-table__head .connectors-table__row {
149 background-color: lightgrey;
150 }
151
152 .connectors-table__column {
153 width: calc(100% / 5);
154 text-align: center;
155 }
156 </style>