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