Skip to content

Commit 692bb99

Browse files
112970: Added missing breadcrumbs to create community/collection pages
1 parent ca86437 commit 692bb99

6 files changed

Lines changed: 82 additions & 10 deletions

File tree

src/app/collection-page/collection-page-routing.module.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,32 @@ import { CollectionPageAdministratorGuard } from './collection-page-administrato
2121
import { LinkMenuItemModel } from '../shared/menu/menu-item/models/link.model';
2222
import { ThemedCollectionPageComponent } from './themed-collection-page.component';
2323
import { MenuItemType } from '../shared/menu/menu-item-type.model';
24+
import { CommunityBreadcrumbResolver } from '../core/breadcrumbs/community-breadcrumb.resolver';
2425

2526
@NgModule({
2627
imports: [
2728
RouterModule.forChild([
2829
{
2930
path: COLLECTION_CREATE_PATH,
30-
component: CreateCollectionPageComponent,
31-
canActivate: [AuthenticatedGuard, CreateCollectionPageGuard]
31+
children: [
32+
{
33+
path: '',
34+
component: CreateCollectionPageComponent,
35+
resolve: {
36+
breadcrumb: I18nBreadcrumbResolver,
37+
},
38+
data: {
39+
breadcrumbKey: 'collection.create',
40+
},
41+
},
42+
],
43+
canActivate: [AuthenticatedGuard, CreateCollectionPageGuard],
44+
data: {
45+
breadcrumbQueryParam: 'parent',
46+
},
47+
resolve: {
48+
breadcrumb: CommunityBreadcrumbResolver,
49+
},
3250
},
3351
{
3452
path: ':id',
@@ -90,7 +108,8 @@ import { MenuItemType } from '../shared/menu/menu-item-type.model';
90108
DSOBreadcrumbsService,
91109
LinkService,
92110
CreateCollectionPageGuard,
93-
CollectionPageAdministratorGuard
111+
CollectionPageAdministratorGuard,
112+
CommunityBreadcrumbResolver,
94113
]
95114
})
96115
export class CollectionPageRoutingModule {

src/app/community-page/community-page-routing.module.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,32 @@ import { CommunityPageAdministratorGuard } from './community-page-administrator.
1414
import { LinkMenuItemModel } from '../shared/menu/menu-item/models/link.model';
1515
import { ThemedCommunityPageComponent } from './themed-community-page.component';
1616
import { MenuItemType } from '../shared/menu/menu-item-type.model';
17+
import { I18nBreadcrumbResolver } from '../core/breadcrumbs/i18n-breadcrumb.resolver';
1718

1819
@NgModule({
1920
imports: [
2021
RouterModule.forChild([
2122
{
2223
path: COMMUNITY_CREATE_PATH,
23-
component: CreateCommunityPageComponent,
24-
canActivate: [AuthenticatedGuard, CreateCommunityPageGuard]
24+
children: [
25+
{
26+
path: '',
27+
component: CreateCommunityPageComponent,
28+
resolve: {
29+
breadcrumb: I18nBreadcrumbResolver,
30+
},
31+
data: {
32+
breadcrumbKey: 'community.create',
33+
},
34+
}
35+
],
36+
canActivate: [AuthenticatedGuard, CreateCommunityPageGuard],
37+
data: {
38+
breadcrumbQueryParam: 'parent',
39+
},
40+
resolve: {
41+
breadcrumb: CommunityBreadcrumbResolver,
42+
},
2543
},
2644
{
2745
path: ':id',

src/app/core/breadcrumbs/community-breadcrumb.resolver.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { CommunityDataService } from '../data/community-data.service';
55
import { Community } from '../shared/community.model';
66
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
77
import { COMMUNITY_PAGE_LINKS_TO_FOLLOW } from '../../community-page/community-page.resolver';
8+
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
9+
import { Observable } from 'rxjs';
10+
import { BreadcrumbConfig } from '../../breadcrumbs/breadcrumb/breadcrumb-config.model';
11+
import { hasValue } from '../../shared/empty.util';
812

913
/**
1014
* The class that resolves the BreadcrumbConfig object for a Community
@@ -17,6 +21,23 @@ export class CommunityBreadcrumbResolver extends DSOBreadcrumbResolver<Community
1721
super(breadcrumbService, dataService);
1822
}
1923

24+
/**
25+
* Method to retrieve the breadcrumb config by the route id. It is also possible to retrieve the id through the
26+
* query parameters. This is done by defining the name of the query parameter in the data section under the property
27+
* breadcrumbQueryParam.
28+
*
29+
* @param route The current {@link ActivatedRouteSnapshot}
30+
* @param state The current {@link RouterStateSnapshot}
31+
* @returns BreadcrumbConfig object
32+
*/
33+
override resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<BreadcrumbConfig<Community>> {
34+
if (hasValue(route.data.breadcrumbQueryParam) && hasValue(route.queryParams[route.data.breadcrumbQueryParam])) {
35+
return this.resolveById(route.queryParams[route.data.breadcrumbQueryParam]);
36+
} else {
37+
return super.resolve(route, state);
38+
}
39+
}
40+
2041
/**
2142
* Method that returns the follow links to already resolve
2243
* The self links defined in this list are expected to be requested somewhere in the near future

src/app/core/breadcrumbs/dso-breadcrumb.resolver.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ describe('DSOBreadcrumbResolver', () => {
1818
uuid = '1234-65487-12354-1235';
1919
breadcrumbUrl = '/collections/' + uuid;
2020
currentUrl = breadcrumbUrl + '/edit';
21-
testCollection = Object.assign(new Collection(), { uuid });
21+
testCollection = Object.assign(new Collection(), {
22+
uuid: uuid,
23+
type: 'collection',
24+
});
2225
dsoBreadcrumbService = {};
2326
collectionService = {
2427
findById: (id: string) => createSuccessfulRemoteDataObject$(testCollection)

src/app/core/breadcrumbs/dso-breadcrumb.resolver.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ChildHALResource } from '../shared/child-hal-resource.model';
1010
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
1111
import { hasValue } from '../../shared/empty.util';
1212
import { IdentifiableDataService } from '../data/base/identifiable-data.service';
13+
import { getDSORoute } from '../../app-routing-paths';
1314

1415
/**
1516
* The class that resolves the BreadcrumbConfig object for a DSpaceObject
@@ -31,15 +32,22 @@ export abstract class DSOBreadcrumbResolver<T extends ChildHALResource & DSpaceO
3132
* @returns BreadcrumbConfig object
3233
*/
3334
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<BreadcrumbConfig<T>> {
34-
const uuid = route.params.id;
35+
return this.resolveById(route.params.id);
36+
}
37+
38+
/**
39+
* Method for resolving a breadcrumb by id
40+
*
41+
* @param uuid The uuid to resolve
42+
* @returns BreadcrumbConfig object
43+
*/
44+
resolveById(uuid: string): Observable<BreadcrumbConfig<T>> {
3545
return this.dataService.findById(uuid, true, false, ...this.followLinks).pipe(
3646
getFirstCompletedRemoteData(),
3747
getRemoteDataPayload(),
3848
map((object: T) => {
3949
if (hasValue(object)) {
40-
const fullPath = state.url;
41-
const url = fullPath.substr(0, fullPath.indexOf(uuid)) + uuid;
42-
return { provider: this.breadcrumbService, key: object, url: url };
50+
return { provider: this.breadcrumbService, key: object, url: getDSORoute(object) };
4351
} else {
4452
return undefined;
4553
}

src/assets/i18n/en.json5

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@
781781
"chips.remove": "Remove chip",
782782

783783

784+
"collection.create.breadcrumbs": "Create collection",
784785

785786
"collection.create.head": "Create a Collection",
786787

@@ -1053,6 +1054,8 @@
10531054

10541055

10551056

1057+
"community.create.breadcrumbs": "Create Community",
1058+
10561059
"community.create.head": "Create a Community",
10571060

10581061
"community.create.notifications.success": "Successfully created the Community",

0 commit comments

Comments
 (0)