mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	fixes in recent changes and handling encrypted notes
This commit is contained in:
		| @@ -1,47 +1,21 @@ | |||||||
| function showRecentChanges() { | const recentChangesDialog = $("#recent-changes-dialog"); | ||||||
|     $("#recent-changes-dialog").dialog({ |  | ||||||
|  | async function showRecentChanges() { | ||||||
|  |     recentChangesDialog.dialog({ | ||||||
|         modal: true, |         modal: true, | ||||||
|         width: 800, |         width: 800, | ||||||
|         height: 700 |         height: 700 | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     $.ajax({ |     const result = await $.ajax({ | ||||||
|         url: baseApiUrl + 'recent-changes/', |         url: baseApiUrl + 'recent-changes/', | ||||||
|         type: 'GET', |         type: 'GET', | ||||||
|         success: result => { |         error: () => error("Error getting recent changes.") | ||||||
|             const groupedByDate = new Map(); |     }); | ||||||
|             const dayCache = {}; |  | ||||||
|  |  | ||||||
|             for (const row of result) { |     recentChangesDialog.html(''); | ||||||
|                 if (row.encryption > 0 && !isEncryptionAvailable()) { |  | ||||||
|                     row.note_title = "[encrypted]"; |  | ||||||
|                 } |  | ||||||
|                 else { |  | ||||||
|                     row.note_title = getFullName(row.note_id); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|  |     const groupedByDate = groupByDate(result); | ||||||
|                 let dateDay = getDateFromTS(row.date_modified_to); |  | ||||||
|                 dateDay.setHours(0); |  | ||||||
|                 dateDay.setMinutes(0); |  | ||||||
|                 dateDay.setSeconds(0); |  | ||||||
|                 dateDay.setMilliseconds(0); |  | ||||||
|  |  | ||||||
|                 // this stupidity is to make sure that we always use the same day object because Map uses only |  | ||||||
|                 // reference equality |  | ||||||
|                 if (dayCache[dateDay]) { |  | ||||||
|                     dateDay = dayCache[dateDay]; |  | ||||||
|                 } |  | ||||||
|                 else { |  | ||||||
|                     dayCache[dateDay] = dateDay; |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 if (!groupedByDate.has(dateDay)) { |  | ||||||
|                     groupedByDate.set(dateDay, []); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 groupedByDate.get(dateDay).push(row); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|     for (const [dateDay, dayChanges] of groupedByDate) { |     for (const [dateDay, dayChanges] of groupedByDate) { | ||||||
|         const changesListEl = $('<ul>'); |         const changesListEl = $('<ul>'); | ||||||
| @@ -67,17 +41,46 @@ function showRecentChanges() { | |||||||
|                 .append(' (').append(revLink).append(')')); |                 .append(' (').append(revLink).append(')')); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|                 $("#recent-changes-dialog").append(dayEl); |         recentChangesDialog.append(dayEl); | ||||||
|     } |     } | ||||||
|         }, |  | ||||||
|         error: () => error("Error getting recent changes.") |  | ||||||
|     }); |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function groupByDate(result) { | ||||||
|  |     const groupedByDate = new Map(); | ||||||
|  |     const dayCache = {}; | ||||||
|  |  | ||||||
|  |     for (const row of result) { | ||||||
|  |         row.note_title = getFullName(row.note_id); | ||||||
|  |  | ||||||
|  |         let dateDay = getDateFromTS(row.date_modified_to); | ||||||
|  |         dateDay.setHours(0); | ||||||
|  |         dateDay.setMinutes(0); | ||||||
|  |         dateDay.setSeconds(0); | ||||||
|  |         dateDay.setMilliseconds(0); | ||||||
|  |  | ||||||
|  |         // this stupidity is to make sure that we always use the same day object because Map uses only | ||||||
|  |         // reference equality | ||||||
|  |         if (dayCache[dateDay]) { | ||||||
|  |             dateDay = dayCache[dateDay]; | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             dayCache[dateDay] = dateDay; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (!groupedByDate.has(dateDay)) { | ||||||
|  |             groupedByDate.set(dateDay, []); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         groupedByDate.get(dateDay).push(row); | ||||||
|  |     } | ||||||
|  |     return groupedByDate; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| $(document).bind('keydown', 'alt+r', showRecentChanges); | $(document).bind('keydown', 'alt+r', showRecentChanges); | ||||||
|  |  | ||||||
| $(document).on('click', '#recent-changes-dialog a', e => { | $(document).on('click', '#recent-changes-dialog a', e => { | ||||||
|     goToInternalNote(e, () => { |     goToInternalNote(e, () => { | ||||||
|         $("#recent-changes-dialog").dialog('close'); |         recentChangesDialog.dialog('close'); | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
| @@ -20,21 +20,21 @@ function showRecentNotes() { | |||||||
|         width: 800 |         width: 800 | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     let recentNotesSelectBox = $('#recent-notes-select-box'); |     const recentNotesSelectBox = $('#recent-notes-select-box'); | ||||||
|  |  | ||||||
|     recentNotesSelectBox.find('option').remove(); |     recentNotesSelectBox.find('option').remove(); | ||||||
|  |  | ||||||
|     // remove the current note |     // remove the current note | ||||||
|     let recNotes = glob.recentNotes.filter(note => note !== glob.currentNote.detail.note_id); |     const recNotes = glob.recentNotes.filter(note => note !== glob.currentNote.detail.note_id); | ||||||
|  |  | ||||||
|     $.each(recNotes, (key, valueNoteId) => { |     $.each(recNotes, (key, valueNoteId) => { | ||||||
|         let noteTitle = getFullName(valueNoteId); |         const noteTitle = getFullName(valueNoteId); | ||||||
|  |  | ||||||
|         if (!noteTitle) { |         if (!noteTitle) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         let option = $("<option></option>") |         const option = $("<option></option>") | ||||||
|                 .attr("value", valueNoteId) |                 .attr("value", valueNoteId) | ||||||
|                 .text(noteTitle); |                 .text(noteTitle); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -32,14 +32,20 @@ function getFullName(noteId) { | |||||||
|         return "[unknown]"; |         return "[unknown]"; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (note.data.is_clone || (note.data.encryption > 0 && !isEncryptionAvailable())) { |     // why? | ||||||
|  |     if (note.data.is_clone) { | ||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const path = []; |     const path = []; | ||||||
|  |  | ||||||
|     while (note) { |     while (note) { | ||||||
|  |         if (note.data.encryption > 0 && !isEncryptionAvailable()) { | ||||||
|  |             path.push("[encrypted]"); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|             path.push(note.title); |             path.push(note.title); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         note = note.getParent(); |         note = note.getParent(); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user