more compact note revisions widget

This commit is contained in:
zadam 2020-09-05 23:35:24 +02:00
parent b148f3d032
commit a7505682ed

View File

@ -46,6 +46,8 @@ class NoteRevisionsWidget extends CollapsibleWidget {
return; return;
} }
const groupedRevisionItems = this.getGroupedRevisionItems(revisionItems);
if (note.noteId !== this.noteId) { if (note.noteId !== this.noteId) {
return; return;
} }
@ -54,23 +56,47 @@ class NoteRevisionsWidget extends CollapsibleWidget {
const $list = this.$body.find('.note-revision-list'); const $list = this.$body.find('.note-revision-list');
for (const item of revisionItems) { for (const [date, items] of groupedRevisionItems) {
const $listItem = $('<li>').append($("<a>", { const $listItem = $('<li>').append($("<strong>").text(date + ": "));
const revsWithinADay = [];
for (const item of items) {
const $rev = $("<span>");
$rev.append($("<a>", {
'data-action': 'note-revision', 'data-action': 'note-revision',
'data-note-path': note.noteId, 'data-note-path': note.noteId,
'data-note-revision-id': item.noteRevisionId, 'data-note-revision-id': item.noteRevisionId,
title: 'This revision was last edited on ' + item.dateLastEdited, title: 'This revision was last edited on ' + item.dateLastEdited,
href: 'javascript:' href: 'javascript:'
}).text(item.dateLastEdited.substr(0, 16))); })
.text(item.dateLastEdited.substr(11, 5)));
if (item.contentLength !== null) { revsWithinADay.push($rev.html());
$listItem.append($("<span>").text(` (${item.contentLength} bytes)`))
} }
$listItem.append(revsWithinADay.join(", "));
$list.append($listItem); $list.append($listItem);
} }
} }
getGroupedRevisionItems(revisionItems) {
const grouped = new Map(); // map preserves order of insertion
for (const item of revisionItems) {
const [date] = item.dateLastEdited.substr(0, 16).split(" ");
if (!grouped.has(date)) {
grouped.set(date, []);
}
grouped.get(date).push(item);
}
return grouped;
}
entitiesReloadedEvent({loadResults}) { entitiesReloadedEvent({loadResults}) {
if (loadResults.hasNoteRevisionForNote(this.noteId)) { if (loadResults.hasNoteRevisionForNote(this.noteId)) {
this.refresh(); this.refresh();