mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 19:49:01 +01: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() { |     let historyItems = []; | ||||||
|     showNoteHistoryDialog(glob.currentNote.detail.note_id); |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| function showNoteHistoryDialog(noteId, noteHistoryId) { |     async function showCurrentNoteHistory() { | ||||||
|     $("#note-history-dialog").dialog({ |         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, |             modal: true, | ||||||
|             width: 800, |             width: 800, | ||||||
|             height: 700 |             height: 700 | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|     $("#note-history-list").empty(); |         listEl.empty(); | ||||||
|     $("#note-history-content").empty(); |         contentEl.empty(); | ||||||
| 
 | 
 | ||||||
|     $.ajax({ |         historyItems = await $.ajax({ | ||||||
|             url: baseApiUrl + 'notes-history/' + noteId, |             url: baseApiUrl + 'notes-history/' + noteId, | ||||||
|             type: 'GET', |             type: 'GET', | ||||||
|         success: result => { |             error: () => error("Error getting note history.") | ||||||
|             glob.historyItems = result; |         }); | ||||||
| 
 | 
 | ||||||
|             for (const row of result) { |         for (const item of historyItems) { | ||||||
|                 const dateModified = getDateFromTS(row.date_modified_to); |             const dateModified = getDateFromTS(item.date_modified_to); | ||||||
| 
 | 
 | ||||||
|             $("#note-history-list").append($('<option>', { |             $("#note-history-list").append($('<option>', { | ||||||
|                     value: row.note_history_id, |                 value: item.note_history_id, | ||||||
|                 text: formatDateTime(dateModified) |                 text: formatDateTime(dateModified) | ||||||
|             })); |             })); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|             if (result.length > 0) { |         if (historyItems.length > 0) { | ||||||
|             if (!noteHistoryId) { |             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', () => { |     listEl.on('change', () => { | ||||||
|     const optVal = $("#note-history-list").find(":selected").val(); |         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 noteTitle = historyItem.note_title; | ||||||
|         let noteText = historyItem.note_text; |         let noteText = historyItem.note_text; | ||||||
| @ -56,6 +64,13 @@ $("#note-history-list").on('change', () => { | |||||||
|             noteText = decryptString(noteText); |             noteText = decryptString(noteText); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|     $("#note-history-title").html(noteTitle); |         titleEl.html(noteTitle); | ||||||
|     $("#note-history-content").html(noteText); |         contentEl.html(noteText); | ||||||
| }); |     }); | ||||||
|  | 
 | ||||||
|  |     return { | ||||||
|  |         showCurrentNoteHistory, | ||||||
|  |         showNoteHistoryDialog, | ||||||
|  |         showNoteHistoryDialogNotAsync | ||||||
|  |     }; | ||||||
|  | })(); | ||||||
| @ -32,7 +32,7 @@ const recentChanges = (function() { | |||||||
|                 }); |                 }); | ||||||
| 
 | 
 | ||||||
|                 const revLink = $("<a>", { |                 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' |                     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"> |           <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> | ||||||
|       </div> |       </div> | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner