From 242bea236f518a87bd865ed2a8e8845594885453 Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 27 Aug 2019 21:24:31 +0200 Subject: [PATCH] removed link remnants --- docs/backend_api/Note.html | 222 +----------------- docs/backend_api/entities_note.js.html | 18 -- .../services_backend_script_api.js.html | 6 +- docs/frontend_api/FrontendScriptApi.html | 66 +++--- docs/frontend_api/global.html | 2 +- .../services_frontend_script_api.js.html | 1 - src/entities/note.js | 18 -- src/public/javascripts/dialogs/link_map.js | 203 +--------------- src/public/javascripts/services/attributes.js | 2 - .../services/frontend_script_api.js | 1 - src/public/javascripts/services/link_map.js | 1 - .../services/note_detail_relation_map.js | 8 - src/routes/api/links.js | 28 --- src/routes/routes.js | 3 - src/services/repository.js | 6 - 15 files changed, 53 insertions(+), 532 deletions(-) delete mode 100644 src/routes/api/links.js diff --git a/docs/backend_api/Note.html b/docs/backend_api/Note.html index 4ffc94575..2c8828dbb 100644 --- a/docs/backend_api/Note.html +++ b/docs/backend_api/Note.html @@ -1034,7 +1034,7 @@
Source:
@@ -1136,7 +1136,7 @@
Source:
@@ -1242,7 +1242,7 @@
Source:
@@ -2987,112 +2987,6 @@ -

(async) getLinksWithDeleted() → {Promise.<Array.<Link>>}

- - - - - - -
- Return all links from this note, including deleted ones. -
- - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -Promise.<Array.<Link>> - - -
-
- - - - - - - - - - - - -

(async) getOwnedAttributes() → {Promise.<Array.<Attribute>>}

@@ -3247,7 +3141,7 @@
Source:
@@ -4482,112 +4376,6 @@ - - - - - - - -
- Get list of links targetting this note. -
- - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - - - - - - - -
Returns:
- - - - -
-
- Type -
-
- -Promise.<Array.<Link>> - - -
-
- - - - - - - - - - - - -

(async) getTargetRelations() → {Promise.<Array.<Attribute>>}

