Skip to content

Commit 8a3a202

Browse files
committed
make the default tab for browsing communities and collections configurable
1 parent fde7e46 commit 8a3a202

File tree

11 files changed

+78
-4
lines changed

11 files changed

+78
-4
lines changed

config/config.example.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,20 @@ item:
367367

368368
# Community Page Config
369369
community:
370+
# Default tab to be shown when browsing a Community. Valid values are: comcols, search, or browse_<field>
371+
# <field> must be any of the configured "browse by" fields, e.g., dateissued, author, title, or subject
372+
# When the default tab is not the 'search' tab, the search tab is moved to the last position
373+
defaultBrowseTab: search
370374
# Search tab config
371375
searchSection:
372376
showSidebar: true
373377

374378
# Collection Page Config
375379
collection:
380+
# Default tab to be shown when browsing a Collection. Valid values are: search, or browse_<field>
381+
# <field> must be any of the configured "browse by" fields, e.g., dateissued, author, title, or subject
382+
# When the default tab is not the 'search' tab, the search tab is moved to the last position
383+
defaultBrowseTab: search
376384
# Search tab config
377385
searchSection:
378386
showSidebar: true

src/app/collection-page/collection-page-routes.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ export const ROUTES: Route[] = [
9393
pathMatch: 'full',
9494
component: ComcolSearchSectionComponent,
9595
},
96+
{
97+
path: 'search',
98+
pathMatch: 'full',
99+
component: ComcolSearchSectionComponent,
100+
resolve: {
101+
breadcrumb: i18nBreadcrumbResolver,
102+
},
103+
data: { breadcrumbKey: 'collection.search' },
104+
},
96105
{
97106
path: 'browse/:id',
98107
pathMatch: 'full',

src/app/community-page/community-page-routes.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ export const ROUTES: Route[] = [
8080
pathMatch: 'full',
8181
component: ComcolSearchSectionComponent,
8282
},
83+
{
84+
path: 'search',
85+
pathMatch: 'full',
86+
component: ComcolSearchSectionComponent,
87+
resolve: {
88+
breadcrumb: i18nBreadcrumbResolver,
89+
},
90+
data: { breadcrumbKey: 'community.search' },
91+
},
8392
{
8493
path: 'subcoms-cols',
8594
pathMatch: 'full',

src/app/shared/comcol/comcol-page-browse-by/comcol-page-browse-by.component.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '@angular/common';
66
import {
77
Component,
8+
Inject,
89
Input,
910
OnDestroy,
1011
OnInit,
@@ -33,6 +34,10 @@ import {
3334
take,
3435
} from 'rxjs/operators';
3536

37+
import {
38+
APP_CONFIG,
39+
AppConfig,
40+
} from '../../../../config/app-config.interface';
3641
import { getCollectionPageRoute } from '../../../collection-page/collection-page-routing-paths';
3742
import { getCommunityPageRoute } from '../../../community-page/community-page-routing-paths';
3843
import { BrowseService } from '../../../core/browse/browse.service';
@@ -82,6 +87,7 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
8287
subs: Subscription[] = [];
8388

8489
constructor(
90+
@Inject(APP_CONFIG) public appConfig: AppConfig,
8591
public router: Router,
8692
private browseService: BrowseService,
8793
) {
@@ -99,14 +105,14 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
99105
allOptions.push({
100106
id: 'search',
101107
label: 'collection.page.browse.search.head',
102-
routerLink: comColRoute,
108+
routerLink: `${comColRoute}/search`,
103109
});
104110
} else if (this.contentType === 'community') {
105111
comColRoute = getCommunityPageRoute(this.id);
106112
allOptions.push({
107113
id: 'search',
108114
label: 'collection.page.browse.search.head',
109-
routerLink: comColRoute,
115+
routerLink: `${comColRoute}/search`,
110116
});
111117
allOptions.push({
112118
id: 'comcols',
@@ -120,11 +126,24 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
120126
label: `browse.comcol.by.${config.id}`,
121127
routerLink: `${comColRoute}/browse/${config.id}`,
122128
})));
129+
130+
// When the default tab is not the "search" tab, the "search" tab is moved
131+
// at the end of the tabs ribbon for aesthetics purposes.
132+
if (this.appConfig[this.contentType].defaultBrowseTab !== 'search') {
133+
allOptions.push(allOptions.shift());
134+
}
123135
}
124136
return allOptions;
125137
}),
126138
);
127139

