From 8f91b8f5d532ca0b734404eb579c17297bb5da29 Mon Sep 17 00:00:00 2001 From: azivner Date: Mon, 2 Oct 2017 23:38:05 -0400 Subject: [PATCH] we now add link to exact history revision to recent changes --- TODO | 4 ++-- static/js/note_history.js | 14 ++++++++++---- static/js/recent_changes.js | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index c235a2756..8dc158f9e 100644 --- a/TODO +++ b/TODO @@ -4,10 +4,10 @@ New features: - what links here - link between encrypted notes could be done by encrypting note_ids of both sides of relations. Encryption must be deterministic to allow lookup by cipher text -- recent changes - link to note should lead to the revision +- recent changes - links don't look like links (no underline, black) - db upgrade / migration - db backup into directory -- recent notes can either go to or add link +- DONE: recent notes can either go to or add link - might do the same thing with alt-j and alt-l - ctrl-b nad linkem by mohlo byt goto do notu - potencialne nova navigace back - forward diff --git a/static/js/note_history.js b/static/js/note_history.js index 69cc05cc7..eb95c5d4c 100644 --- a/static/js/note_history.js +++ b/static/js/note_history.js @@ -1,6 +1,6 @@ let globalHistoryItems = null; -$(document).bind('keydown', 'alt+h', function() { +function showNoteHistoryDialog(noteId, noteHistoryId) { $("#noteHistoryDialog").dialog({ modal: true, width: 800, @@ -11,7 +11,7 @@ $(document).bind('keydown', 'alt+h', function() { $("#noteHistoryContent").empty(); $.ajax({ - url: baseApiUrl + 'notes-history/' + globalCurrentNote.detail.note_id, + url: baseApiUrl + 'notes-history/' + noteId, type: 'GET', success: function (result) { globalHistoryItems = result; @@ -26,13 +26,19 @@ $(document).bind('keydown', 'alt+h', function() { } if (result.length > 0) { - const firstOptionValue = $("#noteHistoryList option:first").val(); + if (!noteHistoryId) { + noteHistoryId = $("#noteHistoryList option:first").val(); + } - $("#noteHistoryList").val(firstOptionValue).trigger('change'); + $("#noteHistoryList").val(noteHistoryId).trigger('change'); } }, error: () => alert("Error getting note history.") }); +} + +$(document).bind('keydown', 'alt+h', function() { + showNoteHistoryDialog(globalCurrentNote.detail.note_id); }); $("#noteHistoryList").on('change', () => { diff --git a/static/js/recent_changes.js b/static/js/recent_changes.js index ae093cf0d..9d3e78bdb 100644 --- a/static/js/recent_changes.js +++ b/static/js/recent_changes.js @@ -27,6 +27,7 @@ $(document).bind('keydown', 'alt+r', function() { dateDay.setSeconds(0); dateDay.setMilliseconds(0); + // FIXME: we can use Map object instead to avoid this hack const dateDayTS = dateDay.getTime(); // we can't use dateDay as key because complex objects can't be keys if (!groupedByDate[dateDayTS]) { @@ -51,11 +52,19 @@ $(document).bind('keydown', 'alt+r', function() { const formattedTime = formatTime(getDateFromTS(dayChanges.date_modified)); const noteLink = $("", { - href: 'app#' + dayChanges.note_id, - text: dayChanges.note_title + href: 'app#' + dayChanges.note_id, + text: dayChanges.note_title }); - changesListEl.append($('
  • ').append(formattedTime + ' - ').append(noteLink)); + const revLink = $("", { + href: "javascript: showNoteHistoryDialog('" + dayChanges.note_id + "', " + dayChanges.id + ");", + text: 'rev' + }); + + changesListEl.append($('
  • ') + .append(formattedTime + ' - ') + .append(noteLink) + .append(' (').append(revLink).append(')')); } $("#recentChangesDialog").append(dayEl);