[CST-12109] improvement code

This commit is contained in:
Mykhaylo Boychuk
2023-11-28 00:17:04 +01:00
parent 1c3776b2d3
commit 101cd0a553
9 changed files with 110 additions and 44 deletions

View File

@@ -27,6 +27,9 @@ import { hasValue } from '../../../../shared/empty.util';
import { DeleteByIDRequest, PostRequest } from '../../../data/request.models'; import { DeleteByIDRequest, PostRequest } from '../../../data/request.models';
import { HttpHeaders, HttpParams } from '@angular/common/http'; import { HttpHeaders, HttpParams } from '@angular/common/http';
import { HttpOptions } from '../../../dspace-rest/dspace-rest.service'; import { HttpOptions } from '../../../dspace-rest/dspace-rest.service';
import {
QualityAssuranceEventData
} from '../../../../suggestion-notifications/qa/project-entry-import-modal/project-entry-import-modal.component';
/** /**
* The service handling all Quality Assurance topic REST requests. * The service handling all Quality Assurance topic REST requests.
@@ -241,4 +244,9 @@ export class QualityAssuranceEventDataService extends IdentifiableDataService<Qu
}) })
); );
} }
public deleteQAEvent(qaEvent: QualityAssuranceEventData): Observable<RemoteData<NoContent>> {
return this.deleteData.delete(qaEvent.id);
}
} }

View File

@@ -2,10 +2,11 @@
<ng-container *ngFor="let source of (getQualityAssuranceSources$() | async)"> <ng-container *ngFor="let source of (getQualityAssuranceSources$() | async)">
<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">{{'item.qa-event-notification.check.notification-withdrawn' | translate : {num: source.totalEvents } }} </div> <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>
<button [routerLink]="['/admin/notifications/quality-assurance/' + source.id]" <button [routerLink]="['/admin/notifications/quality-assurance/' + source.id]"
class="btn btn-primary align-self-center">{{'item.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)
}}</button> : ('qa-event-notification-undo-reinstate.check.button' | translate) }}</button>
</div> </div>
</div> </div>
</ng-container> </ng-container>

View File

@@ -35,7 +35,6 @@ export class QaEventNotificationComponent {
* Note: sourceId is composed as: id: "sourceName:<target>" * Note: sourceId is composed as: id: "sourceName:<target>"
*/ */
getQualityAssuranceSources$(): Observable<QualityAssuranceSourceObject[]> { getQualityAssuranceSources$(): Observable<QualityAssuranceSourceObject[]> {
console.log('ciao');
const findListTopicOptions: FindListOptions = { const findListTopicOptions: FindListOptions = {
searchParams: [new RequestParam('target', this.item.uuid)] searchParams: [new RequestParam('target', this.item.uuid)]
}; };

View File

@@ -1,16 +1,22 @@
<div *ngIf="!(this.submitted$ | async); else waiting"> <div *ngIf="!(this.submitted$ | async); else waiting">
<div *ngIf="this.canWithdraw; else reinstateHeader" class="modal-header"> <div *ngIf="this.canWithdraw; else reinstateHeader" class="modal-header">
{{'item.qa.withdrawn.modal.header' | translate}} {{ 'item.qa.withdrawn.modal.header' | translate }}
<button type="button" class="close" (click)="onModalClose()" aria-label="Close"> <button type="button" class="close" (click)="onModalClose()" aria-label="Close">
<span aria-hidden="true">×</span> <span aria-hidden="true">×</span>
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="form-group"> <div class="form-group">
<label for="reason">{{'item.qa-withdrawn-reinstate.create.modal.form.summary.label' | translate }}:</label> <label for="reason">{{ this.canWithdraw ? ('qa-withdrawn.create.modal.form.summary.label' | translate)
<input type="text" id="reason" class="form-control" [(ngModel)]="reason" : ('qa-reinstate.create.modal.form.summary.label' | translate) }}</label>
(keyup.enter)="onModalSubmit()" <label for="reason">{{ this.canWithdraw ? ('qa-withdrawn.create.modal.form.summary2.label' | translate)
placeholder="{{'item.qa.withdrown-reinstate.modal.form.summary.placeholder' | translate }}"/> : ('qa-reinstate.create.modal.form.summary2.label' | translate) }}</label>
<textarea class="form-control" id="reason"
rows="6"
[(ngModel)]="reason"
placeholder="{{ this.canWithdraw ? ('qa-withdrown.modal.form.summary.placeholder' | translate)
: ('qa-reinstate.modal.form.summary.placeholder' | translate) }}"
name="message"></textarea>
</div> </div>
</div> </div>
<div class="modal-footer space-children-mr"> <div class="modal-footer space-children-mr">
@@ -24,7 +30,8 @@
type="submit" type="submit"
(click)="onModalSubmit()" (click)="onModalSubmit()"
title="{{'item.qa.withdrawn-reinstate.modal.button.confirm.tooltip' | translate}}"> title="{{'item.qa.withdrawn-reinstate.modal.button.confirm.tooltip' | translate}}">
<i class="fas fa-check fa-fw"></i> {{'item.qa.withdrown-reinstate.create.modal.button.confirm' | translate}} <i class="fas fa-check fa-fw"></i> {{ this.canWithdraw ? ('qa-withdrown.create.modal.button.confirm' | translate)
: ('qa-reinstate.create.modal.button.confirm' | translate) }}
</button> </button>
</div> </div>
</div> </div>
@@ -39,7 +46,7 @@
</ng-template> </ng-template>
<ng-template #reinstateHeader> <ng-template #reinstateHeader>
<div *ngIf="this.canReinstate" class="modal-header"> <div *ngIf="!this.canWithdraw" class="modal-header">
{{'item.qa.reinstate.modal.header' | translate}} {{'item.qa.reinstate.modal.header' | translate}}
<button type="button" class="close" (click)="onModalClose()" aria-label="Close"> <button type="button" class="close" (click)="onModalClose()" aria-label="Close">
<span aria-hidden="true">×</span> <span aria-hidden="true">×</span>

