Merge pull request #566 from atmire/submit-this-collection

Submit this collection
This commit is contained in:
Tim Donohue
2020-01-21 11:16:41 -06:00
committed by GitHub
8 changed files with 62 additions and 25 deletions

View File

@@ -17,6 +17,7 @@ import { CreateCollectionParentSelectorComponent } from '../../shared/dso-select
import { EditItemSelectorComponent } from '../../shared/dso-selector/modal-wrappers/edit-item-selector/edit-item-selector.component'; import { EditItemSelectorComponent } from '../../shared/dso-selector/modal-wrappers/edit-item-selector/edit-item-selector.component';
import { EditCommunitySelectorComponent } from '../../shared/dso-selector/modal-wrappers/edit-community-selector/edit-community-selector.component'; import { EditCommunitySelectorComponent } from '../../shared/dso-selector/modal-wrappers/edit-community-selector/edit-community-selector.component';
import { EditCollectionSelectorComponent } from '../../shared/dso-selector/modal-wrappers/edit-collection-selector/edit-collection-selector.component'; import { EditCollectionSelectorComponent } from '../../shared/dso-selector/modal-wrappers/edit-collection-selector/edit-collection-selector.component';
import {CreateItemParentSelectorComponent} from '../../shared/dso-selector/modal-wrappers/create-item-parent-selector/create-item-parent-selector.component';
/** /**
* Component representing the admin sidebar * Component representing the admin sidebar
@@ -137,18 +138,18 @@ export class AdminSidebarComponent extends MenuComponent implements OnInit {
parentID: 'new', parentID: 'new',
active: false, active: false,
visible: true, visible: true,
// model: {
// type: MenuItemType.ONCLICK,
// text: 'menu.section.new_item',
// function: () => {
// this.modalService.open(CreateItemParentSelectorComponent);
// }
// } as OnClickMenuItemModel,
model: { model: {
type: MenuItemType.LINK, type: MenuItemType.ONCLICK,
text: 'menu.section.new_item', text: 'menu.section.new_item',
link: '/submit' function: () => {
} as LinkMenuItemModel, this.modalService.open(CreateItemParentSelectorComponent);
}
} as OnClickMenuItemModel,
// model: {
// type: MenuItemType.LINK,
// text: 'menu.section.new_item',
// link: '/submit'
// } as LinkMenuItemModel,
}, },
{ {
id: 'new_item_version', id: 'new_item_version',

View File

@@ -20,6 +20,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { ErrorResponse, RestResponse, SubmissionSuccessResponse } from '../cache/response.models'; import { ErrorResponse, RestResponse, SubmissionSuccessResponse } from '../cache/response.models';
import { getResponseFromEntry } from '../shared/operators'; import { getResponseFromEntry } from '../shared/operators';
import {URLCombiner} from '../url-combiner/url-combiner';
/** /**
* The service handling all submission REST requests * The service handling all submission REST requests
@@ -65,9 +66,15 @@ export class SubmissionRestService {
* The base endpoint for the type of object * The base endpoint for the type of object
* @param resourceID * @param resourceID
* The identifier for the object * The identifier for the object
* @param collectionId
* The owning collection for the object
*/ */
protected getEndpointByIDHref(endpoint, resourceID): string { protected getEndpointByIDHref(endpoint, resourceID, collectionId?: string): string {
return isNotEmpty(resourceID) ? `${endpoint}/${resourceID}` : `${endpoint}`; let url = isNotEmpty(resourceID) ? `${endpoint}/${resourceID}` : `${endpoint}`;
if (collectionId) {
url = new URLCombiner(url, `?owningCollection=${collectionId}`).toString();
}
return url;
} }
/** /**
@@ -130,12 +137,14 @@ export class SubmissionRestService {
* The [HttpOptions] object * The [HttpOptions] object
* @return Observable<SubmitDataResponseDefinitionObject> * @return Observable<SubmitDataResponseDefinitionObject>
* server response * server response
* @param collectionId
* The owning collection id
*/ */
public postToEndpoint(linkName: string, body: any, scopeId?: string, options?: HttpOptions): Observable<SubmitDataResponseDefinitionObject> { public postToEndpoint(linkName: string, body: any, scopeId?: string, options?: HttpOptions, collectionId?: string): Observable<SubmitDataResponseDefinitionObject> {
const requestId = this.requestService.generateRequestId(); const requestId = this.requestService.generateRequestId();
return this.halService.getEndpoint(linkName).pipe( return this.halService.getEndpoint(linkName).pipe(
filter((href: string) => isNotEmpty(href)), filter((href: string) => isNotEmpty(href)),
map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId)), map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId, collectionId)),
distinctUntilChanged(), distinctUntilChanged(),
map((endpointURL: string) => new SubmissionPostRequest(requestId, endpointURL, body, options)), map((endpointURL: string) => new SubmissionPostRequest(requestId, endpointURL, body, options)),
tap((request: PostRequest) => this.requestService.configure(request)), tap((request: PostRequest) => this.requestService.configure(request)),

View File

@@ -59,9 +59,8 @@ describe('CreateItemParentSelectorComponent', () => {
}); });
it('should call navigate on the router with the correct create path when navigate is called', () => { it('should call navigate on the router with the correct create path when navigate is called', () => {
/* TODO when there is a specific submission path */ component.navigate(collection);
// component.navigate(item); expect(router.navigate).toHaveBeenCalledWith(['/submit'], { queryParams: { collection: collection.uuid } });
// expect(router.navigate).toHaveBeenCalledWith([createPath]);
}); });
}); });

View File

