2019-07-26 04:31:09 +08:00
|
|
|
import server from "../services/server.js";
|
2019-08-16 03:18:33 +08:00
|
|
|
import StandardWidget from "./standard_widget.js";
|
2019-07-26 04:31:09 +08:00
|
|
|
|
|
|
|
const TPL = `
|
|
|
|
<ul class="note-revision-list" style="max-height: 150px; overflow: auto;">
|
|
|
|
</ul>
|
|
|
|
`;
|
|
|
|
|
2019-08-16 03:18:33 +08:00
|
|
|
class NoteRevisionsWidget extends StandardWidget {
|
2019-08-17 16:45:20 +08:00
|
|
|
getWidgetTitle() { return "Note revisions"; }
|
2019-07-26 04:31:09 +08:00
|
|
|
|
2019-09-10 03:23:04 +08:00
|
|
|
getHelp() {
|
|
|
|
return {
|
|
|
|
title: "Note revisions track changes in the note across the time.",
|
|
|
|
url: "https://github.com/zadam/trilium/wiki/Note-revisions"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-30 05:08:30 +08:00
|
|
|
getHeaderActions() {
|
|
|
|
const $showFullButton = $("<a>").append("show dialog").addClass('widget-header-action');
|
|
|
|
$showFullButton.click(async () => {
|
|
|
|
const attributesDialog = await import("../dialogs/note_revisions.js");
|
2019-10-11 02:00:06 +08:00
|
|
|
attributesDialog.showCurrentNoteRevisions(this.ctx.note.noteId);
|
2019-08-30 05:08:30 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return [$showFullButton];
|
|
|
|
}
|
|
|
|
|
2019-08-16 03:18:33 +08:00
|
|
|
async doRenderBody() {
|
2019-11-02 02:21:48 +08:00
|
|
|
const revisionItems = await server.get(`notes/${this.ctx.note.noteId}/revisions`);
|
2019-07-26 04:31:09 +08:00
|
|
|
|
|
|
|
if (revisionItems.length === 0) {
|
2019-08-16 03:18:33 +08:00
|
|
|
this.$body.text("No revisions yet...");
|
2019-07-26 04:31:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-16 03:18:33 +08:00
|
|
|
this.$body.html(TPL);
|
2019-07-26 04:31:09 +08:00
|
|
|
|
2019-08-16 03:18:33 +08:00
|
|
|
const $list = this.$body.find('.note-revision-list');
|
2019-07-26 04:31:09 +08:00
|
|
|
|
|
|
|
for (const item of revisionItems) {
|
2019-09-08 15:17:16 +08:00
|
|
|
const $listItem = $('<li>').append($("<a>", {
|
2019-07-26 04:31:09 +08:00
|
|
|
'data-action': 'note-revision',
|
|
|
|
'data-note-path': this.ctx.note.noteId,
|
|
|
|
'data-note-revision-id': item.noteRevisionId,
|
|
|
|
href: 'javascript:'
|
2019-11-02 02:21:48 +08:00
|
|
|
}).text(item.dateLastEdited.substr(0, 16)));
|
2019-09-08 15:17:16 +08:00
|
|
|
|
|
|
|
if (item.contentLength !== null) {
|
|
|
|
$listItem.append($("<span>").text(` (${item.contentLength} characters)`))
|
|
|
|
}
|
|
|
|
|
|
|
|
$list.append($listItem);
|
2019-07-26 04:31:09 +08:00
|
|
|
}
|
|
|
|
}
|
2019-08-07 05:20:27 +08:00
|
|
|
|
2019-09-04 03:31:39 +08:00
|
|
|
eventReceived(name, data) {
|
|
|
|
if (name === 'syncData') {
|
|
|
|
if (data.find(sd => sd.entityName === 'note_revisions' && sd.noteId === this.ctx.note.noteId)) {
|
|
|
|
this.doRenderBody();
|
|
|
|
}
|
2019-08-07 05:20:27 +08:00
|
|
|
}
|
|
|
|
}
|
2019-07-26 04:31:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default NoteRevisionsWidget;
|