2017-10-07 10:46:30 +08:00
|
|
|
function showRecentChanges() {
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#recent-changes-dialog").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
|
|
|
|
});
|
|
|
|
|
|
|
|
$.ajax({
|
2017-09-30 22:05:12 +08:00
|
|
|
url: baseApiUrl + 'recent-changes/',
|
2017-09-27 11:23:03 +08:00
|
|
|
type: 'GET',
|
2017-10-10 06:53:11 +08:00
|
|
|
success: result => {
|
2017-10-03 12:02:58 +08:00
|
|
|
const groupedByDate = new Map();
|
|
|
|
const dayCache = {};
|
2017-09-27 11:23:03 +08:00
|
|
|
|
|
|
|
for (const row of result) {
|
2017-10-12 07:41:45 +08:00
|
|
|
if (row.encryption > 0 && !isEncryptionAvailable()) {
|
|
|
|
row.note_title = "[encrypted]";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
row.note_title = getFullName(row.note_id);
|
2017-09-27 12:15:00 +08:00
|
|
|
}
|
|
|
|
|
2017-10-03 12:02:58 +08:00
|
|
|
|
|
|
|
let dateDay = getDateFromTS(row.date_modified);
|
2017-10-02 10:47:41 +08:00
|
|
|
dateDay.setHours(0);
|
|
|
|
dateDay.setMinutes(0);
|
|
|
|
dateDay.setSeconds(0);
|
|
|
|
dateDay.setMilliseconds(0);
|
2017-09-27 11:23:03 +08:00
|
|
|
|
2017-10-03 12:02:58 +08:00
|
|
|
// 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;
|
|
|
|
}
|
2017-10-02 10:47:41 +08:00
|
|
|
|
2017-10-03 12:02:58 +08:00
|
|
|
if (!groupedByDate.has(dateDay)) {
|
|
|
|
groupedByDate.set(dateDay, []);
|
2017-09-27 11:23:03 +08:00
|
|
|
}
|
|
|
|
|
2017-10-03 12:02:58 +08:00
|
|
|
groupedByDate.get(dateDay).push(row);
|
2017-09-27 11:23:03 +08:00
|
|
|
}
|
|
|
|
|
2017-10-03 12:02:58 +08:00
|
|
|
for (const [dateDay, dayChanges] of groupedByDate) {
|
2017-09-27 11:23:03 +08:00
|
|
|
const changesListEl = $('<ul>');
|
|
|
|
|
2017-10-03 12:02:58 +08:00
|
|
|
const dayEl = $('<div>').append($('<b>').html(formatDate(dateDay))).append(changesListEl);
|
2017-09-27 11:23:03 +08:00
|
|
|
|
2017-10-03 12:02:58 +08:00
|
|
|
for (const change of dayChanges) {
|
|
|
|
const formattedTime = formatTime(getDateFromTS(change.date_modified));
|
2017-09-27 11:23:03 +08:00
|
|
|
|
|
|
|
const noteLink = $("<a>", {
|
2017-10-03 12:02:58 +08:00
|
|
|
href: 'app#' + change.note_id,
|
|
|
|
text: change.note_title
|
2017-09-27 11:23:03 +08:00
|
|
|
});
|
|
|
|
|
2017-10-03 11:38:05 +08:00
|
|
|
const revLink = $("<a>", {
|
2017-10-03 12:02:58 +08:00
|
|
|
href: "javascript: showNoteHistoryDialog('" + change.note_id + "', " + change.id + ");",
|
2017-10-03 11:38:05 +08:00
|
|
|
text: 'rev'
|
|
|
|
});
|
|
|
|
|
|
|
|
changesListEl.append($('<li>')
|
|
|
|
.append(formattedTime + ' - ')
|
|
|
|
.append(noteLink)
|
|
|
|
.append(' (').append(revLink).append(')'));
|
2017-09-27 11:23:03 +08:00
|
|
|
}
|
|
|
|
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#recent-changes-dialog").append(dayEl);
|
2017-09-27 11:23:03 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
error: () => alert("Error getting recent changes.")
|
|
|
|
});
|
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-10-11 08:19:16 +08:00
|
|
|
$("#recent-changes-dialog").dialog('close');
|
2017-09-27 11:23:03 +08:00
|
|
|
});
|
|
|
|
});
|