| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | import {UIElement} from "./UIElement"; | 
					
						
							|  |  |  | import {UIEventSource} from "./UIEventSource"; | 
					
						
							| 
									
										
										
										
											2020-07-19 00:13:45 +02:00
										 |  |  | import {Changes} from "../Logic/Changes"; | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-27 03:06:51 +02:00
										 |  |  | export class PendingChanges extends UIElement { | 
					
						
							|  |  |  |     private _pendingChangesCount: UIEventSource<number>; | 
					
						
							|  |  |  |     private _countdown: UIEventSource<number>; | 
					
						
							|  |  |  |     private _isSaving: UIEventSource<boolean>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-19 00:13:45 +02:00
										 |  |  |     constructor(changes: Changes, | 
					
						
							|  |  |  |                 countdown: UIEventSource<number>) { | 
					
						
							|  |  |  |         super(changes.pendingChangesES); | 
					
						
							|  |  |  |         this.ListenTo(changes.isSaving); | 
					
						
							| 
									
										
										
										
											2020-06-27 03:06:51 +02:00
										 |  |  |         this.ListenTo(countdown); | 
					
						
							| 
									
										
										
										
											2020-07-19 00:13:45 +02:00
										 |  |  |         this._pendingChangesCount = changes.pendingChangesES; | 
					
						
							| 
									
										
										
										
											2020-06-27 03:06:51 +02:00
										 |  |  |         this._countdown = countdown; | 
					
						
							| 
									
										
										
										
											2020-07-19 00:13:45 +02:00
										 |  |  |         this._isSaving = changes.isSaving; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.onClick(() => { | 
					
						
							|  |  |  |             changes.uploadAll(); | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-06-27 03:06:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-21 00:07:04 +02:00
										 |  |  |     InnerRender(): string { | 
					
						
							| 
									
										
										
										
											2020-06-27 03:06:51 +02:00
										 |  |  |         if (this._isSaving.data) { | 
					
						
							|  |  |  |             return "<span class='alert'>Saving</span>"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (this._pendingChangesCount.data == 0) { | 
					
						
							|  |  |  |             return ""; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         var restingSeconds = this._countdown.data / 1000; | 
					
						
							|  |  |  |         var dots = ""; | 
					
						
							|  |  |  |         while (restingSeconds > 0) { | 
					
						
							|  |  |  |             dots += "."; | 
					
						
							|  |  |  |             restingSeconds = restingSeconds - 1; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return "Saving "+this._pendingChangesCount.data; | 
					
						
							|  |  |  |     }   | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |      | 
					
						
							|  |  |  | } |