<h1 id="action">Action</h1>
<h2>Add Charging Stations</h2>
<p>Template:</p>
- <select v-show="state.ready" v-model="state.template">
+ <select
+ v-show="
+ Array.isArray(app?.appContext.config.globalProperties.$templates) &&
+ app?.appContext.config.globalProperties.$templates.length > 0
+ "
+ v-model="state.template"
+ >
<option disabled value="">Please select a template</option>
<option v-for="template in app?.appContext.config.globalProperties.$templates">
{{ template }}
</template>
<script setup lang="ts">
-import { getCurrentInstance, onMounted, reactive } from 'vue'
+import { getCurrentInstance, ref } from 'vue'
import { useToast } from 'vue-toast-notification'
import Button from '@/components/buttons/Button.vue'
-import type { ResponsePayload } from '@/types'
import { convertToBoolean } from '@/composables'
-const state = reactive({
- ready: false,
+const state = ref({
template: '',
numberOfStations: 1,
supervisionUrl: '',
const uiClient = app?.appContext.config.globalProperties.$uiClient
const $toast = useToast()
-
-onMounted(() => {
- uiClient
- .listTemplates()
- .then((response: ResponsePayload) => {
- if (app != null && app.appContext.config.globalProperties.$templates == null) {
- app.appContext.config.globalProperties.$templates = response.templates
- }
- })
- .catch((error: Error) => {
- $toast.error('Error at fetching charging station templates')
- console.error('Error at fetching charging station templates:', error)
- })
- .finally(() => {
- state.ready = true
- })
-})
</script>
<style>
'open',
() => {
setToLocalStorage<number>('uiServerConfigurationIndex', state.uiServerIndex)
- delete app?.appContext.config.globalProperties.$templates
$router.currentRoute.value.name !== 'charging-stations' &&
$router.push({ name: 'charging-stations' })
},
</template>
<script setup lang="ts">
-import { getCurrentInstance, onMounted, reactive } from 'vue'
+import { getCurrentInstance, onMounted, ref } from 'vue'
import { useToast } from 'vue-toast-notification'
import CSTable from '@/components/charging-stations/CSTable.vue'
import type { ResponsePayload, UIServerConfigurationSection } from '@/types'
const initializeWSEventListeners = () => {
app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('open', () => {
- loadChargingStations(() => (state.renderChargingStationsList = randomUUID()))
+ uiClient
+ .listTemplates()
+ .then((response: ResponsePayload) => {
+ if (app != null) {
+ app.appContext.config.globalProperties.$templates = response.templates
+ }
+ })
+ .catch((error: Error) => {
+ if (app != null) {
+ app.appContext.config.globalProperties.$templates = []
+ }
+ $toast.error('Error at fetching charging station templates')
+ console.error('Error at fetching charging station templates:', error)
+ })
+ loadChargingStations(() => (state.value.renderChargingStationsList = randomUUID()))
})
app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('error', () => {
app.appContext.config.globalProperties.$chargingStations = []
- state.renderChargingStationsList = randomUUID()
+ state.value.renderChargingStationsList = randomUUID()
})
app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('close', () => {
app.appContext.config.globalProperties.$chargingStations = []
- state.renderChargingStationsList = randomUUID()
+ state.value.renderChargingStationsList = randomUUID()
})
}
initializeWSEventListeners()
})
-const state = reactive({
+const state = ref({
renderChargingStationsList: randomUUID(),
loading: false,
uiServerIndex: getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
const $toast = useToast()
const loadChargingStations = (renderCallback?: () => void): void => {
- if (state.loading === false) {
- state.loading = true
+ if (state.value.loading === false) {
+ state.value.loading = true
uiClient
.listChargingStations()
.then((response: ResponsePayload) => {
if (renderCallback != null) {
renderCallback()
}
- state.loading = false
+ state.value.loading = false
})
}
}