diff --git a/public/javascripts/recent_changes.js b/public/javascripts/recent_changes.js
index 246e10d60..05fe01273 100644
--- a/public/javascripts/recent_changes.js
+++ b/public/javascripts/recent_changes.js
@@ -1,86 +1,92 @@
-const recentChangesDialog = $("#recent-changes-dialog");
+const recentChanges = (function() {
+ const dialog = $("#recent-changes-dialog");
-async function showRecentChanges() {
- recentChangesDialog.dialog({
- modal: true,
- width: 800,
- height: 700
- });
+ async function showDialog() {
+ dialog.dialog({
+ modal: true,
+ width: 800,
+ height: 700
+ });
- const result = await $.ajax({
- url: baseApiUrl + 'recent-changes/',
- type: 'GET',
- error: () => error("Error getting recent changes.")
- });
+ const result = await $.ajax({
+ url: baseApiUrl + 'recent-changes/',
+ type: 'GET',
+ error: () => error("Error getting recent changes.")
+ });
- recentChangesDialog.html('');
+ dialog.html('');
- const groupedByDate = groupByDate(result);
+ const groupedByDate = groupByDate(result);
- for (const [dateDay, dayChanges] of groupedByDate) {
- const changesListEl = $('
');
+ for (const [dateDay, dayChanges] of groupedByDate) {
+ const changesListEl = $('');
- const dayEl = $('').append($('
').html(formatDate(dateDay))).append(changesListEl);
+ const dayEl = $('').append($('
').html(formatDate(dateDay))).append(changesListEl);
- for (const change of dayChanges) {
- const formattedTime = formatTime(getDateFromTS(change.date_modified_to));
+ for (const change of dayChanges) {
+ const formattedTime = formatTime(getDateFromTS(change.date_modified_to));
- const noteLink = $("", {
- href: 'app#' + change.note_id,
- text: change.note_title
- });
+ const noteLink = $("", {
+ href: 'app#' + change.note_id,
+ text: change.note_title
+ });
- const revLink = $("", {
- href: "javascript: showNoteHistoryDialog('" + change.note_id + "', '" + change.note_history_id + "');",
- text: 'rev'
- });
+ const revLink = $("", {
+ href: "javascript: showNoteHistoryDialog('" + change.note_id + "', '" + change.note_history_id + "');",
+ text: 'rev'
+ });
- changesListEl.append($('- ')
- .append(formattedTime + ' - ')
- .append(noteLink)
- .append(' (').append(revLink).append(')'));
+ changesListEl.append($('
- ')
+ .append(formattedTime + ' - ')
+ .append(noteLink)
+ .append(' (').append(revLink).append(')'));
+ }
+
+ dialog.append(dayEl);
}
-
- recentChangesDialog.append(dayEl);
}
-}
-function groupByDate(result) {
- const groupedByDate = new Map();
- const dayCache = {};
+ function groupByDate(result) {
+ const groupedByDate = new Map();
+ const dayCache = {};
- for (const row of result) {
- row.note_title = getFullName(row.note_id);
+ 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);
+ 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];
+ // 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);
}
- else {
- dayCache[dateDay] = dateDay;
- }
-
- if (!groupedByDate.has(dateDay)) {
- groupedByDate.set(dateDay, []);
- }
-
- groupedByDate.get(dateDay).push(row);
+ return groupedByDate;
}
- return groupedByDate;
-}
-$(document).bind('keydown', 'alt+r', showRecentChanges);
+ $(document).bind('keydown', 'alt+r', showDialog);
-$(document).on('click', '#recent-changes-dialog a', e => {
- goToInternalNote(e, () => {
- recentChangesDialog.dialog('close');
+ $(document).on('click', '#recent-changes-dialog a', e => {
+ goToInternalNote(e, () => {
+ dialog.dialog('close');
+ });
});
-});
\ No newline at end of file
+
+ return {
+ showDialog
+ };
+})();
\ No newline at end of file
diff --git a/public/javascripts/recent_notes.js b/public/javascripts/recent_notes.js
index 92d933fa2..ce8831cfe 100644
--- a/public/javascripts/recent_notes.js
+++ b/public/javascripts/recent_notes.js
@@ -1,36 +1,39 @@
-glob.recentNotes = [];
-
-recentNotes = (function() {
- const recentNotesSelectBox = $('#recent-notes-select-box');
- const recentNotesDialog = $("#recent-notes-dialog");
- const recentNotesJumpTo = $('#recentNotesJumpTo');
- const recentNotesAddLink = $('#recentNotesAddLink');
+const recentNotes = (function() {
+ const dialog = $("#recent-notes-dialog");
+ const selectBox = $('#recent-notes-select-box');
+ const jumpToButton = $('#recentNotesJumpTo');
+ const addLinkButton = $('#recentNotesAddLink');
const noteDetail = $('#note-detail');
+ let list = [];
function addRecentNote(noteTreeId, noteContentId) {
setTimeout(() => {
// we include the note into recent list only if the user stayed on the note at least 5 seconds
if (noteTreeId === glob.currentNote.detail.note_id || noteContentId === glob.currentNote.detail.note_id) {
// if it's already there, remove the note
- glob.recentNotes = glob.recentNotes.filter(note => note !== noteTreeId);
+ list = list.filter(note => note !== noteTreeId);
- glob.recentNotes.unshift(noteTreeId);
+ list.unshift(noteTreeId);
}
}, 1500);
}
- function showRecentNotes() {
+ function removeRecentNote(noteIdToRemove) {
+ list = list.filter(note => note !== noteIdToRemove);
+ }
+
+ function showDialog() {
noteDetail.summernote('editor.saveRange');
- recentNotesDialog.dialog({
+ dialog.dialog({
modal: true,
width: 800
});
- recentNotesSelectBox.find('option').remove();
+ selectBox.find('option').remove();
// remove the current note
- const recNotes = glob.recentNotes.filter(note => note !== glob.currentNote.detail.note_id);
+ const recNotes = list.filter(note => note !== glob.currentNote.detail.note_id);
$.each(recNotes, (key, valueNoteId) => {
const noteTitle = getFullName(valueNoteId);
@@ -48,14 +51,12 @@ recentNotes = (function() {
option.attr("selected", "selected");
}
- recentNotesSelectBox.append(option);
+ selectBox.append(option);
});
}
- $(document).bind('keydown', 'alt+q', showRecentNotes);
-
function getSelectedNoteIdFromRecentNotes() {
- return recentNotesSelectBox.find("option:selected").val();
+ return selectBox.find("option:selected").val();
}
function setActiveNoteBasedOnRecentNotes() {
@@ -63,7 +64,7 @@ recentNotes = (function() {
getNodeByKey(noteId).setActive();
- recentNotesDialog.dialog('close');
+ dialog.dialog('close');
}
function addLinkBasedOnRecentNotes() {
@@ -71,7 +72,7 @@ recentNotes = (function() {
const linkTitle = getNoteTitle(noteId);
- recentNotesDialog.dialog("close");
+ dialog.dialog("close");
noteDetail.summernote('editor.restoreRange');
@@ -82,7 +83,7 @@ recentNotes = (function() {
});
}
- recentNotesSelectBox.keydown(e => {
+ selectBox.keydown(e => {
const key = e.which;
if (key === 13)// the enter key code
@@ -99,14 +100,18 @@ recentNotes = (function() {
e.preventDefault();
});
- recentNotesSelectBox.dblclick(e => {
+ $(document).bind('keydown', 'alt+q', showDialog);
+
+ selectBox.dblclick(e => {
setActiveNoteBasedOnRecentNotes();
});
- recentNotesJumpTo.click(setActiveNoteBasedOnRecentNotes);
- recentNotesAddLink.click(addLinkBasedOnRecentNotes);
+ jumpToButton.click(setActiveNoteBasedOnRecentNotes);
+ addLinkButton.click(addLinkBasedOnRecentNotes);
return {
- addRecentNote
+ showDialog,
+ addRecentNote,
+ removeRecentNote
};
})();
\ No newline at end of file
diff --git a/public/javascripts/tree_mutations.js b/public/javascripts/tree_mutations.js
index e0c39da38..ca667e380 100644
--- a/public/javascripts/tree_mutations.js
+++ b/public/javascripts/tree_mutations.js
@@ -49,8 +49,7 @@ function deleteNode(node) {
glob.allNoteIds = glob.allNoteIds.filter(e => e !== node.key);
- // remove from recent notes
- glob.recentNotes = glob.recentNotes.filter(note => note !== node.key);
+ recentNotes.removeRecentNote(node.key);
let next = node.getNextSibling();
if (!next) {
diff --git a/views/index.ejs b/views/index.ejs
index afcbd999d..b724879db 100644
--- a/views/index.ejs
+++ b/views/index.ejs
@@ -12,8 +12,8 @@
-
-
+
+