mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
basic recent changes implementation
This commit is contained in:
parent
c6472a1c0c
commit
b30bc19bd2
@ -19,4 +19,11 @@ notes_history_api = Blueprint('notes_history_api', __name__)
|
|||||||
def getNoteHistory(note_id):
|
def getNoteHistory(note_id):
|
||||||
history = getResults("select * from notes_history where note_id = ? order by date_modified desc", [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)
|
@ -184,6 +184,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="recentChangesDialog" title="Recent changes" style="display: none; padding: 20px;">
|
||||||
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
const baseUrl = '';
|
const baseUrl = '';
|
||||||
</script>
|
</script>
|
||||||
@ -244,6 +247,7 @@
|
|||||||
<script src="stat/js/jump_to_note.js"></script>
|
<script src="stat/js/jump_to_note.js"></script>
|
||||||
<script src="stat/js/settings.js"></script>
|
<script src="stat/js/settings.js"></script>
|
||||||
<script src="stat/js/note_history.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/utils.js"></script>
|
||||||
<script src="stat/js/convert2html.js"></script>
|
<script src="stat/js/convert2html.js"></script>
|
||||||
|
@ -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
|
// 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
|
// of opening the link in new window/tab
|
||||||
$(document).on('click', 'div.popover-content a', function(e) {
|
$(document).on('click', 'div.popover-content a', function(e) {
|
||||||
|
goToInternalNote(e);
|
||||||
|
});
|
||||||
|
|
||||||
|
function goToInternalNote(e, callback) {
|
||||||
const targetUrl = $(e.target).attr("href");
|
const targetUrl = $(e.target).attr("href");
|
||||||
|
|
||||||
const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(targetUrl);
|
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();
|
getNodeByKey(noteId).setActive();
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
function getNodeIdFromLabel(label) {
|
function getNodeIdFromLabel(label) {
|
||||||
const noteIdMatch = / \(([A-Za-z0-9]{22})\)/.exec(label);
|
const noteIdMatch = / \(([A-Za-z0-9]{22})\)/.exec(label);
|
||||||
|
@ -15,16 +15,22 @@ $(document).bind('keydown', 'alt+s', function() {
|
|||||||
$("input[name=search]").focus();
|
$("input[name=search]").focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function formatTime(date) {
|
||||||
|
return (date.getHours() <= 9 ? "0" : "") + date.getHours() + ":" + (date.getMinutes() <= 9 ? "0" : "") + date.getMinutes();
|
||||||
|
}
|
||||||
|
|
||||||
function formatDate(date) {
|
function formatDate(date) {
|
||||||
const dateString = date.getDate() + ". " + (date.getMonth() + 1) + ". " + date.getFullYear() + " " +
|
return date.getDate() + ". " + (date.getMonth() + 1) + ". " + date.getFullYear();
|
||||||
date.getHours() + ":" + (date.getMinutes() <= 9 ? "0": "") + date.getMinutes();
|
}
|
||||||
return dateString;
|
|
||||||
|
function formatDateTime(date) {
|
||||||
|
return formatDate(date) + " " + formatTime(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
// hide (toggle) everything except for the note content for distraction free writing
|
// hide (toggle) everything except for the note content for distraction free writing
|
||||||
$(document).bind('keydown', 'alt+t', function() {
|
$(document).bind('keydown', 'alt+t', function() {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const dateString = formatDate(date);
|
const dateString = formatDateTime(date);
|
||||||
|
|
||||||
$('#noteDetail').summernote('insertText', dateString);
|
$('#noteDetail').summernote('insertText', dateString);
|
||||||
});
|
});
|
||||||
|
@ -21,7 +21,7 @@ $(document).bind('keydown', 'alt+h', function() {
|
|||||||
|
|
||||||
$("#noteHistoryList").append($('<option>', {
|
$("#noteHistoryList").append($('<option>', {
|
||||||
value: row.id,
|
value: row.id,
|
||||||
text: formatDate(dateModified)
|
text: formatDateTime(dateModified)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
56
static/js/recent_changes.js
Normal file
56
static/js/recent_changes.js
Normal 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');
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user