2017-11-04 23:32:05 +08:00
|
|
|
const recentChangesDialog = $("#recent-changes-dialog");
|
|
|
|
|
|
|
|
async function showRecentChanges() {
|
|
|
|
recentChangesDialog.dialog({
|
2017-09-27 11:23:03 +08:00
|
|
|
modal: true,
|
2017-10-12 07:41:45 +08:00
|
|
|
width: 800,
|
2017-09-27 11:23:03 +08:00
|
|
|
height: 700
|
|
|
|
});
|
|
|
|
|
2017-11-04 23:32:05 +08:00
|
|
|
const result = await $.ajax({
|
2017-09-30 22:05:12 +08:00
|
|
|
url: baseApiUrl + 'recent-changes/',
|
2017-09-27 11:23:03 +08:00
|
|
|
type: 'GET',
|
2017-11-04 10:08:27 +08:00
|
|
|
error: () => error("Error getting recent changes.")
|
2017-09-27 11:23:03 +08:00
|
|
|
});
|
2017-11-04 23:32:05 +08:00
|
|
|
|
|
|
|
recentChangesDialog.html('');
|
|
|
|
|
|
|
|
const groupedByDate = groupByDate(result);
|
|
|
|
|
|
|
|
for (const [dateDay, dayChanges] of groupedByDate) {
|
|
|
|
const changesListEl = $('<ul>');
|
|
|
|
|
|
|
|
const dayEl = $('<div>').append($('<b>').html(formatDate(dateDay))).append(changesListEl);
|
|
|
|
|
|
|
|
for (const change of dayChanges) {
|
|
|
|
const formattedTime = formatTime(getDateFromTS(change.date_modified_to));
|
|
|
|
|
|
|
|
const noteLink = $("<a>", {
|
|
|
|
href: 'app#' + change.note_id,
|
|
|
|
text: change.note_title
|
|
|
|
});
|
|
|
|
|
|
|
|
const revLink = $("<a>", {
|
|
|
|
href: "javascript: showNoteHistoryDialog('" + change.note_id + "', '" + change.note_history_id + "');",
|
|
|
|
text: 'rev'
|
|
|
|
});
|
|
|
|
|
|
|
|
changesListEl.append($('<li>')
|
|
|
|
.append(formattedTime + ' - ')
|
|
|
|
.append(noteLink)
|
|
|
|
.append(' (').append(revLink).append(')'));
|
|
|
|
}
|
|
|
|
|
|
|
|
recentChangesDialog.append(dayEl);
|
|
|
|
}
|
2017-10-07 10:46:30 +08:00
|
|
|
}
|
|
|
|
|
2017-11-04 23:32:05 +08:00
|
|
|
function groupByDate(result) {
|
|
|
|
const groupedByDate = new Map();
|
|
|
|
const dayCache = {};
|
|
|
|
|
|
|
|
for (const row of result) {
|
|
|
|
row.note_title = getFullName(row.note_id);
|
|
|
|
|
|
|
|
let dateDay = getDateFromTS(row.date_modified_to);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
return groupedByDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-07 10:46:30 +08:00
|
|
|
$(document).bind('keydown', 'alt+r', showRecentChanges);
|
2017-09-27 11:23:03 +08:00
|
|
|
|
2017-10-11 08:19:16 +08:00
|
|
|
$(document).on('click', '#recent-changes-dialog a', e => {
|
2017-09-27 11:23:03 +08:00
|
|
|
goToInternalNote(e, () => {
|
2017-11-04 23:32:05 +08:00
|
|
|
recentChangesDialog.dialog('close');
|
2017-09-27 11:23:03 +08:00
|
|
|
});
|
|
|
|
});
|