mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 04:53:06 +00:00
54472: refactoring feedback pt1
This commit is contained in:
@@ -12,6 +12,7 @@ import { Observable } from 'rxjs/Observable';
|
||||
import { ResponseCacheEntry } from '../../core/cache/response-cache.reducer';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { isNotEmpty } from '../../shared/empty.util';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-create-collection',
|
||||
@@ -27,37 +28,34 @@ export class CreateCollectionPageComponent {
|
||||
public constructor(private collectionDataService: CollectionDataService, private communityDataService: CommunityDataService, private routeService: RouteService, private router: Router) {
|
||||
this.parentUUID$ = this.routeService.getQueryParameterValue('parent');
|
||||
this.parentUUID$.subscribe((uuid: string) => {
|
||||
this.communityRDObs = this.communityDataService.findById(uuid);
|
||||
if (isNotEmpty(uuid)) {
|
||||
this.communityRDObs = this.communityDataService.findById(uuid);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onSubmit(data: any) {
|
||||
const collection = Object.assign(new Collection(), {
|
||||
name: data.name,
|
||||
metadata: [
|
||||
{ key: 'dc.description', value: data.introductory },
|
||||
{ key: 'dc.description.abstract', value: data.description },
|
||||
{ key: 'dc.rights', value: data.copyright },
|
||||
{ key: 'dc.rights.license', value: data.license }
|
||||
// TODO: metadata for news and provenance
|
||||
]
|
||||
});
|
||||
this.parentUUID$.subscribe((uuid: string) => {
|
||||
let response$: Observable<ResponseCacheEntry>;
|
||||
if (uuid) {
|
||||
response$ = this.collectionDataService.create(collection, uuid);
|
||||
} else {
|
||||
response$ = this.collectionDataService.create(collection);
|
||||
}
|
||||
this.error$ = response$.pipe(
|
||||
map((response: ResponseCacheEntry) => {
|
||||
if (!response.response.isSuccessful && response.response instanceof ErrorResponse) {
|
||||
return response.response;
|
||||
} else if (response.response instanceof DSOSuccessResponse) {
|
||||
this.router.navigateByUrl('');
|
||||
}
|
||||
})
|
||||
);
|
||||
const collection = Object.assign(new Collection(), {
|
||||
name: data.name,
|
||||
metadata: [
|
||||
{ key: 'dc.description', value: data.introductory },
|
||||
{ key: 'dc.description.abstract', value: data.description },
|
||||
{ key: 'dc.rights', value: data.copyright },
|
||||
{ key: 'dc.rights.license', value: data.license }
|
||||
// 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<Collection>) => {
|
||||
console.log(rd);
|
||||
if (rd.hasSucceeded) {
|
||||
this.router.navigateByUrl('');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user