From 56b53ec873d458b5efbad7d24a8527609649b218 Mon Sep 17 00:00:00 2001 From: "Darryl L. Pierce" Date: Sun, 19 Jul 2020 14:22:31 -0400 Subject: [PATCH] Added the TaskAuditLogPage component [#413] --- .../backend-status-routing.module.ts | 7 ++ .../backend-status/backend-status.module.ts | 6 +- .../task-audit-log-page.component.html | 28 ++++++++ .../task-audit-log-page.component.scss | 0 .../task-audit-log-page.component.spec.ts | 67 +++++++++++++++++++ .../task-audit-log-page.component.ts | 67 +++++++++++++++++++ .../navigation-bar.component.ts | 11 +++ .../src/assets/i18n/en/backend-status.json | 10 +++ .../src/assets/i18n/en/common.json | 1 + .../src/assets/i18n/es/backend-status.json | 10 +++ .../src/assets/i18n/es/common.json | 1 + .../src/assets/i18n/fr/backend-status.json | 10 +++ .../src/assets/i18n/fr/common.json | 1 + .../src/assets/i18n/pt/backend-status.json | 10 +++ .../src/assets/i18n/pt/common.json | 1 + 15 files changed, 228 insertions(+), 2 deletions(-) create mode 100644 comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.html create mode 100644 comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.scss create mode 100644 comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.spec.ts create mode 100644 comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.ts diff --git a/comixed-frontend/src/app/backend-status/backend-status-routing.module.ts b/comixed-frontend/src/app/backend-status/backend-status-routing.module.ts index f8f76e3777..2da9ef694f 100644 --- a/comixed-frontend/src/app/backend-status/backend-status-routing.module.ts +++ b/comixed-frontend/src/app/backend-status/backend-status-routing.module.ts @@ -19,11 +19,18 @@ import { RouterModule, Routes } from '@angular/router'; import { BuildDetailsPageComponent } from 'app/backend-status/pages/build-details-page/build-details-page.component'; import { NgModule } from '@angular/core'; +import { TaskAuditLogPageComponent } from 'app/backend-status/pages/task-audit-log-page/task-audit-log-page.component'; +import { AdminGuard } from 'app/user'; const routes: Routes = [ { path: 'build/details', component: BuildDetailsPageComponent + }, + { + path: 'admin/tasks/logs', + component: TaskAuditLogPageComponent, + canActivate: [AdminGuard] } ]; diff --git a/comixed-frontend/src/app/backend-status/backend-status.module.ts b/comixed-frontend/src/app/backend-status/backend-status.module.ts index 5c0a54e0a0..2fdd146fe1 100644 --- a/comixed-frontend/src/app/backend-status/backend-status.module.ts +++ b/comixed-frontend/src/app/backend-status/backend-status.module.ts @@ -31,9 +31,10 @@ import { TranslateModule } from '@ngx-translate/core'; import { TaskAuditLogEffects } from 'app/backend-status/effects/task-audit-log.effects'; import { TaskAuditLogPageComponent } from './pages/task-audit-log-page/task-audit-log-page.component'; import { TaskAuditLogAdaptor } from 'app/backend-status/adaptors/task-audit-log.adaptor'; +import { TableModule } from 'primeng/table'; @NgModule({ - declarations: [BuildDetailsPageComponent], + declarations: [BuildDetailsPageComponent, TaskAuditLogPageComponent], imports: [ CommonModule, BackendStatusRoutingModule, @@ -46,7 +47,8 @@ import { TaskAuditLogAdaptor } from 'app/backend-status/adaptors/task-audit-log. fromTaskAuditLog.TASK_AUDIT_LOG_FEATURE_KEY, fromTaskAuditLog.reducer ), - EffectsModule.forFeature([BuildDetailsEffects, TaskAuditLogEffects]) + EffectsModule.forFeature([BuildDetailsEffects, TaskAuditLogEffects]), + TableModule ], exports: [CommonModule], providers: [BuildDetailsService, BuildDetailsAdaptor, TaskAuditLogAdaptor] diff --git a/comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.html b/comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.html new file mode 100644 index 0000000000..1bd047ff86 --- /dev/null +++ b/comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.html @@ -0,0 +1,28 @@ + + + + + + + + + + {{"task-audit-log-page.table.header.start-time"|translate}} + {{"task-audit-log-page.table.header.end-time"|translate}} + {{"task-audit-log-page.table.header.successful"|translate}} + {{"task-audit-log-page.table.header.description"|translate}} + + + + + {{entry.startTime|date:'medium'}} + {{entry.endTime|date:'medium'}} + {{entry.successful}} + {{entry.description}} + + + diff --git a/comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.scss b/comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.spec.ts b/comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.spec.ts new file mode 100644 index 0000000000..8b586c460c --- /dev/null +++ b/comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.spec.ts @@ -0,0 +1,67 @@ +/* + * ComiXed - A digital comic book library management application. + * Copyright (C) 2020, The ComiXed Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ + +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { TaskAuditLogPageComponent } from './task-audit-log-page.component'; +import { TableModule } from 'primeng/table'; +import { TranslateModule } from '@ngx-translate/core'; +import { LoggerModule } from '@angular-ru/logger'; +import { StoreModule } from '@ngrx/store'; +import { + reducer, + TASK_AUDIT_LOG_FEATURE_KEY +} from 'app/backend-status/reducers/task-audit-log.reducer'; +import { EffectsModule } from '@ngrx/effects'; +import { TaskAuditLogEffects } from 'app/backend-status/effects/task-audit-log.effects'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { MessageService } from 'primeng/api'; +import { LibraryModule } from 'app/library/library.module'; +import { RouterTestingModule } from '@angular/router/testing'; + +describe('TaskAuditLogPageComponent', () => { + let component: TaskAuditLogPageComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + LibraryModule, + RouterTestingModule, + HttpClientTestingModule, + TranslateModule.forRoot(), + LoggerModule.forRoot(), + StoreModule.forRoot({}), + StoreModule.forFeature(TASK_AUDIT_LOG_FEATURE_KEY, reducer), + EffectsModule.forRoot([]), + EffectsModule.forFeature([TaskAuditLogEffects]), + TableModule + ], + declarations: [TaskAuditLogPageComponent], + providers: [MessageService] + }).compileComponents(); + + fixture = TestBed.createComponent(TaskAuditLogPageComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + })); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.ts b/comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.ts new file mode 100644 index 0000000000..a149f23770 --- /dev/null +++ b/comixed-frontend/src/app/backend-status/pages/task-audit-log-page/task-audit-log-page.component.ts @@ -0,0 +1,67 @@ +/* + * ComiXed - A digital comic book library management application. + * Copyright (C) 2020, The ComiXed Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ + +import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Subscription } from 'rxjs'; +import { TaskAuditLogEntry } from 'app/backend-status/models/task-audit-log-entry'; +import { LoggerService } from '@angular-ru/logger'; +import { TaskAuditLogAdaptor } from 'app/backend-status/adaptors/task-audit-log.adaptor'; +import { LibraryDisplayAdaptor } from 'app/user/adaptors/library-display.adaptor'; + +@Component({ + selector: 'app-task-audit-log-page', + templateUrl: './task-audit-log-page.component.html', + styleUrls: ['./task-audit-log-page.component.scss'] +}) +export class TaskAuditLogPageComponent implements OnInit, OnDestroy { + fetchingSubscription: Subscription; + fetching = false; + entriesSubscription: Subscription; + entries: TaskAuditLogEntry[] = []; + rowsSubscription: Subscription; + rows = 0; + + constructor( + private logger: LoggerService, + private taskAuditLogAdaptor: TaskAuditLogAdaptor, + private libraryDisplayAdaptor: LibraryDisplayAdaptor + ) { + this.fetchingSubscription = this.taskAuditLogAdaptor.fetchingEntries$.subscribe( + fetching => { + this.fetching = fetching; + if (fetching === false) { + this.taskAuditLogAdaptor.getEntries(); + } + } + ); + this.entriesSubscription = this.taskAuditLogAdaptor.entries$.subscribe( + entries => (this.entries = entries) + ); + this.rowsSubscription = this.libraryDisplayAdaptor.rows$.subscribe( + rows => (this.rows = rows) + ); + } + + ngOnInit() {} + + ngOnDestroy() { + this.fetchingSubscription.unsubscribe(); + this.entriesSubscription.unsubscribe(); + this.rowsSubscription.unsubscribe(); + } +} diff --git a/comixed-frontend/src/app/components/navigation-bar/navigation-bar.component.ts b/comixed-frontend/src/app/components/navigation-bar/navigation-bar.component.ts index ac0d7a5fd3..1e44503c86 100644 --- a/comixed-frontend/src/app/components/navigation-bar/navigation-bar.component.ts +++ b/comixed-frontend/src/app/components/navigation-bar/navigation-bar.component.ts @@ -177,6 +177,17 @@ export class NavigationBarComponent implements OnInit { routerLink: ['/comics/missing'], visible: this.isAdmin }, + { + separator: true, + visible: this.authenticated + }, + { + label: this.translateService.instant( + 'main-menu.item.admin.task-audit-log' + ), + routerLink: ['/admin/tasks/logs'], + visible: this.isAdmin + }, { label: this.translateService.instant( 'main-menu.item.admin.clear-image-cache' diff --git a/comixed-frontend/src/assets/i18n/en/backend-status.json b/comixed-frontend/src/assets/i18n/en/backend-status.json index 0aec48e6e2..dba63b1761 100644 --- a/comixed-frontend/src/assets/i18n/en/backend-status.json +++ b/comixed-frontend/src/assets/i18n/en/backend-status.json @@ -27,5 +27,15 @@ "detail": "Failed to get task audit log entries." } } + }, + "task-audit-log-page": { + "table": { + "header": { + "start-time": "Started", + "end-time": "Ended", + "successful": "Success?", + "description": "Description" + } + } } } diff --git a/comixed-frontend/src/assets/i18n/en/common.json b/comixed-frontend/src/assets/i18n/en/common.json index ee2e5e360d..9c987fa2e8 100644 --- a/comixed-frontend/src/assets/i18n/en/common.json +++ b/comixed-frontend/src/assets/i18n/en/common.json @@ -31,6 +31,7 @@ "import": "Import", "duplicate-pages": "Duplicate Pages", "missing-comics": "Missing Comics", + "task-audit-log": "Task Logs", "clear-image-cache": "Clear Image Cache" }, "help": { diff --git a/comixed-frontend/src/assets/i18n/es/backend-status.json b/comixed-frontend/src/assets/i18n/es/backend-status.json index 39fb1e728b..b6de000101 100644 --- a/comixed-frontend/src/assets/i18n/es/backend-status.json +++ b/comixed-frontend/src/assets/i18n/es/backend-status.json @@ -27,5 +27,15 @@ "detail": "Failed to get task audit log entries." } } + }, + "task-audit-log-page": { + "table": { + "header": { + "start-time": "Started", + "end-time": "Ended", + "successful": "Success?", + "description": "Description" + } + } } } diff --git a/comixed-frontend/src/assets/i18n/es/common.json b/comixed-frontend/src/assets/i18n/es/common.json index 3b6a811d90..d32ce5db7b 100644 --- a/comixed-frontend/src/assets/i18n/es/common.json +++ b/comixed-frontend/src/assets/i18n/es/common.json @@ -31,6 +31,7 @@ "import": "Importar", "duplicate-pages": "Páginas duplicadas", "missing-comics": "Cómics que faltan", + "task-audit-log": "Task Logs", "clear-image-cache": "Clear Image Cache" }, "help": { diff --git a/comixed-frontend/src/assets/i18n/fr/backend-status.json b/comixed-frontend/src/assets/i18n/fr/backend-status.json index 2137619b04..17f7ce649f 100644 --- a/comixed-frontend/src/assets/i18n/fr/backend-status.json +++ b/comixed-frontend/src/assets/i18n/fr/backend-status.json @@ -27,5 +27,15 @@ "detail": "Failed to get task audit log entries." } } + }, + "task-audit-log-page": { + "table": { + "header": { + "start-time": "Started", + "end-time": "Ended", + "successful": "Success?", + "description": "Description" + } + } } } diff --git a/comixed-frontend/src/assets/i18n/fr/common.json b/comixed-frontend/src/assets/i18n/fr/common.json index a5ca4ac5bd..1e94f42c99 100644 --- a/comixed-frontend/src/assets/i18n/fr/common.json +++ b/comixed-frontend/src/assets/i18n/fr/common.json @@ -31,6 +31,7 @@ "import": "Importer", "duplicate-pages": "Pages dupliquées", "missing-comics": "Bandes dessinées manquantes", + "task-audit-log": "Task Logs", "clear-image-cache": "Vider le cache des images" }, "help": { diff --git a/comixed-frontend/src/assets/i18n/pt/backend-status.json b/comixed-frontend/src/assets/i18n/pt/backend-status.json index 0aec48e6e2..dba63b1761 100644 --- a/comixed-frontend/src/assets/i18n/pt/backend-status.json +++ b/comixed-frontend/src/assets/i18n/pt/backend-status.json @@ -27,5 +27,15 @@ "detail": "Failed to get task audit log entries." } } + }, + "task-audit-log-page": { + "table": { + "header": { + "start-time": "Started", + "end-time": "Ended", + "successful": "Success?", + "description": "Description" + } + } } } diff --git a/comixed-frontend/src/assets/i18n/pt/common.json b/comixed-frontend/src/assets/i18n/pt/common.json index ee2e5e360d..9c987fa2e8 100644 --- a/comixed-frontend/src/assets/i18n/pt/common.json +++ b/comixed-frontend/src/assets/i18n/pt/common.json @@ -31,6 +31,7 @@ "import": "Import", "duplicate-pages": "Duplicate Pages", "missing-comics": "Missing Comics", + "task-audit-log": "Task Logs", "clear-image-cache": "Clear Image Cache" }, "help": {