mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
converted note history to module
This commit is contained in:
parent
6d82a0e03f
commit
394fd6f527
@ -1,52 +1,60 @@
|
||||
glob.historyItems = null;
|
||||
const noteHistory = (function() {
|
||||
const dialogEl = $("#note-history-dialog");
|
||||
const listEl = $("#note-history-list");
|
||||
const contentEl = $("#note-history-content");
|
||||
const titleEl = $("#note-history-title");
|
||||
|
||||
function showCurrentNoteHistory() {
|
||||
showNoteHistoryDialog(glob.currentNote.detail.note_id);
|
||||
}
|
||||
let historyItems = [];
|
||||
|
||||
function showNoteHistoryDialog(noteId, noteHistoryId) {
|
||||
$("#note-history-dialog").dialog({
|
||||
async function showCurrentNoteHistory() {
|
||||
await showNoteHistoryDialog(glob.currentNote.detail.note_id);
|
||||
}
|
||||
|
||||
// weird hack because browser doesn't like we're returning promise and displays promise page
|
||||
function showNoteHistoryDialogNotAsync(noteId, noteHistoryId) {
|
||||
showNoteHistoryDialog(noteId, noteHistoryId);
|
||||
}
|
||||
|
||||
async function showNoteHistoryDialog(noteId, noteHistoryId) {
|
||||
dialogEl.dialog({
|
||||
modal: true,
|
||||
width: 800,
|
||||
height: 700
|
||||
});
|
||||
|
||||
$("#note-history-list").empty();
|
||||
$("#note-history-content").empty();
|
||||
listEl.empty();
|
||||
contentEl.empty();
|
||||
|
||||
$.ajax({
|
||||
historyItems = await $.ajax({
|
||||
url: baseApiUrl + 'notes-history/' + noteId,
|
||||
type: 'GET',
|
||||
success: result => {
|
||||
glob.historyItems = result;
|
||||
error: () => error("Error getting note history.")
|
||||
});
|
||||
|
||||
for (const row of result) {
|
||||
const dateModified = getDateFromTS(row.date_modified_to);
|
||||
for (const item of historyItems) {
|
||||
const dateModified = getDateFromTS(item.date_modified_to);
|
||||
|
||||
$("#note-history-list").append($('<option>', {
|
||||
value: row.note_history_id,
|
||||
value: item.note_history_id,
|
||||
text: formatDateTime(dateModified)
|
||||
}));
|
||||
}
|
||||
|
||||
if (result.length > 0) {
|
||||
if (historyItems.length > 0) {
|
||||
if (!noteHistoryId) {
|
||||
noteHistoryId = $("#note-history-list option:first").val();
|
||||
noteHistoryId = listEl.find("option:first").val();
|
||||
}
|
||||
|
||||
$("#note-history-list").val(noteHistoryId).trigger('change');
|
||||
listEl.val(noteHistoryId).trigger('change');
|
||||
}
|
||||
}
|
||||
},
|
||||
error: () => error("Error getting note history.")
|
||||
});
|
||||
}
|
||||
|
||||
$(document).bind('keydown', 'alt+h', showCurrentNoteHistory);
|
||||
$(document).bind('keydown', 'alt+h', showCurrentNoteHistory);
|
||||
|
||||
$("#note-history-list").on('change', () => {
|
||||
const optVal = $("#note-history-list").find(":selected").val();
|
||||
listEl.on('change', () => {
|
||||
const optVal = listEl.find(":selected").val();
|
||||
|
||||
const historyItem = glob.historyItems.find(r => r.note_history_id === optVal);
|
||||
const historyItem = historyItems.find(r => r.note_history_id === optVal);
|
||||
|
||||
let noteTitle = historyItem.note_title;
|
||||
let noteText = historyItem.note_text;
|
||||
@ -56,6 +64,13 @@ $("#note-history-list").on('change', () => {
|
||||
noteText = decryptString(noteText);
|
||||
}
|
||||
|
||||
$("#note-history-title").html(noteTitle);
|
||||
$("#note-history-content").html(noteText);
|
||||
});
|
||||
titleEl.html(noteTitle);
|
||||
contentEl.html(noteText);
|
||||
});
|
||||
|
||||
return {
|
||||
showCurrentNoteHistory,
|
||||
showNoteHistoryDialog,
|
||||
showNoteHistoryDialogNotAsync
|
||||
};
|
||||
})();
|
@ -32,7 +32,7 @@ const recentChanges = (function() {
|
||||
});
|
||||
|
||||
const revLink = $("<a>", {
|
||||
href: "javascript: showNoteHistoryDialog('" + change.note_id + "', '" + change.note_history_id + "');",
|
||||
href: "javascript: noteHistory.showNoteHistoryDialogNotAsync('" + change.note_id + "', '" + change.note_history_id + "');",
|
||||
text: 'rev'
|
||||
});
|
||||
|
||||
|
@ -84,7 +84,7 @@
|
||||
|
||||
<input autocomplete="off" value="" id="note-title" style="font-size: x-large; border: 0; flex-grow: 100;" tabindex="1">
|
||||
|
||||
<button class="btn btn-xs" onclick="showCurrentNoteHistory();">History</button>
|
||||
<button class="btn btn-xs" onclick="noteHistory.showCurrentNoteHistory();">History</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user