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-07-26 04:31:09 +08:00
|
|
|
/**
|
|
|
|
* @param {TabContext} ctx
|
2019-08-16 03:18:33 +08:00
|
|
|
* @param {object} state
|
2019-07-26 04:31:09 +08:00
|
|
|
*/
|
2019-08-16 03:18:33 +08:00
|
|
|
constructor(ctx, state) {
|
2019-08-17 03:29:44 +08:00
|
|
|
super(ctx, state);
|
2019-08-16 03:18:33 +08:00
|
|
|
|
2019-07-26 04:31:09 +08:00
|
|
|
this.$title.text("Note revisions");
|
|
|
|
}
|
|
|
|
|
2019-08-16 03:18:33 +08:00
|
|
|
async doRenderBody() {
|
2019-07-26 04:31:09 +08:00
|
|
|
const revisionItems = await server.get(`notes/${this.ctx.note.noteId}/revisions`);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
$list.append($('<li>').append($("<a>", {
|
|
|
|
'data-action': 'note-revision',
|
|
|
|
'data-note-path': this.ctx.note.noteId,
|
|
|
|
'data-note-revision-id': item.noteRevisionId,
|
|
|
|
href: 'javascript:'
|
|
|
|
}).text(item.dateModifiedFrom)));
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 05:20:27 +08:00
|
|
|
|
|
|
|
syncDataReceived(syncData) {
|
|
|
|
if (syncData.find(sd => sd.entityName === 'note_revisions' && sd.noteId === this.ctx.note.noteId)) {
|
2019-08-16 03:18:33 +08:00
|
|
|
this.doRenderBody();
|
2019-08-07 05:20:27 +08:00
|
|
|
}
|
|
|
|
}
|
2019-07-26 04:31:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default NoteRevisionsWidget;
|