mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
submit to this collection
This commit is contained in:
@@ -32,6 +32,13 @@
|
|||||||
</ds-comcol-page-content>
|
</ds-comcol-page-content>
|
||||||
|
|
||||||
</header>
|
</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">
|
<section class="comcol-page-browse-section">
|
||||||
<!-- Browse-By Links -->
|
<!-- Browse-By Links -->
|
||||||
<ds-comcol-page-browse-by
|
<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 { 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)),
|
||||||
|
@@ -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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -109,11 +109,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]),
|
map((workspaceitem: SubmissionObject) => workspaceitem[0]),
|
||||||
catchError(() => observableOf({})))
|
catchError(() => observableOf({})))
|
||||||
}
|
}
|
||||||
|
@@ -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]
|
||||||
|
@@ -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)) {
|
||||||
|
Reference in New Issue
Block a user