Added tests and comments

This commit is contained in:
Giuseppe Digilio
2019-04-02 15:18:06 +02:00
parent 607beb1bef
commit 16b8e91585
36 changed files with 1693 additions and 247 deletions

View File

@@ -1,4 +1,4 @@
import { ChangeDetectorRef, Component, Injector, Input, OnInit } from '@angular/core';
import { Component, Injector, Input, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { BehaviorSubject, Observable } from 'rxjs';
@@ -8,41 +8,75 @@ import { TranslateService } from '@ngx-translate/core';
import { ClaimedTaskDataService } from '../../../core/tasks/claimed-task-data.service';
import { ClaimedTask } from '../../../core/tasks/models/claimed-task-object.model';
import { ProcessTaskResponse } from '../../../core/tasks/models/process-task-response';
import { NotificationsService } from '../../notifications/notifications.service';
import { NotificationOptions } from '../../notifications/models/notification-options.model';
import { isNotUndefined } from '../../empty.util';
import { Workflowitem } from '../../../core/submission/models/workflowitem.model';
import { RemoteData } from '../../../core/data/remote-data';
import { MyDSpaceActionsComponent } from '../mydspace-actions';
import { ResourceType } from '../../../core/shared/resource-type';
import { NotificationsService } from '../../notifications/notifications.service';
/**
* This component represents mydspace actions related to ClaimedTask object.
*/
@Component({
selector: 'ds-claimed-task-actions',
styleUrls: ['./claimed-task-actions.component.scss'],
templateUrl: './claimed-task-actions.component.html',
})
export class ClaimedTaskActionsComponent extends MyDSpaceActionsComponent<ClaimedTask, ClaimedTaskDataService> implements OnInit {
/**
* The ClaimedTask object
*/
@Input() object: ClaimedTask;
/**
* The workflowitem object that belonging to the ClaimedTask object
*/
public workflowitem$: Observable<Workflowitem>;
/**
* A boolean representing if an approve operation is pending
*/
public processingApprove$ = new BehaviorSubject<boolean>(false);
/**
* A boolean representing if a reject operation is pending
*/
public processingReject$ = new BehaviorSubject<boolean>(false);
/**
* A boolean representing if a return to pool operation is pending
*/
public processingReturnToPool$ = new BehaviorSubject<boolean>(false);
/**
* Initialize instance variables
*
* @param {Injector} injector
* @param {Router} router
* @param {NotificationsService} notificationsService
* @param {TranslateService} translate
*/
constructor(protected injector: Injector,
protected router: Router,
private cd: ChangeDetectorRef,
private notificationsService: NotificationsService,
private translate: TranslateService) {
super(ResourceType.ClaimedTask, injector, router)
protected notificationsService: NotificationsService,
protected translate: TranslateService) {
super(ResourceType.ClaimedTask, injector, router, notificationsService, translate);
}
/**
* Initialize objects
*/
ngOnInit() {
this.initObjects(this.object);
}
/**
* Init the ClaimedTask and Workflowitem objects
*
* @param {PoolTask} object
*/
initObjects(object: ClaimedTask) {
this.object = object;
this.workflowitem$ = (this.object.workflowitem as Observable<RemoteData<Workflowitem>>).pipe(
@@ -50,44 +84,40 @@ export class ClaimedTaskActionsComponent extends MyDSpaceActionsComponent<Claime
map((rd: RemoteData<Workflowitem>) => rd.payload));
}
/**
* Approve the task.
*/
approve() {
this.processingApprove$.next(true);
this.objectDataService.approveTask(this.object.id)
.subscribe((res: ProcessTaskResponse) => {
this.responseHandle(res);
this.processingApprove$.next(false);
this.handleActionResponse(res.hasSucceeded);
});
}
/**
* Reject the task.
*/
reject(reason) {
this.processingReject$.next(true);
this.objectDataService.rejectTask(reason, this.object.id)
.subscribe((res: ProcessTaskResponse) => {
this.responseHandle(res);
this.processingReject$.next(false);
this.handleActionResponse(res.hasSucceeded);
});
}
/**
* Return task to the pool.
*/
returnToPool() {
this.processingReturnToPool$.next(true);
this.objectDataService.returnToPoolTask(this.object.id)
.subscribe((res: ProcessTaskResponse) => {
this.responseHandle(res);
this.processingReturnToPool$.next(false);
this.handleActionResponse(res.hasSucceeded);
});
}
private responseHandle(res: ProcessTaskResponse) {
this.processingApprove$.next(false);
this.processingReject$.next(false);
this.processingReturnToPool$.next(false);
if (res.hasSucceeded) {
this.reload();
this.notificationsService.success(null,
this.translate.get('submission.workflow.tasks.generic.success'),
new NotificationOptions(5000, false));
} else {
this.notificationsService.error(null,
this.translate.get('submission.workflow.tasks.generic.error'),
new NotificationOptions(20000, true));
}
}
}