basic recent changes implementation

This commit is contained in:
azivner 2017-09-26 23:23:03 -04:00
parent c6472a1c0c
commit b30bc19bd2
6 changed files with 88 additions and 7 deletions

View file

@ -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)
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)

View file

@ -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>

View file

@ -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);

View file

@ -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);
});

View file

@ -21,7 +21,7 @@ $(document).bind('keydown', 'alt+h', function() {
$("#noteHistoryList").append($('<option>', {
value: row.id,
text: formatDate(dateModified)
text: formatDateTime(dateModified)
}));
}

View file

@ -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');
});
});