diff --git a/src/app/admin/admin-notify-dashboard/admin-notify-dashboard.component.spec.ts b/src/app/admin/admin-notify-dashboard/admin-notify-dashboard.component.spec.ts index a8bc2eea8e..82dc0f5d7d 100644 --- a/src/app/admin/admin-notify-dashboard/admin-notify-dashboard.component.spec.ts +++ b/src/app/admin/admin-notify-dashboard/admin-notify-dashboard.component.spec.ts @@ -7,6 +7,8 @@ import { ActivatedRoute } from '@angular/router'; import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap'; import { TranslateModule } from '@ngx-translate/core'; +import { APP_CONFIG } from '../../../config/app-config.interface'; +import { environment } from '../../../environments/environment.test'; import { buildPaginatedList } from '../../core/data/paginated-list.model'; import { SearchService } from '../../core/shared/search/search.service'; import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils'; @@ -28,9 +30,89 @@ describe('AdminNotifyDashboardComponent', () => { let searchResult3; let results; - const mockBoxes = [ - { title: 'admin-notify-dashboard.received-ldn', boxes: [ undefined, undefined, undefined, undefined, undefined ] }, - { title: 'admin-notify-dashboard.generated-ldn', boxes: [ undefined, undefined, undefined, undefined, undefined ] }, + const mockBoxes = [ + { + title: 'admin-notify-dashboard.received-ldn', + boxes: [ + { + color: '#B8DAFF', + title: 'admin-notify-dashboard.NOTIFY.incoming.accepted', + config: 'NOTIFY.incoming.accepted', + description: 'admin-notify-dashboard.NOTIFY.incoming.accepted.description', + count: undefined, + }, + { + color: '#D4EDDA', + title: 'admin-notify-dashboard.NOTIFY.incoming.processed', + config: 'NOTIFY.incoming.processed', + description: 'admin-notify-dashboard.NOTIFY.incoming.processed.description', + count: undefined, + }, + { + color: '#FDBBC7', + title: 'admin-notify-dashboard.NOTIFY.incoming.failure', + config: 'NOTIFY.incoming.failure', + description: 'admin-notify-dashboard.NOTIFY.incoming.failure.description', + count: undefined, + }, + { + color: '#FDBBC7', + title: 'admin-notify-dashboard.NOTIFY.incoming.untrusted', + config: 'NOTIFY.incoming.untrusted', + description: 'admin-notify-dashboard.NOTIFY.incoming.untrusted.description', + count: undefined, + }, + { + color: '#43515F', + title: 'admin-notify-dashboard.NOTIFY.incoming.involvedItems', + textColor: '#fff', + config: 'NOTIFY.incoming.involvedItems', + description: 'admin-notify-dashboard.NOTIFY.incoming.involvedItems.description', + count: undefined, + }, + ], + }, + { + title: 'admin-notify-dashboard.generated-ldn', + boxes: [ + { + color: '#D4EDDA', + title: 'admin-notify-dashboard.NOTIFY.outgoing.delivered', + config: 'NOTIFY.outgoing.delivered', + description: 'admin-notify-dashboard.NOTIFY.outgoing.delivered.description', + count: undefined, + }, + { + color: '#B8DAFF', + title: 'admin-notify-dashboard.NOTIFY.outgoing.queued', + config: 'NOTIFY.outgoing.queued', + description: 'admin-notify-dashboard.NOTIFY.outgoing.queued.description', + count: undefined, + }, + { + color: '#FDEEBB', + title: 'admin-notify-dashboard.NOTIFY.outgoing.queued_for_retry', + config: 'NOTIFY.outgoing.queued_for_retry', + description: 'admin-notify-dashboard.NOTIFY.outgoing.queued_for_retry.description', + count: undefined, + }, + { + color: '#FDBBC7', + title: 'admin-notify-dashboard.NOTIFY.outgoing.failure', + config: 'NOTIFY.outgoing.failure', + description: 'admin-notify-dashboard.NOTIFY.outgoing.failure.description', + count: undefined, + }, + { + color: '#43515F', + title: 'admin-notify-dashboard.NOTIFY.outgoing.involvedItems', + textColor: '#fff', + config: 'NOTIFY.outgoing.involvedItems', + description: 'admin-notify-dashboard.NOTIFY.outgoing.involvedItems.description', + count: undefined, + }, + ], + }, ]; beforeEach(async () => { @@ -45,6 +127,7 @@ describe('AdminNotifyDashboardComponent', () => { await TestBed.configureTestingModule({ imports: [TranslateModule.forRoot(), NgbNavModule, AdminNotifyDashboardComponent], providers: [ + { provide: APP_CONFIG, useValue: environment }, { provide: SearchService, useValue: { search: () => createSuccessfulRemoteDataObject$(results) } }, { provide: ActivatedRoute, useValue: new ActivatedRouteStub() }, ], diff --git a/src/app/admin/admin-notify-dashboard/admin-notify-dashboard.component.ts b/src/app/admin/admin-notify-dashboard/admin-notify-dashboard.component.ts index 69ca118fff..5508c18030 100644 --- a/src/app/admin/admin-notify-dashboard/admin-notify-dashboard.component.ts +++ b/src/app/admin/admin-notify-dashboard/admin-notify-dashboard.component.ts @@ -4,17 +4,21 @@ import { } from '@angular/common'; import { Component, + Inject, OnInit, } from '@angular/core'; import { RouterLink } from '@angular/router'; import { TranslateModule } from '@ngx-translate/core'; import { + BehaviorSubject, forkJoin, - Observable, } from 'rxjs'; import { map } from 'rxjs/operators'; -import { environment } from '../../../environments/environment'; +import { + APP_CONFIG, + AppConfig, +} from '../../../config/app-config.interface'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { getFirstCompletedRemoteData } from '../../core/shared/operators'; import { SearchService } from '../../core/shared/search/search.service'; @@ -51,20 +55,25 @@ import { /** * Component used for visual representation and search of LDN messages for Admins */ -export class AdminNotifyDashboardComponent implements OnInit{ +export class AdminNotifyDashboardComponent implements OnInit { - public notifyMetricsRows$: Observable; + public notifyMetricsRows$: BehaviorSubject = new BehaviorSubject([]); + + private metricsConfig: AdminNotifyMetricsRow[]; - private metricsConfig = environment.notifyMetrics; private singleResultOptions = Object.assign(new PaginationComponentOptions(), { id: 'single-result-options', pageSize: 1, }); - constructor(private searchService: SearchService) { + constructor( + @Inject(APP_CONFIG) protected appConfig: AppConfig, + private searchService: SearchService, + ) { } ngOnInit() { + this.metricsConfig = this.appConfig.notifyMetrics; const mertricsRowsConfigurations = this.metricsConfig .map(row => row.boxes) .map(boxes => boxes.map(box => box.config).filter(config => !!config)); @@ -74,15 +83,18 @@ export class AdminNotifyDashboardComponent implements OnInit{ { configuration: config, pagination: this.singleResultOptions }, )); - this.notifyMetricsRows$ = forkJoin(searchConfigurations.map(config => this.searchService.search(config) - .pipe( - getFirstCompletedRemoteData(), - map(response => this.mapSearchObjectsToMetricsBox(response.payload)), + forkJoin( + searchConfigurations.map(config => this.searchService.search(config) + .pipe( + getFirstCompletedRemoteData(), + map(response => this.mapSearchObjectsToMetricsBox(config.configuration, response.payload)), + ), ), - ), ).pipe( map(metricBoxes => this.mapUpdatedBoxesToMetricsRows(metricBoxes)), - ); + ).subscribe((metricBoxes: AdminNotifyMetricsRow[]) => { + this.notifyMetricsRows$.next(metricBoxes); + }); } /** @@ -91,13 +103,12 @@ export class AdminNotifyDashboardComponent implements OnInit{ * @param searchObject The object to map * @private */ - private mapSearchObjectsToMetricsBox(searchObject: SearchObjects): AdminNotifyMetricsBox { + private mapSearchObjectsToMetricsBox(configuration: string, searchObject: SearchObjects): AdminNotifyMetricsBox { const count = searchObject.pageInfo.totalElements; - const objectConfig = searchObject.configuration; - const metricsBoxes = [].concat(...this.metricsConfig.map((config) => config.boxes)); + const metricsBoxes = [].concat(...this.metricsConfig.map((config: AdminNotifyMetricsRow) => config.boxes)); return { - ...metricsBoxes.find(box => box.config === objectConfig), + ...metricsBoxes.find(box => box.config === configuration), count, }; } diff --git a/src/app/shared/notification-box/notification-box.component.html b/src/app/shared/notification-box/notification-box.component.html index 8e4b5bc2f6..29be1f475e 100644 --- a/src/app/shared/notification-box/notification-box.component.html +++ b/src/app/shared/notification-box/notification-box.component.html @@ -1,4 +1,4 @@ -