mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-12109] "refresh" page refactor
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, SimpleChanges } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges } from '@angular/core';
|
||||
import { Item } from '../../../core/shared/item.model';
|
||||
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
|
||||
import { Observable } from 'rxjs';
|
||||
@@ -10,7 +10,6 @@ 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',
|
||||
@@ -37,16 +36,7 @@ export class QaEventNotificationComponent implements OnChanges {
|
||||
*/
|
||||
constructor(
|
||||
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.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
||||
import { QualityAssuranceSourceDataService } from '../../core/notifications/qa/source/quality-assurance-source-data.service';
|
||||
import { getFirstCompletedRemoteData, getPaginatedListPayload, getRemoteDataPayload } from '../../core/shared/operators';
|
||||
import { Observable, of, tap } from 'rxjs';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { QualityAssuranceSourceObject } from 'src/app/core/notifications/qa/models/quality-assurance-source.model';
|
||||
import { getNotificatioQualityAssuranceRoute } from '../../admin/admin-routing-paths';
|
||||
|
||||
@@ -30,11 +30,6 @@ export class MyDspaceQaEventsNotificationsComponent implements OnInit {
|
||||
this.sources$ = this.qualityAssuranceSourceDataService.getSources()
|
||||
.pipe(
|
||||
getFirstCompletedRemoteData(),
|
||||
tap((rd) => {
|
||||
if (rd.hasFailed) {
|
||||
throw new Error('Can\'t retrieve Quality Assurance sources');
|
||||
}
|
||||
}),
|
||||
getRemoteDataPayload(),
|
||||
getPaginatedListPayload(),
|
||||
);
|
||||
|
@@ -50,6 +50,15 @@ export class DsoWithdrawnReinstateModalService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a quality assurance request.
|
||||
*
|
||||
* @param target - The target - the item's UUID.
|
||||
* @param correctionType - The type of correction.
|
||||
* @param reason - The reason for the request.
|
||||
* Reloads the current page in order to update the withdrawn/reinstate button.
|
||||
* and desplay a notification box.
|
||||
*/
|
||||
sendQARequest(target: string, correctionType: string, reason: string): void {
|
||||
this.qaEventDataService.postData(target, correctionType, '', reason)
|
||||
.pipe (
|
||||
@@ -62,11 +71,24 @@ 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
|
||||
this.reloadPage(true);
|
||||
} else {
|
||||
this.notificationsService.error(this.translateService.get('correction-type.manage-relation.action.notification.error'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the current page or navigates to a specified URL.
|
||||
* @param self - A boolean indicating whether to reload the current page (true) or navigate to a specified URL (false).
|
||||
* @param urlToNavigateTo - The URL to navigate to if `self` is false.
|
||||
* skipLocationChange:true means dont update the url to / when navigating
|
||||
*/
|
||||
reloadPage(self: boolean, urlToNavigateTo?: string) {
|
||||
const url = self ? this.router.url : urlToNavigateTo;
|
||||
this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => {
|
||||
this.router.navigate([`/${url}`]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user