From 9e61df79836e971462c2f8704468978de30b94c0 Mon Sep 17 00:00:00 2001 From: Lukas Mertens Date: Wed, 10 Apr 2024 15:32:07 +0200 Subject: [PATCH] refactor(EVBackendClient): move available configs to pinia store Signed-off-by: Lukas Mertens commit-id:14f3764c --- src/components/EvModuleList.vue | 3 +-- src/modules/evbc/client.ts | 12 +++++++----- src/plugins/evbc.ts | 2 +- src/store/evbc.ts | 6 ++++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/components/EvModuleList.vue b/src/components/EvModuleList.vue index 975c6aca..0a0f252a 100644 --- a/src/components/EvModuleList.vue +++ b/src/components/EvModuleList.vue @@ -143,8 +143,7 @@ export default defineComponent({ } }, config_list(): Array { - const configs: Record = evbc._configs; - return Object.entries(configs).map(([key]) => key); + return Object.entries(evbcStore.available_configs).map(([key]) => key); }, }, methods: { diff --git a/src/modules/evbc/client.ts b/src/modules/evbc/client.ts index 4407edee..1d3eaca1 100644 --- a/src/modules/evbc/client.ts +++ b/src/modules/evbc/client.ts @@ -10,6 +10,7 @@ import { } from "."; import EVConfigModel from "./config_model"; import EVBackendConnection, {ConnectionStatus} from "./connection"; +import {useEvbcStore} from "@/store/evbc"; type ConnectionStateEvent = { type: "INFO" | "INITIALIZED" | "FAILED" | "RECONNECT" | "IDLE"; @@ -33,7 +34,7 @@ class EVBackendClient { _cxn: EVBackendConnection = null; _event_handler_map: ClientEventHandlerMap = {}; _last_event_map: LastEventMap = {}; - _configs: EverestConfigList; + private evbcStore = useEvbcStore(); readonly everest_definitions: EverestDefinitions = { modules: null, interfaces: null, @@ -70,10 +71,10 @@ class EVBackendClient { // - these shouldn't be callable, until we're successfully connected // - it would be nice, if we got an object after successful connection, that contains that load_config(name: string) { - if (!(name in this._configs)) { + if (!(name in this.evbcStore.available_configs)) { throw Error(`Configuration "${name}" not found`); } - const config = this._configs[name]; + const config = this.evbcStore.available_configs[name]; return new EVConfigModel(this.everest_definitions, name, config); } @@ -135,8 +136,9 @@ class EVBackendClient { } async _reload_configs(): Promise { - this._configs = await this._cxn.rpc_issuer.get_configs(); - this._publish("connection_state", { type: "INFO", text: `Received ${Object.keys(this._configs).length} config files` }); + const cfgs = (await this._cxn.rpc_issuer.get_configs()); + Object.assign(this.evbcStore.available_configs, cfgs); + this._publish("connection_state", { type: "INFO", text: `Received ${Object.keys(cfgs).length} config files` }); } _reload_instance_data(): Promise { diff --git a/src/plugins/evbc.ts b/src/plugins/evbc.ts index ab027d7d..cfeb98cc 100644 --- a/src/plugins/evbc.ts +++ b/src/plugins/evbc.ts @@ -4,10 +4,10 @@ import EVBackendClient from "@/modules/evbc/client"; import { App } from "vue"; -const evbc = new EVBackendClient(); export default { install(app: App) { + const evbc = new EVBackendClient(); app.provide('evbc', evbc); }, }; diff --git a/src/store/evbc.ts b/src/store/evbc.ts index 805bf8d6..dc470f0a 100644 --- a/src/store/evbc.ts +++ b/src/store/evbc.ts @@ -3,15 +3,16 @@ // Copyright 2020 - 2024 Pionix GmbH and Contributors to EVerest import {defineStore} from 'pinia'; -import {reactive, ref} from 'vue'; +import {reactive, Ref, ref} from 'vue'; import EVConfigModel from "@/modules/evbc/config_model"; import ConfigStageContext, {SelectionType} from "@/modules/evconf_konva/stage_context"; -import {ConnectionID, ModuleInstanceID, Terminal} from "@/modules/evbc"; +import {ConnectionID, EverestConfigList, ModuleInstanceID, Terminal} from "@/modules/evbc"; export const useEvbcStore = defineStore('evbc', () => { const selection = ref({ type: "NONE" } as SelectionType); const current_config = ref(null); const config_context = reactive(new ConfigStageContext()); + const available_configs: Ref = ref({}); config_context.add_observer((ev) => { if (ev.type === "SELECT") { @@ -31,6 +32,7 @@ export const useEvbcStore = defineStore('evbc', () => { const get_selected_connection = (): ConnectionID | null => get_is_config_opened() && selection.value.type === "CONNECTION" ? selection.value.id : null; return { + available_configs, selection, current_config, config_context,