mirror of
https://github.com/zadam/trilium.git
synced 2025-11-08 14:25:51 +01:00
added "what links here" widget
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user