trilium/src/public/javascripts/widgets/edited_notes.js

58 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-09-07 16:11:59 +08:00
import StandardWidget from "./standard_widget.js";
import linkService from "../services/link.js";
import server from "../services/server.js";
import treeCache from "../services/tree_cache.js";
class EditedNotesWidget extends StandardWidget {
getWidgetTitle() { return "Edited notes on this day"; }
getHelp() {
return {
title: "This contains a list of notes created or updated on this day."
};
}
2019-09-07 16:11:59 +08:00
getMaxHeight() { return "200px"; }
async isEnabled() {
return await super.isEnabled()
&& await this.tabContext.note.hasLabel("dateNote");
2019-09-07 16:11:59 +08:00
}
async doRenderBody() {
const note = this.tabContext.note;
2019-09-07 16:11:59 +08:00
// remember which title was when we found the similar notes
this.title = note.title;
let editedNotes = await server.get('edited-notes/' + await note.getLabelValue("dateNote"));
2019-09-07 16:11:59 +08:00
editedNotes = editedNotes.filter(n => n.noteId !== note.noteId);
2019-09-07 16:11:59 +08:00
if (editedNotes.length === 0) {
this.$body.text("No edited notes on this day yet ...");
return;
}
const noteIds = editedNotes.flatMap(n => n.noteId);
2019-09-07 16:11:59 +08:00
2019-09-08 17:25:57 +08:00
await treeCache.getNotes(noteIds, true); // preload all at once
2019-09-07 16:11:59 +08:00
const $list = $('<ul>');
for (const editedNote of editedNotes) {
2019-09-08 17:25:57 +08:00
const $item = $("<li>");
2019-09-07 16:11:59 +08:00
2019-10-23 03:59:51 +08:00
if (editedNote.isDeleted) {
2019-09-08 17:25:57 +08:00
$item.append($("<i>").text(editedNote.title + " (deleted)"));
}
else {
2019-12-29 04:10:02 +08:00
$item.append(editedNote.notePath ? await linkService.createNoteLink(editedNote.notePath.join("/"), {showNotePath: true}) : editedNote.title);
2019-09-07 16:11:59 +08:00
}
$list.append($item);
}
this.$body.empty().append($list);
}
}
export default EditedNotesWidget;