mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-14 05:23:06 +00:00
54472: Passing parent as parameter and fixed duplicate collection created
This commit is contained in:
@@ -10,7 +10,7 @@ import { Router } from '@angular/router';
|
|||||||
import { DSOSuccessResponse, ErrorResponse } from '../../core/cache/response-cache.models';
|
import { DSOSuccessResponse, ErrorResponse } from '../../core/cache/response-cache.models';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { ResponseCacheEntry } from '../../core/cache/response-cache.reducer';
|
import { ResponseCacheEntry } from '../../core/cache/response-cache.reducer';
|
||||||
import { map } from 'rxjs/operators';
|
import { map, take } from 'rxjs/operators';
|
||||||
import { RemoteData } from '../../core/data/remote-data';
|
import { RemoteData } from '../../core/data/remote-data';
|
||||||
import { isNotEmpty } from '../../shared/empty.util';
|
import { isNotEmpty } from '../../shared/empty.util';
|
||||||
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
||||||
@@ -36,7 +36,7 @@ export class CreateCollectionPageComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSubmit(data: any) {
|
onSubmit(data: any) {
|
||||||
this.parentUUID$.subscribe((uuid: string) => {
|
this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => {
|
||||||
const collection = Object.assign(new Collection(), {
|
const collection = Object.assign(new Collection(), {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
metadata: [
|
metadata: [
|
||||||
@@ -45,20 +45,13 @@ export class CreateCollectionPageComponent {
|
|||||||
{ key: 'dc.rights', value: data.copyright },
|
{ key: 'dc.rights', value: data.copyright },
|
||||||
{ key: 'dc.rights.license', value: data.license }
|
{ key: 'dc.rights.license', value: data.license }
|
||||||
// TODO: metadata for news and provenance
|
// TODO: metadata for news and provenance
|
||||||
],
|
]
|
||||||
owner: Observable.of(new RemoteData(false, false, true, null, Object.assign(new Community(), {
|
|
||||||
id: uuid,
|
|
||||||
uuid: uuid
|
|
||||||
})))
|
|
||||||
});
|
});
|
||||||
this.collectionDataService.create(collection).subscribe((rd: RemoteData<DSpaceObject>) => {
|
this.collectionDataService.create(collection, uuid).pipe(take(1)).subscribe((rd: RemoteData<DSpaceObject>) => {
|
||||||
if (rd.hasSucceeded) {
|
if (rd.hasSucceeded) {
|
||||||
this.router.navigateByUrl('');
|
this.router.navigateByUrl('');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// this.collectionDataService.createSimple(collection).subscribe((httpEvent: HttpEvent<{}>) => {
|
|
||||||
// console.log(httpEvent);
|
|
||||||
// });
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,7 +30,7 @@ export class CreateCommunityPageComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSubmit(data: any) {
|
onSubmit(data: any) {
|
||||||
this.parentUUID$.subscribe((uuid: string) => {
|
this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => {
|
||||||
const community = Object.assign(new Community(), {
|
const community = Object.assign(new Community(), {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
metadata: [
|
metadata: [
|
||||||
@@ -38,13 +38,9 @@ export class CreateCommunityPageComponent {
|
|||||||
{ key: 'dc.description.abstract', value: data.description },
|
{ key: 'dc.description.abstract', value: data.description },
|
||||||
{ key: 'dc.rights', value: data.copyright }
|
{ key: 'dc.rights', value: data.copyright }
|
||||||
// TODO: metadata for news
|
// TODO: metadata for news
|
||||||
],
|
]
|
||||||
owner: Observable.of(new RemoteData(false, false, true, null, Object.assign(new Community(), {
|
|
||||||
id: uuid,
|
|
||||||
uuid: uuid
|
|
||||||
})))
|
|
||||||
});
|
});
|
||||||
this.communityDataService.create(community).pipe(take(1)).subscribe((rd: RemoteData<DSpaceObject>) => {
|
this.communityDataService.create(community, uuid).pipe(take(1)).subscribe((rd: RemoteData<DSpaceObject>) => {
|
||||||
if (rd.hasSucceeded) {
|
if (rd.hasSucceeded) {
|
||||||
this.router.navigateByUrl('');
|
this.router.navigateByUrl('');
|
||||||
}
|
}
|
||||||
|
@@ -66,25 +66,20 @@ export abstract class ComColDataService<TNormalized extends NormalizedObject, TD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public buildCreateBody(comcol): Observable<any> {
|
public buildFormData(comcol, parentUUID): FormData {
|
||||||
return comcol.owner.pipe(
|
const form: FormData = new FormData();
|
||||||
map((rd: RemoteData<Community | Collection>) => {
|
form.append('name', comcol.name);
|
||||||
const form: any = {
|
if (isNotEmpty(parentUUID)) {
|
||||||
name: comcol.name
|
form.append('parent', parentUUID);
|
||||||
};
|
}
|
||||||
if (rd.payload.id) {
|
if (comcol.metadata) {
|
||||||
form.parent = rd.payload.id;
|
for (const i of Object.keys(comcol.metadata)) {
|
||||||
|
if (isNotEmpty(comcol.metadata[i].value)) {
|
||||||
|
form.append(comcol.metadata[i].key, comcol.metadata[i].value);
|
||||||
}
|
}
|
||||||
if (comcol.metadata) {
|
}
|
||||||
for (const i of Object.keys(comcol.metadata)) {
|
}
|
||||||
if (isNotEmpty(comcol.metadata[i].value)) {
|
return form;
|
||||||
form[comcol.metadata[i].key] = comcol.metadata[i].value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return form;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -117,7 +117,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
|
|||||||
return this.rdbService.buildSingle<TNormalized, TDomain>(href);
|
return this.rdbService.buildSingle<TNormalized, TDomain>(href);
|
||||||
}
|
}
|
||||||
|
|
||||||
public create(dso: TDomain): Observable<RemoteData<TDomain>> {
|
public create(dso: TDomain, parentUUID: string): Observable<RemoteData<TDomain>> {
|
||||||
const requestId = this.requestService.generateRequestId();
|
const requestId = this.requestService.generateRequestId();
|
||||||
const endpoint$ = this.halService.getEndpoint(this.linkPath).pipe(
|
const endpoint$ = this.halService.getEndpoint(this.linkPath).pipe(
|
||||||
isNotEmptyOperator(),
|
isNotEmptyOperator(),
|
||||||
@@ -126,8 +126,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
|
|||||||
|
|
||||||
const request$ = endpoint$.pipe(
|
const request$ = endpoint$.pipe(
|
||||||
take(1),
|
take(1),
|
||||||
withLatestFrom(this.buildCreateBody(dso)),
|
map((endpoint: string) => new CreateRequest(requestId, endpoint, this.buildFormData(dso, parentUUID))),
|
||||||
map(([endpoint, formdata]) => new CreateRequest(requestId, endpoint, this.buildFormData(formdata))),
|
|
||||||
configureRequest(this.requestService)
|
configureRequest(this.requestService)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -154,31 +153,6 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
|
|||||||
return this.rdbService.toRemoteDataObservable(requestEntry$, responseCache$, payload$);
|
return this.rdbService.toRemoteDataObservable(requestEntry$, responseCache$, payload$);
|
||||||
}
|
}
|
||||||
|
|
||||||
public createSimple(dso: TDomain): Observable<HttpEvent<{}>> {
|
public abstract buildFormData(dso: TDomain, parentUUID: string): FormData;
|
||||||
const endpoint$ = this.halService.getEndpoint(this.linkPath).pipe(
|
|
||||||
isNotEmptyOperator(),
|
|
||||||
distinctUntilChanged()
|
|
||||||
);
|
|
||||||
|
|
||||||
return endpoint$.pipe(
|
|
||||||
withLatestFrom(this.buildCreateBody(dso)),
|
|
||||||
switchMap(([endpoint, form]) => {
|
|
||||||
const req = new HttpRequest('POST', endpoint, this.buildFormData(form));
|
|
||||||
return this.http.request(req);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract buildCreateBody(dso: TDomain): Observable<any>;
|
|
||||||
|
|
||||||
protected buildFormData(form: any): FormData {
|
|
||||||
const formdata = new FormData();
|
|
||||||
for (const param in form) {
|
|
||||||
if (form.hasOwnProperty(param)) {
|
|
||||||
formdata.append(param, form[param]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return formdata;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -38,7 +38,7 @@ class DataServiceImpl extends DataService<NormalizedDSpaceObject, DSpaceObject>
|
|||||||
return endpoint.replace(/\{\?uuid\}/,`?uuid=${resourceID}`);
|
return endpoint.replace(/\{\?uuid\}/,`?uuid=${resourceID}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
buildCreateBody(dso: DSpaceObject): Observable<FormData> {
|
buildFormData(dso: DSpaceObject, parentUUID: string): FormData {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -47,8 +47,8 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildCreateBody(dso: Item): Observable<FormData> {
|
buildFormData(dso: Item, parentUUID: string): FormData {
|
||||||
// TODO: Build http body for creating an Item on the REST service
|
// TODO: build FormData for creating an Item
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user