Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
basic recent changes implementation
azivnerb30bc19bd2b5
diff --git a/src/notes_history_api.py b/src/notes_history_api.pyindex 8b94e5976f..8b8e26a3f2 100644--- a/src/notes_history_api.py+++ b/src/notes_history_api.py@@ -19,4 +19,11 @@ notes_history_api = Blueprint('notes_history_api', __name__)def getNoteHistory(note_id):history = getResults("select * from notes_history where note_id = ? order by date_modified desc", [note_id])- return jsonify(history)\ No newline at end of file+ return jsonify(history)++@notes_history_api.route('/recent-changes/', methods = ['GET'])+@login_required+def getRecentChanges():+ recent_changes = getResults("select * from notes_history order by date_modified desc limit 1000")++ return jsonify(recent_changes)\ No newline at end of filediff --git a/src/templates/app.html b/src/templates/app.htmlindex 1cb2eb8cff..90e7652472 100644--- a/src/templates/app.html+++ b/src/templates/app.html@@ -184,6 +184,9 @@</div></div>+ <div id="recentChangesDialog" title="Recent changes" style="display: none; padding: 20px;">+ </div>+<script type="text/javascript">const baseUrl = '';</script>@@ -244,6 +247,7 @@<script src="stat/js/jump_to_note.js"></script><script src="stat/js/settings.js"></script><script src="stat/js/note_history.js"></script>+ <script src="stat/js/recent_changes.js"></script><script src="stat/js/utils.js"></script><script src="stat/js/convert2html.js"></script>diff --git a/static/js/add_link.js b/static/js/add_link.jsindex 66f183a6fa..c06c777970 100644--- a/static/js/add_link.js+++ b/static/js/add_link.js@@ -72,6 +72,10 @@ $("#insertLinkForm").submit(function() {// when click on link popup, in case of internal link, just go the the referenced note instead of default behavior// of opening the link in new window/tab$(document).on('click', 'div.popover-content a', function(e) {+ goToInternalNote(e);+});++function goToInternalNote(e, callback) {const targetUrl = $(e.target).attr("href");const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(targetUrl);@@ -82,8 +86,12 @@ $(document).on('click', 'div.popover-content a', function(e) {getNodeByKey(noteId).setActive();e.preventDefault();++ if (callback) {+ callback();+ }}-});+}function getNodeIdFromLabel(label) {const noteIdMatch = / \(([A-Za-z0-9]{22})\)/.exec(label);diff --git a/static/js/init.js b/static/js/init.jsindex ab6f6f1e79..6056f660a8 100644--- a/static/js/init.js+++ b/static/js/init.js@@ -15,16 +15,22 @@ $(document).bind('keydown', 'alt+s', function() {$("input[name=search]").focus();});+function formatTime(date) {+ return (date.getHours() <= 9 ? "0" : "") + date.getHours() + ":" + (date.getMinutes() <= 9 ? "0" : "") + date.getMinutes();+}+function formatDate(date) {- const dateString = date.getDate() + ". " + (date.getMonth() + 1) + ". " + date.getFullYear() + " " +- date.getHours() + ":" + (date.getMinutes() <= 9 ? "0": "") + date.getMinutes();- return dateString;+ return date.getDate() + ". " + (date.getMonth() + 1) + ". " + date.getFullYear();+}++function formatDateTime(date) {+ return formatDate(date) + " " + formatTime(date);}// hide (toggle) everything except for the note content for distraction free writing$(document).bind('keydown', 'alt+t', function() {const date = new Date();- const dateString = formatDate(date);+ const dateString = formatDateTime(date);$('#noteDetail').summernote('insertText', dateString);});diff --git a/static/js/note_history.js b/static/js/note_history.jsindex 9e022d0ae7..cf085e0b31 100644--- a/static/js/note_history.js+++ b/static/js/note_history.js@@ -21,7 +21,7 @@ $(document).bind('keydown', 'alt+h', function() {$("#noteHistoryList").append($('<option>', {value: row.id,- text: formatDate(dateModified)+ text: formatDateTime(dateModified)}));}diff --git a/static/js/recent_changes.js b/static/js/recent_changes.jsnew file mode 100644index 0000000000..d13e6e514b--- /dev/null+++ b/static/js/recent_changes.js@@ -0,0 +1,56 @@+$(document).bind('keydown', 'alt+r', function() {+ $("#recentChangesDialog").dialog({+ modal: true,+ width: 400,+ height: 700+ });++ $.ajax({+ url: baseUrl + 'recent-changes/',+ type: 'GET',+ success: function (result) {+ const groupedByDate = {};++ for (const row of result) {+ const dateModified = new Date(row.date_modified * 1000);+ const formattedDate = formatDate(dateModified);++ if (!groupedByDate[formattedDate]) {+ groupedByDate[formattedDate] = [];+ }++ groupedByDate[formattedDate].push(row);+ }++ const sortedDates = Object.keys(groupedByDate);+ sortedDates.sort();+ sortedDates.reverse();++ for (const formattedDay of sortedDates) {+ const changesListEl = $('<ul>');++ const dayEl = $('<div>').append($('<b>').html(formattedDay)).append(changesListEl);++ for (const dayChanges of groupedByDate[formattedDay]) {+ const formattedTime = formatTime(new Date(dayChanges.date_modified * 1000));++ const noteLink = $("<a>", {+ href: 'app#' + dayChanges.note_id,+ text: dayChanges.note_title+ });++ changesListEl.append($('<li>').append(formattedTime + ' - ').append(noteLink));+ }++ $("#recentChangesDialog").append(dayEl);+ }+ },+ error: () => alert("Error getting recent changes.")+ });+});++$(document).on('click', '#recentChangesDialog a', function(e) {+ goToInternalNote(e, () => {+ $("#recentChangesDialog").dialog('close');+ });+});\ No newline at end of file