@@ -4920,7 +4708,7 @@
Source:
diff --git a/docs/backend_api/entities_note.js.html b/docs/backend_api/entities_note.js.html index 1b350728b..dcc2418d9 100644 --- a/docs/backend_api/entities_note.js.html +++ b/docs/backend_api/entities_note.js.html @@ -669,24 +669,6 @@ class Note extends Entity { name IN ('internal-link', 'image-link', 'relation-map-link')`, [this.noteId]); } - /** - * Get list of links targetting this note. - * - * @returns {Promise<Link[]>} - */ - async getTargetLinks() { - return await repository.getEntities("SELECT * FROM links WHERE targetNoteId = ? AND isDeleted = 0", [this.noteId]); - } - - /** - * Return all links from this note, including deleted ones. - * - * @returns {Promise<Link[]>} - */ - async getLinksWithDeleted() { - return await repository.getEntities("SELECT * FROM links WHERE noteId = ?", [this.noteId]); - } - /** * @returns {Promise<Branch[]>} */ diff --git a/docs/backend_api/services_backend_script_api.js.html b/docs/backend_api/services_backend_script_api.js.html index 8e5438ee3..9afc0aea4 100644 --- a/docs/backend_api/services_backend_script_api.js.html +++ b/docs/backend_api/services_backend_script_api.js.html @@ -38,7 +38,7 @@ const repository = require('./repository'); const axios = require('axios'); const dayjs = require('dayjs'); const cloningService = require('./cloning'); -const messagingService = require('./messaging'); +const ws = require('./ws.js'); const appInfo = require('./app_info'); const searchService = require('./search'); @@ -239,7 +239,7 @@ function BackendScriptApi(currentNote, apiParams) { this.createNoteAndRefresh = async function(parentNoteId, title, content, extraOptions) { await noteService.createNote(parentNoteId, title, content, extraOptions); - messagingService.refreshTree(); + ws.refreshTree(); }; /** @@ -335,7 +335,7 @@ function BackendScriptApi(currentNote, apiParams) { * * @returns {Promise<void>} */ - this.refreshTree = messagingService.refreshTree; + this.refreshTree = ws.refreshTree; /** * @return {{syncVersion, appVersion, buildRevision, dbVersion, dataDirectory, buildDate}|*} - object representing basic info about running Trilium version diff --git a/docs/frontend_api/FrontendScriptApi.html b/docs/frontend_api/FrontendScriptApi.html index b6a5c6857..58f9fcc86 100644 --- a/docs/frontend_api/FrontendScriptApi.html +++ b/docs/frontend_api/FrontendScriptApi.html @@ -81,7 +81,7 @@
Source:
@@ -223,7 +223,7 @@
Source:
@@ -336,7 +336,7 @@
Source:
@@ -442,7 +442,7 @@
Source:
@@ -552,7 +552,7 @@
Source:
@@ -661,7 +661,7 @@
Source:
@@ -790,7 +790,7 @@
Source:
@@ -945,7 +945,7 @@
Source:
@@ -1100,7 +1100,7 @@
Source:
@@ -1280,7 +1280,7 @@
Source:
@@ -1413,7 +1413,7 @@
Source:
@@ -1519,7 +1519,7 @@
Source:
@@ -1625,7 +1625,7 @@
Source:
@@ -1784,7 +1784,7 @@
Source:
@@ -1891,7 +1891,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -2046,7 +2046,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -2202,7 +2202,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -2403,7 +2403,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -2509,7 +2509,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -2664,7 +2664,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -2773,7 +2773,7 @@ note.
Source:
@@ -2928,7 +2928,7 @@ note.
Source:
@@ -3061,7 +3061,7 @@ note.
Source:
@@ -3167,7 +3167,7 @@ note.
Source:
@@ -3255,7 +3255,7 @@ note.
Source:
@@ -3406,7 +3406,7 @@ note.
Source:
@@ -3539,7 +3539,7 @@ note.
Source:
@@ -3700,7 +3700,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -3860,7 +3860,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -4016,7 +4016,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -4167,7 +4167,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -4304,7 +4304,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -4441,7 +4441,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
diff --git a/docs/frontend_api/global.html b/docs/frontend_api/global.html index cb036d1f8..0a422518d 100644 --- a/docs/frontend_api/global.html +++ b/docs/frontend_api/global.html @@ -303,7 +303,7 @@
Source:
diff --git a/docs/frontend_api/services_frontend_script_api.js.html b/docs/frontend_api/services_frontend_script_api.js.html index 40e144f13..74d1bb234 100644 --- a/docs/frontend_api/services_frontend_script_api.js.html +++ b/docs/frontend_api/services_frontend_script_api.js.html @@ -33,7 +33,6 @@ import infoService from './info.js'; import linkService from './link.js'; import treeCache from './tree_cache.js'; import noteDetailService from './note_detail.js'; -import noteTypeService from './note_type.js'; import noteTooltipService from './note_tooltip.js'; import protectedSessionService from './protected_session.js'; import dateNotesService from './date_notes.js'; diff --git a/src/entities/note.js b/src/entities/note.js index 39b3cbe9f..c7426ecfb 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -641,24 +641,6 @@ class Note extends Entity { name IN ('internal-link', 'image-link', 'relation-map-link')`, [this.noteId]); } - /** - * Get list of links targetting this note. - * - * @returns {Promise} - */ - async getTargetLinks() { - return await repository.getEntities("SELECT * FROM links WHERE targetNoteId = ? AND isDeleted = 0", [this.noteId]); - } - - /** - * Return all links from this note, including deleted ones. - * - * @returns {Promise} - */ - async getLinksWithDeleted() { - return await repository.getEntities("SELECT * FROM links WHERE noteId = ?", [this.noteId]); - } - /** * @returns {Promise} */ diff --git a/src/public/javascripts/dialogs/link_map.js b/src/public/javascripts/dialogs/link_map.js index 6f0ca6ba4..ffc69d598 100644 --- a/src/public/javascripts/dialogs/link_map.js +++ b/src/public/javascripts/dialogs/link_map.js @@ -1,30 +1,15 @@ -import server from '../services/server.js'; -import noteDetailService from "../services/note_detail.js"; -import libraryLoader from "../services/library_loader.js"; -import treeCache from "../services/tree_cache.js"; -import linkService from "../services/link.js"; import utils from "../services/utils.js"; +import LinkMapService from "../services/link_map.js"; +import noteDetailService from "../services/note_detail.js"; const $linkMapContainer = $("#link-map-container"); -const linkOverlays = [ - [ "Arrow", { - location: 1, - id: "arrow", - length: 10, - width: 10, - foldback: 0.7 - } ] -]; - const LINK_TYPES = [ "hyper", "image", "relation", "relation-map" ]; const $dialog = $("#link-map-dialog"); const $maxNotesInput = $("#link-map-max-notes"); -let jsPlumbInstance = null; -let pzInstance = null; -let renderer = null; +let linkMapService; export async function showDialog() { utils.closeActiveDialog(); @@ -35,184 +20,18 @@ export async function showDialog() { $maxNotesInput.val(10); LINK_TYPES.forEach(lt => $("#link-map-" + lt).prop('checked', true)); - await libraryLoader.requireLibrary(libraryLoader.LINK_MAP); + const note = noteDetailService.getActiveNoteId(); - jsPlumb.ready(() => { - initJsPlumbInstance(); + if (!note) { + return; + } - initPanZoom(); - - loadNotesAndRelations(); - }); + linkMapService = new LinkMapService(note, $linkMapContainer); + linkMapService.render(); $dialog.modal(); } -async function loadNotesAndRelations() { - cleanup(); +$(".link-map-settings").change(() => linkMapService.loadNotesAndRelations()); - const linkTypes = LINK_TYPES.filter(lt => $(`#link-map-${lt}:checked`).length > 0); - const maxNotes = parseInt($maxNotesInput.val()); - - const activeNoteId = noteDetailService.getActiveNoteId(); - - const links = await server.post(`notes/${activeNoteId}/link-map`, { - linkTypes, - maxNotes - }); - - const noteIds = new Set(links.map(l => l.noteId).concat(links.map(l => l.targetNoteId))); - - if (noteIds.size === 0) { - noteIds.add(activeNoteId); - } - - // preload all notes - const notes = await treeCache.getNotes(Array.from(noteIds)); - - const graph = new Springy.Graph(); - graph.addNodes(...noteIds); - graph.addEdges(...links.map(l => [l.noteId, l.targetNoteId])); - - const layout = new Springy.Layout.ForceDirected( - graph, - 400.0, // Spring stiffness - 400.0, // Node repulsion - 0.5 // Damping - ); - - function getNoteBox(noteId) { - const noteBoxId = noteIdToId(noteId); - const $existingNoteBox = $("#" + noteBoxId); - - if ($existingNoteBox.length > 0) { - return $existingNoteBox; - } - - const note = notes.find(n => n.noteId === noteId); - - const $noteBox = $("
") - .addClass("note-box") - .prop("id", noteBoxId); - - linkService.createNoteLink(noteId, note.title).then($link => { - $noteBox.append($("").addClass("title").append($link)); - }); - - if (activeNoteId === noteId) { - $noteBox.addClass("link-map-active-note"); - } - - jsPlumbInstance.getContainer().appendChild($noteBox[0]); - - jsPlumbInstance.draggable($noteBox[0], { - start: params => { - renderer.stop(); - }, - drag: params => {}, - stop: params => {} - }); - - - return $noteBox; - } - - renderer = new Springy.Renderer( - layout, - () => {}, - (edge, p1, p2) => { - const connectionId = edge.source.id + '-' + edge.target.id; - - if ($("#" + connectionId).length > 0) { - return; - } - - getNoteBox(edge.source.id); - getNoteBox(edge.target.id); - - const connection = jsPlumbInstance.connect({ - source: noteIdToId(edge.source.id), - target: noteIdToId(edge.target.id), - type: 'link' - }); - - connection.canvas.id = connectionId; - }, - (node, p) => { - const $noteBox = getNoteBox(node.id); - const middleW = $linkMapContainer.width() / 2; - const middleH = $linkMapContainer.height() / 2; - - $noteBox - .css("left", (middleW + p.x * 100) + "px") - .css("top", (middleH + p.y * 100) + "px"); - }, - () => {}, - () => {}, - () => { - jsPlumbInstance.repaintEverything(); - } - ); - - renderer.start(); -} - -function initPanZoom() { - if (pzInstance) { - return; - } - - pzInstance = panzoom($linkMapContainer[0], { - maxZoom: 2, - minZoom: 0.3, - smoothScroll: false, - filterKey: function (e, dx, dy, dz) { - // if ALT is pressed then panzoom should bubble the event up - // this is to preserve ALT-LEFT, ALT-RIGHT navigation working - return e.altKey; - } - }); -} - -function cleanup() { - if (renderer) { - renderer.stop(); - } - - // delete all endpoints and connections - // this is done at this point (after async operations) to reduce flicker to the minimum - jsPlumbInstance.deleteEveryEndpoint(); - - // without this we still end up with note boxes remaining in the canvas - $linkMapContainer.empty(); - - // reset zoom/pan - pzInstance.zoomTo(0, 0, 1); - pzInstance.moveTo(0, 0); -} - -function initJsPlumbInstance() { - if (jsPlumbInstance) { - cleanup(); - - return; - } - - jsPlumbInstance = jsPlumb.getInstance({ - Endpoint: ["Blank", {}], - ConnectionOverlays: linkOverlays, - PaintStyle: { stroke: "var(--muted-text-color)", strokeWidth: 1 }, - HoverPaintStyle: { stroke: "var(--main-text-color)", strokeWidth: 1 }, - Container: $linkMapContainer.attr("id") - }); - - jsPlumbInstance.registerConnectionType("link", { anchor: "Continuous", connector: "Straight", overlays: linkOverlays }); -} - -function noteIdToId(noteId) { - return "link-map-note-" + noteId; -} - -$(".link-map-settings").change(loadNotesAndRelations); - -$maxNotesInput.on("input", loadNotesAndRelations); +$maxNotesInput.on("input", () => linkMapService.loadNotesAndRelations()); diff --git a/src/public/javascripts/services/attributes.js b/src/public/javascripts/services/attributes.js index 5a62e60f9..36c6d95bf 100644 --- a/src/public/javascripts/services/attributes.js +++ b/src/public/javascripts/services/attributes.js @@ -1,9 +1,7 @@ import server from "./server.js"; -import utils from "./utils.js"; import ws from "./ws.js"; import treeUtils from "./tree_utils.js"; import noteAutocompleteService from "./note_autocomplete.js"; -import linkService from "./link.js"; class Attributes { /** diff --git a/src/public/javascripts/services/frontend_script_api.js b/src/public/javascripts/services/frontend_script_api.js index 846a9471f..41337f4bc 100644 --- a/src/public/javascripts/services/frontend_script_api.js +++ b/src/public/javascripts/services/frontend_script_api.js @@ -5,7 +5,6 @@ import infoService from './info.js'; import linkService from './link.js'; import treeCache from './tree_cache.js'; import noteDetailService from './note_detail.js'; -import noteTypeService from './note_type.js'; import noteTooltipService from './note_tooltip.js'; import protectedSessionService from './protected_session.js'; import dateNotesService from './date_notes.js'; diff --git a/src/public/javascripts/services/link_map.js b/src/public/javascripts/services/link_map.js index 6f1522516..f74ec8763 100644 --- a/src/public/javascripts/services/link_map.js +++ b/src/public/javascripts/services/link_map.js @@ -55,7 +55,6 @@ export default class LinkMap { const graph = new Springy.Graph(); graph.addNodes(...noteIds); - graph.addEdges(...links.map(l => [l.noteId, l.targetNoteId])); const layout = new Springy.Layout.ForceDirected( graph, diff --git a/src/public/javascripts/services/note_detail_relation_map.js b/src/public/javascripts/services/note_detail_relation_map.js index fff5b3320..63dfb6d0a 100644 --- a/src/public/javascripts/services/note_detail_relation_map.js +++ b/src/public/javascripts/services/note_detail_relation_map.js @@ -316,14 +316,6 @@ class NoteDetailRelationMap { connection.canvas.setAttribute("data-connection-id", connection.id); } - - for (const link of data.links) { - this.jsPlumbInstance.connect({ - source: this.noteIdToId(link.sourceNoteId), - target: this.noteIdToId(link.targetNoteId), - type: 'link' - }); - } }); } diff --git a/src/routes/api/links.js b/src/routes/api/links.js deleted file mode 100644 index 04a2bab36..000000000 --- a/src/routes/api/links.js +++ /dev/null @@ -1,28 +0,0 @@ -"use strict"; - -const repository = require('../../services/repository'); - -async function getLinks(req) { - const note = await repository.getNote(req.params.noteId); - - if (!note) { - return [404, `Note ${req.params.noteId} not found`]; - } - - return await note.getLinks(); -} - -async function getIncomingLinks(req) { - const note = await repository.getNote(req.params.noteId); - - if (!note) { - return [404, `Note ${req.params.noteId} not found`]; - } - - note.getTargetRelations() -} - -module.exports = { - getLinks, - getIncomingLinks -}; \ No newline at end of file diff --git a/src/routes/routes.js b/src/routes/routes.js index a5898fbcf..ce2cf85d3 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -33,7 +33,6 @@ const filesRoute = require('./api/file_upload'); const searchRoute = require('./api/search'); const dateNotesRoute = require('./api/date_notes'); const linkMapRoute = require('./api/link_map'); -const linksRoute = require('./api/links'); const clipperRoute = require('./api/clipper'); const customCodeMimeTypesRoute = require('./api/custom_code_mime_types.js'); @@ -161,8 +160,6 @@ function register(app) { apiRoute(GET, '/api/notes/:noteId/target-relations', attributesRoute.getTargetRelations); apiRoute(POST, '/api/notes/:noteId/link-map', linkMapRoute.getLinkMap); - apiRoute(GET, '/api/notes/:noteId/links', linksRoute.getLinks); - apiRoute(GET, '/api/notes/:noteId/incoming-links', linksRoute.getIncomingLinks); apiRoute(GET, '/api/date-notes/date/:date', dateNotesRoute.getDateNote); apiRoute(GET, '/api/date-notes/month/:month', dateNotesRoute.getMonthNote); diff --git a/src/services/repository.js b/src/services/repository.js index ccbebdd30..808ab6185 100644 --- a/src/services/repository.js +++ b/src/services/repository.js @@ -72,11 +72,6 @@ async function getOption(name) { return await getEntity("SELECT * FROM options WHERE name = ?", [name]); } -/** @returns {Promise} */ -async function getLink(linkId) { - return await getEntity("SELECT * FROM links WHERE linkId = ?", [linkId]); -} - async function updateEntity(entity) { const entityName = entity.constructor.entityName; const primaryKeyName = entity.constructor.primaryKeyName; @@ -144,7 +139,6 @@ module.exports = { getBranch, getAttribute, getOption, - getLink, updateEntity, setEntityConstructor }; \ No newline at end of file