diff --git a/src/app/shared/mydspace-actions/claimed-task/approve/claimed-task-actions-approve.component.html b/src/app/shared/mydspace-actions/claimed-task/approve/claimed-task-actions-approve.component.html new file mode 100644 index 0000000000..39b0f34a7b --- /dev/null +++ b/src/app/shared/mydspace-actions/claimed-task/approve/claimed-task-actions-approve.component.html @@ -0,0 +1,8 @@ + diff --git a/src/app/shared/mydspace-actions/claimed-task/approve/claimed-task-actions-approve.component.scss b/src/app/shared/mydspace-actions/claimed-task/approve/claimed-task-actions-approve.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/shared/mydspace-actions/claimed-task/approve/claimed-task-actions-approve.component.ts b/src/app/shared/mydspace-actions/claimed-task/approve/claimed-task-actions-approve.component.ts new file mode 100644 index 0000000000..b4355c4a9f --- /dev/null +++ b/src/app/shared/mydspace-actions/claimed-task/approve/claimed-task-actions-approve.component.ts @@ -0,0 +1,19 @@ +import { Component, EventEmitter, Input, Output } from '@angular/core'; + +@Component({ + selector: 'ds-claimed-task-actions-approve', + styleUrls: ['./claimed-task-actions-approve.component.scss'], + templateUrl: './claimed-task-actions-approve.component.html', +}) + +export class ClaimedTaskActionsApproveComponent { + @Input() processingApprove: boolean; + @Input() taskId: string; + @Input() wrapperClass: string; + + @Output() approve: EventEmitter = new EventEmitter(); + + click() { + this.approve.emit(); + } +} diff --git a/src/app/shared/mydspace-actions/claimed-task/claimed-task-actions.component.html b/src/app/shared/mydspace-actions/claimed-task/claimed-task-actions.component.html new file mode 100644 index 0000000000..ced206ac53 --- /dev/null +++ b/src/app/shared/mydspace-actions/claimed-task/claimed-task-actions.component.html @@ -0,0 +1,33 @@ + + + {{'submission.workflow.tasks.claimed.edit' | translate}} + + + + + + + + + + diff --git a/src/app/shared/mydspace-actions/claimed-task/claimed-task-actions.component.scss b/src/app/shared/mydspace-actions/claimed-task/claimed-task-actions.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/shared/mydspace-actions/claimed-task/claimed-task-actions.component.ts b/src/app/shared/mydspace-actions/claimed-task/claimed-task-actions.component.ts new file mode 100644 index 0000000000..8c3a649782 --- /dev/null +++ b/src/app/shared/mydspace-actions/claimed-task/claimed-task-actions.component.ts @@ -0,0 +1,94 @@ +import { ChangeDetectorRef, Component, Injector, Input, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; + +import { BehaviorSubject, Observable } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +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 { NormalizedClaimedTask } from '../../../core/tasks/models/normalized-claimed-task-object.model'; +import { MyDSpaceActionsComponent } from '../mydspace-actions'; +import { ResourceType } from '../../../core/shared/resource-type'; + +@Component({ + selector: 'ds-claimed-task-actions', + styleUrls: ['./claimed-task-actions.component.scss'], + templateUrl: './claimed-task-actions.component.html', +}) + +export class ClaimedTaskActionsComponent extends MyDSpaceActionsComponent implements OnInit { + @Input() object: ClaimedTask; + + public workflowitem$: Observable; + + public processingApprove$ = new BehaviorSubject(false); + public processingReject$ = new BehaviorSubject(false); + public processingReturnToPool$ = new BehaviorSubject(false); + + constructor(protected injector: Injector, + protected router: Router, + private cd: ChangeDetectorRef, + private notificationsService: NotificationsService, + private translate: TranslateService) { + super(ResourceType.ClaimedTask, injector, router) + } + + ngOnInit() { + this.initObjects(this.object); + } + + initObjects(object: ClaimedTask) { + this.object = object; + this.workflowitem$ = (this.object.workflowitem as Observable>).pipe( + filter((rd: RemoteData) => ((!rd.isRequestPending) && isNotUndefined(rd.payload))), + map((rd: RemoteData) => rd.payload)); + } + + approve() { + this.processingApprove$.next(true); + this.objectDataService.approveTask(this.object.id) + .subscribe((res: ProcessTaskResponse) => { + this.responseHandle(res); + }); + } + + reject(reason) { + this.processingReject$.next(true); + this.objectDataService.rejectTask(reason, this.object.id) + .subscribe((res: ProcessTaskResponse) => { + this.responseHandle(res); + }); + } + + returnToPool() { + this.processingReturnToPool$.next(true); + this.objectDataService.returnToPoolTask(this.object.id) + .subscribe((res: ProcessTaskResponse) => { + this.responseHandle(res); + }); + } + + 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)); + } + } + +} diff --git a/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.html b/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.html new file mode 100644 index 0000000000..29835f2b40 --- /dev/null +++ b/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.html @@ -0,0 +1,40 @@ +

