diff --git a/resources/i18n/en.json b/resources/i18n/en.json
index 963dfae80f..af9d1a08c8 100644
--- a/resources/i18n/en.json
+++ b/resources/i18n/en.json
@@ -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": {
diff --git a/src/app/+collection-page/create-collection-page/create-collection-page.component.html b/src/app/+collection-page/create-collection-page/create-collection-page.component.html
index 53a55571f6..9cf01f7c88 100644
--- a/src/app/+collection-page/create-collection-page/create-collection-page.component.html
+++ b/src/app/+collection-page/create-collection-page/create-collection-page.component.html
@@ -1,8 +1,15 @@
+
+
{{error.statusCode}}
+
{{error.errorMessage}}
+
diff --git a/src/app/+collection-page/create-collection-page/create-collection-page.component.ts b/src/app/+collection-page/create-collection-page/create-collection-page.component.ts
index 689bd30dfc..2e8d9b557d 100644
--- a/src/app/+collection-page/create-collection-page/create-collection-page.component.ts
+++ b/src/app/+collection-page/create-collection-page/create-collection-page.component.ts
@@ -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;
+ private parentUUID$: Observable;
+ private communityRDObs: Observable>;
+ 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;
+ 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('');
+ }
+ })
+ );
+ });
}
}
diff --git a/src/app/+community-page/create-community-page/create-community-page.component.html b/src/app/+community-page/create-community-page/create-community-page.component.html
index ea270db92b..53ca4f5020 100644
--- a/src/app/+community-page/create-community-page/create-community-page.component.html
+++ b/src/app/+community-page/create-community-page/create-community-page.component.html
@@ -1,8 +1,15 @@
+
+
{{error.statusCode}}
+
{{error.errorMessage}}
+
diff --git a/src/app/+community-page/create-community-page/create-community-page.component.ts b/src/app/+community-page/create-community-page/create-community-page.component.ts
index 255d88c21b..1da0299e66 100644
--- a/src/app/+community-page/create-community-page/create-community-page.component.ts
+++ b/src/app/+community-page/create-community-page/create-community-page.component.ts
@@ -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;
+ private parentUUID$: Observable;
+ private communityRDObs: Observable>;
+ 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;
+ 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('');
+ }
+ })
+ );
+ });
}
}
diff --git a/src/app/core/data/collection-data.service.ts b/src/app/core/data/collection-data.service.ts
index 765cba0a8b..70c11ca5fc 100644
--- a/src/app/core/data/collection-data.service.ts
+++ b/src/app/core/data/collection-data.service.ts
@@ -31,8 +31,4 @@ export class CollectionDataService extends ComColDataService {
+ return this.halService.getEndpoint(this.linkPath).pipe(
isNotEmptyOperator(),
distinctUntilChanged(),
map((endpointURL: string) => {
@@ -75,12 +75,22 @@ export abstract class ComColDataService 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;
+ }
+ }
}
diff --git a/src/app/core/data/community-data.service.ts b/src/app/core/data/community-data.service.ts
index acc915c093..9d6af5ee6f 100644
--- a/src/app/core/data/community-data.service.ts
+++ b/src/app/core/data/community-data.service.ts
@@ -34,8 +34,4 @@ export class CommunityDataService extends ComColDataService