| 
									
										
										
										
											2017-10-06 22:46:30 -04:00
										 |  |  | function showRecentChanges() { | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  |     $("#recentChangesDialog").dialog({ | 
					
						
							|  |  |  |         modal: true, | 
					
						
							|  |  |  |         width: 400, | 
					
						
							|  |  |  |         height: 700 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $.ajax({ | 
					
						
							| 
									
										
										
										
											2017-09-30 10:05:12 -04:00
										 |  |  |         url: baseApiUrl + 'recent-changes/', | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  |         type: 'GET', | 
					
						
							| 
									
										
										
										
											2017-10-09 18:53:11 -04:00
										 |  |  |         success: result => { | 
					
						
							| 
									
										
										
										
											2017-10-03 00:02:58 -04:00
										 |  |  |             const groupedByDate = new Map(); | 
					
						
							|  |  |  |             const dayCache = {}; | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             for (const row of result) { | 
					
						
							| 
									
										
										
										
											2017-09-27 00:15:00 -04:00
										 |  |  |                 if (row.encryption > 0) { | 
					
						
							| 
									
										
										
										
											2017-09-27 00:16:55 -04:00
										 |  |  |                     if (isEncryptionAvailable()) { | 
					
						
							|  |  |  |                         row.note_title = decryptString(row.note_title); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     else { | 
					
						
							|  |  |  |                         row.note_title = "[encrypted]"; | 
					
						
							| 
									
										
										
										
											2017-09-27 00:15:00 -04:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 00:02:58 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 let dateDay = getDateFromTS(row.date_modified); | 
					
						
							| 
									
										
										
										
											2017-10-01 22:47:41 -04:00
										 |  |  |                 dateDay.setHours(0); | 
					
						
							|  |  |  |                 dateDay.setMinutes(0); | 
					
						
							|  |  |  |                 dateDay.setSeconds(0); | 
					
						
							|  |  |  |                 dateDay.setMilliseconds(0); | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 00:02:58 -04:00
										 |  |  |                 // 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; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2017-10-01 22:47:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 00:02:58 -04:00
										 |  |  |                 if (!groupedByDate.has(dateDay)) { | 
					
						
							|  |  |  |                     groupedByDate.set(dateDay, []); | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 00:02:58 -04:00
										 |  |  |                 groupedByDate.get(dateDay).push(row); | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 00:02:58 -04:00
										 |  |  |             for (const [dateDay, dayChanges] of groupedByDate) { | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  |                 const changesListEl = $('<ul>'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 00:02:58 -04:00
										 |  |  |                 const dayEl = $('<div>').append($('<b>').html(formatDate(dateDay))).append(changesListEl); | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 00:02:58 -04:00
										 |  |  |                 for (const change of dayChanges) { | 
					
						
							|  |  |  |                     const formattedTime = formatTime(getDateFromTS(change.date_modified)); | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     const noteLink = $("<a>", { | 
					
						
							| 
									
										
										
										
											2017-10-03 00:02:58 -04:00
										 |  |  |                         href: 'app#' + change.note_id, | 
					
						
							|  |  |  |                         text: change.note_title | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  |                     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-02 23:38:05 -04:00
										 |  |  |                     const revLink = $("<a>", { | 
					
						
							| 
									
										
										
										
											2017-10-03 00:02:58 -04:00
										 |  |  |                         href: "javascript: showNoteHistoryDialog('" + change.note_id + "', " + change.id + ");", | 
					
						
							| 
									
										
										
										
											2017-10-02 23:38:05 -04:00
										 |  |  |                         text: 'rev' | 
					
						
							|  |  |  |                     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     changesListEl.append($('<li>') | 
					
						
							|  |  |  |                         .append(formattedTime + ' - ') | 
					
						
							|  |  |  |                         .append(noteLink) | 
					
						
							|  |  |  |                         .append(' (').append(revLink).append(')')); | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 $("#recentChangesDialog").append(dayEl); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         error: () => alert("Error getting recent changes.") | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-10-06 22:46:30 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(document).bind('keydown', 'alt+r', showRecentChanges); | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 18:53:11 -04:00
										 |  |  | $(document).on('click', '#recentChangesDialog a', e => { | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  |     goToInternalNote(e, () => { | 
					
						
							|  |  |  |         $("#recentChangesDialog").dialog('close'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }); |