diff --git a/src/public/javascripts/services/messaging.js b/src/public/javascripts/services/messaging.js index db8140c24..62ee07bf7 100644 --- a/src/public/javascripts/services/messaging.js +++ b/src/public/javascripts/services/messaging.js @@ -41,7 +41,7 @@ function handleMessage(event) { lastPingTs = new Date().getTime(); if (message.data.length > 0) { - console.log(utils.now(), "Sync data: ", message.data); + console.debug(utils.now(), "Sync data: ", message.data); lastSyncId = message.data[message.data.length - 1].id; } @@ -67,7 +67,7 @@ function connectWebSocket() { // use wss for secure messaging const ws = new WebSocket(protocol + "://" + location.host); - ws.onopen = event => console.log(utils.now(), "Connected to server with WebSocket"); + ws.onopen = event => console.debug(utils.now(), "Connected to server with WebSocket"); ws.onmessage = handleMessage; ws.onclose = function(){ // Try to reconnect in 5 seconds diff --git a/src/public/javascripts/services/note_detail_relation_map.js b/src/public/javascripts/services/note_detail_relation_map.js index dfb2d7e80..984ee6610 100644 --- a/src/public/javascripts/services/note_detail_relation_map.js +++ b/src/public/javascripts/services/note_detail_relation_map.js @@ -4,14 +4,34 @@ import libraryLoader from "./library_loader.js"; const $noteDetailRelationMap = $("#note-detail-relation-map"); const $relationMapCanvas = $("#relation-map-canvas"); +const $addChildNotesButton = $("#relation-map-add-child-notes"); + +let mapData; +let instance; +let initDone = false; async function show() { $noteDetailRelationMap.show(); await libraryLoader.requireLibrary(libraryLoader.RELATION_MAP); + const currentNote = noteDetailService.getCurrentNote(); + mapData = { + notes: [], + relations: [] + }; + + if (currentNote.content) { + try { + mapData = JSON.parse(currentNote.content); + } + catch (e) { + console.log("Could not parse content: ", e); + } + } + jsPlumb.ready(function () { - const instance = jsPlumb.getInstance({ + instance = jsPlumb.getInstance({ Endpoint: ["Dot", {radius: 2}], Connector: "StateMachine", HoverPaintStyle: {stroke: "#1e8151", strokeWidth: 2 }, @@ -29,156 +49,30 @@ async function show() { instance.registerConnectionType("basic", { anchor:"Continuous", connector:"StateMachine" }); - window.jsp = instance; - - let data; - let initDone = false; - - instance.bind("connection", function (info) { - const connection = info.connection; - let type; - - if (initDone) { - type = prompt("Specify new connection label:"); - - data.relations.push({ - connectionId: connection.id, - source: connection.sourceId, - target: connection.targetId, - type: type - }); - - saveData(); - } - else { - type = "none"; - } - - connection.getOverlay("label").setLabel(type); - }); + // instance.bind("connection", function (info) { + // const connection = info.connection; + // let name = "none"; + // + // if (initDone) { + // name = prompt("Specify new connection label:"); + // + // mapData.relations.push({ + // connectionId: connection.id, + // source: connection.sourceId, + // target: connection.targetId, + // name: name + // }); + // + // saveData(); + // } + // + // connection.getOverlay("label").setLabel(name); + // }); jsPlumb.on($relationMapCanvas[0], "dblclick", function(e) { newNode(jsPlumbUtil.uuid(),"new", e.offsetX, e.offsetY, "auto", "auto"); }); - function saveData() { - localStorage.setItem('triliumData', JSON.stringify(data)); - } - - function initNode(el) { - instance.draggable(el, { - handle: ".handle", - start:function(params) { - }, - drag:function(params) { - - }, - stop:function(params) { - const note = data.notes.find(note => note.id === params.el.id); - - if (!note) { - console.error(`Note ${params.el.id} not found!`); - return; - } - - [note.x, note.y] = params.finalPos; - - saveData(); - } - }); - - instance.makeSource(el, { - filter: ".endpoint", - anchor: "Continuous", - connectorStyle: { stroke: "#5c96bc", strokeWidth: 2, outlineStroke: "transparent", outlineWidth: 4 }, - connectionType:"basic", - extract:{ - "action":"the-action" - } - }); - - instance.makeTarget(el, { - dropOptions: { hoverClass: "dragHover" }, - anchor: "Continuous", - allowLoopback: true - }); - - // this is not part of the core demo functionality; it is a means for the Toolkit edition's wrapped - // version of this demo to find out about new nodes being added. - // - instance.fire("jsPlumbDemoNodeAdded", el); - - $(el).resizable({ - resize: function(event, ui) { -// instance.repaint(ui.helper.prop("id")); - - instance.repaintEverything(); - }, - stop: function(event, ui) { - const note = data.notes.find(note => note.id === ui.helper.prop("id")); - - note.width = ui.helper.width(); - note.height = ui.helper.height(); - - saveData(); - }, - handles: "all" - }); - } - - function newNode(id, title, x, y, width, height) { - const $noteBox = $("