mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
submit to this collection
This commit is contained in:
@@ -32,6 +32,13 @@
|
||||
</ds-comcol-page-content>
|
||||
|
||||
</header>
|
||||
|
||||
<div class="add">
|
||||
<a class="btn btn-lg btn-primary mt-1 ml-2" [routerLink]="['/submit']" [queryParams]="{collection:collection.id}" role="button">
|
||||
<i class="fa fa-plus-circle" aria-hidden="true"></i> {{'mydspace.new-submission' | translate}}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<section class="comcol-page-browse-section">
|
||||
<!-- Browse-By Links -->
|
||||
<ds-comcol-page-browse-by
|
||||
|
@@ -20,6 +20,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { ErrorResponse, RestResponse, SubmissionSuccessResponse } from '../cache/response.models';
|
||||
import { getResponseFromEntry } from '../shared/operators';
|
||||
import {URLCombiner} from '../url-combiner/url-combiner';
|
||||
|
||||
/**
|
||||
* The service handling all submission REST requests
|
||||
@@ -65,9 +66,15 @@ export class SubmissionRestService {
|
||||
* The base endpoint for the type of object
|
||||
* @param resourceID
|
||||
* The identifier for the object
|
||||
* @param collectionId
|
||||
* The owning collection for the object
|
||||
*/
|
||||
protected getEndpointByIDHref(endpoint, resourceID): string {
|
||||
return isNotEmpty(resourceID) ? `${endpoint}/${resourceID}` : `${endpoint}`;
|
||||
protected getEndpointByIDHref(endpoint, resourceID, collectionId?: string): string {
|
||||
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
|
||||
* @return Observable<SubmitDataResponseDefinitionObject>
|
||||
* 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();
|
||||
return this.halService.getEndpoint(linkName).pipe(
|
||||
filter((href: string) => isNotEmpty(href)),
|
||||
map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId)),
|
||||
map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId, collectionId)),
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) => new SubmissionPostRequest(requestId, endpointURL, body, options)),
|
||||
tap((request: PostRequest) => this.requestService.configure(request)),
|
||||
|
@@ -401,6 +401,14 @@ describe('SubmissionService test suite', () => {
|
||||
service.createSubmission();
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -109,11 +109,13 @@ export class SubmissionService {
|
||||
/**
|
||||
* Perform a REST call to create a new workspaceitem and return response
|
||||
*
|
||||
* @param collectionId
|
||||
* The owning collection id
|
||||
* @return Observable<SubmissionObject>
|
||||
* observable of SubmissionObject
|
||||
*/
|
||||
createSubmission(): Observable<SubmissionObject> {
|
||||
return this.restService.postToEndpoint(this.workspaceLinkPath, {}).pipe(
|
||||
createSubmission(collectionId?: string): Observable<SubmissionObject> {
|
||||
return this.restService.postToEndpoint(this.workspaceLinkPath, {}, null, null, collectionId).pipe(
|
||||
map((workspaceitem: SubmissionObject) => workspaceitem[0]),
|
||||
catchError(() => observableOf({})))
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { async, ComponentFixture, fakeAsync, TestBed } from '@angular/core/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 { 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 { mockSubmissionObject } from '../../shared/mocks/mock-submission';
|
||||
import { SubmissionSubmitComponent } from './submission-submit.component';
|
||||
import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
|
||||
|
||||
describe('SubmissionSubmitComponent Component', () => {
|
||||
|
||||
@@ -39,6 +40,7 @@ describe('SubmissionSubmitComponent Component', () => {
|
||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||
{ provide: TranslateService, useValue: getMockTranslateService() },
|
||||
{ provide: Router, useValue: new RouterStub() },
|
||||
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
|
||||
ViewContainerRef
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { ChangeDetectorRef, Component, OnDestroy, OnInit, ViewContainerRef } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
@@ -27,6 +27,12 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit {
|
||||
*/
|
||||
public collectionId: string;
|
||||
|
||||
/**
|
||||
* The collection id input to create a new submission
|
||||
* @type {string}
|
||||
*/
|
||||
public collectionParam: string;
|
||||
|
||||
/**
|
||||
* The submission self url
|
||||
* @type {string}
|
||||
@@ -60,13 +66,18 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit {
|
||||
* @param {Router} router
|
||||
* @param {TranslateService} translate
|
||||
* @param {ViewContainerRef} viewContainerRef
|
||||
* @param {ActivatedRoute} route
|
||||
*/
|
||||
constructor(private changeDetectorRef: ChangeDetectorRef,
|
||||
private notificationsService: NotificationsService,
|
||||
private router: Router,
|
||||
private submissionService: SubmissionService,
|
||||
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() {
|
||||
// NOTE execute the code on the browser side only, otherwise it is executed twice
|
||||
this.subs.push(
|
||||
this.submissionService.createSubmission()
|
||||
this.submissionService.createSubmission(this.collectionParam)
|
||||
.subscribe((submissionObject: SubmissionObject) => {
|
||||
// NOTE new submission is created on the browser side only
|
||||
if (isNotNull(submissionObject)) {
|
||||
|
Reference in New Issue
Block a user