Merge branch 'master' into metadata-and-relationships-combined-in-submission

This commit is contained in:
Art Lowel
2020-06-22 11:50:44 +02:00
173 changed files with 8474 additions and 2423 deletions

View File

@@ -0,0 +1,6 @@
<div class="container" *ngVar="item$ | async as item">
<h2>{{'workflow-item.' + type + '.header' | translate}}</h2>
<ds-modify-item-overview *ngIf="item" [item]="item"></ds-modify-item-overview>
<button class="btn btn-default" (click)="previousPage()">{{'workflow-item.' + type + '.button.cancel' | translate}}</button>
<button class="btn btn-danger" (click)="performAction()">{{'workflow-item.' + type + '.button.confirm' | translate}}</button>
</div>

View File

@@ -0,0 +1,124 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
import { WorkflowItemActionPageComponent } from './workflow-item-action-page.component';
import { NotificationsService } from '../shared/notifications/notifications.service';
import { RouteService } from '../core/services/route.service';
import { Component, NO_ERRORS_SCHEMA } from '@angular/core';
import { WorkflowItemDataService } from '../core/submission/workflowitem-data.service';
import { ActivatedRoute, Router } from '@angular/router';
import { WorkflowItem } from '../core/submission/models/workflowitem.model';
import { Observable, of as observableOf } from 'rxjs';
import { VarDirective } from '../shared/utils/var.directive';
import { By } from '@angular/platform-browser';
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils';
import { TranslateLoaderMock } from '../shared/mocks/translate-loader.mock';
import { ActivatedRouteStub } from '../shared/testing/active-router.stub';
import { RouterStub } from '../shared/testing/router.stub';
import { NotificationsServiceStub } from '../shared/testing/notifications-service.stub';
const type = 'testType';
describe('WorkflowItemActionPageComponent', () => {
let component: WorkflowItemActionPageComponent;
let fixture: ComponentFixture<WorkflowItemActionPageComponent>;
let wfiService;
let wfi;
let itemRD$;
let id;
function init() {
wfiService = jasmine.createSpyObj('workflowItemService', {
sendBack: observableOf(true)
});
itemRD$ = createSuccessfulRemoteDataObject$(itemRD$);
wfi = new WorkflowItem();
wfi.item = itemRD$;
id = 'de11b5e5-064a-4e98-a7ac-a1a6a65ddf80';
}
beforeEach(async(() => {
init();
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderMock
}
})],
declarations: [TestComponent, VarDirective],
providers: [
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub({}, { wfi: createSuccessfulRemoteDataObject(wfi) }) },
{ provide: Router, useClass: RouterStub },
{ provide: RouteService, useValue: {} },
{ provide: NotificationsService, useClass: NotificationsServiceStub },
{ provide: WorkflowItemDataService, useValue: wfiService },
],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should set the initial type correctly', () => {
expect(component.type).toEqual(type);
});
describe('clicking the button with class btn-danger', () => {
beforeEach(() => {
spyOn(component, 'performAction');
});
it('should call performAction on clicking the btn-danger', () => {
const button = fixture.debugElement.query(By.css('.btn-danger')).nativeElement;
button.click();
fixture.detectChanges();
expect(component.performAction).toHaveBeenCalled();
});
});
describe('clicking the button with class btn-default', () => {
beforeEach(() => {
spyOn(component, 'previousPage');
});
it('should call performAction on clicking the btn-default', () => {
const button = fixture.debugElement.query(By.css('.btn-default')).nativeElement;
button.click();
fixture.detectChanges();
expect(component.previousPage).toHaveBeenCalled();
});
});
});
@Component({
selector: 'ds-workflow-item-test-action-page',
templateUrl: 'workflow-item-action-page.component.html'
}
)
class TestComponent extends WorkflowItemActionPageComponent {
constructor(protected route: ActivatedRoute,
protected workflowItemService: WorkflowItemDataService,
protected router: Router,
protected routeService: RouteService,
protected notificationsService: NotificationsService,
protected translationService: TranslateService) {
super(route, workflowItemService, router, routeService, notificationsService, translationService);
}
getType(): string {
return type;
}
sendRequest(id: string): Observable<boolean> {
return observableOf(true);
}
}