+ + + + + + diff --git a/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.scss b/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.ts b/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.ts new file mode 100644 index 0000000000..7f09896b4c --- /dev/null +++ b/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.ts @@ -0,0 +1,43 @@ +import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; + +import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; + +@Component({ + selector: 'ds-claimed-task-actions-reject', + styleUrls: ['./claimed-task-actions-reject.component.scss'], + templateUrl: './claimed-task-actions-reject.component.html', +}) + +export class ClaimedTaskActionsRejectComponent implements OnInit { + @Input() processingReject: boolean; + @Input() taskId: string; + @Input() wrapperClass: string; + + @Output() reject: EventEmitter = new EventEmitter(); + + public rejectForm: FormGroup; + public modalRef: NgbModalRef; + + constructor(private formBuilder: FormBuilder, private modalService: NgbModal) { + } + + ngOnInit() { + this.rejectForm = this.formBuilder.group({ + reason: ['', Validators.required] + }); + + } + + click() { + this.processingReject = true; + this.modalRef.close('Send Button'); + const reason = this.rejectForm.get('reason').value; + this.reject.emit(reason); + } + + openRejectModal(rejectModal) { + this.rejectForm.reset(); + this.modalRef = this.modalService.open(rejectModal); + } +} diff --git a/src/app/shared/mydspace-actions/item/item-actions.component.html b/src/app/shared/mydspace-actions/item/item-actions.component.html new file mode 100644 index 0000000000..7b762bd71a --- /dev/null +++ b/src/app/shared/mydspace-actions/item/item-actions.component.html @@ -0,0 +1,11 @@ + + {{"submission.workflow.generic.view" | translate}} + + + + + + diff --git a/src/app/shared/mydspace-actions/item/item-actions.component.scss b/src/app/shared/mydspace-actions/item/item-actions.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/shared/mydspace-actions/item/item-actions.component.ts b/src/app/shared/mydspace-actions/item/item-actions.component.ts new file mode 100644 index 0000000000..8c403cc3ef --- /dev/null +++ b/src/app/shared/mydspace-actions/item/item-actions.component.ts @@ -0,0 +1,40 @@ +import { Component, Injector, Input, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; + +import { Observable } from 'rxjs'; + +import { MyDSpaceActionsComponent } from '../mydspace-actions'; +import { ResourceType } from '../../../core/shared/resource-type'; +import { ItemDataService } from '../../../core/data/item-data.service'; +import { NormalizedItem } from '../../../core/cache/models/normalized-item.model'; +import { Item } from '../../../core/shared/item.model'; +import { RoleService } from '../../../core/roles/role.service'; + +@Component({ + selector: 'ds-item-actions', + styleUrls: ['./item-actions.component.scss'], + templateUrl: './item-actions.component.html', +}) + +export class ItemActionsComponent extends MyDSpaceActionsComponent implements OnInit { + @Input() object: Item; + + public isAdmin: Observable; + public itemUrl: string; + + constructor(protected injector: Injector, + protected roleService: RoleService, + protected router: Router) { + super(ResourceType.Workspaceitem, injector, router); + } + + ngOnInit() { + this.isAdmin = this.roleService.isAdmin(); + this.itemUrl = this.object.firstMetadataValue('dc.identifier.uri'); + } + + initObjects(object: Item) { + this.object = object; + } + +} diff --git a/src/app/shared/mydspace-actions/mydspace-actions-service.factory.ts b/src/app/shared/mydspace-actions/mydspace-actions-service.factory.ts new file mode 100644 index 0000000000..e9fae599c9 --- /dev/null +++ b/src/app/shared/mydspace-actions/mydspace-actions-service.factory.ts @@ -0,0 +1,30 @@ +import { DataService } from '../../core/data/data.service'; +import { ResourceType } from '../../core/shared/resource-type'; +import { WorkspaceitemDataService } from '../../core/submission/workspaceitem-data.service'; +import { ClaimedTaskDataService } from '../../core/tasks/claimed-task-data.service'; +import { PoolTaskDataService } from '../../core/tasks/pool-task-data.service'; +import { WorkflowitemDataService } from '../../core/submission/workflowitem-data.service'; +import { NormalizedObject } from '../../core/cache/models/normalized-object.model'; +import { CacheableObject } from '../../core/cache/object-cache.reducer'; + +export class MydspaceActionsServiceFactory> { + public getConstructor(type: ResourceType): TService { + switch (type) { + case ResourceType.Workspaceitem: { + return WorkspaceitemDataService as any; + } + case ResourceType.Workflowitem: { + return WorkflowitemDataService as any; + } + case ResourceType.ClaimedTask: { + return ClaimedTaskDataService as any; + } + case ResourceType.PoolTask: { + return PoolTaskDataService as any; + } + default: { + return undefined; + } + } + } +} diff --git a/src/app/shared/mydspace-actions/mydspace-actions.ts b/src/app/shared/mydspace-actions/mydspace-actions.ts new file mode 100644 index 0000000000..2a231f6bf0 --- /dev/null +++ b/src/app/shared/mydspace-actions/mydspace-actions.ts @@ -0,0 +1,42 @@ +import { Router } from '@angular/router'; +import { Injector, Input } from '@angular/core'; + +import { find } from 'rxjs/operators'; + +import { MydspaceActionsServiceFactory } from './mydspace-actions-service.factory'; +import { RemoteData } from '../../core/data/remote-data'; +import { NormalizedObject } from '../../core/cache/models/normalized-object.model'; +import { DataService } from '../../core/data/data.service'; +import { DSpaceObject } from '../../core/shared/dspace-object.model'; +import { ResourceType } from '../../core/shared/resource-type'; + +export abstract class MyDSpaceActionsComponent> { + @Input() abstract object: T; + protected objectDataService: TService; + + constructor(protected objectType: ResourceType, protected injector: Injector, protected router: Router) { + const factory = new MydspaceActionsServiceFactory(); + this.objectDataService = injector.get(factory.getConstructor(objectType)); + } + + abstract initObjects(object: T): void; + + reload() { + // override the route reuse strategy + this.router.routeReuseStrategy.shouldReuseRoute = () => { + return false; + }; + this.router.navigated = false; + const url = decodeURIComponent(this.router.url); + this.router.navigateByUrl(url); + } + + refresh() { + // override the object with a refreshed one + this.objectDataService.findById(this.object.id).pipe( + find((rd: RemoteData) => rd.hasSucceeded) + ).subscribe((rd: RemoteData) => { + this.initObjects(rd.payload as T); + }); + } +} diff --git a/src/app/shared/mydspace-actions/pool-task/pool-task-actions.component.html b/src/app/shared/mydspace-actions/pool-task/pool-task-actions.component.html new file mode 100644 index 0000000000..a66bc6877b --- /dev/null +++ b/src/app/shared/mydspace-actions/pool-task/pool-task-actions.component.html @@ -0,0 +1,17 @@ + + + + + + + diff --git a/src/app/shared/mydspace-actions/pool-task/pool-task-actions.component.scss b/src/app/shared/mydspace-actions/pool-task/pool-task-actions.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/shared/mydspace-actions/pool-task/pool-task-actions.component.ts b/src/app/shared/mydspace-actions/pool-task/pool-task-actions.component.ts new file mode 100644 index 0000000000..037434fed0 --- /dev/null +++ b/src/app/shared/mydspace-actions/pool-task/pool-task-actions.component.ts @@ -0,0 +1,73 @@ +import { Component, Injector, Input } from '@angular/core'; +import { Router } from '@angular/router'; + +import { BehaviorSubject, Observable } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { TranslateService } from '@ngx-translate/core'; + +import { Workflowitem } from '../../../core/submission/models/workflowitem.model'; +import { ProcessTaskResponse } from '../../../core/tasks/models/process-task-response'; +import { RemoteData } from '../../../core/data/remote-data'; +import { PoolTask } from '../../../core/tasks/models/pool-task-object.model'; +import { PoolTaskDataService } from '../../../core/tasks/pool-task-data.service'; +import { NotificationsService } from '../../notifications/notifications.service'; +import { NotificationOptions } from '../../notifications/models/notification-options.model'; +import { isNotUndefined } from '../../empty.util'; +import { NormalizedPoolTask } from '../../../core/tasks/models/normalized-pool-task-object.model'; +import { MyDSpaceActionsComponent } from '../mydspace-actions'; +import { ResourceType } from '../../../core/shared/resource-type'; + +@Component({ + selector: 'ds-pool-task-actions', + styleUrls: ['./pool-task-actions.component.scss'], + templateUrl: './pool-task-actions.component.html', +}) + +export class PoolTaskActionsComponent extends MyDSpaceActionsComponent { + @Input() object: PoolTask; + + public processingClaim$ = new BehaviorSubject(false); + public workflowitem$: Observable; + + constructor(protected injector: Injector, + protected router: Router, + private notificationsService: NotificationsService, + private translate: TranslateService) { + super(ResourceType.PoolTask, injector, router); + } + + ngOnInit() { + this.initObjects(this.object); + } + + initObjects(object: PoolTask) { + this.object = object; + this.workflowitem$ = (this.object.workflowitem as Observable>).pipe( + filter((rd: RemoteData) => ((!rd.isRequestPending) && isNotUndefined(rd.payload))), + map((rd: RemoteData) => rd.payload)); + } + + claim() { + this.processingClaim$.next(true); + this.objectDataService.claimTask(this.object.id) + .subscribe((res: ProcessTaskResponse) => { + this.responseHandle(res); + }); + } + + private responseHandle(res: ProcessTaskResponse) { + if (res.hasSucceeded) { + this.processingClaim$.next(false); + this.reload(); + this.notificationsService.success(null, + this.translate.get('submission.workflow.tasks.generic.success'), + new NotificationOptions(5000, false)); + } else { + this.processingClaim$.next(false); + this.notificationsService.error(null, + this.translate.get('submission.workflow.tasks.generic.error'), + new NotificationOptions(20000, true)); + } + } + +} diff --git a/src/app/shared/mydspace-actions/workflowitem/workflowitem-actions.component.html b/src/app/shared/mydspace-actions/workflowitem/workflowitem-actions.component.html new file mode 100644 index 0000000000..b19299e164 --- /dev/null +++ b/src/app/shared/mydspace-actions/workflowitem/workflowitem-actions.component.html @@ -0,0 +1,5 @@ + + diff --git a/src/app/shared/mydspace-actions/workflowitem/workflowitem-actions.component.scss b/src/app/shared/mydspace-actions/workflowitem/workflowitem-actions.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/shared/mydspace-actions/workflowitem/workflowitem-actions.component.ts b/src/app/shared/mydspace-actions/workflowitem/workflowitem-actions.component.ts new file mode 100644 index 0000000000..932035f730 --- /dev/null +++ b/src/app/shared/mydspace-actions/workflowitem/workflowitem-actions.component.ts @@ -0,0 +1,27 @@ +import { Component, Injector, Input } from '@angular/core'; +import { Router } from '@angular/router'; +import { MyDSpaceActionsComponent } from '../mydspace-actions'; +import { ResourceType } from '../../../core/shared/resource-type'; +import { Workflowitem } from '../../../core/submission/models/workflowitem.model'; +import { NormalizedWorkflowItem } from '../../../core/submission/models/normalized-workflowitem.model'; +import { WorkflowitemDataService } from '../../../core/submission/workflowitem-data.service'; + +@Component({ + selector: 'ds-workflowitem-actions', + styleUrls: ['./workflowitem-actions.component.scss'], + templateUrl: './workflowitem-actions.component.html', +}) + +export class WorkflowitemActionsComponent extends MyDSpaceActionsComponent { + @Input() object: Workflowitem; + + constructor(protected injector: Injector, + protected router: Router) { + super(ResourceType.Workflowitem, injector, router); + } + + initObjects(object: Workflowitem) { + this.object = object; + } + +} diff --git a/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.html b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.html new file mode 100644 index 0000000000..3114e070a5 --- /dev/null +++ b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.html @@ -0,0 +1,36 @@ + + {{'submission.workflow.generic.edit' | translate}} + + + + + + + + + + + + diff --git a/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.scss b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.ts b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.ts new file mode 100644 index 0000000000..1ad229d950 --- /dev/null +++ b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.ts @@ -0,0 +1,59 @@ +import { Component, Injector, Input } from '@angular/core'; +import { Router } from '@angular/router'; + +import { BehaviorSubject } from 'rxjs'; +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { TranslateService } from '@ngx-translate/core'; + +import { Workspaceitem } from '../../../core/submission/models/workspaceitem.model'; +import { MyDSpaceActionsComponent } from '../mydspace-actions'; +import { NormalizedWorkspaceItem } from '../../../core/submission/models/normalized-workspaceitem.model'; +import { SubmissionRestService } from '../../../submission/submission-rest.service'; +import { WorkspaceitemDataService } from '../../../core/submission/workspaceitem-data.service'; +import { ResourceType } from '../../../core/shared/resource-type'; +import { NotificationsService } from '../../notifications/notifications.service'; +import { NotificationOptions } from '../../notifications/models/notification-options.model'; + +@Component({ + selector: 'ds-workspaceitem-actions', + styleUrls: ['./workspaceitem-actions.component.scss'], + templateUrl: './workspaceitem-actions.component.html', +}) + +export class WorkspaceitemActionsComponent extends MyDSpaceActionsComponent { + @Input() object: Workspaceitem; + + public processingDelete$ = new BehaviorSubject(false); + + constructor(protected injector: Injector, + protected router: Router, + private modalService: NgbModal, + private notificationsService: NotificationsService, + private restService: SubmissionRestService, + private translate: TranslateService) { + super(ResourceType.Workspaceitem, injector, router); + } + + public confirmDiscard(content) { + this.modalService.open(content).result.then( + (result) => { + if (result === 'ok') { + this.processingDelete$.next(true); + this.restService.deleteById(this.object.id) + .subscribe(() => { + this.notificationsService.success(null, + this.translate.get('submission.workflow.tasks.generic.success'), + new NotificationOptions(5000, false)); + this.processingDelete$.next(false); + this.reload(); + }) + } + } + ); + } + + initObjects(object: Workspaceitem) { + this.object = object; + } + +}