<template>
<h1 id="action">Add Charging Stations</h1>
<p>Template:</p>
- <select v-model="state.template">
+ <select :key="state.renderTemplates" v-model="state.template">
<option disabled value="">Please select a template</option>
<option
v-for="template in $templates.value"
</template>
<script setup lang="ts">
-import { ref } from 'vue'
+import { getCurrentInstance, ref, watch } from 'vue'
import Button from '@/components/buttons/Button.vue'
-import { convertToBoolean } from '@/composables'
+import { convertToBoolean, randomUUID } from '@/composables'
const state = ref<{
+ renderTemplates: `${string}-${string}-${string}-${string}-${string}`
template: string
numberOfStations: number
supervisionUrl: string
ocppStrictCompliance: boolean
enableStatistics: boolean
}>({
+ renderTemplates: randomUUID(),
template: '',
numberOfStations: 1,
supervisionUrl: '',
ocppStrictCompliance: true,
enableStatistics: false
})
+
+watch(getCurrentInstance()?.appContext.config.globalProperties.$templates, () => {
+ state.value.renderTemplates = randomUUID()
+})
</script>
<style>
<ToggleButton
:id="'simulator'"
:key="state.renderSimulator"
- :status="state.simulatorState?.started"
+ :status="simulatorState?.started"
:on="() => startSimulator()"
:off="() => stopSimulator()"
:class="simulatorButtonClass"
</template>
<script setup lang="ts">
-import { computed, getCurrentInstance, onMounted, onUnmounted, ref } from 'vue'
+import { computed, getCurrentInstance, onMounted, onUnmounted, ref, watch } from 'vue'
import { useToast } from 'vue-toast-notification'
import CSTable from '@/components/charging-stations/CSTable.vue'
import type { ResponsePayload, SimulatorState, UIServerConfigurationSection } from '@/types'
} from '@/composables'
import ToggleButton from '@/components/buttons/ToggleButton.vue'
+const simulatorState = ref<SimulatorState | undefined>(undefined)
+
+const simulatorButtonClass = computed<string>(() =>
+ simulatorState.value?.started === true ? 'simulator-stop-button' : 'simulator-start-button'
+)
+const simulatorButtonMessage = computed<string>(
+ () =>
+ `${simulatorState.value?.started === true ? 'Stop' : 'Start'} Simulator${simulatorState.value?.version != null ? ` (${simulatorState.value.version})` : ''}`
+)
+
const state = ref<{
renderSimulator: `${string}-${string}-${string}-${string}-${string}`
renderAddChargingStations: `${string}-${string}-${string}-${string}-${string}`
gettingSimulatorState: boolean
gettingTemplates: boolean
gettingChargingStations: boolean
- simulatorState?: SimulatorState
uiServerIndex: number
}>({
renderSimulator: randomUUID(),
uiServerIndex: getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
})
-const simulatorButtonClass = computed<string>(() =>
- state.value.simulatorState?.started === true ? 'simulator-stop-button' : 'simulator-start-button'
-)
-const simulatorButtonMessage = computed<string>(
- () =>
- `${state.value.simulatorState?.started === true ? 'Stop' : 'Start'} Simulator${state.value.simulatorState?.version != null ? ` (${state.value.simulatorState.version})` : ''}`
-)
-
const clearToggleButtons = (): void => {
for (const key in getLocalStorage()) {
if (key.includes('toggle-button')) {
const app = getCurrentInstance()
+watch(app?.appContext.config.globalProperties.$chargingStations, () => {
+ state.value.renderChargingStations = randomUUID()
+})
+
+watch(simulatorState, () => {
+ state.value.renderSimulator = randomUUID()
+})
+
+const clearTemplates = (): void => {
+ if (app != null) {
+ app.appContext.config.globalProperties.$templates.value = []
+ }
+}
+
const clearChargingStations = (): void => {
if (app != null) {
app.appContext.config.globalProperties.$chargingStations.value = []
}
- state.value.renderChargingStations = randomUUID()
}
const uiClient = useUIClient()
uiClient
.simulatorState()
.then((response: ResponsePayload) => {
- state.value.simulatorState = response.state as SimulatorState
+ simulatorState.value = response.state as SimulatorState
})
.catch((error: Error) => {
$toast.error('Error at fetching simulator state')
console.error('Error at fetching simulator state:', error)
})
.finally(() => {
- state.value.renderSimulator = randomUUID()
state.value.gettingSimulatorState = false
})
}
}
})
.catch((error: Error) => {
- if (app != null) {
- app.appContext.config.globalProperties.$templates.value = []
- }
+ clearTemplates()
$toast.error('Error at fetching charging station templates')
console.error('Error at fetching charging station templates:', error)
})
}
})
.catch((error: Error) => {
- if (app != null) {
- app.appContext.config.globalProperties.$chargingStations.value = []
- }
+ clearChargingStations()
$toast.error('Error at fetching charging stations')
console.error('Error at fetching charging stations:', error)
})
.finally(() => {
- state.value.renderChargingStations = randomUUID()
state.value.gettingChargingStations = false
})
}
uiClient
.stopSimulator()
.then(() => {
- if (app != null) {
- app.appContext.config.globalProperties.$chargingStations.value = []
- }
+ clearChargingStations()
$toast.success('Simulator successfully stopped')
})
.catch((error: Error) => {