[CST-5339] Fix queue refresh after preferences are changed

This commit is contained in:
Giuseppe Digilio
2022-06-15 18:54:30 +02:00
parent d1c012407a
commit 793169dd31
4 changed files with 103 additions and 57 deletions

View File

@@ -76,17 +76,23 @@ export class OrcidQueueService {
} }
/** /**
* @param itemId It represent a Id of owner * @param itemId It represent an Id of owner
* @param paginationOptions * @param paginationOptions The pagination options object
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* no valid cached version. Defaults to true
* @param reRequestOnStale Whether or not the request should automatically be re-
* requested after the response becomes stale
* @returns { OrcidQueue } * @returns { OrcidQueue }
*/ */
searchByOwnerId(itemId: string, paginationOptions: PaginationComponentOptions): Observable<RemoteData<PaginatedList<OrcidQueue>>> { searchByOwnerId(itemId: string, paginationOptions: PaginationComponentOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true): Observable<RemoteData<PaginatedList<OrcidQueue>>> {
return this.dataService.searchBy('findByOwner', { return this.dataService.searchBy('findByOwner', {
searchParams: [new RequestParam('ownerId', itemId)], searchParams: [new RequestParam('ownerId', itemId)],
elementsPerPage: paginationOptions.pageSize, elementsPerPage: paginationOptions.pageSize,
currentPage: paginationOptions.currentPage currentPage: paginationOptions.currentPage
},false, },
true); useCachedVersionIfAvailable,
reRequestOnStale
);
} }
/** /**

View File

@@ -109,6 +109,7 @@ export class OrcidPageComponent implements OnInit {
* Retrieve the updated profile item * Retrieve the updated profile item
*/ */
updateItem(): void { updateItem(): void {
this.clearRouteParams();
this.itemService.findById(this.itemId, false).pipe( this.itemService.findById(this.itemId, false).pipe(
getFirstCompletedRemoteData() getFirstCompletedRemoteData()
).subscribe((itemRD: RemoteData<Item>) => { ).subscribe((itemRD: RemoteData<Item>) => {
@@ -135,11 +136,18 @@ export class OrcidPageComponent implements OnInit {
} else { } else {
this.item.next(person); this.item.next(person);
this.connectionStatus.next(false); this.connectionStatus.next(false);
this.clearRouteParams();
} }
// update route removing the code from query params
const redirectUrl = this.router.url.split('?')[0];
this.router.navigate([redirectUrl]);
}); });
} }
/**
* Update route removing the code from query params
* @private
*/
private clearRouteParams(): void {
// update route removing the code from query params
const redirectUrl = this.router.url.split('?')[0];
this.router.navigate([redirectUrl]);
}
} }

View File

@@ -23,7 +23,7 @@
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let entry of (getList() | async)?.payload?.page" data-test="orcidQueueElementRow"> <tr *ngFor="let entry of (getList() | async)?.payload?.page" data-test="orcidQueueElementRow">
<td class="text-center align-middle"> <td style="width: 15%" class="text-center align-middle">
<i [ngClass]="getIconClass(entry)" [ngbTooltip]="getIconTooltip(entry) | translate" <i [ngClass]="getIconClass(entry)" [ngbTooltip]="getIconTooltip(entry) | translate"
class="fa-2x" aria-hidden="true"></i> class="fa-2x" aria-hidden="true"></i>
</td> </td>
@@ -32,11 +32,7 @@
</td> </td>
<td style="width: 20%" class="text-center"> <td style="width: 20%" class="text-center">
<div class="btn-group edit-field"> <div class="btn-group edit-field">
<!--<button [ngbTooltip]="getOperationTooltip(entry) | translate" container="body" <button [ngbTooltip]="getOperationTooltip(entry) | translate" container="body"
class="btn btn-outline-success my-1 col-md">
<i [ngClass]="getOperationClass(entry)"></i>
</button>-->
<button [ngbTooltip]="'person.page.orcid.sync-queue.send' | translate" container="body"
class="btn btn-outline-success my-1 col-md" (click)="send(entry)"> class="btn btn-outline-success my-1 col-md" (click)="send(entry)">
<i [ngClass]="getOperationClass(entry)"></i> <i [ngClass]="getOperationClass(entry)"></i>
</button> </button>

View File

