| 
									
										
										
										
											2017-11-04 19:38:50 -04:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  | const recentChanges = (function() { | 
					
						
							| 
									
										
										
										
											2017-11-04 17:03:15 -04:00
										 |  |  |     const dialogEl = $("#recent-changes-dialog"); | 
					
						
							| 
									
										
										
										
											2017-11-04 11:32:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |     async function showDialog() { | 
					
						
							| 
									
										
										
										
											2017-11-04 17:03:15 -04:00
										 |  |  |         glob.activeDialog = dialogEl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         dialogEl.dialog({ | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |             modal: true, | 
					
						
							|  |  |  |             width: 800, | 
					
						
							|  |  |  |             height: 700 | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2017-11-04 11:32:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |         const result = await $.ajax({ | 
					
						
							|  |  |  |             url: baseApiUrl + 'recent-changes/', | 
					
						
							|  |  |  |             type: 'GET', | 
					
						
							| 
									
										
										
										
											2017-11-08 22:33:08 -05:00
										 |  |  |             error: () => showError("Error getting recent changes.") | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2017-11-04 11:32:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 17:03:15 -04:00
										 |  |  |         dialogEl.html(''); | 
					
						
							| 
									
										
										
										
											2017-11-04 11:32:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |         const groupedByDate = groupByDate(result); | 
					
						
							| 
									
										
										
										
											2017-11-04 11:32:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |         for (const [dateDay, dayChanges] of groupedByDate) { | 
					
						
							|  |  |  |             const changesListEl = $('<ul>'); | 
					
						
							| 
									
										
										
										
											2017-11-04 11:32:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |             const dayEl = $('<div>').append($('<b>').html(formatDate(dateDay))).append(changesListEl); | 
					
						
							| 
									
										
										
										
											2017-11-04 11:32:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |             for (const change of dayChanges) { | 
					
						
							|  |  |  |                 const formattedTime = formatTime(getDateFromTS(change.date_modified_to)); | 
					
						
							| 
									
										
										
										
											2017-10-06 22:46:30 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |                 const revLink = $("<a>", { | 
					
						
							| 
									
										
										
										
											2017-11-04 17:03:15 -04:00
										 |  |  |                     href: 'javascript:', | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |                     text: 'rev' | 
					
						
							| 
									
										
										
										
											2017-11-04 17:03:15 -04:00
										 |  |  |                 }).attr('action', 'note-history') | 
					
						
							|  |  |  |                     .attr('note-id', change.note_id) | 
					
						
							|  |  |  |                     .attr('note-history-id', change.note_history_id); | 
					
						
							| 
									
										
										
										
											2017-11-04 11:32:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |                 changesListEl.append($('<li>') | 
					
						
							|  |  |  |                     .append(formattedTime + ' - ') | 
					
						
							| 
									
										
										
										
											2017-11-04 17:07:03 -04:00
										 |  |  |                     .append(link.createNoteLink(change.note_id)) | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |                     .append(' (').append(revLink).append(')')); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-11-04 11:32:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 17:03:15 -04:00
										 |  |  |             dialogEl.append(dayEl); | 
					
						
							| 
									
										
										
										
											2017-11-04 11:32:05 -04:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-04 11:32:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |     function groupByDate(result) { | 
					
						
							|  |  |  |         const groupedByDate = new Map(); | 
					
						
							|  |  |  |         const dayCache = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (const row of 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); | 
					
						
							| 
									
										
										
										
											2017-11-04 11:32:05 -04:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |         return groupedByDate; | 
					
						
							| 
									
										
										
										
											2017-11-04 11:32:05 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |     $(document).bind('keydown', 'alt+r', showDialog); | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:39:26 -04:00
										 |  |  |     return { | 
					
						
							|  |  |  |         showDialog | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | })(); |