mirror of
https://github.com/zadam/trilium.git
synced 2025-11-05 12:55:55 +01:00
added "edited notes on date" widget
This commit is contained in:
51
src/public/javascripts/widgets/edited_notes.js
Normal file
51
src/public/javascripts/widgets/edited_notes.js
Normal file
@@ -0,0 +1,51 @@
|
||||
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"; }
|
||||
|
||||
getMaxHeight() { return "200px"; }
|
||||
|
||||
async isEnabled() {
|
||||
return await this.ctx.note.hasLabel("dateNote");
|
||||
}
|
||||
|
||||
async doRenderBody() {
|
||||
// remember which title was when we found the similar notes
|
||||
this.title = this.ctx.note.title;
|
||||
|
||||
let editedNotes = await server.get('edited-notes/' + await this.ctx.note.getLabelValue("dateNote"));
|
||||
|
||||
editedNotes = editedNotes.filter(note => note.noteId !== this.ctx.note.noteId);
|
||||
|
||||
if (editedNotes.length === 0) {
|
||||
this.$body.text("No edited notes on this day yet ...");
|
||||
return;
|
||||
}
|
||||
|
||||
const noteIds = editedNotes.flatMap(note => note.notePath);
|
||||
|
||||
await treeCache.getNotes(noteIds); // preload all at once
|
||||
|
||||
const $list = $('<ul>');
|
||||
|
||||
for (const editedNote of editedNotes) {
|
||||
const note = await treeCache.getNote(editedNote.noteId);
|
||||
|
||||
if (!note) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const $item = $("<li>")
|
||||
.append(editedNote.notePath ? await linkService.createNoteLinkWithPath(editedNote.notePath.join("/")) : editedNote.title);
|
||||
|
||||
$list.append($item);
|
||||
}
|
||||
|
||||
this.$body.empty().append($list);
|
||||
}
|
||||
}
|
||||
|
||||
export default EditedNotesWidget;
|
||||
Reference in New Issue
Block a user