Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(EVBackendClient): move available configs to pinia store #127

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/components/EvModuleList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ export default defineComponent({
}
},
config_list(): Array<string> {
const configs: Record<string, unknown> = evbc._configs;
return Object.entries(configs).map(([key]) => key);
return Object.entries(evbcStore.available_configs).map(([key]) => key);
},
},
methods: {
Expand Down
12 changes: 7 additions & 5 deletions src/modules/evbc/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -135,8 +136,9 @@ class EVBackendClient {
}

async _reload_configs(): Promise<void> {
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<void[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/evbc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
};
6 changes: 4 additions & 2 deletions src/store/evbc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<EVConfigModel | null>(null);
const config_context = reactive(new ConfigStageContext());
const available_configs: Ref<EverestConfigList> = ref({});

config_context.add_observer((ev) => {
if (ev.type === "SELECT") {
Expand All @@ -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,
Expand Down
Loading