View File

@@ -0,0 +1,86 @@
import { OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { map, switchMap, take } from 'rxjs/operators';
import { TranslateService } from '@ngx-translate/core';
import { WorkflowItem } from '../core/submission/models/workflowitem.model';
import { Item } from '../core/shared/item.model';
import { ActivatedRoute, Data, Router } from '@angular/router';
import { WorkflowItemDataService } from '../core/submission/workflowitem-data.service';
import { RouteService } from '../core/services/route.service';
import { NotificationsService } from '../shared/notifications/notifications.service';
import { RemoteData } from '../core/data/remote-data';
import { getAllSucceededRemoteData, getRemoteDataPayload } from '../core/shared/operators';
import { isEmpty } from '../shared/empty.util';
/**
* Abstract component representing a page to perform an action on a workflow item
*/
export abstract class WorkflowItemActionPageComponent implements OnInit {
public type;
public wfi$: Observable<WorkflowItem>;
public item$: Observable<Item>;
constructor(protected route: ActivatedRoute,
protected workflowItemService: WorkflowItemDataService,
protected router: Router,
protected routeService: RouteService,
protected notificationsService: NotificationsService,
protected translationService: TranslateService) {
}
/**
* Sets up the type, workflow item and its item object
*/
ngOnInit() {
this.type = this.getType();
this.wfi$ = this.route.data.pipe(map((data: Data) => data.wfi as RemoteData<WorkflowItem>), getRemoteDataPayload());
this.item$ = this.wfi$.pipe(switchMap((wfi: WorkflowItem) => (wfi.item as Observable<RemoteData<Item>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload())));
}
/**
* Performs the action and shows a notification based on the outcome of the action
*/
performAction() {
this.wfi$.pipe(
take(1),
switchMap((wfi: WorkflowItem) => this.sendRequest(wfi.id))
).subscribe((successful: boolean) => {
if (successful) {
const title = this.translationService.get('workflow-item.' + this.type + '.notification.success.title');
const content = this.translationService.get('workflow-item.' + this.type + '.notification.success.content');
this.notificationsService.success(title, content)
} else {
const title = this.translationService.get('workflow-item.' + this.type + '.notification.error.title');
const content = this.translationService.get('workflow-item.' + this.type + '.notification.error.content');
this.notificationsService.error(title, content)
}
this.previousPage();
})
}
/**
* Navigates to the previous url
* If there's not previous url, it continues to the mydspace page instead
*/
previousPage() {
this.routeService.getPreviousUrl().pipe(take(1))
.subscribe((url) => {
if (isEmpty(url)) {
url = '/mydspace';
}
this.router.navigateByUrl(url);
}
);
}
/**
* Performs the action of this workflow item action page
* @param id The id of the WorkflowItem
*/
abstract sendRequest(id: string): Observable<boolean>;
/**
* Returns the type of page
*/
abstract getType(): string;
}

View File

@@ -0,0 +1,76 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { WorkflowItemDeleteComponent } from './workflow-item-delete.component';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { ActivatedRoute, Router } from '@angular/router';
import { RouteService } from '../../core/services/route.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { WorkflowItemDataService } from '../../core/submission/workflowitem-data.service';
import { WorkflowItem } from '../../core/submission/models/workflowitem.model';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { VarDirective } from '../../shared/utils/var.directive';
import { of as observableOf } from 'rxjs';
import { RequestService } from '../../core/data/request.service';
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
import { TranslateLoaderMock } from '../../shared/mocks/translate-loader.mock';
import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
import { RouterStub } from '../../shared/testing/router.stub';
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
import { getMockRequestService } from '../../shared/mocks/request.service.mock';
describe('WorkflowItemDeleteComponent', () => {
let component: WorkflowItemDeleteComponent;
let fixture: ComponentFixture<WorkflowItemDeleteComponent>;
let wfiService;
let wfi;
let itemRD$;
let id;
function init() {
wfiService = jasmine.createSpyObj('workflowItemService', {
delete: observableOf(true)
});
itemRD$ = createSuccessfulRemoteDataObject$(itemRD$);
wfi = new WorkflowItem();
wfi.item = itemRD$;
id = 'de11b5e5-064a-4e98-a7ac-a1a6a65ddf80';
}
beforeEach(async(() => {
init();
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderMock
}
})],
declarations: [WorkflowItemDeleteComponent, VarDirective],
providers: [
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub({}, { wfi: createSuccessfulRemoteDataObject(wfi) }) },
{ provide: Router, useClass: RouterStub },
{ provide: RouteService, useValue: {} },
{ provide: NotificationsService, useClass: NotificationsServiceStub },
{ provide: WorkflowItemDataService, useValue: wfiService },
{ provide: RequestService, useValue: getMockRequestService() },
],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(WorkflowItemDeleteComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should call delete on the workflow-item service when sendRequest is called', () => {
component.sendRequest(id);
expect(wfiService.delete).toHaveBeenCalledWith(id);
});
});

