mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Changed DataService's create method in the way to accept array of request params
This commit is contained in:
@@ -152,6 +152,33 @@ export abstract class DataService<T extends CacheableObject> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn an array of RequestParam into a query string and combine it with the given HREF
|
||||
*
|
||||
* @param href The HREF to which the query string should be appended
|
||||
* @param params Array with additional params to combine with query string
|
||||
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
|
||||
*
|
||||
* @return {Observable<string>}
|
||||
* Return an observable that emits created HREF
|
||||
*/
|
||||
protected buildHrefWithParams(href: string, params: RequestParam[], ...linksToFollow: Array<FollowLinkConfig<T>>): string {
|
||||
|
||||
let args = [];
|
||||
if (hasValue(params)) {
|
||||
params.forEach((param: RequestParam) => {
|
||||
args.push(`${param.fieldName}=${param.fieldValue}`);
|
||||
})
|
||||
}
|
||||
|
||||
args = this.addEmbedParams(args, ...linksToFollow);
|
||||
|
||||
if (isNotEmpty(args)) {
|
||||
return new URLCombiner(href, `?${args.join('&')}`).toString();
|
||||
} else {
|
||||
return href;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds the embed options to the link for the request
|
||||
* @param args params for the query string
|
||||
@@ -379,15 +406,15 @@ export abstract class DataService<T extends CacheableObject> {
|
||||
*
|
||||
* @param {DSpaceObject} dso
|
||||
* The object to create
|
||||
* @param {string} parentUUID
|
||||
* The UUID of the parent to create the new object under
|
||||
* @param {RequestParam[]} params
|
||||
* Array with additional params to combine with query string
|
||||
*/
|
||||
create(dso: T, parentUUID: string): Observable<RemoteData<T>> {
|
||||
create(dso: T, ...params: RequestParam[]): Observable<RemoteData<T>> {
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
const endpoint$ = this.halService.getEndpoint(this.linkPath).pipe(
|
||||
isNotEmptyOperator(),
|
||||
distinctUntilChanged(),
|
||||
map((endpoint: string) => parentUUID ? `${endpoint}?parent=${parentUUID}` : endpoint)
|
||||
map((endpoint: string) => this.buildHrefWithParams(endpoint, params))
|
||||
);
|
||||
|
||||
const serializedDso = new DSpaceSerializer(getClassForType((dso as any).type)).serialize(dso);
|
||||
|
@@ -13,6 +13,7 @@ import { getSucceededRemoteData } from '../../../core/shared/operators';
|
||||
import { ResourceType } from '../../../core/shared/resource-type';
|
||||
import { hasValue, isNotEmpty, isNotUndefined } from '../../empty.util';
|
||||
import { NotificationsService } from '../../notifications/notifications.service';
|
||||
import { RequestParam } from '../../../core/cache/models/request-param.model';
|
||||
|
||||
/**
|
||||
* Component representing the create page for communities and collections
|
||||
@@ -76,7 +77,7 @@ export class CreateComColPageComponent<TDomain extends DSpaceObject> implements
|
||||
const uploader = event.uploader;
|
||||
|
||||
this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => {
|
||||
this.dsoDataService.create(dso, uuid)
|
||||
this.dsoDataService.create(dso, new RequestParam('parent', uuid))
|
||||
.pipe(getSucceededRemoteData())
|
||||
.subscribe((dsoRD: RemoteData<TDomain>) => {
|
||||
if (isNotUndefined(dsoRD)) {
|
||||
|
Reference in New Issue
Block a user