mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
54472: Create community/collection with parent community + error messages
This commit is contained in:
@@ -5,6 +5,13 @@ import { NormalizedCommunity } from '../../core/cache/models/normalized-communit
|
||||
import { CommunityDataService } from '../../core/data/community-data.service';
|
||||
import { CollectionDataService } from '../../core/data/collection-data.service';
|
||||
import { Collection } from '../../core/shared/collection.model';
|
||||
import { RouteService } from '../../shared/services/route.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { DSOSuccessResponse, ErrorResponse } from '../../core/cache/response-cache.models';
|
||||
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';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-create-collection',
|
||||
@@ -13,15 +20,38 @@ import { Collection } from '../../core/shared/collection.model';
|
||||
})
|
||||
export class CreateCollectionPageComponent {
|
||||
|
||||
public constructor(private collectionDataService: CollectionDataService) {
|
||||
private error$: Observable<ErrorResponse>;
|
||||
private parentUUID$: Observable<string>;
|
||||
private communityRDObs: Observable<RemoteData<Community>>;
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
onSubmit(data: any) {
|
||||
const collection = Object.assign(new Collection(), {
|
||||
name: data.name
|
||||
});
|
||||
this.collectionDataService.create(collection);
|
||||
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('');
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user