@@ -1,7 +1,9 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core'; import { Component, Input, OnDestroy, OnInit, SimpleChanges } from '@angular/core';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { BehaviorSubject, combineLatest, Observable, Subscription } from 'rxjs'; import { BehaviorSubject, combineLatest, Observable, Subscription } from 'rxjs';
import { switchMap, tap } from 'rxjs/operators'; import { debounceTime, distinctUntilChanged, switchMap, tap } from 'rxjs/operators';
import { PaginatedList } from '../../../core/data/paginated-list.model'; import { PaginatedList } from '../../../core/data/paginated-list.model';
import { RemoteData } from '../../../core/data/remote-data'; import { RemoteData } from '../../../core/data/remote-data';
import { OrcidHistory } from '../../../core/orcid/model/orcid-history.model'; import { OrcidHistory } from '../../../core/orcid/model/orcid-history.model';
@@ -9,7 +11,7 @@ import { OrcidQueue } from '../../../core/orcid/model/orcid-queue.model';
import { OrcidHistoryDataService } from '../../../core/orcid/orcid-history-data.service'; import { OrcidHistoryDataService } from '../../../core/orcid/orcid-history-data.service';
import { OrcidQueueService } from '../../../core/orcid/orcid-queue.service'; import { OrcidQueueService } from '../../../core/orcid/orcid-queue.service';
import { PaginationService } from '../../../core/pagination/pagination.service'; import { PaginationService } from '../../../core/pagination/pagination.service';
import { getFinishedRemoteData, getFirstCompletedRemoteData } from '../../../core/shared/operators'; import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
import { hasValue } from '../../../shared/empty.util'; import { hasValue } from '../../../shared/empty.util';
import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
@@ -57,22 +59,35 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
* @type {Array} * @type {Array}
*/ */
private subs: Subscription[] = []; private subs: Subscription[] = [];
constructor(private orcidQueueService: OrcidQueueService, constructor(private orcidQueueService: OrcidQueueService,
protected translateService: TranslateService, protected translateService: TranslateService,
private paginationService: PaginationService, private paginationService: PaginationService,
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private orcidHistoryService: OrcidHistoryDataService, private orcidHistoryService: OrcidHistoryDataService,
) { } ) {
}
ngOnInit(): void { ngOnInit(): void {
this.updateList(); this.updateList();
} }
ngOnChanges(changes: SimpleChanges): void {
if (!changes.item.isFirstChange() && changes.item.currentValue !== changes.item.previousValue) {
this.updateList();
}
}
/**
* Retrieve queue list
*/
updateList() { updateList() {
this.subs.push( this.subs.push(
this.paginationService.getCurrentPagination(this.paginationOptions.id, this.paginationOptions).pipe( this.paginationService.getCurrentPagination(this.paginationOptions.id, this.paginationOptions).pipe(
debounceTime(100),
distinctUntilChanged(),
tap(() => this.processing$.next(true)), tap(() => this.processing$.next(true)),
switchMap((config: PaginationComponentOptions) => this.orcidQueueService.searchByOwnerId(this.item.id, config)), switchMap((config: PaginationComponentOptions) => this.orcidQueueService.searchByOwnerId(this.item.id, config, false)),
getFirstCompletedRemoteData() getFirstCompletedRemoteData()
).subscribe((result: RemoteData<PaginatedList<OrcidQueue>>) => { ).subscribe((result: RemoteData<PaginatedList<OrcidQueue>>) => {
this.processing$.next(false); this.processing$.next(false);
@@ -82,7 +97,6 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
); );
} }
/** /**
* Return the list of orcid queue records * Return the list of orcid queue records
*/ */
@@ -90,6 +104,11 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
return this.list$.asObservable(); return this.list$.asObservable();
} }
/**
* Return the icon class for the queue object type
*
* @param orcidQueue The OrcidQueue object
*/
getIconClass(orcidQueue: OrcidQueue): string { getIconClass(orcidQueue: OrcidQueue): string {
if (!orcidQueue.recordType) { if (!orcidQueue.recordType) {
return 'fa fa-user'; return 'fa fa-user';
@@ -113,6 +132,11 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
} }
} }
/**
* Return the icon tooltip message for the queue object type
*
* @param orcidQueue The OrcidQueue object
*/
getIconTooltip(orcidQueue: OrcidQueue): string { getIconTooltip(orcidQueue: OrcidQueue): string {
if (!orcidQueue.recordType) { if (!orcidQueue.recordType) {
return ''; return '';
@@ -121,24 +145,11 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
return 'person.page.orcid.sync-queue.tooltip.' + orcidQueue.recordType.toLowerCase(); return 'person.page.orcid.sync-queue.tooltip.' + orcidQueue.recordType.toLowerCase();
} }
getOperationBadgeClass(orcidQueue: OrcidQueue): string { /**
* Return the icon tooltip message for the queue object operation
if (!orcidQueue.operation) { *
return ''; * @param orcidQueue The OrcidQueue object
} */
switch (orcidQueue.operation.toLowerCase()) {
case 'insert':
return 'badge badge-pill badge-success';
case 'update':
return 'badge badge-pill badge-primary';
case 'delete':
return 'badge badge-pill badge-danger';
default:
return '';
}
}
getOperationTooltip(orcidQueue: OrcidQueue): string { getOperationTooltip(orcidQueue: OrcidQueue): string {
if (!orcidQueue.operation) { if (!orcidQueue.operation) {
return ''; return '';
@@ -147,6 +158,11 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
return 'person.page.orcid.sync-queue.tooltip.' + orcidQueue.operation.toLowerCase(); return 'person.page.orcid.sync-queue.tooltip.' + orcidQueue.operation.toLowerCase();
} }
/**
* Return the icon class for the queue object operation
*
* @param orcidQueue The OrcidQueue object
*/
getOperationClass(orcidQueue: OrcidQueue): string { getOperationClass(orcidQueue: OrcidQueue): string {
if (!orcidQueue.operation) { if (!orcidQueue.operation) {
@@ -165,10 +181,15 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
} }
} }
/**
* Discard a queue entry from the synchronization
*
* @param orcidQueue The OrcidQueue object to discard
*/
discardEntry(orcidQueue: OrcidQueue) { discardEntry(orcidQueue: OrcidQueue) {
this.processing$.next(true); this.processing$.next(true);
this.subs.push(this.orcidQueueService.deleteById(orcidQueue.id).pipe( this.subs.push(this.orcidQueueService.deleteById(orcidQueue.id).pipe(
getFinishedRemoteData() getFirstCompletedRemoteData()
).subscribe((remoteData) => { ).subscribe((remoteData) => {
this.processing$.next(false); this.processing$.next(false);
if (remoteData.isSuccess) { if (remoteData.isSuccess) {
@@ -180,10 +201,15 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
})); }));
} }
send( orcidQueue: OrcidQueue ) { /**
* Send a queue entry to orcid for the synchronization
*
* @param orcidQueue The OrcidQueue object to synchronize
*/
send(orcidQueue: OrcidQueue) {
this.processing$.next(true); this.processing$.next(true);
this.subs.push(this.orcidHistoryService.sendToORCID(orcidQueue).pipe( this.subs.push(this.orcidHistoryService.sendToORCID(orcidQueue).pipe(
getFinishedRemoteData() getFirstCompletedRemoteData()
).subscribe((remoteData) => { ).subscribe((remoteData) => {
this.processing$.next(false); this.processing$.next(false);
if (remoteData.isSuccess) { if (remoteData.isSuccess) {
@@ -196,7 +222,22 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
})); }));
} }
handleOrcidHistoryRecordCreation(orcidHistory: OrcidHistory) {
/**
* Return the error message for Unauthorized response
* @private
*/
private getUnauthorizedErrorContent(): Observable<string> {
return this.orcidQueueService.getOrcidAuthorizeUrl(this.item.id).pipe(
switchMap((authorizeUrl) => this.translateService.get('person.page.orcid.sync-queue.send.unauthorized-error.content', { orcid: authorizeUrl }))
);
}
/**
* Manage notification by response
* @private
*/
private handleOrcidHistoryRecordCreation(orcidHistory: OrcidHistory) {
switch (orcidHistory.status) { switch (orcidHistory.status) {
case 200: case 200:
case 201: case 201:
@@ -212,7 +253,7 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
this.translateService.get('person.page.orcid.sync-queue.send.unauthorized-error.title'), this.translateService.get('person.page.orcid.sync-queue.send.unauthorized-error.title'),
this.getUnauthorizedErrorContent()], this.getUnauthorizedErrorContent()],
).subscribe(([title, content]) => { ).subscribe(([title, content]) => {
this.notificationsService.error(title, content, { timeOut: -1}, true); this.notificationsService.error(title, content, { timeOut: -1 }, true);
}); });
break; break;
case 404: case 404:
@@ -226,7 +267,11 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
} }
} }
handleValidationErrors(remoteData: RemoteData<OrcidHistory>) { /**
* Manage validation errors
* @private
*/
private handleValidationErrors(remoteData: RemoteData<OrcidHistory>) {
const translations = [this.translateService.get('person.page.orcid.sync-queue.send.validation-error')]; const translations = [this.translateService.get('person.page.orcid.sync-queue.send.validation-error')];
const errorMessage = remoteData.errorMessage; const errorMessage = remoteData.errorMessage;
if (errorMessage && errorMessage.indexOf('Error codes:') > 0) { if (errorMessage && errorMessage.indexOf('Error codes:') > 0) {
@@ -240,11 +285,6 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
}); });
} }
private getUnauthorizedErrorContent(): Observable<string> {
return this.orcidQueueService.getOrcidAuthorizeUrl(this.item.id).pipe(
switchMap((authorizeUrl) => this.translateService.get('person.page.orcid.sync-queue.send.unauthorized-error.content', { orcid : authorizeUrl}))
);
}
/** /**
* Unsubscribe from all subscriptions * Unsubscribe from all subscriptions
@@ -255,8 +295,4 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
.forEach((subscription) => subscription.unsubscribe()); .forEach((subscription) => subscription.unsubscribe());
} }
isProfileRecord(orcidQueue: OrcidQueue): boolean {
return orcidQueue.recordType !== 'Publication' && orcidQueue.recordType !== 'Project';
}
} }