[CST-12109] "refresh" page on item withdrawn from details page

This commit is contained in:
Alisa Ismailati
2024-01-18 17:27:13 +01:00
parent a4b0c5a13d
commit 80a0cd40cb
5 changed files with 40 additions and 15 deletions

View File

@@ -1,10 +1,10 @@
<ng-container *ngIf="(getQualityAssuranceSources$() | async)?.length > 0"> <ng-container *ngIf="(sources$ | async) as sources">
<ng-container *ngFor="let source of (getQualityAssuranceSources$() | async)"> <ng-container *ngFor="let source of sources">
<div class="alert alert-info d-flex flex-row" *ngIf="source.totalEvents > 0"> <div class="alert alert-info d-flex flex-row" *ngIf="source.totalEvents > 0">
<div class="w-100 d-flex justify-content-between"> <div class="w-100 d-flex justify-content-between">
<div class="pl-4 align-self-center">{{ this.item.isArchived ? ('qa-event-notification.check.notification-withdrawn' | translate) <div class="pl-4 align-self-center">{{ this.item.isArchived ? ('qa-event-notification.check.notification-withdrawn' | translate)
: ('qa-event-notification.check.notification-reinstate' | translate) }} </div> : ('qa-event-notification.check.notification-reinstate' | translate) }} </div>
<button [routerLink]="['/admin/notifications/quality-assurance/' + source.id]" <button [routerLink]="[ getQualityAssuranceRoute(), (source.id | dsSplit: ':')[0]]"
class="btn btn-primary align-self-center">{{ this.item.isArchived ? ('qa-event-notification-undo-withdrawn.check.button' | translate) class="btn btn-primary align-self-center">{{ this.item.isArchived ? ('qa-event-notification-undo-withdrawn.check.button' | translate)
: ('qa-event-notification-undo-reinstate.check.button' | translate) }}</button> : ('qa-event-notification-undo-reinstate.check.button' | translate) }}</button>
</div> </div>

View File

@@ -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 { Item } from '../../../core/shared/item.model';
import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
import { Observable } from 'rxjs'; 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 { RequestParam } from '../../../core/cache/models/request-param.model';
import { QualityAssuranceSourceDataService } from '../../../core/notifications/qa/source/quality-assurance-source-data.service'; import { QualityAssuranceSourceDataService } from '../../../core/notifications/qa/source/quality-assurance-source-data.service';
import { QualityAssuranceSourceObject } from '../../../core/notifications/qa/models/quality-assurance-source.model'; 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 { RemoteData } from '../../../core/data/remote-data';
import { getNotificatioQualityAssuranceRoute } from '../../../admin/admin-routing-paths'; import { getNotificatioQualityAssuranceRoute } from '../../../admin/admin-routing-paths';
import { PaginatedList } from 'src/app/core/data/paginated-list.model';
import { NavigationEnd, Router } from '@angular/router';
@Component({ @Component({
selector: 'ds-qa-event-notification', 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. * 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. * The item to display quality assurance event notifications for.
*/ */
@Input() item: Item; @Input() item: Item;
/**
* An observable that emits an array of QualityAssuranceSourceObject.
*/
sources$: Observable<QualityAssuranceSourceObject[]>;
/** /**
* The type of alert to display for the notification. * The type of alert to display for the notification.
*/ */
constructor( 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.
* @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 = { const findListTopicOptions: FindListOptions = {
searchParams: [new RequestParam('target', this.item.uuid)] searchParams: [new RequestParam('target', this.item.uuid)]
}; };
return this.qualityAssuranceSourceDataService.getSourcesByTarget(findListTopicOptions) return this.qualityAssuranceSourceDataService.getSourcesByTarget(findListTopicOptions, false)
.pipe( .pipe(
getFirstCompletedRemoteData(), getFirstCompletedRemoteData(),
tap(console.log), map((data: RemoteData<PaginatedList<QualityAssuranceSourceObject>>) => {
map((data: RemoteData<any>) => {
if (data.hasSucceeded) { if (data.hasSucceeded) {
return data.payload.page; return data.payload.page;
} }

View File

@@ -185,7 +185,7 @@
</div> </div>
<div class="row text-right"> <div class="row text-right">
<div class="col-md-12"> <div class="col-md-12">
<a class="btn btn-outline-secondary" [routerLink]="['/admin/notifications/quality-assurance']"> <a class="btn btn-outline-secondary" [routerLink]="['/notifications/quality-assurance']">
<i class="fas fa-angle-double-left"></i> <i class="fas fa-angle-double-left"></i>
{{'quality-assurance.events.back' | translate}} {{'quality-assurance.events.back' | translate}}
</a> </a>

View File

@@ -193,7 +193,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
{ {
id: 'withdrawn-item', id: 'withdrawn-item',
active: false, active: false,
visible: dso.isArchived && correction.totalElements > 0, visible: dso.isArchived && correction?.totalElements > 0,
model: { model: {
type: MenuItemType.ONCLICK, type: MenuItemType.ONCLICK,
text:'item.page.withdrawn', text:'item.page.withdrawn',
@@ -207,7 +207,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
{ {
id: 'reinstate-item', id: 'reinstate-item',
active: false, active: false,
visible: dso.isWithdrawn && correction.totalElements > 0, visible: dso.isWithdrawn && correction?.totalElements > 0,
model: { model: {
type: MenuItemType.ONCLICK, type: MenuItemType.ONCLICK,
text:'item.page.reinstate', text:'item.page.reinstate',

View File

@@ -28,7 +28,7 @@ export class DsoWithdrawnReinstateModalService {
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
protected authorizationService: AuthorizationDataService, protected authorizationService: AuthorizationDataService,
private translateService: TranslateService, private translateService: TranslateService,
protected qaEventDataService: QualityAssuranceEventDataService protected qaEventDataService: QualityAssuranceEventDataService,
) {} ) {}
/** /**
@@ -62,6 +62,7 @@ export class DsoWithdrawnReinstateModalService {
const message = (correctionType === 'request-withdrawn') ? withdrawnMessage : reinstateMessage; const message = (correctionType === 'request-withdrawn') ? withdrawnMessage : reinstateMessage;
this.notificationsService.success(this.translateService.get(message)); this.notificationsService.success(this.translateService.get(message));
this.authorizationService.invalidateAuthorizationsRequestCache(); this.authorizationService.invalidateAuthorizationsRequestCache();
this.router.navigate([this.router.url]); // refresh page
} else { } else {
this.notificationsService.error(this.translateService.get('correction-type.manage-relation.action.notification.error')); this.notificationsService.error(this.translateService.get('correction-type.manage-relation.action.notification.error'));
} }