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:
@@ -29,7 +29,8 @@
|
||||
}
|
||||
},
|
||||
"create": {
|
||||
"head": "Create a Collection"
|
||||
"head": "Create a Collection",
|
||||
"sub-head": "Create a Collection for Community {{ parent }}"
|
||||
}
|
||||
},
|
||||
"community": {
|
||||
@@ -53,7 +54,8 @@
|
||||
}
|
||||
},
|
||||
"create": {
|
||||
"head": "Create a Community"
|
||||
"head": "Create a Community",
|
||||
"sub-head": "Create a Sub-Community for Community {{ parent }}"
|
||||
}
|
||||
},
|
||||
"item": {
|
||||
|
@@ -1,8 +1,15 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12 pb-4">
|
||||
<h2 id="header" class="border-bottom pb-2">{{ 'collection.create.head' | translate }}</h2>
|
||||
<ng-container *ngVar="(communityRDObs | async).payload as community">
|
||||
<h2 *ngIf="!community" id="header" class="border-bottom pb-2">{{ 'collection.create.head' | translate }}</h2>
|
||||
<h2 *ngIf="community" id="sub-header" class="border-bottom pb-2">{{ 'collection.create.sub-head' | translate:{ parent: community.name } }}</h2>
|
||||
</ng-container>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="(error$ | async) as error" class="alert alert-danger">
|
||||
<strong>{{error.statusCode}}</strong>
|
||||
<p class="mb-0">{{error.errorMessage}}</p>
|
||||
</div>
|
||||
<ds-collection-form (submitted)="onSubmit($event)"></ds-collection-form>
|
||||
</div>
|
||||
|
@@ -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('');
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,8 +1,15 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12 pb-4">
|
||||
<h2 id="header" class="border-bottom pb-2">{{ 'community.create.head' | translate }}</h2>
|
||||
<ng-container *ngVar="(communityRDObs | async).payload as community">
|
||||
<h2 *ngIf="!community" id="header" class="border-bottom pb-2">{{ 'community.create.head' | translate }}</h2>
|
||||
<h2 *ngIf="community" id="sub-header" class="border-bottom pb-2">{{ 'community.create.sub-head' | translate:{ parent: community.name } }}</h2>
|
||||
</ng-container>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="(error$ | async) as error" class="alert alert-danger">
|
||||
<strong>{{error.statusCode}}</strong>
|
||||
<p class="mb-0">{{error.errorMessage}}</p>
|
||||
</div>
|
||||
<ds-community-form (submitted)="onSubmit($event)"></ds-community-form>
|
||||
</div>
|
||||
|
@@ -3,6 +3,13 @@ import { Community } from '../../core/shared/community.model';
|
||||
import { ComColDataService } from '../../core/data/comcol-data.service';
|
||||
import { NormalizedCommunity } from '../../core/cache/models/normalized-community.model';
|
||||
import { CommunityDataService } from '../../core/data/community-data.service';
|
||||
import { ResponseCacheEntry } from '../../core/cache/response-cache.reducer';
|
||||
import { DSOSuccessResponse, ErrorResponse, RestResponse } from '../../core/cache/response-cache.models';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { RouteService } from '../../shared/services/route.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-create-community',
|
||||
@@ -11,15 +18,38 @@ import { CommunityDataService } from '../../core/data/community-data.service';
|
||||
})
|
||||
export class CreateCommunityPageComponent {
|
||||
|
||||
public constructor(private communityDataService: CommunityDataService) {
|
||||
private error$: Observable<ErrorResponse>;
|
||||
private parentUUID$: Observable<string>;
|
||||
private communityRDObs: Observable<RemoteData<Community>>;
|
||||
|
||||
public constructor(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 community = Object.assign(new Community(), {
|
||||
name: data.name
|
||||
});
|
||||
this.communityDataService.create(community);
|
||||
this.parentUUID$.subscribe((uuid: string) => {
|
||||
let response$: Observable<ResponseCacheEntry>;
|
||||
if (uuid) {
|
||||
response$ = this.communityDataService.create(community, uuid);
|
||||
} else {
|
||||
response$ = this.communityDataService.create(community);
|
||||
}
|
||||
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('');
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -31,8 +31,4 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio
|
||||
super();
|
||||
}
|
||||
|
||||
buildCreateParams(collection: Collection) {
|
||||
const urlParams = '?name=' + collection.name;
|
||||
return urlParams;
|
||||
}
|
||||
}
|
||||
|
@@ -8,14 +8,14 @@ import { ResponseCacheEntry } from '../cache/response-cache.reducer';
|
||||
import { CommunityDataService } from './community-data.service';
|
||||
|
||||
import { DataService } from './data.service';
|
||||
import { FindByIDRequest, PostRequest, PutRequest } from './request.models';
|
||||
import { FindByIDRequest, PostRequest, PutRequest, RequestError, RestRequest } from './request.models';
|
||||
import { NormalizedObject } from '../cache/models/normalized-object.model';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||
import { Community } from '../shared/community.model';
|
||||
import { Collection } from '../shared/collection.model';
|
||||
import { distinctUntilChanged, map } from 'rxjs/operators';
|
||||
import { configureRequest } from '../shared/operators';
|
||||
import { catchError, distinctUntilChanged, map } from 'rxjs/operators';
|
||||
import { configureRequest, getResponseFromSelflink } from '../shared/operators';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
||||
import { HttpHeaders } from '@angular/common/http';
|
||||
@@ -66,8 +66,8 @@ export abstract class ComColDataService<TNormalized extends NormalizedObject, TD
|
||||
}
|
||||
}
|
||||
|
||||
public create(comcol: TDomain) {
|
||||
this.halService.getEndpoint(this.linkPath).pipe(
|
||||
public create(comcol: TDomain, parentUUID?: string): Observable<ResponseCacheEntry> {
|
||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||
isNotEmptyOperator(),
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) => {
|
||||
@@ -75,12 +75,22 @@ export abstract class ComColDataService<TNormalized extends NormalizedObject, TD
|
||||
const headers = new HttpHeaders();
|
||||
headers.append('Authentication', this.authService.buildAuthHeader());
|
||||
options.headers = headers;
|
||||
return new PostRequest(this.requestService.generateRequestId(), endpointURL + this.buildCreateParams(comcol));
|
||||
return new PostRequest(this.requestService.generateRequestId(), endpointURL + ((parentUUID) ? this.buildCreateParams(comcol, parentUUID) : this.buildCreateParams(comcol)));
|
||||
}),
|
||||
configureRequest(this.requestService)
|
||||
).subscribe();
|
||||
configureRequest(this.requestService),
|
||||
map((request: RestRequest) => request.href),
|
||||
getResponseFromSelflink(this.responseCache)
|
||||
);
|
||||
}
|
||||
|
||||
abstract buildCreateParams(comcol: TDomain): string;
|
||||
public buildCreateParams(comcol: TDomain, parentUUID?: string): string {
|
||||
if (comcol instanceof Community || comcol instanceof Collection) {
|
||||
let urlParams = '?name=' + comcol.name;
|
||||
if (parentUUID) {
|
||||
urlParams += '&parent=' + parentUUID;
|
||||
}
|
||||
return urlParams;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -34,8 +34,4 @@ export class CommunityDataService extends ComColDataService<NormalizedCommunity,
|
||||
return this.halService.getEndpoint(this.linkPath);
|
||||
}
|
||||
|
||||
buildCreateParams(community: Community) {
|
||||
const urlParams = '?name=' + community.name;
|
||||
return urlParams;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user