trilium/src/public/javascripts/dialogs/recent_changes.js

92 lines
2.6 KiB
JavaScript
Raw Normal View History

"use strict";
2017-11-05 01:39:26 +08:00
const recentChanges = (function() {
const $showDialogButton = $("#recent-changes-button");
const $dialog = $("#recent-changes-dialog");
2017-11-05 01:39:26 +08:00
async function showDialog() {
glob.activeDialog = $dialog;
2017-11-05 05:03:15 +08:00
$dialog.dialog({
2017-11-05 01:39:26 +08:00
modal: true,
width: 800,
height: 700
});
const result = await server.get('recent-changes/');
$dialog.html('');
2017-11-05 01:39:26 +08:00
const groupedByDate = groupByDate(result);
2017-11-05 01:39:26 +08:00
for (const [dateDay, dayChanges] of groupedByDate) {
const changesListEl = $('<ul>');
2018-03-25 11:37:55 +08:00
const dayEl = $('<div>').append($('<b>').html(utils.formatDate(dateDay))).append(changesListEl);
2017-11-05 01:39:26 +08:00
for (const change of dayChanges) {
2018-03-25 11:37:55 +08:00
const formattedTime = utils.formatTime(utils.parseDate(change.dateModifiedTo));
2017-10-07 10:46:30 +08:00
2017-11-05 01:39:26 +08:00
const revLink = $("<a>", {
2017-11-05 05:03:15 +08:00
href: 'javascript:',
2017-11-05 01:39:26 +08:00
text: 'rev'
2017-11-05 05:03:15 +08:00
}).attr('action', 'note-history')
2018-01-29 08:30:14 +08:00
.attr('note-path', change.noteId)
.attr('note-history-id', change.noteRevisionId);
2017-12-04 06:46:56 +08:00
let noteLink;
2018-01-29 08:30:14 +08:00
if (change.current_isDeleted) {
noteLink = change.current_title;
2017-12-04 06:46:56 +08:00
}
else {
2018-01-29 08:30:14 +08:00
noteLink = link.createNoteLink(change.noteId, change.title);
2017-12-04 06:46:56 +08:00
}
2017-11-05 01:39:26 +08:00
changesListEl.append($('<li>')
.append(formattedTime + ' - ')
2017-12-04 06:46:56 +08:00
.append(noteLink)
2017-11-05 01:39:26 +08:00
.append(' (').append(revLink).append(')'));
}
$dialog.append(dayEl);
}
2017-11-05 01:39:26 +08:00
}
2017-11-05 01:39:26 +08:00
function groupByDate(result) {
const groupedByDate = new Map();
const dayCache = {};
for (const row of result) {
2018-03-25 11:37:55 +08:00
let dateDay = utils.parseDate(row.dateModifiedTo);
2017-11-05 01:39:26 +08:00
dateDay.setHours(0);
dateDay.setMinutes(0);
dateDay.setSeconds(0);
dateDay.setMilliseconds(0);
// this stupidity is to make sure that we always use the same day object because Map uses only
// reference equality
if (dayCache[dateDay]) {
dateDay = dayCache[dateDay];
}
else {
dayCache[dateDay] = dateDay;
}
if (!groupedByDate.has(dateDay)) {
groupedByDate.set(dateDay, []);
}
groupedByDate.get(dateDay).push(row);
}
2017-11-05 01:39:26 +08:00
return groupedByDate;
}
2017-11-05 01:39:26 +08:00
$(document).bind('keydown', 'alt+r', showDialog);
2017-09-27 11:23:03 +08:00
$showDialogButton.click(showDialog);
2017-11-05 01:39:26 +08:00
return {
showDialog
};
})();