| 1 | <template> |
| 2 | <h2>Action Add Charging Stations</h2> |
| 3 | <p>Template:</p> |
| 4 | <select v-if="state.ready" v-model="state.template"> |
| 5 | <option v-for="template in app?.appContext.config.globalProperties.$templates"> |
| 6 | {{ template }} |
| 7 | </option> |
| 8 | </select> |
| 9 | <p>Number of stations:</p> |
| 10 | <input |
| 11 | id="number-of-stations" |
| 12 | v-model="state.numberOfStations" |
| 13 | type="text" |
| 14 | name="number-of-station" |
| 15 | placeholder="number of stations" |
| 16 | /> |
| 17 | <br /> |
| 18 | <Button |
| 19 | @click=" |
| 20 | () => { |
| 21 | uiClient |
| 22 | .addChargingStations(state.template, state.numberOfStations) |
| 23 | .catch((error: Error) => { |
| 24 | // TODO: add code for UI notifications or other error handling logic |
| 25 | console.error('Error at adding charging stations:', error) |
| 26 | }) |
| 27 | .finally(() => { |
| 28 | $router.push({ name: 'charging-stations' }) |
| 29 | }) |
| 30 | } |
| 31 | " |
| 32 | >Add Charging Stations</Button |
| 33 | > |
| 34 | <Button @click="$router.push({ name: 'charging-stations' })">Cancel</Button> |
| 35 | </template> |
| 36 | |
| 37 | <script setup lang="ts"> |
| 38 | import { getCurrentInstance, onMounted, reactive } from 'vue' |
| 39 | import Button from '@/components/buttons/Button.vue' |
| 40 | |
| 41 | const state = reactive({ |
| 42 | ready: false, |
| 43 | template: '', |
| 44 | numberOfStations: 1 |
| 45 | }) |
| 46 | |
| 47 | const app = getCurrentInstance() |
| 48 | const uiClient = app?.appContext.config.globalProperties.$uiClient |
| 49 | |
| 50 | onMounted(() => { |
| 51 | uiClient |
| 52 | .listTemplates() |
| 53 | .then((response: ResponsePayload) => { |
| 54 | if (app != null && app.appContext.config.globalProperties.$templates == null) { |
| 55 | app.appContext.config.globalProperties.$templates = response.templates |
| 56 | } |
| 57 | }) |
| 58 | .catch((error: Error) => { |
| 59 | // TODO: add code for UI notifications or other error handling logic |
| 60 | console.error('Error at fetching charging station templates:', error) |
| 61 | }) |
| 62 | .finally(() => { |
| 63 | state.ready = true |
| 64 | }) |
| 65 | }) |
| 66 | </script> |
| 67 | |
| 68 | <style> |
| 69 | #number-of-stations { |
| 70 | text-align: center; |
| 71 | } |
| 72 | </style> |