140+
let comColRoute: string;
141+
if (this.contentType === 'collection') {
142+
comColRoute = getCollectionPageRoute(this.id);
143+
} else if (this.contentType === 'community') {
144+
comColRoute = getCommunityPageRoute(this.id);
145+
}
146+
128147
this.subs.push(combineLatest([
129148
this.allOptions$,
130149
this.router.events.pipe(
@@ -135,11 +154,29 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
135154
),
136155
]).subscribe(([navOptions, url]: [ComColPageNavOption[], string]) => {
137156
for (const option of navOptions) {
138-
if (option.routerLink === url?.split('?')[0]) {
157+
if (url?.split('?')[0] === comColRoute && option.id === this.appConfig[this.contentType].defaultBrowseTab) {
158+
void this.router.navigate([option.routerLink], { queryParams: option.params });
159+
break;
160+
} else if (option.routerLink === url?.split('?')[0]) {
139161
this.currentOption$.next(option);
162+
break;
140163
}
141164
}
142165
}));
166+
167+
if (this.router.url?.split('?')[0] === comColRoute) {
168+
this.allOptions$.pipe(
169+
take(1),
170+
).subscribe((allOptions: ComColPageNavOption[]) => {
171+
for (const option of allOptions) {
172+
if (option.id === this.appConfig[this.contentType].defaultBrowseTab) {
173+
this.currentOption$.next(option[0]);
174+
void this.router.navigate([option.routerLink], { queryParams: option.params });
175+
break;
176+
}
177+
}
178+
});
179+
}
143180
}
144181

145182
ngOnDestroy(): void {

src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('ComcolSearchSectionComponent', () => {
1818

1919
beforeEach(async () => {
2020
route = new ActivatedRouteStub();
21+
route.parent = new ActivatedRouteStub();
2122

2223
await TestBed.configureTestingModule({
2324
imports: [ComcolSearchSectionComponent],

src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class ComcolSearchSectionComponent implements OnInit {
5555
}
5656

5757
ngOnInit(): void {
58-
this.comcol$ = this.route.data.pipe(
58+
this.comcol$ = this.route.parent.data.pipe(
5959
map((data: Data) => (data.dso as RemoteData<Community | Collection>).payload),
6060
);
6161
this.showSidebar$ = this.comcol$.pipe(

src/assets/i18n/en.json5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,8 @@
13231323

13241324
"collection.page.news": "News",
13251325

1326+
"collection.search.breadcrumbs": "Search",
1327+
13261328
"collection.search.results.head": "Search Results",
13271329

13281330
"collection.select.confirm": "Confirm selected",
@@ -1561,6 +1563,8 @@
15611563

15621564
"community.all-lists.head": "Subcommunities and Collections",
15631565

1566+
"community.search.breadcrumbs": "Search",
1567+
15641568
"community.search.results.head": "Search Results",
15651569

15661570
"community.sub-collection-list.head": "Collections in this Community",

src/config/collection-page-config.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Config } from './config.interface';
44
* Collection Page Config
55
*/
66
export interface CollectionPageConfig extends Config {
7+
defaultBrowseTab: string;
78
searchSection: CollectionSearchSectionConfig;
89
edit: {
910
undoTimeout: number;

src/config/community-page-config.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Config } from './config.interface';
44
* Community Page Config
55
*/
66
export interface CommunityPageConfig extends Config {
7+
defaultBrowseTab: string;
78
searchSection: CommunitySearchSectionConfig;
89
}
910

src/config/default-app-config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,15 @@ export class DefaultAppConfig implements AppConfig {
334334

335335
// Community Page Config
336336
community: CommunityPageConfig = {
337+
defaultBrowseTab: 'search',
337338
searchSection: {
338339
showSidebar: true,
339340
},
340341
};
341342

342343
// Collection Page Config
343344
collection: CollectionPageConfig = {
345+
defaultBrowseTab: 'search',
344346
searchSection: {
345347
showSidebar: true,
346348
},

0 commit comments

Comments
 (0)