diff --git a/config/config.example.yml b/config/config.example.yml index 57a3a21316..4554369da3 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -355,12 +355,20 @@ item: # Community Page Config community: + # Default tab to be shown when browsing a Community. Valid values are: comcols, search, or browse_ + # must be any of the configured "browse by" fields, e.g., dateissued, author, title, or subject + # When the default tab is not the 'search' tab, the search tab is moved to the last position + defaultBrowseTab: search # Search tab config searchSection: showSidebar: true # Collection Page Config collection: + # Default tab to be shown when browsing a Collection. Valid values are: search, or browse_ + # must be any of the configured "browse by" fields, e.g., dateissued, author, title, or subject + # When the default tab is not the 'search' tab, the search tab is moved to the last position + defaultBrowseTab: search # Search tab config searchSection: showSidebar: true diff --git a/src/app/collection-page/collection-page-routes.ts b/src/app/collection-page/collection-page-routes.ts index e20e3ba8af..2606293bfd 100644 --- a/src/app/collection-page/collection-page-routes.ts +++ b/src/app/collection-page/collection-page-routes.ts @@ -91,6 +91,15 @@ export const ROUTES: Route[] = [ pathMatch: 'full', component: ComcolSearchSectionComponent, }, + { + path: 'search', + pathMatch: 'full', + component: ComcolSearchSectionComponent, + resolve: { + breadcrumb: i18nBreadcrumbResolver, + }, + data: { breadcrumbKey: 'collection.search' }, + }, { path: 'browse/:id', pathMatch: 'full', diff --git a/src/app/community-page/community-page-routes.ts b/src/app/community-page/community-page-routes.ts index 2c8a7942a4..5b2a8f8133 100644 --- a/src/app/community-page/community-page-routes.ts +++ b/src/app/community-page/community-page-routes.ts @@ -78,6 +78,15 @@ export const ROUTES: Route[] = [ pathMatch: 'full', component: ComcolSearchSectionComponent, }, + { + path: 'search', + pathMatch: 'full', + component: ComcolSearchSectionComponent, + resolve: { + breadcrumb: i18nBreadcrumbResolver, + }, + data: { breadcrumbKey: 'community.search' }, + }, { path: 'subcoms-cols', pathMatch: 'full', diff --git a/src/app/shared/comcol/comcol-page-browse-by/comcol-page-browse-by.component.ts b/src/app/shared/comcol/comcol-page-browse-by/comcol-page-browse-by.component.ts index 33b6d91e22..5b8f12a75d 100644 --- a/src/app/shared/comcol/comcol-page-browse-by/comcol-page-browse-by.component.ts +++ b/src/app/shared/comcol/comcol-page-browse-by/comcol-page-browse-by.component.ts @@ -1,6 +1,7 @@ import { AsyncPipe } from '@angular/common'; import { Component, + Inject, Input, OnDestroy, OnInit, @@ -29,6 +30,10 @@ import { take, } from 'rxjs/operators'; +import { + APP_CONFIG, + AppConfig, +} from '../../../../config/app-config.interface'; import { getCollectionPageRoute } from '../../../collection-page/collection-page-routing-paths'; import { getCommunityPageRoute } from '../../../community-page/community-page-routing-paths'; import { BrowseService } from '../../../core/browse/browse.service'; @@ -76,6 +81,7 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit { subs: Subscription[] = []; constructor( + @Inject(APP_CONFIG) public appConfig: AppConfig, public router: Router, private browseService: BrowseService, ) { @@ -93,14 +99,14 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit { allOptions.push({ id: 'search', label: 'collection.page.browse.search.head', - routerLink: comColRoute, + routerLink: `${comColRoute}/search`, }); } else if (this.contentType === 'community') { comColRoute = getCommunityPageRoute(this.id); allOptions.push({ id: 'search', label: 'collection.page.browse.search.head', - routerLink: comColRoute, + routerLink: `${comColRoute}/search`, }); allOptions.push({ id: 'comcols', @@ -114,11 +120,24 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit { label: `browse.comcol.by.${config.id}`, routerLink: `${comColRoute}/browse/${config.id}`, }))); + + // When the default tab is not the "search" tab, the "search" tab is moved + // at the end of the tabs ribbon for aesthetics purposes. + if (this.appConfig[this.contentType].defaultBrowseTab !== 'search') { + allOptions.push(allOptions.shift()); + } } return allOptions; }), ); + let comColRoute: string; + if (this.contentType === 'collection') { + comColRoute = getCollectionPageRoute(this.id); + } else if (this.contentType === 'community') { + comColRoute = getCommunityPageRoute(this.id); + } + this.subs.push(combineLatest([ this.allOptions$, this.router.events.pipe( @@ -129,11 +148,29 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit { ), ]).subscribe(([navOptions, url]: [ComColPageNavOption[], string]) => { for (const option of navOptions) { - if (option.routerLink === url?.split('?')[0]) { + if (url?.split('?')[0] === comColRoute && option.id === this.appConfig[this.contentType].defaultBrowseTab) { + void this.router.navigate([option.routerLink], { queryParams: option.params }); + break; + } else if (option.routerLink === url?.split('?')[0]) { this.currentOption$.next(option); + break; } } })); + + if (this.router.url?.split('?')[0] === comColRoute) { + this.allOptions$.pipe( + take(1), + ).subscribe((allOptions: ComColPageNavOption[]) => { + for (const option of allOptions) { + if (option.id === this.appConfig[this.contentType].defaultBrowseTab) { + this.currentOption$.next(option[0]); + void this.router.navigate([option.routerLink], { queryParams: option.params }); + break; + } + } + }); + } } ngOnDestroy(): void { diff --git a/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.spec.ts b/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.spec.ts index 48ad8e1c04..f887d1d524 100644 --- a/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.spec.ts +++ b/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.spec.ts @@ -18,6 +18,7 @@ describe('ComcolSearchSectionComponent', () => { beforeEach(async () => { route = new ActivatedRouteStub(); + route.parent = new ActivatedRouteStub(); await TestBed.configureTestingModule({ imports: [ComcolSearchSectionComponent], diff --git a/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.ts b/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.ts index 1672ad169f..d0f88ae54e 100644 --- a/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.ts +++ b/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.ts @@ -55,7 +55,7 @@ export class ComcolSearchSectionComponent implements OnInit { } ngOnInit(): void { - this.comcol$ = this.route.data.pipe( + this.comcol$ = this.route.parent.data.pipe( map((data: Data) => (data.dso as RemoteData).payload), ); this.showSidebar$ = this.comcol$.pipe( diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index b9b4195425..ca5f7def52 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -1338,6 +1338,8 @@ "collection.page.news": "News", + "collection.search.breadcrumbs": "Search", + "collection.search.results.head": "Search Results", "collection.select.confirm": "Confirm selected", @@ -1576,6 +1578,8 @@ "community.all-lists.head": "Subcommunities and Collections", + "community.search.breadcrumbs": "Search", + "community.search.results.head": "Search Results", "community.sub-collection-list.head": "Collections in this Community", diff --git a/src/config/collection-page-config.interface.ts b/src/config/collection-page-config.interface.ts index 6b8352e686..5aec06daea 100644 --- a/src/config/collection-page-config.interface.ts +++ b/src/config/collection-page-config.interface.ts @@ -4,6 +4,7 @@ import { Config } from './config.interface'; * Collection Page Config */ export interface CollectionPageConfig extends Config { + defaultBrowseTab: string; searchSection: CollectionSearchSectionConfig; edit: { undoTimeout: number; diff --git a/src/config/community-page-config.interface.ts b/src/config/community-page-config.interface.ts index 268f4d6a5e..72b859bffc 100644 --- a/src/config/community-page-config.interface.ts +++ b/src/config/community-page-config.interface.ts @@ -4,6 +4,7 @@ import { Config } from './config.interface'; * Community Page Config */ export interface CommunityPageConfig extends Config { + defaultBrowseTab: string; searchSection: CommunitySearchSectionConfig; } diff --git a/src/config/default-app-config.ts b/src/config/default-app-config.ts index 3c3f89240a..3da131c814 100644 --- a/src/config/default-app-config.ts +++ b/src/config/default-app-config.ts @@ -337,6 +337,7 @@ export class DefaultAppConfig implements AppConfig { // Community Page Config community: CommunityPageConfig = { + defaultBrowseTab: 'search', searchSection: { showSidebar: true, }, @@ -344,6 +345,7 @@ export class DefaultAppConfig implements AppConfig { // Collection Page Config collection: CollectionPageConfig = { + defaultBrowseTab: 'search', searchSection: { showSidebar: true, }, diff --git a/src/environments/environment.test.ts b/src/environments/environment.test.ts index 4c7a9b13ab..abe4790b2e 100644 --- a/src/environments/environment.test.ts +++ b/src/environments/environment.test.ts @@ -274,11 +274,13 @@ export const environment: BuildConfig = { }, }, community: { + defaultBrowseTab: 'search', searchSection: { showSidebar: true, }, }, collection: { + defaultBrowseTab: 'search', searchSection: { showSidebar: true, },