From 133d43ae3057bceb56cbedaf96742ce62c0d7930 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 30 Nov 2023 19:08:03 -0800 Subject: [PATCH] Enhancement: auto-refresh logs & tasks (#4680) --- src-ui/messages.xlf | 72 +++++++++---------- .../components/admin/logs/logs.component.html | 13 ++-- .../admin/logs/logs.component.spec.ts | 20 +++++- .../components/admin/logs/logs.component.ts | 14 ++++ .../admin/tasks/tasks.component.html | 15 ++-- .../admin/tasks/tasks.component.spec.ts | 18 ++++- .../components/admin/tasks/tasks.component.ts | 14 ++++ 7 files changed, 113 insertions(+), 53 deletions(-) diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf index 870f7c696..f80457c42 100644 --- a/src-ui/messages.xlf +++ b/src-ui/messages.xlf @@ -410,15 +410,26 @@ 228 + + Auto refresh + + src/app/components/admin/logs/logs.component.html + 4 + + + src/app/components/admin/tasks/tasks.component.html + 15 + + Loading... src/app/components/admin/logs/logs.component.html - 11 + 16 src/app/components/admin/logs/logs.component.html - 20 + 25 src/app/components/admin/settings/settings.component.html @@ -426,11 +437,7 @@ src/app/components/admin/tasks/tasks.component.html - 19 - - - src/app/components/admin/tasks/tasks.component.html - 27 + 22 src/app/components/admin/users-groups/users-groups.component.html @@ -995,7 +1002,7 @@ src/app/components/admin/tasks/tasks.component.html - 40 + 35 src/app/components/admin/users-groups/users-groups.component.html @@ -1131,7 +1138,7 @@ src/app/components/admin/tasks/tasks.component.html - 44 + 39 src/app/components/admin/users-groups/users-groups.component.html @@ -1462,18 +1469,11 @@ 22 - - Refresh - - src/app/components/admin/tasks/tasks.component.html - 20 - - Created src/app/components/admin/tasks/tasks.component.html - 41 + 36 src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.html @@ -1496,130 +1496,130 @@ Results src/app/components/admin/tasks/tasks.component.html - 42 + 37 Info src/app/components/admin/tasks/tasks.component.html - 43 + 38 click for full output src/app/components/admin/tasks/tasks.component.html - 66 + 61 Dismiss src/app/components/admin/tasks/tasks.component.html - 81 + 76 src/app/components/admin/tasks/tasks.component.ts - 63 + 66 Open Document src/app/components/admin/tasks/tasks.component.html - 87 + 82 {VAR_PLURAL, plural, =1 {One task} other { total tasks}} src/app/components/admin/tasks/tasks.component.html - 103 + 98 Failed src/app/components/admin/tasks/tasks.component.html - 110 + 105 Complete src/app/components/admin/tasks/tasks.component.html - 116 + 111 Started src/app/components/admin/tasks/tasks.component.html - 122 + 117 Queued src/app/components/admin/tasks/tasks.component.html - 128 + 123 Dismiss selected src/app/components/admin/tasks/tasks.component.ts - 28 + 30 Dismiss all src/app/components/admin/tasks/tasks.component.ts - 29 + 31 Confirm Dismiss All src/app/components/admin/tasks/tasks.component.ts - 60 + 63 Dismiss all tasks? src/app/components/admin/tasks/tasks.component.ts - 61 + 64 queued src/app/components/admin/tasks/tasks.component.ts - 129 + 132 started src/app/components/admin/tasks/tasks.component.ts - 131 + 134 completed src/app/components/admin/tasks/tasks.component.ts - 133 + 136 failed src/app/components/admin/tasks/tasks.component.ts - 135 + 138 diff --git a/src-ui/src/app/components/admin/logs/logs.component.html b/src-ui/src/app/components/admin/logs/logs.component.html index 91f7f3bd6..628886c62 100644 --- a/src-ui/src/app/components/admin/logs/logs.component.html +++ b/src-ui/src/app/components/admin/logs/logs.component.html @@ -1,14 +1,19 @@ - +
+ + +
diff --git a/src-ui/src/app/components/admin/logs/logs.component.spec.ts b/src-ui/src/app/components/admin/logs/logs.component.spec.ts index a9c4b4613..690bbcdde 100644 --- a/src-ui/src/app/components/admin/logs/logs.component.spec.ts +++ b/src-ui/src/app/components/admin/logs/logs.component.spec.ts @@ -1,4 +1,9 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing' +import { + ComponentFixture, + TestBed, + fakeAsync, + tick, +} 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' @@ -26,6 +31,7 @@ describe('LogsComponent', () => { let fixture: ComponentFixture let logService: LogService let logSpy + let reloadSpy beforeEach(async () => { TestBed.configureTestingModule({ @@ -42,7 +48,9 @@ describe('LogsComponent', () => { }) fixture = TestBed.createComponent(LogsComponent) component = fixture.componentInstance + reloadSpy = jest.spyOn(component, 'reloadLogs') window.HTMLElement.prototype.scroll = function () {} // mock scroll + jest.useFakeTimers() fixture.detectChanges() }) @@ -68,4 +76,14 @@ describe('LogsComponent', () => { component.reloadLogs() expect(component.logs).toHaveLength(0) }) + + it('should auto refresh, allow toggle', () => { + jest.advanceTimersByTime(6000) + expect(reloadSpy).toHaveBeenCalledTimes(2) + + component.toggleAutoRefresh() + expect(component.autoRefreshInterval).toBeNull() + jest.advanceTimersByTime(6000) + expect(reloadSpy).toHaveBeenCalledTimes(2) + }) }) diff --git a/src-ui/src/app/components/admin/logs/logs.component.ts b/src-ui/src/app/components/admin/logs/logs.component.ts index cf88077e7..2ca259218 100644 --- a/src-ui/src/app/components/admin/logs/logs.component.ts +++ b/src-ui/src/app/components/admin/logs/logs.component.ts @@ -27,6 +27,8 @@ export class LogsComponent implements OnInit, AfterViewChecked, OnDestroy { public isLoading: boolean = false + public autoRefreshInterval: any + @ViewChild('logContainer') logContainer: ElementRef ngOnInit(): void { @@ -41,6 +43,7 @@ export class LogsComponent implements OnInit, AfterViewChecked, OnDestroy { this.activeLog = this.logFiles[0] this.reloadLogs() } + this.toggleAutoRefresh() }) } @@ -91,4 +94,15 @@ export class LogsComponent implements OnInit, AfterViewChecked, OnDestroy { behavior: 'auto', }) } + + toggleAutoRefresh(): void { + if (this.autoRefreshInterval) { + clearInterval(this.autoRefreshInterval) + this.autoRefreshInterval = null + } else { + this.autoRefreshInterval = setInterval(() => { + this.reloadLogs() + }, 5000) + } + } } diff --git a/src-ui/src/app/components/admin/tasks/tasks.component.html b/src-ui/src/app/components/admin/tasks/tasks.component.html index 62799c9f6..7e0ac4cae 100644 --- a/src-ui/src/app/components/admin/tasks/tasks.component.html +++ b/src-ui/src/app/components/admin/tasks/tasks.component.html @@ -1,5 +1,5 @@ -
+
- +
+ + +
diff --git a/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts b/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts index c981dac6f..b86a170b7 100644 --- a/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts +++ b/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts @@ -112,6 +112,7 @@ describe('TasksComponent', () => { let modalService: NgbModal let router: Router let httpTestingController: HttpTestingController + let reloadSpy beforeEach(async () => { TestBed.configureTestingModule({ @@ -141,11 +142,13 @@ describe('TasksComponent', () => { }).compileComponents() tasksService = TestBed.inject(TasksService) + reloadSpy = jest.spyOn(tasksService, 'reload') httpTestingController = TestBed.inject(HttpTestingController) modalService = TestBed.inject(NgbModal) router = TestBed.inject(Router) fixture = TestBed.createComponent(TasksComponent) component = fixture.componentInstance + jest.useFakeTimers() fixture.detectChanges() httpTestingController .expectOne(`${environment.apiBaseUrl}tasks/`) @@ -164,7 +167,7 @@ describe('TasksComponent', () => { `Failed${currentTasksLength}` ) expect( - fixture.debugElement.queryAll(By.css('input[type="checkbox"]')) + fixture.debugElement.queryAll(By.css('table input[type="checkbox"]')) ).toHaveLength(currentTasksLength + 1) currentTasksLength = tasks.filter( @@ -245,7 +248,7 @@ describe('TasksComponent', () => { it('should support toggle all tasks', () => { const toggleCheck = fixture.debugElement.query( - By.css('input[type=checkbox]') + By.css('table input[type=checkbox]') ) toggleCheck.nativeElement.dispatchEvent(new MouseEvent('click')) fixture.detectChanges() @@ -269,4 +272,15 @@ describe('TasksComponent', () => { tasks[3].related_document, ]) }) + + it('should auto refresh, allow toggle', () => { + expect(reloadSpy).toHaveBeenCalledTimes(1) + jest.advanceTimersByTime(5000) + expect(reloadSpy).toHaveBeenCalledTimes(2) + + component.toggleAutoRefresh() + expect(component.autoRefreshInterval).toBeNull() + jest.advanceTimersByTime(6000) + expect(reloadSpy).toHaveBeenCalledTimes(2) + }) }) diff --git a/src-ui/src/app/components/admin/tasks/tasks.component.ts b/src-ui/src/app/components/admin/tasks/tasks.component.ts index 32cf6800f..5a1949e77 100644 --- a/src-ui/src/app/components/admin/tasks/tasks.component.ts +++ b/src-ui/src/app/components/admin/tasks/tasks.component.ts @@ -23,6 +23,8 @@ export class TasksComponent public pageSize: number = 25 public page: number = 1 + public autoRefreshInterval: any + get dismissButtonText(): string { return this.selectedTasks.size > 0 ? $localize`Dismiss selected` @@ -39,6 +41,7 @@ export class TasksComponent ngOnInit() { this.tasksService.reload() + this.toggleAutoRefresh() } ngOnDestroy() { @@ -135,4 +138,15 @@ export class TasksComponent return $localize`failed` } } + + toggleAutoRefresh(): void { + if (this.autoRefreshInterval) { + clearInterval(this.autoRefreshInterval) + this.autoRefreshInterval = null + } else { + this.autoRefreshInterval = setInterval(() => { + this.tasksService.reload() + }, 5000) + } + } }