View File

@@ -14,7 +14,6 @@ export class ItemWithdrawnReinstateModalComponent implements ModalBeforeDismiss
reason: string; reason: string;
canWithdraw: boolean; canWithdraw: boolean;
canReinstate: boolean;
submitted$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false); submitted$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
@Output() createQAEvent: EventEmitter<string> = new EventEmitter<string>(); @Output() createQAEvent: EventEmitter<string> = new EventEmitter<string>();
@@ -40,12 +39,6 @@ export class ItemWithdrawnReinstateModalComponent implements ModalBeforeDismiss
public setWithdraw(state: boolean) { public setWithdraw(state: boolean) {
this.canWithdraw = state; this.canWithdraw = state;
this.canReinstate = !state;
}
public setReinstate(state: boolean) {
this.canReinstate = state;
this.canWithdraw = !state;
} }
} }

View File

@@ -9,8 +9,7 @@ import { Item } from '../../core/shared/item.model';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { OnClickMenuItemModel } from '../menu/menu-item/models/onclick.model'; import { OnClickMenuItemModel } from '../menu/menu-item/models/onclick.model';
import { import {
getFirstCompletedRemoteData, getFirstCompletedRemoteData, getRemoteDataPayload,
getRemoteDataPayload
} from '../../core/shared/operators'; } from '../../core/shared/operators';
import { map, switchMap } from 'rxjs/operators'; import { map, switchMap } from 'rxjs/operators';
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service'; import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
@@ -25,13 +24,10 @@ import { ResearcherProfileDataService } from '../../core/profile/researcher-prof
import { NotificationsService } from '../notifications/notifications.service'; import { NotificationsService } from '../notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { DsoWithdrawnReinstateModalService } from './dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service'; import { DsoWithdrawnReinstateModalService } from './dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service';
import { EPerson } from '../../core/eperson/models/eperson.model';
import { AuthService } from '../../core/auth/auth.service'; import { AuthService } from '../../core/auth/auth.service';
import {
QualityAssuranceSourceDataService
} from '../../core/suggestion-notifications/qa/source/quality-assurance-source-data.service';
import { FindListOptions } from '../../core/data/find-list-options.model'; 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 { CorrectionTypeDataService } from '../../core/submission/correctiontype-data.service';
/** /**
* Creates the menus for the dspace object pages * Creates the menus for the dspace object pages
@@ -52,7 +48,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
protected translate: TranslateService, protected translate: TranslateService,
protected dsoWithdrawnReinstateModalService: DsoWithdrawnReinstateModalService, protected dsoWithdrawnReinstateModalService: DsoWithdrawnReinstateModalService,
private auth: AuthService, private auth: AuthService,
private qualityAssuranceSourceDataService: QualityAssuranceSourceDataService private correctionTypeDataService: CorrectionTypeDataService
) { ) {
} }
@@ -142,9 +138,9 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
this.dsoVersioningModalService.getVersioningTooltipMessage(dso, 'item.page.version.hasDraft', 'item.page.version.create'), this.dsoVersioningModalService.getVersioningTooltipMessage(dso, 'item.page.version.hasDraft', 'item.page.version.create'),
this.authorizationService.isAuthorized(FeatureID.CanSynchronizeWithORCID, dso.self), this.authorizationService.isAuthorized(FeatureID.CanSynchronizeWithORCID, dso.self),
this.authorizationService.isAuthorized(FeatureID.CanClaimItem, dso.self), this.authorizationService.isAuthorized(FeatureID.CanClaimItem, dso.self),
this.qualityAssuranceSourceDataService.getSourcesByTarget(findListTopicOptions).pipe( this.correctionTypeDataService.findByItem(dso.uuid, false).pipe(
getFirstCompletedRemoteData(), getFirstCompletedRemoteData(),
getRemoteDataPayload()) getRemoteDataPayload())
]).pipe( ]).pipe(
map(([canCreateVersion, disableVersioning, versionTooltip, canSynchronizeWithOrcid, canClaimItem, correction]) => { map(([canCreateVersion, disableVersioning, versionTooltip, canSynchronizeWithOrcid, canClaimItem, correction]) => {
const isPerson = this.getDsoType(dso) === 'person'; const isPerson = this.getDsoType(dso) === 'person';
@@ -193,29 +189,29 @@ 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',
function: () => { function: () => {
this.dsoWithdrawnReinstateModalService.openCreateWithdrawnReinstateModal(dso, 'request-withdrawn', dso.isArchived && correction.totalElements === 0); this.dsoWithdrawnReinstateModalService.openCreateWithdrawnReinstateModal(dso, 'request-withdrawn', dso.isArchived);
} }
} as OnClickMenuItemModel, } as OnClickMenuItemModel,
icon: 'lock', icon: 'eye-slash',
index: 4 index: 4
}, },
{ {
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',
function: () => { function: () => {
this.dsoWithdrawnReinstateModalService.openCreateWithdrawnReinstateModal(dso, 'request-reinstate', dso.isWithdrawn && correction.totalElements === 0); this.dsoWithdrawnReinstateModalService.openCreateWithdrawnReinstateModal(dso, 'request-reinstate', dso.isArchived);
} }
} as OnClickMenuItemModel, } as OnClickMenuItemModel,
icon: 'unlock-keyhole', icon: 'eye',
index: 5 index: 5
} }
]; ];

View File

@@ -124,7 +124,7 @@
</div> </div>
</td> </td>
<td> <td>
<div class="btn-group button-width"> <div *ngIf="(isAdmin$ | async)" class="btn-group button-width">
<button *ngIf="showTopic.indexOf('/PROJECT') !== -1" <button *ngIf="showTopic.indexOf('/PROJECT') !== -1"
class="btn btn-outline-success btn-sm button-width" class="btn btn-outline-success btn-sm button-width"
ngbTooltip="{{'quality-assurance.event.action.import' | translate}}" ngbTooltip="{{'quality-assurance.event.action.import' | translate}}"
@@ -156,6 +156,15 @@
<i class="fas fa-trash-alt"></i> <i class="fas fa-trash-alt"></i>
</button> </button>
</div> </div>
<div *ngIf="!(isAdmin$ | async)" class="btn-group button-width">
<button class="btn btn-outline-danger btn-sm button-width"
ngbTooltip="{{'quality-assurance.event.action.undo' | translate}}"
container="body"
[disabled]="eventElement.isRunning"
(click)="openModal('UNDO', eventElement, undoModal)">
<i class="fas fa-trash-alt"></i>
</button>
</div>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@@ -226,3 +235,20 @@
</button> </button>
</div> </div>
</ng-template> </ng-template>
<ng-template #undoModal let-modal>
<div class="modal-header">
<h4 class="modal-title" id="undoModal">{{'quality-assurance.event.sure' | translate}}</h4>
</div>
<div class="modal-body">
<p>{{'quality-assurance.event.undo.description' | translate}}</p>
<button class="btn btn-outline-danger float-right" (click)="modal.close('do')">
<i class="fas fa-trash-alt"></i>
<span class="d-none d-sm-inline"> {{'quality-assurance.event.action.undo' | translate}}</span>
</button>
<button class="btn btn-outline-secondary" (click)="modal.close('cancel')">
<i class="fas fa-close"></i>
<span class="d-none d-sm-inline"> {{'quality-assurance.event.action.cancel' | translate}}</span>
</button>
</div>
</ng-template>

View File

@@ -30,6 +30,9 @@ import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
import { PaginationService } from '../../../core/pagination/pagination.service'; import { PaginationService } from '../../../core/pagination/pagination.service';
import { Item } from '../../../core/shared/item.model'; import { Item } from '../../../core/shared/item.model';
import { FindListOptions } from '../../../core/data/find-list-options.model'; import { FindListOptions } from '../../../core/data/find-list-options.model';
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
import { NoContent } from '../../../core/shared/NoContent.model';
/** /**
* Component to display the Quality Assurance event list. * Component to display the Quality Assurance event list.
@@ -85,6 +88,7 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
* @type {Observable<boolean>} * @type {Observable<boolean>}
*/ */
public isEventPageLoading: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false); public isEventPageLoading: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
/** /**
* The modal reference. * The modal reference.
* @type {any} * @type {any}
@@ -105,6 +109,8 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
*/ */
protected subs: Subscription[] = []; protected subs: Subscription[] = [];
isAdmin$: Observable<boolean>;
/** /**
* Initialize the component variables. * Initialize the component variables.
* @param {ActivatedRoute} activatedRoute * @param {ActivatedRoute} activatedRoute
@@ -120,7 +126,8 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private qualityAssuranceEventRestService: QualityAssuranceEventDataService, private qualityAssuranceEventRestService: QualityAssuranceEventDataService,
private paginationService: PaginationService, private paginationService: PaginationService,
private translateService: TranslateService private translateService: TranslateService,
private authorizationService: AuthorizationDataService,
) { ) {
} }
@@ -130,6 +137,7 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
ngOnInit(): void { ngOnInit(): void {
this.isEventPageLoading.next(true); this.isEventPageLoading.next(true);
this.isAdmin$ = this.authorizationService.isAuthorized(FeatureID.AdministratorOf);
this.activatedRoute.paramMap.pipe( this.activatedRoute.paramMap.pipe(
map((params) => params.get('topicId')), map((params) => params.get('topicId')),
take(1), take(1),
@@ -239,8 +247,14 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
*/ */
public executeAction(action: string, eventData: QualityAssuranceEventData): void { public executeAction(action: string, eventData: QualityAssuranceEventData): void {
eventData.isRunning = true; eventData.isRunning = true;
let operation;
if (action === 'UNDO') {
operation = this.delete(eventData);
} else {
operation = this.qualityAssuranceEventRestService.patchEvent(action, eventData.event, eventData.reason);
}
this.subs.push( this.subs.push(
this.qualityAssuranceEventRestService.patchEvent(action, eventData.event, eventData.reason).pipe( operation.pipe(
getFirstCompletedRemoteData(), getFirstCompletedRemoteData(),
switchMap((rd: RemoteData<QualityAssuranceEventObject>) => { switchMap((rd: RemoteData<QualityAssuranceEventObject>) => {
if (rd.hasSucceeded) { if (rd.hasSucceeded) {
@@ -427,4 +441,8 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
last() last()
); );
} }
delete(qaEvent: QualityAssuranceEventData): Observable<RemoteData<NoContent>> {
return this.qualityAssuranceEventRestService.deleteQAEvent(qaEvent);
}
} }

View File

@@ -2566,9 +2566,9 @@
"item.version.create.modal.header": "New version", "item.version.create.modal.header": "New version",
"item.qa.withdrawn.modal.header": "Send Withdrawn Item request", "item.qa.withdrawn.modal.header": "Request withdrawal",
"item.qa.reinstate.modal.header": "Send Reinstate Item request", "item.qa.reinstate.modal.header": "Request reinstate",
"item.qa.reinstate.create.modal.header": "New version", "item.qa.reinstate.create.modal.header": "New version",
@@ -2582,7 +2582,9 @@
"item.qa.withdrawn-reinstate.modal.button.confirm.tooltip": "Send request", "item.qa.withdrawn-reinstate.modal.button.confirm.tooltip": "Send request",
"item.qa.withdrown-reinstate.create.modal.button.confirm": "Send Request", "qa-withdrown.create.modal.button.confirm": "Withdrawn",
"qa-reinstate.create.modal.button.confirm": "Reinstate",
"item.version.create.modal.button.cancel": "Cancel", "item.version.create.modal.button.cancel": "Cancel",
@@ -2594,19 +2596,31 @@
"item.version.create.modal.form.summary.label": "Summary", "item.version.create.modal.form.summary.label": "Summary",
"item.qa-withdrawn-reinstate.create.modal.form.summary.label": "Reason", "qa-withdrawn.create.modal.form.summary.label": "You are requesting to withdrawn this item",
"qa-withdrawn.create.modal.form.summary2.label": "Please enter the reason for the withdrawal",
"qa-reinstate.create.modal.form.summary.label": "You are requesting to reinstate this item",
"qa-reinstate.create.modal.form.summary2.label": "Please enter the reason for the reinstatment",
"item.version.create.modal.form.summary.placeholder": "Insert the summary for the new version", "item.version.create.modal.form.summary.placeholder": "Insert the summary for the new version",
"item.qa.withdrown-reinstate.modal.form.summary.placeholder": "Indicates the reasons (optionaly)", "qa-withdrown.modal.form.summary.placeholder": "Enter the reason for the withdrawal",
"qa-reinstate.modal.form.summary.placeholder": "Enter the reason for the reinstate",
"item.version.create.modal.submitted.header": "Creating new version...", "item.version.create.modal.submitted.header": "Creating new version...",
"item.qa.withdrawn.modal.submitted.header": "Sending withdrawn request...", "item.qa.withdrawn.modal.submitted.header": "Sending withdrawn request...",
"item.qa-event-notification.check.notification-withdrawn": "You have requested to withdrawn this item.", "qa-event-notification.check.notification-withdrawn": "You have requested to withdrawn this item.",
"item.qa-event-notification-undo-withdrawn.check.button": "Undo request withdrawal", "qa-event-notification.check.notification-reinstate": "You have requested to reinstate this item.",
"qa-event-notification-undo-withdrawn.check.button": "Undo request withdrawal",
"qa-event-notification-undo-reinstate.check.button": "Undo request reinstatment",
"item.version.create.modal.submitted.text": "The new version is being created. This may take some time if the item has a lot of relationships.", "item.version.create.modal.submitted.text": "The new version is being created. This may take some time if the item has a lot of relationships.",
@@ -3170,6 +3184,8 @@
"quality-assurance.event.action.ignore": "Ignore suggestion", "quality-assurance.event.action.ignore": "Ignore suggestion",
"quality-assurance.event.action.undo": "DELETE",
"quality-assurance.event.action.reject": "Reject suggestion", "quality-assurance.event.action.reject": "Reject suggestion",
"quality-assurance.event.action.import": "Import project and accept suggestion", "quality-assurance.event.action.import": "Import project and accept suggestion",
@@ -3210,6 +3226,8 @@
"quality-assurance.event.ignore.description": "This operation can't be undone. Ignore this suggestion?", "quality-assurance.event.ignore.description": "This operation can't be undone. Ignore this suggestion?",
"quality-assurance.event.undo.description": "This operation can't be undone!",
"quality-assurance.event.reject.description": "This operation can't be undone. Reject this suggestion?", "quality-assurance.event.reject.description": "This operation can't be undone. Reject this suggestion?",
"quality-assurance.event.accept.description": "No DSpace project selected. A new project will be created based on the suggestion data.", "quality-assurance.event.accept.description": "No DSpace project selected. A new project will be created based on the suggestion data.",