feat(ui): add charging stations action support
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 18 Feb 2024 09:25:26 +0000 (10:25 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 18 Feb 2024 09:25:26 +0000 (10:25 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
ui/web/src/components/actions/AddChargingStations.vue
ui/web/src/components/buttons/ReloadButton.vue
ui/web/src/views/ChargingStationsView.vue

index 94879da1c0d089512b144c57e4b01f1d3f7e49e2..164518b1f70e7fd8590d1b9b6dc1ab63998f4da9 100644 (file)
@@ -1,9 +1,48 @@
 <template>
   <h2>Action Add Charging Stations</h2>
+  <p>Template:</p>
+  <select v-if="state.ready" v-model="state.template">
+    <option v-for="template in app?.appContext.config.globalProperties.$templates">
+      {{ template }}
+    </option>
+  </select>
+  <p>Number of stations:</p>
+  <input
+    id="number-of-stations"
+    v-model="state.numberOfStations"
+    type="text"
+    name="number-of-station"
+    placeholder="number of stations"
+  />
+  <br />
+  <Button
+    @click="
+      () => {
+        uiClient
+          .addChargingStations(state.template, state.numberOfStations)
+          .catch((error: Error) => {
+            // TODO: add code for UI notifications or other error handling logic
+            console.error('Error at adding charging stations:', error)
+          })
+          .finally(() => {
+            $router.push({ name: 'charging-stations' })
+          })
+      }
+    "
+    >Add Charging Stations</Button
+  >
+  <Button @click="$router.push({ name: 'charging-stations' })">Cancel</Button>
 </template>
 
 <script setup lang="ts">
-import { getCurrentInstance, onMounted } from 'vue'
+import { getCurrentInstance, onMounted, reactive } from 'vue'
+import Button from '@/components/buttons/Button.vue'
+
+const state = reactive({
+  ready: false,
+  template: '',
+  numberOfStations: 1
+})
 
 const app = getCurrentInstance()
 const uiClient = app?.appContext.config.globalProperties.$uiClient
@@ -20,7 +59,14 @@ onMounted(() => {
       // TODO: add code for UI notifications or other error handling logic
       console.error('Error at fetching charging station templates:', error)
     })
+    .finally(() => {
+      state.ready = true
+    })
 })
 </script>
 
-<style></style>
+<style>
+#number-of-stations {
+  text-align: center;
+}
+</style>
index c43a4688420f9c16b0165892ecc7a5593b4e7514..2fa291af8ae536ceaf4adcfb486482bda08f637e 100644 (file)
@@ -1,13 +1,13 @@
 <template>
   <FlatButton>
-    <span style="display: inline-block" :class="{ spin: props.loading }"> &#8635; </span>
+    <span style="display: inline-block" :class="{ spin: loading }"> &#8635; </span>
   </FlatButton>
 </template>
 
 <script setup lang="ts">
 import FlatButton from '@/components/buttons/FlatButton.vue'
 
-const props = defineProps<{
+defineProps<{
   loading: boolean
 }>()
 </script>
index c2e12cb58c088cbe3cefc67ee4ceb9c9f2e1a21b..d0acc4e3562c9e3a1b5ffb9f531cb5adc82ec614 100644 (file)
@@ -1,8 +1,11 @@
 <template>
   <Container id="charging-stations-container">
     <Container id="buttons-container">
-      <Button id="simulator-button" @click="startSimulator()">Start Simulator</Button>
-      <Button id="simulator-button" @click="stopSimulator()">Stop Simulator</Button>
+      <Button id="button" @click="startSimulator()">Start Simulator</Button>
+      <Button id="button" @click="stopSimulator()">Stop Simulator</Button>
+      <Button id="button" @click="$router.push({ name: 'add-charging-stations' })"
+        >Add Charging Stations</Button
+      >
       <ReloadButton
         id="reload-button"
         :loading="state.isLoading"
@@ -72,6 +75,10 @@ function stopSimulator(): void {
   flex-direction: row;
 }
 
+#button {
+  flex: auto;
+}
+
 #reload-button {
   flex: auto;
   color: white;
@@ -89,8 +96,4 @@ function stopSimulator(): void {
 #reload-button:active {
   background-color: red;
 }
-
-#simulator-button {
-  flex: auto;
-}
 </style>