View File

@@ -0,0 +1,46 @@
import { Component } from '@angular/core';
import { Observable } from 'rxjs';
import { WorkflowItemActionPageComponent } from '../workflow-item-action-page.component';
import { ActivatedRoute, Router } from '@angular/router';
import { WorkflowItemDataService } from '../../core/submission/workflowitem-data.service';
import { RouteService } from '../../core/services/route.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
import { RequestService } from '../../core/data/request.service';
import { map } from 'rxjs/operators';
import { RestResponse } from '../../core/cache/response.models';
@Component({
selector: 'ds-workflow-item-delete',
templateUrl: '../workflow-item-action-page.component.html'
})
/**
* Component representing a page to delete a workflow item
*/
export class WorkflowItemDeleteComponent extends WorkflowItemActionPageComponent {
constructor(protected route: ActivatedRoute,
protected workflowItemService: WorkflowItemDataService,
protected router: Router,
protected routeService: RouteService,
protected notificationsService: NotificationsService,
protected translationService: TranslateService,
protected requestService: RequestService) {
super(route, workflowItemService, router, routeService, notificationsService, translationService);
}
/**
* Returns the type of page
*/
getType(): string {
return 'delete';
}
/**
* Performs the action of this workflow item action page
* @param id The id of the WorkflowItem
*/
sendRequest(id: string): Observable<boolean> {
this.requestService.removeByHrefSubstring('/discover');
return this.workflowItemService.delete(id).pipe(map((response: RestResponse) => response.isSuccessful));
}
}

View File

@@ -0,0 +1,29 @@
import { first } from 'rxjs/operators';
import { of as observableOf } from 'rxjs';
import { WorkflowItemPageResolver } from './workflow-item-page.resolver';
import { WorkflowItemDataService } from '../core/submission/workflowitem-data.service';
describe('WorkflowItemPageResolver', () => {
describe('resolve', () => {
let resolver: WorkflowItemPageResolver;
let wfiService: WorkflowItemDataService;
const uuid = '1234-65487-12354-1235';
beforeEach(() => {
wfiService = {
findById: (id: string) => observableOf({ payload: { id }, hasSucceeded: true }) as any
} as any;
resolver = new WorkflowItemPageResolver(wfiService);
});
it('should resolve a workflow item with the correct id', () => {
resolver.resolve({ params: { id: uuid } } as any, undefined)
.pipe(first())
.subscribe(
(resolved) => {
expect(resolved.payload.id).toEqual(uuid);
}
);
});
});
});

View File

