| 
									
										
										
										
											2017-11-04 19:38:50 -04:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:35:39 -04:00
										 |  |  | const status = (function() { | 
					
						
							|  |  |  |     const treeEl = $("#tree"); | 
					
						
							|  |  |  |     const $changesToPushCountEl = $("#changesToPushCount"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function checkStatus() { | 
					
						
							|  |  |  |         const resp = await $.ajax({ | 
					
						
							|  |  |  |             url: baseApiUrl + 'status', | 
					
						
							|  |  |  |             type: 'POST', | 
					
						
							|  |  |  |             contentType: "application/json", | 
					
						
							|  |  |  |             data: JSON.stringify({ | 
					
						
							|  |  |  |                 treeLoadTime: noteTree.getTreeLoadTime(), | 
					
						
							|  |  |  |                 currentNoteId: noteEditor.getCurrentNoteId(), | 
					
						
							| 
									
										
										
										
											2017-11-04 21:02:56 -04:00
										 |  |  |                 currentNoteLoadTime: noteEditor.getCurrentNoteLoadTime() | 
					
						
							| 
									
										
										
										
											2017-11-04 19:35:39 -04:00
										 |  |  |             }), | 
					
						
							|  |  |  |             statusCode: { | 
					
						
							|  |  |  |                 401: () => { | 
					
						
							|  |  |  |                     // if the user got logged out then we should display the page
 | 
					
						
							|  |  |  |                     // here we do that by reloading which will force the redirect if the user is really logged out
 | 
					
						
							|  |  |  |                     window.location.reload(true); | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 409: () => { | 
					
						
							|  |  |  |                     // 409 means we need to migrate database, reload will take care of it
 | 
					
						
							|  |  |  |                     window.location.reload(true); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2017-11-01 20:31:44 -04:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-11-04 19:35:39 -04:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2017-11-03 21:20:06 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:35:39 -04:00
										 |  |  |         if (resp.changedTree) { | 
					
						
							|  |  |  |             console.log("Reloading tree because of background changes"); | 
					
						
							| 
									
										
										
										
											2017-11-03 21:20:06 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-05 09:52:28 -05:00
										 |  |  |             noteTree.reload(); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:35:39 -04:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-03 21:20:06 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:35:39 -04:00
										 |  |  |         $changesToPushCountEl.html(resp.changesToPushCount); | 
					
						
							| 
									
										
										
										
											2017-11-03 21:20:06 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:35:39 -04:00
										 |  |  |     setInterval(checkStatus, 5 * 1000); | 
					
						
							| 
									
										
										
										
											2017-11-01 20:31:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:35:39 -04:00
										 |  |  |     return { | 
					
						
							|  |  |  |         checkStatus | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | })(); |