Skip to content

Commit 9c23b4c

Browse files
authored
Merge pull request #3164 from sistedes/config-default-comcol-tab
Make the default tab for browsing communities and collections configurable in DSpace 8
2 parents 8086c22 + 422a714 commit 9c23b4c

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
@@ -355,12 +355,20 @@ item:
355355

356356
# Community Page Config
357357
community:
358+
# Default tab to be shown when browsing a Community. Valid values are: comcols, search, or browse_<field>
359+
# <field> must be any of the configured "browse by" fields, e.g., dateissued, author, title, or subject
360+
# When the default tab is not the 'search' tab, the search tab is moved to the last position
361+
defaultBrowseTab: search
358362
# Search tab config
359363
searchSection:
360364
showSidebar: true
361365

362366
# Collection Page Config
363367
collection:
368+
# Default tab to be shown when browsing a Collection. Valid values are: search, or browse_<field>
369+
# <field> must be any of the configured "browse by" fields, e.g., dateissued, author, title, or subject
370+
# When the default tab is not the 'search' tab, the search tab is moved to the last position
371+
defaultBrowseTab: search
364372
# Search tab config
365373
searchSection:
366374
showSidebar: true

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ export const ROUTES: Route[] = [
9191
pathMatch: 'full',
9292
component: ComcolSearchSectionComponent,
9393
},
94+
{
95+
path: 'search',
96+
pathMatch: 'full',
97+
component: ComcolSearchSectionComponent,
98+
resolve: {
99+
breadcrumb: i18nBreadcrumbResolver,
100+
},
101+
data: { breadcrumbKey: 'collection.search' },
102+
},
94103
{
95104
path: 'browse/:id',
96105
pathMatch: 'full',

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ export const ROUTES: Route[] = [
7878
pathMatch: 'full',
7979
component: ComcolSearchSectionComponent,
8080
},
81+
{
82+
path: 'search',
83+
pathMatch: 'full',
84+
component: ComcolSearchSectionComponent,
85+
resolve: {
86+
breadcrumb: i18nBreadcrumbResolver,
87+
},
88+
data: { breadcrumbKey: 'community.search' },
89+
},
8190
{
8291
path: 'subcoms-cols',
8392
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
@@ -1,6 +1,7 @@
11
import { AsyncPipe } from '@angular/common';
22
import {
33
Component,
4+
Inject,
45
Input,
56
OnDestroy,
67
OnInit,
@@ -29,6 +30,10 @@ import {
2930
take,
3031
} from 'rxjs/operators';
3132

33+
import {
34+
APP_CONFIG,
35+
AppConfig,
36+
} from '../../../../config/app-config.interface';
3237
import { getCollectionPageRoute } from '../../../collection-page/collection-page-routing-paths';
3338
import { getCommunityPageRoute } from '../../../community-page/community-page-routing-paths';
3439
import { BrowseService } from '../../../core/browse/browse.service';
@@ -76,6 +81,7 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
7681
subs: Subscription[] = [];
7782

7883
constructor(
84+
@Inject(APP_CONFIG) public appConfig: AppConfig,
7985
public router: Router,
8086
private browseService: BrowseService,
8187
) {
@@ -93,14 +99,14 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
9399
allOptions.push({
94100
id: 'search',
95101
label: 'collection.page.browse.search.head',
96-
routerLink: comColRoute,
102+
routerLink: `${comColRoute}/search`,
97103
});
98104
} else if (this.contentType === 'community') {
99105
comColRoute = getCommunityPageRoute(this.id);
100106
allOptions.push({
101107
id: 'search',
102108
label: 'collection.page.browse.search.head',
103-
routerLink: comColRoute,
109+
routerLink: `${comColRoute}/search`,
104110
});
105111
allOptions.push({
106112
id: 'comcols',
@@ -114,11 +120,24 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
114120
label: `browse.comcol.by.${config.id}`,
115121
routerLink: `${comColRoute}/browse/${config.id}`,
116122
})));
123+
124+
// When the default tab is not the "search" tab, the "search" tab is moved
125+
// at the end of the tabs ribbon for aesthetics purposes.
126+
if (this.appConfig[this.contentType].defaultBrowseTab !== 'search') {
127+
allOptions.push(allOptions.shift());
128+
}
117129
}
118130
return allOptions;
119131
}),
120132
);
121133

134+
let comColRoute: string;
135+
if (this.contentType === 'collection') {
136+
comColRoute = getCollectionPageRoute(this.id);
137+
} else if (this.contentType === 'community') {
138+
comColRoute = getCommunityPageRoute(this.id);
139+
}
140+
122141
this.subs.push(combineLatest([
123142
this.allOptions$,
124143
this.router.events.pipe(
@@ -129,11 +148,29 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit {
129148
),
130149
]).subscribe(([navOptions, url]: [ComColPageNavOption[], string]) => {
131150
for (const option of navOptions) {
132-
if (option.routerLink === url?.split('?')[0]) {
151+
if (url?.split('?')[0] === comColRoute && option.id === this.appConfig[this.contentType].defaultBrowseTab) {
152+
void this.router.navigate([option.routerLink], { queryParams: option.params });
153+
break;
154+
} else if (option.routerLink === url?.split('?')[0]) {
133155
this.currentOption$.next(option);
156+
break;
134157
}
135158
}
136159
}));
160+
161+
if (this.router.url?.split('?')[0] === comColRoute) {
162+
this.allOptions$.pipe(
163+
take(1),
164+
).subscribe((allOptions: ComColPageNavOption[]) => {
165+
for (const option of allOptions) {
166+
if (option.id === this.appConfig[this.contentType].defaultBrowseTab) {
167+
this.currentOption$.next(option[0]);
168+
void this.router.navigate([option.routerLink], { queryParams: option.params });
169+
break;
170+
}
171+
}
172+
});
173+
}
137174
}
138175

139176
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
@@ -1338,6 +1338,8 @@
13381338

13391339
"collection.page.news": "News",
13401340

1341+
"collection.search.breadcrumbs": "Search",
1342+
13411343
"collection.search.results.head": "Search Results",
13421344

13431345
"collection.select.confirm": "Confirm selected",
@@ -1576,6 +1578,8 @@
15761578

15771579
"community.all-lists.head": "Subcommunities and Collections",
15781580

1581+
"community.search.breadcrumbs": "Search",
1582+
15791583
"community.search.results.head": "Search Results",
15801584

15811585
"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
@@ -337,13 +337,15 @@ export class DefaultAppConfig implements AppConfig {
337337

338338
// Community Page Config
339339
community: CommunityPageConfig = {
340+
defaultBrowseTab: 'search',
340341
searchSection: {
341342
showSidebar: true,
342343
},
343344
};
344345

345346
// Collection Page Config
346347
collection: CollectionPageConfig = {
348+
defaultBrowseTab: 'search',
347349
searchSection: {
348350
showSidebar: true,
349351
},

0 commit comments

Comments
 (0)