fixes in recent changes and handling encrypted notes

This commit is contained in:
azivner 2017-11-04 11:32:05 -04:00
parent 44cfff09d9
commit ee07d2d2d8
3 changed files with 81 additions and 72 deletions

View File

@ -1,83 +1,86 @@
function showRecentChanges() {
$("#recent-changes-dialog").dialog({
const recentChangesDialog = $("#recent-changes-dialog");
async function showRecentChanges() {
recentChangesDialog.dialog({
modal: true,
width: 800,
height: 700
});
$.ajax({
const result = await $.ajax({
url: baseApiUrl + 'recent-changes/',
type: 'GET',
success: result => {
const groupedByDate = new Map();
const dayCache = {};
for (const row of result) {
if (row.encryption > 0 && !isEncryptionAvailable()) {
row.note_title = "[encrypted]";
}
else {
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);
}
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(')'));
}
$("#recent-changes-dialog").append(dayEl);
}
},
error: () => error("Error getting recent changes.")
});
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);
}
}
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;
}
$(document).bind('keydown', 'alt+r', showRecentChanges);
$(document).on('click', '#recent-changes-dialog a', e => {
goToInternalNote(e, () => {
$("#recent-changes-dialog").dialog('close');
recentChangesDialog.dialog('close');
});
});

View File

@ -20,21 +20,21 @@ function showRecentNotes() {
width: 800
});
let recentNotesSelectBox = $('#recent-notes-select-box');
const recentNotesSelectBox = $('#recent-notes-select-box');
recentNotesSelectBox.find('option').remove();
// remove the current note
let recNotes = glob.recentNotes.filter(note => note !== glob.currentNote.detail.note_id);
const recNotes = glob.recentNotes.filter(note => note !== glob.currentNote.detail.note_id);
$.each(recNotes, (key, valueNoteId) => {
let noteTitle = getFullName(valueNoteId);
const noteTitle = getFullName(valueNoteId);
if (!noteTitle) {
return;
}
let option = $("<option></option>")
const option = $("<option></option>")
.attr("value", valueNoteId)
.text(noteTitle);

View File

@ -32,14 +32,20 @@ function getFullName(noteId) {
return "[unknown]";
}
if (note.data.is_clone || (note.data.encryption > 0 && !isEncryptionAvailable())) {
// why?
if (note.data.is_clone) {
return null;
}
const path = [];
while (note) {
path.push(note.title);
if (note.data.encryption > 0 && !isEncryptionAvailable()) {
path.push("[encrypted]");
}
else {
path.push(note.title);
}
note = note.getParent();
}