diff --git a/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.html b/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.html index 16f1955dc3..e38ecd8239 100644 --- a/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.html +++ b/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.html @@ -1,10 +1,10 @@ - - + +
{{ this.item.isArchived ? ('qa-event-notification.check.notification-withdrawn' | translate) : ('qa-event-notification.check.notification-reinstate' | translate) }}
-
diff --git a/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.ts b/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.ts index adb120e2a5..d7bfb97378 100644 --- a/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.ts +++ b/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, SimpleChanges } from '@angular/core'; import { Item } from '../../../core/shared/item.model'; import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; import { Observable } from 'rxjs'; @@ -6,9 +6,11 @@ import { FindListOptions } from '../../../core/data/find-list-options.model'; import { RequestParam } from '../../../core/cache/models/request-param.model'; import { QualityAssuranceSourceDataService } from '../../../core/notifications/qa/source/quality-assurance-source-data.service'; import { QualityAssuranceSourceObject } from '../../../core/notifications/qa/models/quality-assurance-source.model'; -import { map, tap } from 'rxjs/operators'; +import { map } from 'rxjs/operators'; import { RemoteData } from '../../../core/data/remote-data'; import { getNotificatioQualityAssuranceRoute } from '../../../admin/admin-routing-paths'; +import { PaginatedList } from 'src/app/core/data/paginated-list.model'; +import { NavigationEnd, Router } from '@angular/router'; @Component({ selector: 'ds-qa-event-notification', @@ -20,17 +22,40 @@ import { getNotificatioQualityAssuranceRoute } from '../../../admin/admin-routin /** * Component for displaying quality assurance event notifications for an item. */ -export class QaEventNotificationComponent { +export class QaEventNotificationComponent implements OnChanges { /** * The item to display quality assurance event notifications for. */ @Input() item: Item; + + /** + * An observable that emits an array of QualityAssuranceSourceObject. + */ + sources$: Observable; /** * The type of alert to display for the notification. */ constructor( - private qualityAssuranceSourceDataService: QualityAssuranceSourceDataService - ) { } + private qualityAssuranceSourceDataService: QualityAssuranceSourceDataService, + private router: Router, + private chd: ChangeDetectorRef + ) { + this.router.events.pipe().subscribe((event) => { + if (event instanceof NavigationEnd) { + this.sources$ = this.getQualityAssuranceSources$(); + this.chd.markForCheck(); + } + }); + } + + /** + * Detect changes to the item input and update the sources$ observable. + */ + ngOnChanges(changes: SimpleChanges): void { + if (changes.item && changes.item.currentValue.uuid !== changes.item.previousValue?.uuid) { + this.sources$ = this.getQualityAssuranceSources$(); + } + } /** * Returns an Observable of QualityAssuranceSourceObject[] for the current item. * @returns An Observable of QualityAssuranceSourceObject[] for the current item. @@ -40,11 +65,10 @@ export class QaEventNotificationComponent { const findListTopicOptions: FindListOptions = { searchParams: [new RequestParam('target', this.item.uuid)] }; - return this.qualityAssuranceSourceDataService.getSourcesByTarget(findListTopicOptions) + return this.qualityAssuranceSourceDataService.getSourcesByTarget(findListTopicOptions, false) .pipe( getFirstCompletedRemoteData(), - tap(console.log), - map((data: RemoteData) => { + map((data: RemoteData>) => { if (data.hasSucceeded) { return data.payload.page; } diff --git a/src/app/notifications/qa/events/quality-assurance-events.component.html b/src/app/notifications/qa/events/quality-assurance-events.component.html index 04a43c7ddc..0f7fc01d62 100644 --- a/src/app/notifications/qa/events/quality-assurance-events.component.html +++ b/src/app/notifications/qa/events/quality-assurance-events.component.html @@ -185,7 +185,7 @@
- + {{'quality-assurance.events.back' | translate}} diff --git a/src/app/shared/dso-page/dso-edit-menu.resolver.ts b/src/app/shared/dso-page/dso-edit-menu.resolver.ts index 6fa5382d8d..ef0d10d6f8 100644 --- a/src/app/shared/dso-page/dso-edit-menu.resolver.ts +++ b/src/app/shared/dso-page/dso-edit-menu.resolver.ts @@ -193,7 +193,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection { id: 'withdrawn-item', active: false, - visible: dso.isArchived && correction.totalElements > 0, + visible: dso.isArchived && correction?.totalElements > 0, model: { type: MenuItemType.ONCLICK, text:'item.page.withdrawn', @@ -207,7 +207,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection { id: 'reinstate-item', active: false, - visible: dso.isWithdrawn && correction.totalElements > 0, + visible: dso.isWithdrawn && correction?.totalElements > 0, model: { type: MenuItemType.ONCLICK, text:'item.page.reinstate', diff --git a/src/app/shared/dso-page/dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service.ts b/src/app/shared/dso-page/dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service.ts index a28b8483d2..13e9490bd0 100644 --- a/src/app/shared/dso-page/dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service.ts +++ b/src/app/shared/dso-page/dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service.ts @@ -28,7 +28,7 @@ export class DsoWithdrawnReinstateModalService { private notificationsService: NotificationsService, protected authorizationService: AuthorizationDataService, private translateService: TranslateService, - protected qaEventDataService: QualityAssuranceEventDataService + protected qaEventDataService: QualityAssuranceEventDataService, ) {} /** @@ -62,6 +62,7 @@ export class DsoWithdrawnReinstateModalService { const message = (correctionType === 'request-withdrawn') ? withdrawnMessage : reinstateMessage; this.notificationsService.success(this.translateService.get(message)); this.authorizationService.invalidateAuthorizationsRequestCache(); + this.router.navigate([this.router.url]); // refresh page } else { this.notificationsService.error(this.translateService.get('correction-type.manage-relation.action.notification.error')); }