[CST-12109] improve code

This commit is contained in:
Mykhaylo Boychuk
2023-11-03 12:18:19 +01:00
parent 6dc3528ae8
commit ef1bd9fa3d
8 changed files with 41 additions and 92 deletions

View File

@@ -28,6 +28,8 @@ export interface OpenaireQualityAssuranceEventMessageObject {
*/
type: string;
reason: string;
/**
* The value suggested by Notifications
*/

View File

@@ -7,8 +7,8 @@
</div>
<div class="modal-body">
<div class="form-group">
<label for="summary">{{'item.qa-withdrawn-reinstate.create.modal.form.summary.label' | translate }}:</label>
<input type="text" id="summary" class="form-control" [(ngModel)]="reason"
<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 }}"/>
</div>

View File

@@ -21,8 +21,7 @@ import { getDSORoute } from '../../app-routing-paths';
import { ResearcherProfileDataService } from '../../core/profile/researcher-profile-data.service';
import { NotificationsService } from '../notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
import { DsoWithdrawnModalService } from './dso-withdrawn-service/dso-withdrawn-modal.service';
import { DsoReinstateModalService } from './dso-reinstate-service/dso-reinstate-modal.service';
import { DsoWithdrawnReinstateModalService } from './dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service';
/**
* Creates the menus for the dspace object pages
@@ -41,8 +40,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
protected researcherProfileService: ResearcherProfileDataService,
protected notificationsService: NotificationsService,
protected translate: TranslateService,
protected dsoWithdrawnModalService: DsoWithdrawnModalService,
protected dsoReinstateModalService: DsoReinstateModalService
protected dsoWithdrawnReinstateModalService: DsoWithdrawnReinstateModalService
) {
}
@@ -129,8 +127,8 @@ 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.authorizationService.isAuthorized(FeatureID.WithdrawItem, dso.self),
this.authorizationService.isAuthorized(FeatureID.ReinstateItem, dso.self),
this.authorizationService.isAuthorized(FeatureID.WithdrawItem, dso.self,),
this.authorizationService.isAuthorized(FeatureID.ReinstateItem, dso.self)
]).pipe(
map(([canCreateVersion, disableVersioning, versionTooltip, canSynchronizeWithOrcid, canClaimItem, canWithdrawItem, canReinstateItem]) => {
const isPerson = this.getDsoType(dso) === 'person';
@@ -184,7 +182,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
type: MenuItemType.ONCLICK,
text:'item.page.withdrawn',
function: () => {
this.dsoWithdrawnModalService.openCreateWithdrawnModal(dso, canWithdrawItem);
this.dsoWithdrawnReinstateModalService.openCreateWithdrawnReinstateModal(dso, 'request-withdrawn', canWithdrawItem);
}
} as OnClickMenuItemModel,
icon: 'lock',
@@ -198,7 +196,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
type: MenuItemType.ONCLICK,
text:'item.page.reinstate',
function: () => {
this.dsoReinstateModalService.openCreateReinstateModal(dso, canReinstateItem);
this.dsoWithdrawnReinstateModalService.openCreateWithdrawnReinstateModal(dso, 'request-reinstate', canWithdrawItem);
}
} as OnClickMenuItemModel,
icon: 'unlock-keyhole',

View File

@@ -1,69 +0,0 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ItemDataService } from '../../../core/data/item-data.service';
import { NotificationsService } from '../../notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
import {
QualityAssuranceEventDataService
} from '../../../core/suggestion-notifications/qa/events/quality-assurance-event-data.service';
import { ItemWithdrawnReinstateModalComponent } from '../../correction-suggestion/withdrawn-reinstate-modal.component';
import { take } from 'rxjs/operators';
import { RemoteData } from '../../../core/data/remote-data';
import {
QualityAssuranceEventObject
} from '../../../core/suggestion-notifications/qa/models/quality-assurance-event.model';
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
@Injectable({
providedIn: 'root'
})
export class DsoReinstateModalService {
constructor(
protected router: Router,
protected modalService: NgbModal,
protected itemService: ItemDataService,
private notificationsService: NotificationsService,
private translateService: TranslateService,
protected qaEventDataService: QualityAssuranceEventDataService
) {}
/**
* Open the reinstat modal for the provided dso
*/
openCreateReinstateModal(dso, state: boolean): void {
const target = dso.id;
// Open modal
const activeModal = this.modalService.open(ItemWithdrawnReinstateModalComponent);
(activeModal.componentInstance as ItemWithdrawnReinstateModalComponent).setReinstate(!state);
(activeModal.componentInstance as ItemWithdrawnReinstateModalComponent).createQAEvent
.pipe(
take(1)
).subscribe(
(reason) => {
this.sendQARequest(target, reason);
activeModal.close();
}
);
}
sendQARequest(target: string, reason: string): void {
this.qaEventDataService.postData(target, 'request-reinstate','', reason)
.pipe (
getFirstCompletedRemoteData()
)
.subscribe((res: RemoteData<QualityAssuranceEventObject>) => {
if (res.hasSucceeded) {
const message = 'reinstate';
this.notificationsService.success(this.translateService.get(message));
} else {
this.notificationsService.error(this.translateService.get('correction-type.manage-relation.action.notification.error'));
}
});
}
}

