Skip to content

Build your personal knowledge base with Trilium Notes

fixes in recent changes and handling encrypted notes

azivneree07d2d2d88d
diff --git a/public/javascripts/recent_changes.js b/public/javascripts/recent_changes.js
index 540355c3dd..246e10d600 100644
--- a/public/javascripts/recent_changes.js
+++ b/public/javascripts/recent_changes.js
@@ -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');
});
});
\ No newline at end of file
diff --git a/public/javascripts/recent_notes.js b/public/javascripts/recent_notes.js
index c0a6ad25ff..ebdcc74519 100644
--- a/public/javascripts/recent_notes.js
+++ b/public/javascripts/recent_notes.js
@@ -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);
diff --git a/public/javascripts/tree_utils.js b/public/javascripts/tree_utils.js
index a5cbcbce9d..246398481e 100644
--- a/public/javascripts/tree_utils.js
+++ b/public/javascripts/tree_utils.js
@@ -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();
}