Skip to content

Commit

Permalink
feat(EvModuleList): auto connect module when terminal selected during…
Browse files Browse the repository at this point in the history
… add

closes #92
closes #90

Signed-off-by: Lukas Mertens <git@lukas-mertens.de>

commit-id:424902b7
  • Loading branch information
lukas-mertens committed Mar 18, 2024
1 parent 0032a6b commit 0518f65
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/components/EvModuleList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,26 @@ export default defineComponent({
},
methods: {
add_module_to_config(type: string) {
// FIXME (aw): does this logic belongs to here?
let added_module_id: number;
if (evbcStore.get_current_config()) {
evbcStore.get_current_config()!.add_new_module_instance(type);
added_module_id = evbcStore.get_current_config()!.add_new_module_instance(type);
} else {
const new_config = evbc.create_empty_config("test_config");
new_config.add_new_module_instance(type);
added_module_id = new_config.add_new_module_instance(type);
evbcStore.setOpenedConfig(new_config);
}
if (evbcStore.get_selected_terminal()) {
const selectedTerminal = evbcStore.get_selected_terminal();
const addedModuleInstance = evbcStore.get_current_config().get_module_instance(added_module_id);
const terminals = Object.values(addedModuleInstance.view_config.terminals).flat();
let terminalToClick;
if (selectedTerminal.type === "requirement") {
terminalToClick = terminals.find((t) => t.interface === selectedTerminal.interface && t.type === "provide");
} else {
terminalToClick = terminals.find((t) => t.interface === selectedTerminal.interface && t.type === "requirement");
}
evbcStore.get_config_context().clicked_terminal(terminalToClick, added_module_id);
}
},
load_config_if_empty(name: string) {
if (!this.current_config) {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/evbc/config_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
TerminalAlignment,
TerminalArrangement,
} from ".";
import { default_terminals, generate_interface_parents_map, InterfaceParentMap } from "./utils";
import {default_terminals, generate_interface_parents_map, InterfaceParentMap} from "./utils";

import clone from "just-clone";

Expand Down Expand Up @@ -318,7 +318,7 @@ class EVConfigModel {
});
}

_add_module_instance(type: string, id: string, config?: EverestModuleConfig, view_config?: ModuleViewConfig) {
_add_module_instance(type: string, id: string, config?: EverestModuleConfig, view_config?: ModuleViewConfig): number {
if (!(type in this._module_definitions)) {
throw Error(`Invalid module type: ${type}`);
}
Expand Down

0 comments on commit 0518f65

Please sign in to comment.