refactor(ui): refine connectors table sizing
[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">
1d41bc6b
JB
3 <td class="cs-table__column">{{ getId() }}</td>
4 <td class="cs-table__column">{{ getStarted() }}</td>
9dc8b66f
JB
5 <td class="cs-table__column">
6 {{ getSupervisionUrl() }}
7 </td>
1d41bc6b 8 <td class="cs-table__column">{{ getWsState() }}</td>
9dc8b66f
JB
9 <td class="cs-table__column">
10 {{ getRegistrationStatus() }}
11 </td>
12 <td class="cs-table__column">
13 {{ getInfo().templateName }}
14 </td>
1d41bc6b
JB
15 <td class="cs-table__column">{{ getVendor() }}</td>
16 <td class="cs-table__column">{{ getModel() }}</td>
9dc8b66f
JB
17 <td class="cs-table__column">
18 {{ getFirmwareVersion() }}
19 </td>
20 <td class="cs-table__column">
21 <Button @click="startChargingStation()">Start Charging Station</Button>
22 <Button @click="stopChargingStation()">Stop Charging Station</Button>
23 <Button @click="openConnection()">Open Connection</Button>
24 <Button @click="closeConnection()">Close Connection</Button>
25 </td>
26 <td class="cs-table__connectors-column">
27 <table id="connectors-table">
28 <thead id="connectors-table__head">
29 <tr class="connectors-table__row">
30 <th scope="col" class="connectors-table__column">Identifier</th>
31 <th scope="col" class="connectors-table__column">Status</th>
32 <th scope="col" class="connectors-table__column">Transaction</th>
33 <th scope="col" class="connectors-table__column">ATG Started</th>
34 <th scope="col" class="connectors-table__column">Actions</th>
35 </tr>
36 </thead>
37 <tbody id="connectors-table__body">
38 <!-- eslint-disable-next-line vue/valid-v-for -->
39 <CSConnector
40 v-for="(connector, index) in getConnectors()"
41 :hash-id="getHashId()"
42 :connector-id="index + 1"
43 :connector="connector"
44 :atg-status="getATGStatus(index + 1)"
45 :transaction-id="connector.transactionId"
46 :id-tag="props.idTag"
47 />
48 </tbody>
49 </table>
50 </td>
32de5a57
LM
51 </tr>
52</template>
53
54<script setup lang="ts">
66a7748d 55// import { reactive } from 'vue'
9dc8b66f 56import { getCurrentInstance } from 'vue'
9d76f5ec 57import CSConnector from '@/components/charging-stations/CSConnector.vue'
9dc8b66f 58import type { ChargingStationData, ChargingStationInfo, ConnectorStatus, Status } from '@/types'
32de5a57
LM
59
60const props = defineProps<{
66a7748d
JB
61 chargingStation: ChargingStationData
62 idTag: string
63}>()
32de5a57 64
5a010bf0 65// type State = {
66a7748d
JB
66// isTagModalVisible: boolean
67// idTag: string
68// }
5a010bf0
JB
69
70// const state: State = reactive({
71// isTagModalVisible: false,
66a7748d
JB
72// idTag: ''
73// })
32de5a57 74
9dc8b66f
JB
75function getStarted(): string {
76 return props.chargingStation.started === true ? 'Yes' : 'No'
77}
78function getATGStatus(connectorId: number): Status | undefined {
79 return props.chargingStation.automaticTransactionGenerator
80 ?.automaticTransactionGeneratorStatuses?.[connectorId - 1]
32de5a57
LM
81}
82function getInfo(): ChargingStationInfo {
66a7748d 83 return props.chargingStation.stationInfo
32de5a57 84}
51c83d6f 85function getHashId(): string {
66a7748d 86 return getInfo().hashId
51c83d6f 87}
32de5a57 88function getId(): string {
1d41bc6b 89 return getInfo().chargingStationId ?? 'Ø'
32de5a57
LM
90}
91function getModel(): string {
66a7748d 92 return getInfo().chargePointModel
32de5a57
LM
93}
94function getVendor(): string {
66a7748d 95 return getInfo().chargePointVendor
32de5a57
LM
96}
97function getFirmwareVersion(): string {
1d41bc6b 98 return getInfo().firmwareVersion ?? 'Ø'
32de5a57 99}
1d41bc6b
JB
100function getSupervisionUrl(): string {
101 const supervisionUrl = new URL(props.chargingStation.supervisionUrl)
102 return `${supervisionUrl.protocol}//${supervisionUrl.host.split('.').join('.\u200b')}`
103}
5e3cb728
JB
104function getWsState(): string {
105 switch (props.chargingStation?.wsState) {
106 case WebSocket.CONNECTING:
66a7748d 107 return 'Connecting'
5e3cb728 108 case WebSocket.OPEN:
66a7748d 109 return 'Open'
5e3cb728 110 case WebSocket.CLOSING:
66a7748d 111 return 'Closing'
5e3cb728 112 case WebSocket.CLOSED:
66a7748d 113 return 'Closed'
5e3cb728 114 default:
66a7748d 115 return 'Ø'
5e3cb728
JB
116 }
117}
333c3566 118function getRegistrationStatus(): string {
66a7748d 119 return props.chargingStation?.bootNotificationResponse?.status ?? 'Ø'
8fc2e5cc 120}
9dc8b66f
JB
121function getConnectors(): ConnectorStatus[] {
122 if (Array.isArray(props.chargingStation.evses) && props.chargingStation.evses.length > 0) {
123 const connectorsStatus: ConnectorStatus[] = []
124 for (const [evseId, evseStatus] of props.chargingStation.evses.entries()) {
125 if (evseId > 0 && Array.isArray(evseStatus.connectors) && evseStatus.connectors.length > 0) {
126 for (const connectorStatus of evseStatus.connectors) {
127 connectorsStatus.push(connectorStatus)
128 }
129 }
130 }
131 return connectorsStatus
132 }
133 return props.chargingStation.connectors?.slice(1)
134}
135
136const UIClient = getCurrentInstance()?.appContext.config.globalProperties.$UIClient
137
138function startChargingStation(): void {
139 UIClient.startChargingStation(getHashId())
140}
141function stopChargingStation(): void {
142 UIClient.stopChargingStation(getHashId())
143}
144function openConnection(): void {
145 UIClient.openConnection(getHashId())
146}
147function closeConnection(): void {
148 UIClient.closeConnection(getHashId())
149}
32de5a57 150// function showTagModal(): void {
66a7748d 151// state.isTagModalVisible = true
32de5a57
LM
152// }
153// function hideTagModal(): void {
66a7748d 154// state.isTagModalVisible = false
32de5a57
LM
155// }
156</script>
9dc8b66f
JB
157
158<style>
159#connectors-table {
160 display: flex;
161 background-color: white;
162 flex-direction: column;
163 overflow: auto hidden;
164 border-collapse: collapse;
165 empty-cells: show;
166}
167
168#connectors-table__head,
169#connectors-table__body {
170 display: flex;
171 flex-direction: column;
172}
173
174.connectors-table__row {
2f0851f8 175 min-height: 4rem;
9dc8b66f
JB
176 display: flex;
177 justify-content: center;
178 align-items: center;
179}
180
181#connectors-table__head .connectors-table__row {
182 background-color: lightgrey;
183}
184
185.connectors-table__row:nth-of-type(even) {
186 background-color: whitesmoke;
187}
188
189.connectors-table__column {
190 width: calc(100% / 5);
191 text-align: center;
192}
193</style>