@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
import { DSpaceObjectType } from '../../../../core/shared/dspace-object-type.model'; import { DSpaceObjectType } from '../../../../core/shared/dspace-object-type.model';
import { DSpaceObject } from '../../../../core/shared/dspace-object.model'; import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
@@ -28,6 +28,11 @@ export class CreateItemParentSelectorComponent extends DSOSelectorModalWrapperCo
* Navigate to the item create page * Navigate to the item create page
*/ */
navigate(dso: DSpaceObject) { navigate(dso: DSpaceObject) {
// There's no submit path per collection yet... const navigationExtras: NavigationExtras = {
queryParams: {
['collection']: dso.uuid,
}
};
this.router.navigate(['/submit'], navigationExtras);
} }
} }

View File

@@ -401,6 +401,14 @@ describe('SubmissionService test suite', () => {
service.createSubmission(); service.createSubmission();
expect((service as any).restService.postToEndpoint).toHaveBeenCalled(); expect((service as any).restService.postToEndpoint).toHaveBeenCalled();
expect((service as any).restService.postToEndpoint).toHaveBeenCalledWith('workspaceitems', {}, null, null, undefined);
});
it('should create a new submission with collection', () => {
service.createSubmission(collectionId);
expect((service as any).restService.postToEndpoint).toHaveBeenCalled();
expect((service as any).restService.postToEndpoint).toHaveBeenCalledWith('workspaceitems', {}, null, null, collectionId);
}); });
}); });

View File

@@ -103,11 +103,13 @@ export class SubmissionService {
/** /**
* Perform a REST call to create a new workspaceitem and return response * Perform a REST call to create a new workspaceitem and return response
* *
* @param collectionId
* The owning collection id
* @return Observable<SubmissionObject> * @return Observable<SubmissionObject>
* observable of SubmissionObject * observable of SubmissionObject
*/ */
createSubmission(): Observable<SubmissionObject> { createSubmission(collectionId?: string): Observable<SubmissionObject> {
return this.restService.postToEndpoint(this.workspaceLinkPath, {}).pipe( return this.restService.postToEndpoint(this.workspaceLinkPath, {}, null, null, collectionId).pipe(
map((workspaceitem: SubmissionObject[]) => workspaceitem[0] as SubmissionObject), map((workspaceitem: SubmissionObject[]) => workspaceitem[0] as SubmissionObject),
catchError(() => observableOf({} as SubmissionObject))) catchError(() => observableOf({} as SubmissionObject)))
} }

View File

@@ -1,6 +1,6 @@
import { async, ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { NO_ERRORS_SCHEMA, ViewContainerRef } from '@angular/core'; import { NO_ERRORS_SCHEMA, ViewContainerRef } from '@angular/core';
import { of as observableOf } from 'rxjs'; import { of as observableOf } from 'rxjs';
@@ -14,6 +14,7 @@ import { getMockTranslateService } from '../../shared/mocks/mock-translate.servi
import { RouterStub } from '../../shared/testing/router-stub'; import { RouterStub } from '../../shared/testing/router-stub';
import { mockSubmissionObject } from '../../shared/mocks/mock-submission'; import { mockSubmissionObject } from '../../shared/mocks/mock-submission';
import { SubmissionSubmitComponent } from './submission-submit.component'; import { SubmissionSubmitComponent } from './submission-submit.component';
import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
describe('SubmissionSubmitComponent Component', () => { describe('SubmissionSubmitComponent Component', () => {
@@ -39,6 +40,7 @@ describe('SubmissionSubmitComponent Component', () => {
{ provide: SubmissionService, useClass: SubmissionServiceStub }, { provide: SubmissionService, useClass: SubmissionServiceStub },
{ provide: TranslateService, useValue: getMockTranslateService() }, { provide: TranslateService, useValue: getMockTranslateService() },
{ provide: Router, useValue: new RouterStub() }, { provide: Router, useValue: new RouterStub() },
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
ViewContainerRef ViewContainerRef
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]

View File

@@ -1,5 +1,5 @@
import { ChangeDetectorRef, Component, OnDestroy, OnInit, ViewContainerRef } from '@angular/core'; import { ChangeDetectorRef, Component, OnDestroy, OnInit, ViewContainerRef } from '@angular/core';
import { Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
@@ -27,6 +27,12 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit {
*/ */
public collectionId: string; public collectionId: string;
/**
* The collection id input to create a new submission
* @type {string}
*/
public collectionParam: string;
/** /**
* The submission self url * The submission self url
* @type {string} * @type {string}
@@ -60,13 +66,18 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit {
* @param {Router} router * @param {Router} router
* @param {TranslateService} translate * @param {TranslateService} translate
* @param {ViewContainerRef} viewContainerRef * @param {ViewContainerRef} viewContainerRef
* @param {ActivatedRoute} route
*/ */
constructor(private changeDetectorRef: ChangeDetectorRef, constructor(private changeDetectorRef: ChangeDetectorRef,
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private router: Router, private router: Router,
private submissionService: SubmissionService, private submissionService: SubmissionService,
private translate: TranslateService, private translate: TranslateService,
private viewContainerRef: ViewContainerRef) { private viewContainerRef: ViewContainerRef,
private route: ActivatedRoute) {
this.route
.queryParams
.subscribe((params) => { this.collectionParam = (params.collection); });
} }
/** /**
@@ -75,7 +86,7 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit {
ngOnInit() { ngOnInit() {
// NOTE execute the code on the browser side only, otherwise it is executed twice // NOTE execute the code on the browser side only, otherwise it is executed twice
this.subs.push( this.subs.push(
this.submissionService.createSubmission() this.submissionService.createSubmission(this.collectionParam)
.subscribe((submissionObject: SubmissionObject) => { .subscribe((submissionObject: SubmissionObject) => {
// NOTE new submission is created on the browser side only // NOTE new submission is created on the browser side only
if (isNotNull(submissionObject)) { if (isNotNull(submissionObject)) {