[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 { HttpHeaders, HttpParams } from '@angular/common/http';
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.
@@ -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)">
<div class="alert alert-info d-flex flex-row" *ngIf="source.totalEvents > 0">
<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]"
class="btn btn-primary align-self-center">{{'item.qa-event-notification-undo-withdrawn.check.button' | translate
}}</button>
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>
</div>
</div>
</ng-container>

View File

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

View File

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

View File

@@ -14,7 +14,6 @@ export class ItemWithdrawnReinstateModalComponent implements ModalBeforeDismiss
reason: string;
canWithdraw: boolean;
canReinstate: boolean;
submitted$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
@Output() createQAEvent: EventEmitter<string> = new EventEmitter<string>();
@@ -40,12 +39,6 @@ export class ItemWithdrawnReinstateModalComponent implements ModalBeforeDismiss
public setWithdraw(state: boolean) {
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 { OnClickMenuItemModel } from '../menu/menu-item/models/onclick.model';
import {
getFirstCompletedRemoteData,
getRemoteDataPayload
getFirstCompletedRemoteData, getRemoteDataPayload,
} from '../../core/shared/operators';
import { map, switchMap } from 'rxjs/operators';
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 { TranslateService } from '@ngx-translate/core';
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 {
QualityAssuranceSourceDataService
} from '../../core/suggestion-notifications/qa/source/quality-assurance-source-data.service';
import { FindListOptions } from '../../core/data/find-list-options.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
@@ -52,7 +48,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
protected translate: TranslateService,
protected dsoWithdrawnReinstateModalService: DsoWithdrawnReinstateModalService,
private auth: AuthService,
private qualityAssuranceSourceDataService: QualityAssuranceSourceDataService
private correctionTypeDataService: CorrectionTypeDataService
) {
}
@@ -142,7 +138,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
this.dsoVersioningModalService.getVersioningTooltipMessage(dso, 'item.page.version.hasDraft', 'item.page.version.create'),
this.authorizationService.isAuthorized(FeatureID.CanSynchronizeWithORCID, dso.self),
this.authorizationService.isAuthorized(FeatureID.CanClaimItem, dso.self),
this.qualityAssuranceSourceDataService.getSourcesByTarget(findListTopicOptions).pipe(
this.correctionTypeDataService.findByItem(dso.uuid, false).pipe(
getFirstCompletedRemoteData(),
getRemoteDataPayload())
]).pipe(
@@ -193,29 +189,29 @@ 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',
function: () => {
this.dsoWithdrawnReinstateModalService.openCreateWithdrawnReinstateModal(dso, 'request-withdrawn', dso.isArchived && correction.totalElements === 0);
this.dsoWithdrawnReinstateModalService.openCreateWithdrawnReinstateModal(dso, 'request-withdrawn', dso.isArchived);
}
} as OnClickMenuItemModel,
icon: 'lock',
icon: 'eye-slash',
index: 4
},
{
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',
function: () => {
this.dsoWithdrawnReinstateModalService.openCreateWithdrawnReinstateModal(dso, 'request-reinstate', dso.isWithdrawn && correction.totalElements === 0);
this.dsoWithdrawnReinstateModalService.openCreateWithdrawnReinstateModal(dso, 'request-reinstate', dso.isArchived);
}
} as OnClickMenuItemModel,
icon: 'unlock-keyhole',
icon: 'eye',
index: 5
}
];

View File

@@ -124,7 +124,7 @@
</div>
</td>
<td>
<div class="btn-group button-width">
<div *ngIf="(isAdmin$ | async)" class="btn-group button-width">
<button *ngIf="showTopic.indexOf('/PROJECT') !== -1"
class="btn btn-outline-success btn-sm button-width"
ngbTooltip="{{'quality-assurance.event.action.import' | translate}}"
@@ -156,6 +156,15 @@
<i class="fas fa-trash-alt"></i>
</button>
</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>
</tr>
</tbody>
@@ -226,3 +235,20 @@
</button>
</div>
</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 { Item } from '../../../core/shared/item.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.
@@ -85,6 +88,7 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
* @type {Observable<boolean>}
*/
public isEventPageLoading: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
/**
* The modal reference.
* @type {any}
@@ -105,6 +109,8 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
*/
protected subs: Subscription[] = [];
isAdmin$: Observable<boolean>;
/**
* Initialize the component variables.
* @param {ActivatedRoute} activatedRoute
@@ -120,7 +126,8 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
private notificationsService: NotificationsService,
private qualityAssuranceEventRestService: QualityAssuranceEventDataService,
private paginationService: PaginationService,
private translateService: TranslateService
private translateService: TranslateService,
private authorizationService: AuthorizationDataService,
) {
}
@@ -130,6 +137,7 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.isEventPageLoading.next(true);
this.isAdmin$ = this.authorizationService.isAuthorized(FeatureID.AdministratorOf);
this.activatedRoute.paramMap.pipe(
map((params) => params.get('topicId')),
take(1),
@@ -239,8 +247,14 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
*/
public executeAction(action: string, eventData: QualityAssuranceEventData): void {
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.qualityAssuranceEventRestService.patchEvent(action, eventData.event, eventData.reason).pipe(
operation.pipe(
getFirstCompletedRemoteData(),
switchMap((rd: RemoteData<QualityAssuranceEventObject>) => {
if (rd.hasSucceeded) {
@@ -427,4 +441,8 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
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.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",
@@ -2582,7 +2582,9 @@
"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",
@@ -2594,19 +2596,31 @@
"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.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.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.",
@@ -3170,6 +3184,8 @@
"quality-assurance.event.action.ignore": "Ignore suggestion",
"quality-assurance.event.action.undo": "DELETE",
"quality-assurance.event.action.reject": "Reject 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.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.accept.description": "No DSpace project selected. A new project will be created based on the suggestion data.",