mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CTS-12109] refactoring
This commit is contained in:
@@ -25,7 +25,8 @@ import { SearchData, SearchDataImpl } from '../../../data/base/search-data';
|
||||
import { DefaultChangeAnalyzer } from '../../../data/default-change-analyzer.service';
|
||||
import { hasValue } from '../../../../shared/empty.util';
|
||||
import { DeleteByIDRequest, PostRequest } from '../../../data/request.models';
|
||||
import { HttpHeaders } from '@angular/common/http';
|
||||
import { HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { HttpOptions } from '../../../dspace-rest/dspace-rest.service';
|
||||
|
||||
/**
|
||||
* The service handling all Quality Assurance topic REST requests.
|
||||
@@ -207,13 +208,21 @@ export class QualityAssuranceEventDataService extends IdentifiableDataService<Qu
|
||||
* @param data the data to post
|
||||
* @returns the RestResponse as an Observable
|
||||
*/
|
||||
postData(data: string): Observable<RemoteData<QualityAssuranceEventObject>> {
|
||||
postData(target: string, correctionType: string, related: string, reason: string): Observable<RemoteData<QualityAssuranceEventObject>> {
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
const href$ = this.getBrowseEndpoint();
|
||||
|
||||
return href$.pipe(
|
||||
switchMap((href: string) => {
|
||||
const request = new PostRequest(requestId, href, data, { headers: new HttpHeaders().set('Content-Type', 'text/uri-list') });
|
||||
const options: HttpOptions = Object.create({});
|
||||
let headers = new HttpHeaders();
|
||||
headers = headers.append('Content-Type', 'application/json');
|
||||
options.headers = headers;
|
||||
let params = new HttpParams();
|
||||
params = params.append('target', target)
|
||||
.append('correctionType', correctionType);
|
||||
options.params = params;
|
||||
const request = new PostRequest(requestId, href, {'reason': reason} , options);
|
||||
if (hasValue(this.responseMsToLive)) {
|
||||
request.responseMsToLive = this.responseMsToLive;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<div *ngIf="!(this.submitted$ | async); else waiting">
|
||||
<div *ngIf="(this.canWithdraw$ | async); else reinstateHeader" class="modal-header">
|
||||
<div *ngIf="this.canWithdraw; else reinstateHeader" class="modal-header">
|
||||
{{'item.qa.withdrawn.modal.header' | translate}}
|
||||
<button type="button" class="close" (click)="onModalClose()" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
@@ -8,7 +8,7 @@
|
||||
<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)]="summary"
|
||||
<input type="text" id="summary" class="form-control" [(ngModel)]="reason"
|
||||
(keyup.enter)="onModalSubmit()"
|
||||
placeholder="{{'item.qa.withdrown-reinstate.modal.form.summary.placeholder' | translate }}"/>
|
||||
</div>
|
||||
@@ -39,7 +39,7 @@
|
||||
</ng-template>
|
||||
|
||||
<ng-template #reinstateHeader>
|
||||
<div *ngIf="this.canReinstate$ | async" class="modal-header">
|
||||
<div *ngIf="this.canReinstate" class="modal-header">
|
||||
{{'item.qa.reinstate.modal.header' | translate}}
|
||||
<button type="button" class="close" (click)="onModalClose()" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
|
@@ -1,9 +1,7 @@
|
||||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||
import { Component, EventEmitter, Output } from '@angular/core';
|
||||
import { ModalBeforeDismiss } from '../interfaces/modal-before-dismiss.interface';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { BehaviorSubject, Observable, of } from 'rxjs';
|
||||
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
|
||||
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||
|
||||
@Component({
|
||||
@@ -13,17 +11,17 @@ import { AuthorizationDataService } from '../../core/data/feature-authorization/
|
||||
})
|
||||
export class ItemWithdrawnReinstateModalComponent implements ModalBeforeDismiss {
|
||||
|
||||
summary: string;
|
||||
reason: string;
|
||||
|
||||
canWithdraw$: Observable<boolean> = of(false);
|
||||
canReinstate$: Observable<boolean> = of(false);
|
||||
canWithdraw: boolean;
|
||||
canReinstate: boolean;
|
||||
submitted$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
|
||||
@Output() createQAEvent: EventEmitter<string> = new EventEmitter<string>();
|
||||
|
||||
constructor(
|
||||
protected activeModal: NgbActiveModal,
|
||||
protected authorizationService: AuthorizationDataService
|
||||
protected authorizationService: AuthorizationDataService,
|
||||
) {}
|
||||
|
||||
onModalClose() {
|
||||
@@ -37,11 +35,17 @@ export class ItemWithdrawnReinstateModalComponent implements ModalBeforeDismiss
|
||||
|
||||
onModalSubmit() {
|
||||
this.submitted$.next(true);
|
||||
this.createQAEvent.emit(this.summary);
|
||||
this.createQAEvent.emit(this.reason);
|
||||
}
|
||||
|
||||
public setDso(dso: DSpaceObject) {
|
||||
this.canWithdraw$ = this.authorizationService.isAuthorized(FeatureID.WithdrawItem, dso.self);
|
||||
this.canReinstate$ = this.authorizationService.isAuthorized(FeatureID.ReinstateItem, dso.self);
|
||||
public setWithdraw(state: boolean) {
|
||||
this.canWithdraw = state;
|
||||
this.canReinstate = !state;
|
||||
}
|
||||
|
||||
public setReinstate(state: boolean) {
|
||||
this.canReinstate = state;
|
||||
this.canWithdraw = !state;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -184,7 +184,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
|
||||
type: MenuItemType.ONCLICK,
|
||||
text:'item.page.withdrawn',
|
||||
function: () => {
|
||||
this.dsoWithdrawnModalService.openCreateWithdrawnModal(dso);
|
||||
this.dsoWithdrawnModalService.openCreateWithdrawnModal(dso, canWithdrawItem);
|
||||
}
|
||||
} as OnClickMenuItemModel,
|
||||
icon: 'lock',
|
||||
@@ -198,7 +198,7 @@ export class DSOEditMenuResolver implements Resolve<{ [key: string]: MenuSection
|
||||
type: MenuItemType.ONCLICK,
|
||||
text:'item.page.reinstate',
|
||||
function: () => {
|
||||
this.dsoReinstateModalService.openCreateReinstateModal(dso);
|
||||
this.dsoReinstateModalService.openCreateReinstateModal(dso, canReinstateItem);
|
||||
}
|
||||
} as OnClickMenuItemModel,
|
||||
icon: 'unlock-keyhole',
|
||||
|
@@ -8,11 +8,12 @@ import {
|
||||
QualityAssuranceEventDataService
|
||||
} from '../../../core/suggestion-notifications/qa/events/quality-assurance-event-data.service';
|
||||
import { ItemWithdrawnReinstateModalComponent } from '../../correction-suggestion/withdrawn-reinstate-modal.component';
|
||||
import { filter } from 'rxjs/operators';
|
||||
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({
|
||||
@@ -30,28 +31,30 @@ export class DsoReinstateModalService {
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Open the reinstate modal for the provided dso
|
||||
* Open the reinstat modal for the provided dso
|
||||
*/
|
||||
openCreateReinstateModal(dso): void {
|
||||
const selfHref = dso._links.self.href;
|
||||
openCreateReinstateModal(dso, state: boolean): void {
|
||||
const target = dso.id;
|
||||
|
||||
const data = 'https://localhost:8080/server/api/config/correctiontypes/reinstateRequest' + '\n' + selfHref;
|
||||
// Open modal
|
||||
const activeModal = this.modalService.open(ItemWithdrawnReinstateModalComponent);
|
||||
(activeModal.componentInstance as ItemWithdrawnReinstateModalComponent).setDso(dso);
|
||||
(activeModal.componentInstance as ItemWithdrawnReinstateModalComponent).submitted$
|
||||
(activeModal.componentInstance as ItemWithdrawnReinstateModalComponent).setReinstate(!state);
|
||||
(activeModal.componentInstance as ItemWithdrawnReinstateModalComponent).createQAEvent
|
||||
.pipe(
|
||||
filter((val) => val)
|
||||
take(1)
|
||||
).subscribe(
|
||||
() => {
|
||||
this.sendQARequest(data);
|
||||
(reason) => {
|
||||
this.sendQARequest(target, reason);
|
||||
activeModal.close();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
sendQARequest(data: string): void {
|
||||
this.qaEventDataService.postData(data)
|
||||
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';
|
||||
@@ -63,3 +66,4 @@ export class DsoReinstateModalService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -12,7 +12,8 @@ import {
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { NotificationsService } from '../../notifications/notifications.service';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { take } from 'rxjs/operators';
|
||||
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -31,26 +32,27 @@ export class DsoWithdrawnModalService {
|
||||
/**
|
||||
* Open the create withdrawn modal for the provided dso
|
||||
*/
|
||||
openCreateWithdrawnModal(dso): void {
|
||||
const selfHref = dso._links.self.href;
|
||||
|
||||
const data = 'https://localhost:8080/server/api/config/correctiontypes/withdrawnRequest' + '\n' + selfHref;
|
||||
openCreateWithdrawnModal(dso, state: boolean): void {
|
||||
const target = dso.id;
|
||||
// Open modal
|
||||
const activeModal = this.modalService.open(ItemWithdrawnReinstateModalComponent);
|
||||
(activeModal.componentInstance as ItemWithdrawnReinstateModalComponent).setDso(dso);
|
||||
(activeModal.componentInstance as ItemWithdrawnReinstateModalComponent).submitted$
|
||||
(activeModal.componentInstance as ItemWithdrawnReinstateModalComponent).setWithdraw(!state);
|
||||
(activeModal.componentInstance as ItemWithdrawnReinstateModalComponent).createQAEvent
|
||||
.pipe(
|
||||
filter((val) => val)
|
||||
take(1)
|
||||
).subscribe(
|
||||
() => {
|
||||
this.sendQARequest(data);
|
||||
(reasone) => {
|
||||
this.sendQARequest(target, reasone);
|
||||
activeModal.close();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
sendQARequest(data: string): void {
|
||||
this.qaEventDataService.postData(data)
|
||||
sendQARequest(target: string, reason: string): void {
|
||||
this.qaEventDataService.postData(target, 'request-withdrawn', '', reason)
|
||||
.pipe (
|
||||
getFirstCompletedRemoteData()
|
||||
)
|
||||
.subscribe((res: RemoteData<QualityAssuranceEventObject>) => {
|
||||
if (res.hasSucceeded) {
|
||||
const message = 'withdrawn';
|
||||
|
@@ -65,7 +65,8 @@
|
||||
</p>
|
||||
</td>
|
||||
<td *ngIf="showTopic.indexOf('/SUBJECT') !== -1">
|
||||
<p><span class="small">{{'quality-assurance.event.table.subjectValue' | translate}}</span><br><span class="badge badge-info">{{eventElement.event.message.value}}</span></p>
|
||||
<p><span class="small">{{'quality-assurance.event.table.subjectValue' | translate}}
|
||||
</span><br><span class="badge badge-info">{{eventElement.event.message.value}}</span></p>
|
||||
</td>
|
||||
<td *ngIf="showTopic.indexOf('/ABSTRACT') !== -1">
|
||||
<p class="abstract-container" [class.show]="showMore">
|
||||
|
Reference in New Issue
Block a user