X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=ui%2Fweb%2Fsrc%2Fviews%2FChargingStationsView.vue;h=57ae3e20d7f0ba65d57a1933b1b483887f739189;hb=240fa4da80fd262158004eb576410d02afe0001f;hp=cbd8a34ba64bf13ad17f8e57a679cb67aa455c63;hpb=3eea3ebcd6172a2928aba166e26d5f06cd4dbe42;p=e-mobility-charging-stations-simulator.git diff --git a/ui/web/src/views/ChargingStationsView.vue b/ui/web/src/views/ChargingStationsView.vue index cbd8a34b..57ae3e20 100644 --- a/ui/web/src/views/ChargingStationsView.vue +++ b/ui/web/src/views/ChargingStationsView.vue @@ -20,6 +20,7 @@ 'open', () => { setToLocalStorage('uiServerConfigurationIndex', state.uiServerIndex) + clearToggleButtons() $router.currentRoute.value.name !== 'charging-stations' && $router.push({ name: 'charging-stations' }) }, @@ -51,8 +52,15 @@ - - + + {{ state.simulatorState?.started === true ? 'Stop' : 'Start' }} Simulator + Add Charging Stations @@ -83,6 +96,12 @@ " :key="state.renderChargingStations" :charging-stations="app?.appContext.config.globalProperties.$chargingStations" + @need-refresh=" + () => { + state.renderAddChargingStations = randomUUID() + state.renderChargingStations = randomUUID() + } + " /> @@ -94,7 +113,6 @@ import CSTable from '@/components/charging-stations/CSTable.vue' import type { ResponsePayload, UIServerConfigurationSection } from '@/types' import Container from '@/components/Container.vue' import ReloadButton from '@/components/buttons/ReloadButton.vue' -import Button from '@/components/buttons/Button.vue' import { getFromLocalStorage, getLocalStorage, @@ -104,6 +122,21 @@ import { } from '@/composables' import ToggleButton from '@/components/buttons/ToggleButton.vue' +const state = ref<{ + renderSimulator: `${string}-${string}-${string}-${string}-${string}` + renderAddChargingStations: `${string}-${string}-${string}-${string}-${string}` + renderChargingStations: `${string}-${string}-${string}-${string}-${string}` + loading: boolean + simulatorState?: { started: boolean } + uiServerIndex: number +}>({ + renderSimulator: randomUUID(), + renderAddChargingStations: randomUUID(), + renderChargingStations: randomUUID(), + loading: false, + uiServerIndex: getFromLocalStorage('uiServerConfigurationIndex', 0) +}) + const app = getCurrentInstance() const clearToggleButtons = (): void => { @@ -115,14 +148,30 @@ const clearToggleButtons = (): void => { } const clearChargingStations = (): void => { - clearToggleButtons() app!.appContext.config.globalProperties.$chargingStations = [] - state.value.renderAddChargingStations = randomUUID() state.value.renderChargingStations = randomUUID() } +const uiClient = app?.appContext.config.globalProperties.$uiClient + +const getSimulatorState = (): void => { + uiClient + .simulatorState() + .then((response: ResponsePayload) => { + state.value.simulatorState = response.state as { started: boolean } + }) + .catch((error: Error) => { + $toast.error('Error at fetching simulator state') + console.error('Error at fetching simulator state:', error) + }) + .finally(() => { + state.value.renderSimulator = randomUUID() + }) +} + const initializeWSEventListeners = () => { app?.appContext.config.globalProperties.$uiClient.registerWSEventListener('open', () => { + getSimulatorState() uiClient .listTemplates() .then((response: ResponsePayload) => { @@ -137,8 +186,10 @@ const initializeWSEventListeners = () => { $toast.error('Error at fetching charging station templates') console.error('Error at fetching charging station templates:', error) }) + .finally(() => { + state.value.renderAddChargingStations = randomUUID() + }) loadChargingStations(() => { - state.value.renderAddChargingStations = randomUUID() state.value.renderChargingStations = randomUUID() }) }) @@ -156,14 +207,6 @@ onMounted(() => { initializeWSEventListeners() }) -const state = ref({ - renderAddChargingStations: randomUUID(), - renderChargingStations: randomUUID(), - loading: false, - uiServerIndex: getFromLocalStorage('uiServerConfigurationIndex', 0) -}) - -const uiClient = app?.appContext.config.globalProperties.$uiClient const uiServerConfigurations: { configuration: UIServerConfigurationSection; index: number }[] = app?.appContext.config.globalProperties.$configuration.uiServer.map( (configuration: UIServerConfigurationSection, index: number) => ({ @@ -210,6 +253,9 @@ const startSimulator = (): void => { $toast.error('Error at starting simulator') console.error('Error at starting simulator:', error) }) + .finally(() => { + getSimulatorState() + }) } const stopSimulator = (): void => { uiClient @@ -224,6 +270,9 @@ const stopSimulator = (): void => { $toast.error('Error at stopping simulator') console.error('Error at stopping simulator:', error) }) + .finally(() => { + getSimulatorState() + }) } @@ -269,7 +318,7 @@ const stopSimulator = (): void => { } #reload-button:active { - background-color: red; + background-color: seagreen; } #action {