refactor(ui): remove uneeded encapsulation
[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
JB
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>
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"
9dc8b66f
JB
45 :connector-id="index + 1"
46 :connector="connector"
47 :atg-status="getATGStatus(index + 1)"
48 :transaction-id="connector.transactionId"
49 :id-tag="props.idTag"
50 />
51 </tbody>
52 </table>
53 </td>
32de5a57
LM
54 </tr>
55</template>
56
57<script setup lang="ts">
9dc8b66f 58import { getCurrentInstance } from 'vue'
9d76f5ec 59import CSConnector from '@/components/charging-stations/CSConnector.vue'
f1df3177 60import type { ChargingStationData, ConnectorStatus, Status } from '@/types'
32de5a57
LM
61
62const props = defineProps<{
66a7748d
JB
63 chargingStation: ChargingStationData
64 idTag: string
65}>()
32de5a57 66
f1df3177
JB
67function getConnectors(): ConnectorStatus[] {
68 if (Array.isArray(props.chargingStation.evses) && props.chargingStation.evses.length > 0) {
69 const connectorsStatus: ConnectorStatus[] = []
70 for (const [evseId, evseStatus] of props.chargingStation.evses.entries()) {
71 if (evseId > 0 && Array.isArray(evseStatus.connectors) && evseStatus.connectors.length > 0) {
72 for (const connectorStatus of evseStatus.connectors) {
73 connectorsStatus.push(connectorStatus)
74 }
75 }
76 }
77 return connectorsStatus
78 }
79 return props.chargingStation.connectors?.slice(1)
9dc8b66f
JB
80}
81function getATGStatus(connectorId: number): Status | undefined {
82 return props.chargingStation.automaticTransactionGenerator
83 ?.automaticTransactionGeneratorStatuses?.[connectorId - 1]
32de5a57 84}
1d41bc6b
JB
85function getSupervisionUrl(): string {
86 const supervisionUrl = new URL(props.chargingStation.supervisionUrl)
87 return `${supervisionUrl.protocol}//${supervisionUrl.host.split('.').join('.\u200b')}`
88}
5e3cb728
JB
89function getWsState(): string {
90 switch (props.chargingStation?.wsState) {
91 case WebSocket.CONNECTING:
66a7748d 92 return 'Connecting'
5e3cb728 93 case WebSocket.OPEN:
66a7748d 94 return 'Open'
5e3cb728 95 case WebSocket.CLOSING:
66a7748d 96 return 'Closing'
5e3cb728 97 case WebSocket.CLOSED:
66a7748d 98 return 'Closed'
5e3cb728 99 default:
66a7748d 100 return 'Ø'
5e3cb728
JB
101 }
102}
9dc8b66f
JB
103
104const UIClient = getCurrentInstance()?.appContext.config.globalProperties.$UIClient
105
106function startChargingStation(): void {
f1df3177 107 UIClient.startChargingStation(props.chargingStation.stationInfo.hashId)
9dc8b66f
JB
108}
109function stopChargingStation(): void {
f1df3177 110 UIClient.stopChargingStation(props.chargingStation.stationInfo.hashId)
9dc8b66f
JB
111}
112function openConnection(): void {
f1df3177 113 UIClient.openConnection(props.chargingStation.stationInfo.hashId)
9dc8b66f
JB
114}
115function closeConnection(): void {
f1df3177 116 UIClient.closeConnection(props.chargingStation.stationInfo.hashId)
9dc8b66f 117}
a64b9a64 118function deleteChargingStation(): void {
f1df3177 119 UIClient.deleteChargingStation(props.chargingStation.stationInfo.hashId)
a64b9a64 120}
32de5a57 121</script>
9dc8b66f
JB
122
123<style>
124#connectors-table {
125 display: flex;
9dc8b66f 126 flex-direction: column;
b002bbab 127 background-color: white;
9dc8b66f
JB
128 overflow: auto hidden;
129 border-collapse: collapse;
130 empty-cells: show;
131}
132
9dc8b66f
JB
133#connectors-table__body {
134 display: flex;
135 flex-direction: column;
136}
137
138.connectors-table__row {
139 display: flex;
b002bbab 140 flex-direction: row;
9dc8b66f
JB
141 justify-content: center;
142 align-items: center;
143}
144
9dc8b66f
JB
145.connectors-table__row:nth-of-type(even) {
146 background-color: whitesmoke;
147}
148
b002bbab
JB
149#connectors-table__head .connectors-table__row {
150 background-color: lightgrey;
151}
152
9dc8b66f
JB
153.connectors-table__column {
154 width: calc(100% / 5);
155 text-align: center;
156}
157</style>