mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
[DURACOM-271] Fix error which led to have empty dashboard when new notification is delivered
This commit is contained in:
@@ -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';
|
||||
@@ -29,8 +31,88 @@ describe('AdminNotifyDashboardComponent', () => {
|
||||
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 ] },
|
||||
{
|
||||
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() },
|
||||
],
|
||||
|
@@ -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<AdminNotifyMetricsRow[]>;
|
||||
public notifyMetricsRows$: BehaviorSubject<AdminNotifyMetricsRow[]> = new BehaviorSubject<AdminNotifyMetricsRow[]>([]);
|
||||
|
||||
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)
|
||||
forkJoin(
|
||||
searchConfigurations.map(config => this.searchService.search(config)
|
||||
.pipe(
|
||||
getFirstCompletedRemoteData(),
|
||||
map(response => this.mapSearchObjectsToMetricsBox(response.payload)),
|
||||
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<DSpaceObject>): AdminNotifyMetricsBox {
|
||||
private mapSearchObjectsToMetricsBox(configuration: string, searchObject: SearchObjects<DSpaceObject>): 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,
|
||||
};
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<div role="button"
|
||||
<div role="button" *ngIf="boxConfig"
|
||||
class="w-100 h-100 pt-4 pb-3 px-2 box-container"
|
||||
[ngStyle]="{'background-color': boxConfig.color}"
|
||||
[dsHoverClass]="'shadow-lg'"
|
||||
|
@@ -1,4 +1,7 @@
|
||||
import { NgStyle } from '@angular/common';
|
||||
import {
|
||||
NgIf,
|
||||
NgStyle,
|
||||
} from '@angular/common';
|
||||
import {
|
||||
Component,
|
||||
EventEmitter,
|
||||
@@ -23,6 +26,7 @@ import { listableObjectComponent } from '../object-collection/shared/listable-ob
|
||||
NgStyle,
|
||||
HoverClassDirective,
|
||||
TranslateModule,
|
||||
NgIf,
|
||||
],
|
||||
})
|
||||
/**
|
||||
|
Reference in New Issue
Block a user