added "what links here" widget

This commit is contained in:
zadam
2019-08-19 20:59:40 +02:00
parent c9d0b8cc40
commit 02c9dabcff
7 changed files with 45 additions and 59 deletions

View File

@@ -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 = $("<ul>");
for (const rel of targetRelations) {
const $item = $("<li>")
.append(await linkService.createNoteLink(rel.noteId))
.append($("<span>").text(" (" + rel.name + ")"));
$list.append($item);
}
this.$body.empty().append($list);
}
}