@@ -0,0 +1,33 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { RemoteData } from '../core/data/remote-data';
import { hasValue } from '../shared/empty.util';
import { find } from 'rxjs/operators';
import { followLink } from '../shared/utils/follow-link-config.model';
import { WorkflowItemDataService } from '../core/submission/workflowitem-data.service';
import { WorkflowItem } from '../core/submission/models/workflowitem.model';
/**
* This class represents a resolver that requests a specific workflow item before the route is activated
*/
@Injectable()
export class WorkflowItemPageResolver implements Resolve<RemoteData<WorkflowItem>> {
constructor(private workflowItemService: WorkflowItemDataService) {
}
/**
* Method for resolving a workflow item based on the parameters in the current route
* @param {ActivatedRouteSnapshot} route The current ActivatedRouteSnapshot
* @param {RouterStateSnapshot} state The current RouterStateSnapshot
* @returns Observable<<RemoteData<Item>> Emits the found workflow item based on the parameters in the current route,
* or an error if something went wrong
*/
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<WorkflowItem>> {
return this.workflowItemService.findById(route.params.id,
followLink('item'),
).pipe(
find((RD) => hasValue(RD.error) || RD.hasSucceeded),
);
}
}

View File

@@ -0,0 +1,76 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { ActivatedRoute, Router } from '@angular/router';
import { RouteService } from '../../core/services/route.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { WorkflowItemDataService } from '../../core/submission/workflowitem-data.service';
import { WorkflowItem } from '../../core/submission/models/workflowitem.model';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { VarDirective } from '../../shared/utils/var.directive';
import { of as observableOf } from 'rxjs';
import { WorkflowItemSendBackComponent } from './workflow-item-send-back.component';
import { RequestService } from '../../core/data/request.service';
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
import { RouterStub } from '../../shared/testing/router.stub';
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
import { TranslateLoaderMock } from '../../shared/mocks/translate-loader.mock';
import { getMockRequestService } from '../../shared/mocks/request.service.mock';
describe('WorkflowItemSendBackComponent', () => {
let component: WorkflowItemSendBackComponent;
let fixture: ComponentFixture<WorkflowItemSendBackComponent>;
let wfiService;
let wfi;
let itemRD$;
let id;
function init() {
wfiService = jasmine.createSpyObj('workflowItemService', {
sendBack: observableOf(true)
});
itemRD$ = createSuccessfulRemoteDataObject$(itemRD$);
wfi = new WorkflowItem();
wfi.item = itemRD$;
id = 'de11b5e5-064a-4e98-a7ac-a1a6a65ddf80';
}
beforeEach(async(() => {
init();
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderMock
}
})],
declarations: [WorkflowItemSendBackComponent, VarDirective],
providers: [
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub({}, { wfi: createSuccessfulRemoteDataObject(wfi) }) },
{ provide: Router, useClass: RouterStub },
{ provide: RouteService, useValue: {} },
{ provide: NotificationsService, useClass: NotificationsServiceStub },
{ provide: WorkflowItemDataService, useValue: wfiService },
{ provide: RequestService, useValue: getMockRequestService() },
],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(WorkflowItemSendBackComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should call sendBack on the workflow-item service when sendRequest is called', () => {
component.sendRequest(id);
expect(wfiService.sendBack).toHaveBeenCalledWith(id);
});
});

View File

@@ -0,0 +1,44 @@
import { Component } from '@angular/core';
import { WorkflowItemActionPageComponent } from '../workflow-item-action-page.component';
import { Observable } from 'rxjs';
import { ActivatedRoute, Router } from '@angular/router';
import { WorkflowItemDataService } from '../../core/submission/workflowitem-data.service';
import { RouteService } from '../../core/services/route.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
import { RequestService } from '../../core/data/request.service';
@Component({
selector: 'ds-workflow-item-send-back',
templateUrl: '../workflow-item-action-page.component.html'
})
/**
* Component representing a page to send back a workflow item to the submitter
*/
export class WorkflowItemSendBackComponent extends WorkflowItemActionPageComponent {
constructor(protected route: ActivatedRoute,
protected workflowItemService: WorkflowItemDataService,
protected router: Router,
protected routeService: RouteService,
protected notificationsService: NotificationsService,
protected translationService: TranslateService,
protected requestService: RequestService) {
super(route, workflowItemService, router, routeService, notificationsService, translationService);
}
/**
* Returns the type of page
*/
getType(): string {
return 'send-back';
}
/**
* Performs the action of this workflow item action page
* @param id The id of the WorkflowItem
*/
sendRequest(id: string): Observable<boolean> {
this.requestService.removeByHrefSubstring('/discover');
return this.workflowItemService.sendBack(id);
}
}

