mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-28 03:46:06 -05:00 
			
		
		
		
	Chore: use rxjs instead of JS setInterval for timers (#8461)
This commit is contained in:
		| @@ -1592,7 +1592,7 @@ | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/admin/tasks/tasks.component.ts</context> | ||||
|           <context context-type="linenumber">30</context> | ||||
|           <context context-type="linenumber">31</context> | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/admin/trash/trash.component.html</context> | ||||
| @@ -1818,7 +1818,7 @@ | ||||
|         </context-group> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/admin/tasks/tasks.component.ts</context> | ||||
|           <context context-type="linenumber">122</context> | ||||
|           <context context-type="linenumber">129</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="2134950584701094962" datatype="html"> | ||||
| @@ -1874,63 +1874,63 @@ | ||||
|         <source>Result</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/admin/tasks/tasks.component.ts</context> | ||||
|           <context context-type="linenumber">31</context> | ||||
|           <context context-type="linenumber">32</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="5404910960991552159" datatype="html"> | ||||
|         <source>Dismiss selected</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/admin/tasks/tasks.component.ts</context> | ||||
|           <context context-type="linenumber">75</context> | ||||
|           <context context-type="linenumber">76</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="8829078752502782653" datatype="html"> | ||||
|         <source>Dismiss all</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/admin/tasks/tasks.component.ts</context> | ||||
|           <context context-type="linenumber">76</context> | ||||
|           <context context-type="linenumber">77</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="1323591410517879795" datatype="html"> | ||||
|         <source>Confirm Dismiss All</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/admin/tasks/tasks.component.ts</context> | ||||
|           <context context-type="linenumber">119</context> | ||||
|           <context context-type="linenumber">126</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="4157200209636243740" datatype="html"> | ||||
|         <source>Dismiss all <x id="PH" equiv-text="tasks.size"/> tasks?</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/admin/tasks/tasks.component.ts</context> | ||||
|           <context context-type="linenumber">120</context> | ||||
|           <context context-type="linenumber">127</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="9011556615675272238" datatype="html"> | ||||
|         <source>queued</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/admin/tasks/tasks.component.ts</context> | ||||
|           <context context-type="linenumber">205</context> | ||||
|           <context context-type="linenumber">212</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="6415892379431855826" datatype="html"> | ||||
|         <source>started</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/admin/tasks/tasks.component.ts</context> | ||||
|           <context context-type="linenumber">207</context> | ||||
|           <context context-type="linenumber">214</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="7510279840486540181" datatype="html"> | ||||
|         <source>completed</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/admin/tasks/tasks.component.ts</context> | ||||
|           <context context-type="linenumber">209</context> | ||||
|           <context context-type="linenumber">216</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="4083337005045748464" datatype="html"> | ||||
|         <source>failed</source> | ||||
|         <context-group purpose="location"> | ||||
|           <context context-type="sourcefile">src/app/components/admin/tasks/tasks.component.ts</context> | ||||
|           <context context-type="linenumber">211</context> | ||||
|           <context context-type="linenumber">218</context> | ||||
|         </context-group> | ||||
|       </trans-unit> | ||||
|       <trans-unit id="3418677553313974490" datatype="html"> | ||||
|   | ||||
| @@ -4,7 +4,7 @@ | ||||
|   info="Review the log files for the application and for email checking." | ||||
|   i18n-info> | ||||
|   <div class="form-check form-switch"> | ||||
|     <input class="form-check-input" type="checkbox" role="switch" id="autoRefreshSwitch" (click)="toggleAutoRefresh()" [attr.checked]="autoRefreshInterval"> | ||||
|     <input class="form-check-input" type="checkbox" role="switch" [(ngModel)]="autoRefreshEnabled"> | ||||
|     <label class="form-check-label" for="autoRefreshSwitch" i18n>Auto refresh</label> | ||||
|   </div> | ||||
| </pngx-page-header> | ||||
|   | ||||
| @@ -1,9 +1,4 @@ | ||||
| import { | ||||
|   ComponentFixture, | ||||
|   TestBed, | ||||
|   fakeAsync, | ||||
|   tick, | ||||
| } from '@angular/core/testing' | ||||
| import { ComponentFixture, TestBed } from '@angular/core/testing' | ||||
| import { LogService } from 'src/app/services/rest/log.service' | ||||
| import { PageHeaderComponent } from '../../common/page-header/page-header.component' | ||||
| import { LogsComponent } from './logs.component' | ||||
| @@ -90,8 +85,7 @@ describe('LogsComponent', () => { | ||||
|     jest.advanceTimersByTime(6000) | ||||
|     expect(reloadSpy).toHaveBeenCalledTimes(2) | ||||
|  | ||||
|     component.toggleAutoRefresh() | ||||
|     expect(component.autoRefreshInterval).toBeNull() | ||||
|     component.autoRefreshEnabled = false | ||||
|     jest.advanceTimersByTime(6000) | ||||
|     expect(reloadSpy).toHaveBeenCalledTimes(2) | ||||
|   }) | ||||
|   | ||||
| @@ -6,7 +6,7 @@ import { | ||||
|   ChangeDetectorRef, | ||||
|   OnDestroy, | ||||
| } from '@angular/core' | ||||
| import { takeUntil } from 'rxjs' | ||||
| import { filter, takeUntil, timer } from 'rxjs' | ||||
| import { LogService } from 'src/app/services/rest/log.service' | ||||
| import { LoadingComponentWithPermissions } from '../../loading-component/loading.component' | ||||
|  | ||||
| @@ -32,7 +32,7 @@ export class LogsComponent | ||||
|  | ||||
|   public activeLog: string | ||||
|  | ||||
|   public autoRefreshInterval: any | ||||
|   public autoRefreshEnabled: boolean = true | ||||
|  | ||||
|   @ViewChild('logContainer') logContainer: ElementRef | ||||
|  | ||||
| @@ -47,13 +47,19 @@ export class LogsComponent | ||||
|           this.activeLog = this.logFiles[0] | ||||
|           this.reloadLogs() | ||||
|         } | ||||
|         this.toggleAutoRefresh() | ||||
|         timer(5000, 5000) | ||||
|           .pipe( | ||||
|             filter(() => this.autoRefreshEnabled), | ||||
|             takeUntil(this.unsubscribeNotifier) | ||||
|           ) | ||||
|           .subscribe(() => { | ||||
|             this.reloadLogs() | ||||
|           }) | ||||
|       }) | ||||
|   } | ||||
|  | ||||
|   ngOnDestroy(): void { | ||||
|     super.ngOnDestroy() | ||||
|     clearInterval(this.autoRefreshInterval) | ||||
|   } | ||||
|  | ||||
|   reloadLogs() { | ||||
| @@ -96,15 +102,4 @@ export class LogsComponent | ||||
|       behavior: 'auto', | ||||
|     }) | ||||
|   } | ||||
|  | ||||
|   toggleAutoRefresh(): void { | ||||
|     if (this.autoRefreshInterval) { | ||||
|       clearInterval(this.autoRefreshInterval) | ||||
|       this.autoRefreshInterval = null | ||||
|     } else { | ||||
|       this.autoRefreshInterval = setInterval(() => { | ||||
|         this.reloadLogs() | ||||
|       }, 5000) | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -37,7 +37,7 @@ | ||||
|       </div> | ||||
|     </div> | ||||
|     <div class="form-check form-switch mb-0 ms-2"> | ||||
|       <input class="form-check-input" type="checkbox" role="switch" id="autoRefreshSwitch" (click)="toggleAutoRefresh()" [attr.checked]="autoRefreshInterval"> | ||||
|       <input class="form-check-input" type="checkbox" role="switch" [(ngModel)]="autoRefreshEnabled"> | ||||
|       <label class="form-check-label" for="autoRefreshSwitch" i18n>Auto refresh</label> | ||||
|     </div> | ||||
|   </div> | ||||
|   | ||||
| @@ -283,9 +283,7 @@ describe('TasksComponent', () => { | ||||
|     expect(reloadSpy).toHaveBeenCalledTimes(1) | ||||
|     jest.advanceTimersByTime(5000) | ||||
|     expect(reloadSpy).toHaveBeenCalledTimes(2) | ||||
|  | ||||
|     component.toggleAutoRefresh() | ||||
|     expect(component.autoRefreshInterval).toBeNull() | ||||
|     component.autoRefreshEnabled = false | ||||
|     jest.advanceTimersByTime(6000) | ||||
|     expect(reloadSpy).toHaveBeenCalledTimes(2) | ||||
|   }) | ||||
|   | ||||
| @@ -8,6 +8,7 @@ import { | ||||
|   first, | ||||
|   Subject, | ||||
|   takeUntil, | ||||
|   timer, | ||||
| } from 'rxjs' | ||||
| import { PaperlessTask } from 'src/app/data/paperless-task' | ||||
| import { TasksService } from 'src/app/services/tasks.service' | ||||
| @@ -48,7 +49,7 @@ export class TasksComponent | ||||
|   public pageSize: number = 25 | ||||
|   public page: number = 1 | ||||
|  | ||||
|   public autoRefreshInterval: any | ||||
|   public autoRefreshEnabled: boolean = true | ||||
|  | ||||
|   private _filterText: string = '' | ||||
|   get filterText() { | ||||
| @@ -86,7 +87,14 @@ export class TasksComponent | ||||
|  | ||||
|   ngOnInit() { | ||||
|     this.tasksService.reload() | ||||
|     this.toggleAutoRefresh() | ||||
|     timer(5000, 5000) | ||||
|       .pipe( | ||||
|         filter(() => this.autoRefreshEnabled), | ||||
|         takeUntil(this.unsubscribeNotifier) | ||||
|       ) | ||||
|       .subscribe(() => { | ||||
|         this.tasksService.reload() | ||||
|       }) | ||||
|  | ||||
|     this.filterDebounce | ||||
|       .pipe( | ||||
| @@ -101,7 +109,6 @@ export class TasksComponent | ||||
|   ngOnDestroy() { | ||||
|     super.ngOnDestroy() | ||||
|     this.tasksService.cancelPending() | ||||
|     clearInterval(this.autoRefreshInterval) | ||||
|   } | ||||
|  | ||||
|   dismissTask(task: PaperlessTask) { | ||||
| @@ -212,17 +219,6 @@ export class TasksComponent | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   toggleAutoRefresh(): void { | ||||
|     if (this.autoRefreshInterval) { | ||||
|       clearInterval(this.autoRefreshInterval) | ||||
|       this.autoRefreshInterval = null | ||||
|     } else { | ||||
|       this.autoRefreshInterval = setInterval(() => { | ||||
|         this.tasksService.reload() | ||||
|       }, 5000) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   public resetFilter() { | ||||
|     this._filterText = '' | ||||
|   } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 shamoon
					shamoon