diff --git a/src/public/javascripts/entities/link.js b/src/public/javascripts/entities/link.js
deleted file mode 100644
index 89e7ec380..000000000
--- a/src/public/javascripts/entities/link.js
+++ /dev/null
@@ -1,33 +0,0 @@
-class Link {
- constructor(treeCache, row) {
- this.treeCache = treeCache;
- /** @param {string} linkId */
- this.linkId = row.linkId;
- /** @param {string} noteId */
- this.noteId = row.noteId;
- /** @param {string} type */
- this.type = row.type;
- /** @param {string} targetNoteId */
- this.targetNoteId = row.targetNoteId;
- /** @param {string} utcDateCreated */
- this.utcDateCreated = row.utcDateCreated;
- /** @param {string} utcDateModified */
- this.utcDateModified = row.utcDateModified;
- }
-
- /** @returns {NoteShort} */
- async getNote() {
- return await this.treeCache.getNote(this.noteId);
- }
-
- /** @returns {NoteShort} */
- async getTargetNote() {
- return await this.treeCache.getNote(this.targetNoteId);
- }
-
- get toString() {
- return `Link(linkId=${this.linkId}, type=${this.type}, note=${this.noteId}, targetNoteId=${this.targetNoteId})`;
- }
-}
-
-export default Link;
\ No newline at end of file
diff --git a/src/public/javascripts/entities/note_short.js b/src/public/javascripts/entities/note_short.js
index dccf14850..0c559657e 100644
--- a/src/public/javascripts/entities/note_short.js
+++ b/src/public/javascripts/entities/note_short.js
@@ -1,6 +1,5 @@
import server from '../services/server.js';
import Attribute from './attribute.js';
-import Link from './link.js';
const LABEL = 'label';
const LABEL_DEFINITION = 'label-definition';
@@ -231,11 +230,13 @@ class NoteShort {
}
/**
- * @return {Promise}
+ * Get relations which target this note
+ *
+ * @returns {Promise}
*/
- async getLinks() {
- return (await server.get('notes/' + this.noteId + '/links'))
- .map(linkRow => new Link(this.treeCache, linkRow));
+ async getTargetRelations() {
+ return (await server.get('notes/' + this.noteId + '/target-relations'))
+ .map(attrRow => new Attribute(this.treeCache, attrRow));
}
get toString() {
diff --git a/src/public/javascripts/services/sidebar.js b/src/public/javascripts/services/sidebar.js
index bb8436203..15270c9d9 100644
--- a/src/public/javascripts/services/sidebar.js
+++ b/src/public/javascripts/services/sidebar.js
@@ -2,6 +2,7 @@ import NoteInfoWidget from "../widgets/note_info.js";
import LinkMapWidget from "../widgets/link_map.js";
import NoteRevisionsWidget from "../widgets/note_revisions.js";
import AttributesWidget from "../widgets/attributes.js";
+import WhatLinksHereWidget from "../widgets/what_links_here.js";
import bundleService from "./bundle.js";
import messagingService from "./messaging.js";
@@ -52,7 +53,7 @@ class Sidebar {
this.widgets = [];
this.$widgetContainer.empty();
- const widgetClasses = [AttributesWidget, LinkMapWidget, NoteRevisionsWidget, NoteInfoWidget];
+ const widgetClasses = [AttributesWidget, LinkMapWidget, WhatLinksHereWidget, NoteRevisionsWidget, NoteInfoWidget];
const widgetRelations = await this.ctx.note.getRelations('widget');
diff --git a/src/public/javascripts/widgets/standard_widget.js b/src/public/javascripts/widgets/standard_widget.js
index fea570439..1de2b5ef9 100644
--- a/src/public/javascripts/widgets/standard_widget.js
+++ b/src/public/javascripts/widgets/standard_widget.js
@@ -37,6 +37,13 @@ class StandardWidget {
this.$body = this.$bodyWrapper.find('.card-body');
+ const maxHeight = this.getMaxHeight();
+
+ if (maxHeight) {
+ this.$body.css("max-height", maxHeight);
+ this.$body.css("overflow", "auto");
+ }
+
this.$widget.on('shown.bs.collapse', () => this.renderBody());
this.$widget.on('shown.bs.collapse', () => this.ctx.stateChanged());
this.$widget.on('hidden.bs.collapse', () => this.ctx.stateChanged());
@@ -50,6 +57,8 @@ class StandardWidget {
getHeaderActions() { return []; }
+ getMaxHeight() { return null; }
+
async renderBody() {
if (!this.isVisible() || this.rendered) {
return;
diff --git a/src/public/javascripts/widgets/what_links_here.js b/src/public/javascripts/widgets/what_links_here.js
index 322718013..283d0ad9f 100644
--- a/src/public/javascripts/widgets/what_links_here.js
+++ b/src/public/javascripts/widgets/what_links_here.js
@@ -1,30 +1,30 @@
import StandardWidget from "./standard_widget.js";
+import linkService from "../services/link.js";
class WhatLinksHereWidget extends StandardWidget {
getWidgetTitle() { return "What links here"; }
+ getMaxHeight() { return "200px"; }
+
async doRenderBody() {
+ const targetRelations = await this.ctx.note.getTargetRelations();
-
- const $noteId = this.$body.find(".note-info-note-id");
- const $dateCreated = this.$body.find(".note-info-date-created");
- const $dateModified = this.$body.find(".note-info-date-modified");
- const $type = this.$body.find(".note-info-type");
- const $mime = this.$body.find(".note-info-mime");
-
- const note = this.ctx.note;
-
- $noteId.text(note.noteId);
- $dateCreated.text(note.dateCreated);
- $dateModified.text(note.dateModified);
- $type.text(note.type);
- $mime.text(note.mime);
- }
-
- syncDataReceived(syncData) {
- if (syncData.find(sd => sd.entityName === 'notes' && sd.entityId === this.ctx.note.noteId)) {
- this.doRenderBody();
+ if (targetRelations.length === 0) {
+ this.$body.text("Nothing links here yet ...");
+ return;
}
+
+ const $list = $("");
+
+ for (const rel of targetRelations) {
+ const $item = $("- ")
+ .append(await linkService.createNoteLink(rel.noteId))
+ .append($("").text(" (" + rel.name + ")"));
+
+ $list.append($item);
+ }
+
+ this.$body.empty().append($list);
}
}
diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js
index ac751dab1..5a058fff0 100644
--- a/src/routes/api/attributes.js
+++ b/src/routes/api/attributes.js
@@ -157,6 +157,12 @@ async function deleteRelation(req) {
}
}
+async function getTargetRelations(req) {
+ const note = await repository.getNote(req.params.noteId);
+
+ return await note.getTargetRelations();
+}
+
module.exports = {
updateNoteAttributes,
updateNoteAttribute,
@@ -165,5 +171,6 @@ module.exports = {
getValuesForAttribute,
getEffectiveNoteAttributes,
createRelation,
- deleteRelation
+ deleteRelation,
+ getTargetRelations
};
\ No newline at end of file
diff --git a/src/routes/routes.js b/src/routes/routes.js
index 8792e5197..78aca685d 100644
--- a/src/routes/routes.js
+++ b/src/routes/routes.js
@@ -157,6 +157,7 @@ function register(app) {
apiRoute(DELETE, '/api/notes/:noteId/attributes/:attributeId', attributesRoute.deleteNoteAttribute);
apiRoute(GET, '/api/attributes/names', attributesRoute.getAttributeNames);
apiRoute(GET, '/api/attributes/values/:attributeName', attributesRoute.getValuesForAttribute);
+ 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);