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"; }
|
|
|
|
|
2019-09-10 03:23:04 +08:00
|
|
|
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() {
|
2019-09-07 17:00:15 +08:00
|
|
|
return await super.isEnabled()
|
2020-01-15 04:23:32 +08:00
|
|
|
&& await this.tabContext.note.hasLabel("dateNote");
|
2019-09-07 16:11:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async doRenderBody() {
|
2020-01-15 04:23:32 +08:00
|
|
|
const note = this.tabContext.note;
|
2019-09-07 16:11:59 +08:00
|
|
|
// remember which title was when we found the similar notes
|
2020-01-15 04:23:32 +08:00
|
|
|
this.title = note.title;
|
|
|
|
let editedNotes = await server.get('edited-notes/' + await note.getLabelValue("dateNote"));
|
2019-09-07 16:11:59 +08:00
|
|
|
|
2020-01-15 04:23:32 +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;
|
|
|
|
}
|
|
|
|
|
2020-01-15 04:23:32 +08:00
|
|
|
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;
|