View File

@@ -14,17 +14,19 @@ import { TranslateService } from '@ngx-translate/core';
import { NotificationsService } from '../../notifications/notifications.service';
import { take } from 'rxjs/operators';
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
@Injectable({
providedIn: 'root'
})
export class DsoWithdrawnModalService {
export class DsoWithdrawnReinstateModalService {
constructor(
protected router: Router,
protected modalService: NgbModal,
protected itemService: ItemDataService,
private notificationsService: NotificationsService,
protected authorizationService: AuthorizationDataService,
private translateService: TranslateService,
protected qaEventDataService: QualityAssuranceEventDataService
) {}
@@ -32,7 +34,7 @@ export class DsoWithdrawnModalService {
/**
* Open the create withdrawn modal for the provided dso
*/
openCreateWithdrawnModal(dso, state: boolean): void {
openCreateWithdrawnReinstateModal(dso, correctionType: string, state: boolean): void {
const target = dso.id;
// Open modal
const activeModal = this.modalService.open(ItemWithdrawnReinstateModalComponent);
@@ -42,21 +44,24 @@ export class DsoWithdrawnModalService {
take(1)
).subscribe(
(reasone) => {
this.sendQARequest(target, reasone);
this.sendQARequest(target, correctionType, reasone);
activeModal.close();
}
);
}
sendQARequest(target: string, reason: string): void {
this.qaEventDataService.postData(target, 'request-withdrawn', '', reason)
sendQARequest(target: string, correctionType: string, reason: string): void {
this.qaEventDataService.postData(target, correctionType, '', reason)
.pipe (
getFirstCompletedRemoteData()
)
.subscribe((res: RemoteData<QualityAssuranceEventObject>) => {
if (res.hasSucceeded) {
const message = 'withdrawn';
const withdrawnMessage = 'Withdrawn request sent.';
const reinstateMessage = 'Reinstate request sent.';
const message = (correctionType === 'request-withdrawn') ? withdrawnMessage : reinstateMessage;
this.notificationsService.success(this.translateService.get(message));
this.authorizationService.invalidateAuthorizationsRequestCache();
} else {
this.notificationsService.error(this.translateService.get('correction-type.manage-relation.action.notification.error'));
}

View File

@@ -37,12 +37,12 @@
<tr>
<th scope="col" class="trust-col">{{'quality-assurance.event.table.trust' | translate}}</th>
<th scope="col" class="title-col">{{'quality-assurance.event.table.publication' | translate}}</th>
<th *ngIf="hasDetailColumn() && showTopic.indexOf('/PROJECT') == -1" scope="col" class="content-col">
{{'quality-assurance.event.table.details' | translate}}
</th>
<th *ngIf="hasDetailColumn() && showTopic.indexOf('/PROJECT') !== -1" scope="col" class="content-col">
{{'quality-assurance.event.table.project-details' | translate}}
</th>
<th *ngIf="hasDetailColumn() && (showTopic.indexOf('/REINSTATE') !== -1 || showTopic.indexOf('/WITHDRAWN') !== -1)" scope="col" class="content-col">
{{'quality-assurance.event.table.reasons' | translate}}
</th>
<th scope="col" class="button-col">{{'quality-assurance.event.table.actions' | translate}}</th>
</tr>
</thead>
@@ -79,6 +79,15 @@
{{ (showMore ? 'quality-assurance.event.table.less': 'quality-assurance.event.table.more') | translate }}
</button>
</td>
<td *ngIf="showTopic.indexOf('/REINSTATE') !== -1 || showTopic.indexOf('/WITHDRAWN') !== -1">
<p>
<span *ngIf="eventElement.event.message">
<span class="badge badge-info">{{eventElement.event.message.reason}}</span><br>
</span>
</p>
</td>
<td *ngIf="showTopic.indexOf('/PROJECT') !== -1">
<p>
{{'quality-assurance.event.table.suggestedProject' | translate}}

View File

@@ -151,9 +151,11 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy {
*/
public hasDetailColumn(): boolean {
return (this.showTopic.indexOf('/PROJECT') !== -1 ||
this.showTopic.indexOf('/PID') !== -1 ||
this.showTopic.indexOf('/SUBJECT') !== -1 ||
this.showTopic.indexOf('/ABSTRACT') !== -1
this.showTopic.indexOf('/PID') !== -1 ||
this.showTopic.indexOf('/SUBJECT') !== -1 ||
this.showTopic.indexOf('/WITHDRAWN') !== -1 ||
this.showTopic.indexOf('/REINSTATE') !== -1 ||
this.showTopic.indexOf('/ABSTRACT') !== -1
);
}

View File

@@ -2594,7 +2594,7 @@
"item.version.create.modal.form.summary.label": "Summary",
"item.qa-withdrawn-reinstate.create.modal.form.summary.label": "Summary",
"item.qa-withdrawn-reinstate.create.modal.form.summary.label": "Reason",
"item.version.create.modal.form.summary.placeholder": "Insert the summary for the new version",
@@ -3158,6 +3158,8 @@
"quality-assurance.event.table.project-details": "Project details",
"quality-assurance.event.table.reasons": "Reasons",
"quality-assurance.event.table.actions": "Actions",
"quality-assurance.event.action.accept": "Accept suggestion",