From 49d2d05e31a36167e07bb3d96ac7126fc3c8c543 Mon Sep 17 00:00:00 2001 From: Max <m.giller.dev@gmail.com> Date: Wed, 29 Sep 2021 17:10:16 +0200 Subject: [PATCH] Implemented simple prototype connect tool menu --- editor/editor.php | 11 ++++++++++- editor/js/tools/connecttool.js | 8 +++++++- editor/js/tools/menus/connectmenu.js | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/editor/editor.php b/editor/editor.php index 6818b7b..acdbb04 100644 --- a/editor/editor.php +++ b/editor/editor.php @@ -2,7 +2,16 @@ <h1>Interface</h1> <div id="2d-graph"></div> <section id="toolbar"></section> - <section id="tool-menu" class="hidden"></section> + <section id="tool-menu"> + <div id="connect-menu" class="hidden"> + <label for="link-type">Link Type</label> + <select id="link-type" name="link-type"> + <option value="Vorlesung">Lecture</option> + <option value="Algorithmus">Algorithm</option> + <option value="Definition">Definition</option> + </select> + </div> + </section> <section> <h3 id="selected-item">Nothing selected</h3> <ul id="selected-params"></ul> diff --git a/editor/js/tools/connecttool.js b/editor/js/tools/connecttool.js index 5fb9de1..1253886 100644 --- a/editor/js/tools/connecttool.js +++ b/editor/js/tools/connecttool.js @@ -1,6 +1,7 @@ import Tool from "./tool"; import { graph, state } from "../editor"; import * as Graph from "../graph"; +import ConnectMenu from "./menus/connectmenu"; const KEEP_SOURCE_KEY_ID = 17; @@ -8,6 +9,7 @@ export default class ConnectTool extends Tool { constructor(key) { super("Connect two nodes", "connect", key); this.keepSource = false; + this.menu = new ConnectMenu(this); } onNodeClick(node) { @@ -21,9 +23,13 @@ export default class ConnectTool extends Tool { } // Add new link + var details = {}; + details[Graph.LINK_TYPE] = this.menu.value("link-type"); + var link = graph.addLink( state.selectedItem[Graph.NODE_ID], - node[Graph.NODE_ID] + node[Graph.NODE_ID], + details ); if (link === undefined) { diff --git a/editor/js/tools/menus/connectmenu.js b/editor/js/tools/menus/connectmenu.js index e69de29..d901fff 100644 --- a/editor/js/tools/menus/connectmenu.js +++ b/editor/js/tools/menus/connectmenu.js @@ -0,0 +1,15 @@ +import ToolMenu from "./toolmenu"; + +const LINK_TYPE_SEL = "#link-type"; + +export default class ConnectMenu extends ToolMenu { + constructor(tool) { + super(tool); + } + + beforeGet(key) { + if (key === "link-type") { + return this.getChildren(LINK_TYPE_SEL).val(); + } + } +} \ No newline at end of file -- GitLab