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