View File

@@ -3,21 +3,65 @@ import { RouterModule } from '@angular/router';
import { AuthenticatedGuard } from '../core/auth/authenticated.guard';
import { SubmissionEditComponent } from '../submission/edit/submission-edit.component';
import { URLCombiner } from '../core/url-combiner/url-combiner';
import { getWorkflowItemModulePath } from '../app-routing.module';
import { WorkflowItemDeleteComponent } from './workflow-item-delete/workflow-item-delete.component';
import { WorkflowItemPageResolver } from './workflow-item-page.resolver';
import { WorkflowItemSendBackComponent } from './workflow-item-send-back/workflow-item-send-back.component';
export function getWorkflowItemPageRoute(wfiId: string) {
return new URLCombiner(getWorkflowItemModulePath(), wfiId).toString();
}
export function getWorkflowItemEditPath(wfiId: string) {
return new URLCombiner(getWorkflowItemModulePath(), wfiId, WORKFLOW_ITEM_EDIT_PATH).toString()
}
export function getWorkflowItemDeletePath(wfiId: string) {
return new URLCombiner(getWorkflowItemModulePath(), wfiId, WORKFLOW_ITEM_DELETE_PATH).toString()
}
export function getWorkflowItemSendBackPath(wfiId: string) {
return new URLCombiner(getWorkflowItemModulePath(), wfiId, WORKFLOW_ITEM_SEND_BACK_PATH).toString()
}
const WORKFLOW_ITEM_EDIT_PATH = 'edit';
const WORKFLOW_ITEM_DELETE_PATH = 'delete';
const WORKFLOW_ITEM_SEND_BACK_PATH = 'sendback';
@NgModule({
imports: [
RouterModule.forChild([
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{
canActivate: [AuthenticatedGuard],
path: ':id/edit',
component: SubmissionEditComponent,
data: { title: 'submission.edit.title' }
}
])
]
path: ':id',
resolve: { wfi: WorkflowItemPageResolver },
children: [
{
canActivate: [AuthenticatedGuard],
path: WORKFLOW_ITEM_EDIT_PATH,
component: SubmissionEditComponent,
data: { title: 'submission.edit.title' }
},
{
canActivate: [AuthenticatedGuard],
path: WORKFLOW_ITEM_DELETE_PATH,
component: WorkflowItemDeleteComponent,
data: { title: 'workflow-item.delete.title' }
},
{
canActivate: [AuthenticatedGuard],
path: WORKFLOW_ITEM_SEND_BACK_PATH,
component: WorkflowItemSendBackComponent,
data: { title: 'workflow-item.send-back.title' }
}
]
}]
)
],
providers: [WorkflowItemPageResolver]
})
/**
* This module defines the default component to load when navigating to the workflowitems edit page path.
*/
export class WorkflowItemsEditPageRoutingModule { }
export class WorkflowItemsEditPageRoutingModule {
}

View File

@@ -3,6 +3,8 @@ import { NgModule } from '@angular/core';
import { SharedModule } from '../shared/shared.module';
import { WorkflowItemsEditPageRoutingModule } from './workflowitems-edit-page-routing.module';
import { SubmissionModule } from '../submission/submission.module';
import { WorkflowItemDeleteComponent } from './workflow-item-delete/workflow-item-delete.component';
import { WorkflowItemSendBackComponent } from './workflow-item-send-back/workflow-item-send-back.component';
@NgModule({
imports: [
@@ -11,7 +13,7 @@ import { SubmissionModule } from '../submission/submission.module';
SharedModule,
SubmissionModule,
],
declarations: []
declarations: [WorkflowItemDeleteComponent, WorkflowItemSendBackComponent]
})
/**
* This module handles all modules that need to access the workflowitems edit page.