refactor(ui): fix templates code formatting
[e-mobility-charging-stations-simulator.git] / ui / web / src / components / charging-stations / CSData.vue
index 4502f53cb300f48178119e3462382d2c4e7f7628..b88086396c2fb7faa53391ef5f777a3da7b7920d 100644 (file)
@@ -7,7 +7,7 @@
     <td class="cs-table__column">
       {{ getSupervisionUrl() }}
     </td>
-    <td class="cs-table__column">{{ getWsState() }}</td>
+    <td class="cs-table__column">{{ getWSState() }}</td>
     <td class="cs-table__column">
       {{ props.chargingStation?.bootNotificationResponse?.status ?? 'Ø' }}
     </td>
@@ -32,8 +32,9 @@
             }
           })
         "
-        >Set Supervision Url</Button
       >
+        Set Supervision Url
+      </Button>
       <Button @click="openConnection()">Open Connection</Button>
       <Button @click="closeConnection()">Close Connection</Button>
       <Button @click="deleteChargingStation()">Delete Charging Station</Button>
@@ -52,7 +53,7 @@
         <tbody id="connectors-table__body">
           <!-- eslint-disable-next-line vue/valid-v-for -->
           <CSConnector
-            v-for="(connector, index) in getConnectors()"
+            v-for="(connector, index) in getConnectorStatuses()"
             :hash-id="props.chargingStation.stationInfo.hashId"
             :charging-station-id="props.chargingStation.stationInfo.chargingStationId"
             :connector-id="index + 1"
@@ -67,6 +68,7 @@
 
 <script setup lang="ts">
 import { getCurrentInstance } from 'vue'
+import { useToast } from 'vue-toast-notification'
 import CSConnector from '@/components/charging-stations/CSConnector.vue'
 import Button from '@/components/buttons/Button.vue'
 import type { ChargingStationData, ConnectorStatus, Status } from '@/types'
@@ -75,7 +77,7 @@ const props = defineProps<{
   chargingStation: ChargingStationData
 }>()
 
-function getConnectors(): ConnectorStatus[] {
+const getConnectorStatuses = (): ConnectorStatus[] => {
   if (Array.isArray(props.chargingStation.evses) && props.chargingStation.evses.length > 0) {
     const connectorsStatus: ConnectorStatus[] = []
     for (const [evseId, evseStatus] of props.chargingStation.evses.entries()) {
@@ -89,15 +91,15 @@ function getConnectors(): ConnectorStatus[] {
   }
   return props.chargingStation.connectors?.slice(1)
 }
-function getATGStatus(connectorId: number): Status | undefined {
+const getATGStatus = (connectorId: number): Status | undefined => {
   return props.chargingStation.automaticTransactionGenerator
     ?.automaticTransactionGeneratorStatuses?.[connectorId - 1]
 }
-function getSupervisionUrl(): string {
+const getSupervisionUrl = (): string => {
   const supervisionUrl = new URL(props.chargingStation.supervisionUrl)
   return `${supervisionUrl.protocol}//${supervisionUrl.host.split('.').join('.\u200b')}`
 }
-function getWsState(): string {
+const getWSState = (): string => {
   switch (props.chargingStation?.wsState) {
     case WebSocket.CONNECTING:
       return 'Connecting'
@@ -114,20 +116,62 @@ function getWsState(): string {
 
 const uiClient = getCurrentInstance()?.appContext.config.globalProperties.$uiClient
 
-function startChargingStation(): void {
-  uiClient.startChargingStation(props.chargingStation.stationInfo.hashId)
+const $toast = useToast()
+
+const startChargingStation = (): void => {
+  uiClient
+    .startChargingStation(props.chargingStation.stationInfo.hashId)
+    .then(() => {
+      $toast.success('Charging station successfully started')
+    })
+    .catch((error: Error) => {
+      $toast.error('Error at starting charging station')
+      console.error('Error at starting charging station', error)
+    })
 }
-function stopChargingStation(): void {
-  uiClient.stopChargingStation(props.chargingStation.stationInfo.hashId)
+const stopChargingStation = (): void => {
+  uiClient
+    .stopChargingStation(props.chargingStation.stationInfo.hashId)
+    .then(() => {
+      $toast.success('Charging station successfully stopped')
+    })
+    .catch((error: Error) => {
+      $toast.error('Error at stopping charging station')
+      console.error('Error at stopping charging station', error)
+    })
 }
-function openConnection(): void {
-  uiClient.openConnection(props.chargingStation.stationInfo.hashId)
+const openConnection = (): void => {
+  uiClient
+    .openConnection(props.chargingStation.stationInfo.hashId)
+    .then(() => {
+      $toast.success('Connection successfully opened')
+    })
+    .catch((error: Error) => {
+      $toast.error('Error at opening connection')
+      console.error('Error at opening connection', error)
+    })
 }
-function closeConnection(): void {
-  uiClient.closeConnection(props.chargingStation.stationInfo.hashId)
+const closeConnection = (): void => {
+  uiClient
+    .closeConnection(props.chargingStation.stationInfo.hashId)
+    .then(() => {
+      $toast.success('Connection successfully closed')
+    })
+    .catch((error: Error) => {
+      $toast.error('Error at closing connection')
+      console.error('Error at closing connection', error)
+    })
 }
-function deleteChargingStation(): void {
-  uiClient.deleteChargingStation(props.chargingStation.stationInfo.hashId)
+const deleteChargingStation = (): void => {
+  uiClient
+    .deleteChargingStation(props.chargingStation.stationInfo.hashId)
+    .then(() => {
+      $toast.success('Charging station successfully deleted')
+    })
+    .catch((error: Error) => {
+      $toast.error('Error at deleting charging station')
+      console.error('Error at deleting charging station', error)
+    })
 }
 </script>