From 0e2630d729fcedafe339f7287cd744c38760ffa7 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Thu, 15 Feb 2024 21:55:33 +0100 Subject: [PATCH] 110889: Added search form to the community & collection pages --- .../community-page-routing.module.ts | 11 +++++++ .../sub-com-col-section.component.spec.ts | 1 + .../sub-com-col-section.component.ts | 2 +- .../comcol-page-browse-by.component.ts | 11 +++++-- src/app/shared/comcol/comcol.module.ts | 2 ++ .../comcol-search-section.component.html | 4 +++ .../comcol-search-section.component.spec.ts | 9 ++++++ .../comcol-search-section.component.ts | 32 +++++++++++++++++-- src/app/shared/testing/active-router.stub.ts | 18 +++++------ src/assets/i18n/en.json5 | 4 ++- 10 files changed, 78 insertions(+), 16 deletions(-) diff --git a/src/app/community-page/community-page-routing.module.ts b/src/app/community-page/community-page-routing.module.ts index 5ca544bb54..f38e670546 100644 --- a/src/app/community-page/community-page-routing.module.ts +++ b/src/app/community-page/community-page-routing.module.ts @@ -19,6 +19,8 @@ import { SubComColSectionComponent } from './sections/sub-com-col-section/sub-co import { BrowseByI18nBreadcrumbResolver } from '../browse-by/browse-by-i18n-breadcrumb.resolver'; import { BrowseByGuard } from '../browse-by/browse-by-guard'; import { ComcolBrowseByComponent } from '../shared/comcol/sections/comcol-browse-by/comcol-browse-by.component'; +import { ComcolSearchSectionComponent } from '../shared/comcol/sections/comcol-search-section/comcol-search-section.component'; +import { I18nBreadcrumbResolver } from '../core/breadcrumbs/i18n-breadcrumb.resolver'; @NgModule({ imports: [ @@ -56,7 +58,16 @@ import { ComcolBrowseByComponent } from '../shared/comcol/sections/comcol-browse { path: '', pathMatch: 'full', + component: ComcolSearchSectionComponent, + }, + { + path: 'subcoms-cols', + pathMatch: 'full', component: SubComColSectionComponent, + resolve: { + breadcrumb: I18nBreadcrumbResolver, + }, + data: { breadcrumbKey: 'community.subcoms-cols' }, }, { path: 'browse/:id', diff --git a/src/app/community-page/sections/sub-com-col-section/sub-com-col-section.component.spec.ts b/src/app/community-page/sections/sub-com-col-section/sub-com-col-section.component.spec.ts index 804299d3d9..cb3c41aa97 100644 --- a/src/app/community-page/sections/sub-com-col-section/sub-com-col-section.component.spec.ts +++ b/src/app/community-page/sections/sub-com-col-section/sub-com-col-section.component.spec.ts @@ -11,6 +11,7 @@ describe('SubComColSectionComponent', () => { beforeEach(async () => { activatedRoute = new ActivatedRouteStub(); + activatedRoute.parent = new ActivatedRouteStub(); await TestBed.configureTestingModule({ declarations: [ diff --git a/src/app/community-page/sections/sub-com-col-section/sub-com-col-section.component.ts b/src/app/community-page/sections/sub-com-col-section/sub-com-col-section.component.ts index ff30e51607..a72674adec 100644 --- a/src/app/community-page/sections/sub-com-col-section/sub-com-col-section.component.ts +++ b/src/app/community-page/sections/sub-com-col-section/sub-com-col-section.component.ts @@ -20,7 +20,7 @@ export class SubComColSectionComponent implements OnInit { } ngOnInit(): void { - this.community$ = this.route.data.pipe( + this.community$ = this.route.parent.data.pipe( map((data: Data) => (data.dso as RemoteData).payload), ); } 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 2a3ec220d6..c6e77d49e2 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 @@ -55,16 +55,21 @@ export class ComcolPageBrowseByComponent implements OnDestroy, OnInit { if (this.contentType === 'collection') { comColRoute = getCollectionPageRoute(this.id); allOptions.push({ - id: 'recent_submissions', - label: 'collection.page.browse.recent.head', + id: 'search', + label: 'collection.page.browse.search.head', routerLink: comColRoute, }); } else if (this.contentType === 'community') { comColRoute = getCommunityPageRoute(this.id); + allOptions.push({ + id: 'search', + label: 'collection.page.browse.search.head', + routerLink: comColRoute, + }); allOptions.push({ id: 'comcols', label: 'community.all-lists.head', - routerLink: comColRoute, + routerLink: `${comColRoute}/subcoms-cols`, }); } diff --git a/src/app/shared/comcol/comcol.module.ts b/src/app/shared/comcol/comcol.module.ts index 172931fbad..21c6e36891 100644 --- a/src/app/shared/comcol/comcol.module.ts +++ b/src/app/shared/comcol/comcol.module.ts @@ -18,6 +18,7 @@ import { FormModule } from '../form/form.module'; import { UploadModule } from '../upload/upload.module'; import { ComcolBrowseByComponent } from './sections/comcol-browse-by/comcol-browse-by.component'; import { BrowseByModule } from '../../browse-by/browse-by.module'; +import { SearchModule } from '../search/search.module'; import { ComcolSearchSectionComponent } from './sections/comcol-search-section/comcol-search-section.component'; const COMPONENTS = [ @@ -47,6 +48,7 @@ const COMPONENTS = [ SharedModule, UploadModule, BrowseByModule, + SearchModule, ], exports: [ ...COMPONENTS, diff --git a/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.html b/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.html index e69de29bb2..6cbae34616 100644 --- a/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.html +++ b/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.html @@ -0,0 +1,4 @@ + + 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 0aa89175f2..53406c2cfc 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 @@ -1,15 +1,24 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComcolSearchSectionComponent } from './comcol-search-section.component'; +import { ActivatedRoute } from '@angular/router'; +import { ActivatedRouteStub } from '../../../testing/active-router.stub'; describe('ComcolSearchSectionComponent', () => { let component: ComcolSearchSectionComponent; let fixture: ComponentFixture; + let route: ActivatedRouteStub; + beforeEach(async () => { + route = new ActivatedRouteStub(); + await TestBed.configureTestingModule({ declarations: [ ComcolSearchSectionComponent, ], + providers: [ + { provide: ActivatedRoute, useValue: route }, + ], }).compileComponents(); fixture = TestBed.createComponent(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 e953861bd3..297b8ab2c5 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 @@ -1,9 +1,37 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; +import { Observable } from 'rxjs'; +import { ActivatedRoute, Data } from '@angular/router'; +import { map } from 'rxjs/operators'; +import { SEARCH_CONFIG_SERVICE } from '../../../../my-dspace-page/my-dspace-page.component'; +import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service'; +import { RemoteData } from '../../../../core/data/remote-data'; +import { Community } from '../../../../core/shared/community.model'; +import { Collection } from '../../../../core/shared/collection.model'; @Component({ selector: 'ds-comcol-search-section', templateUrl: './comcol-search-section.component.html', styleUrls: ['./comcol-search-section.component.scss'], + providers: [ + { + provide: SEARCH_CONFIG_SERVICE, + useClass: SearchConfigurationService, + }, + ], }) -export class ComcolSearchSectionComponent { +export class ComcolSearchSectionComponent implements OnInit { + + comcol$: Observable; + + constructor( + protected route: ActivatedRoute, + ) { + } + + ngOnInit(): void { + this.comcol$ = this.route.data.pipe( + map((data: Data) => (data.dso as RemoteData).payload), + ); + } + } diff --git a/src/app/shared/testing/active-router.stub.ts b/src/app/shared/testing/active-router.stub.ts index 495920555b..4c6dd456d3 100644 --- a/src/app/shared/testing/active-router.stub.ts +++ b/src/app/shared/testing/active-router.stub.ts @@ -1,19 +1,19 @@ import { map } from 'rxjs/operators'; -import { convertToParamMap, Params } from '@angular/router'; - +import { ActivatedRoute, convertToParamMap, Data, Params } from '@angular/router'; import { BehaviorSubject } from 'rxjs'; export class ActivatedRouteStub { - private _testParams?: any; - private _testData?: any; + private _testParams?: Params; + private _testData?: Data; // ActivatedRoute.params is Observable - private subject?: BehaviorSubject = new BehaviorSubject(this.testParams); - private dataSubject?: BehaviorSubject = new BehaviorSubject(this.testData); + private subject?: BehaviorSubject = new BehaviorSubject(this.testParams); + private dataSubject?: BehaviorSubject = new BehaviorSubject(this.testData); params = this.subject.asObservable(); queryParams = this.subject.asObservable(); paramMap = this.subject.asObservable().pipe(map((params: Params) => convertToParamMap(params))); + parent: ActivatedRoute | ActivatedRouteStub; queryParamMap = this.subject.asObservable().pipe(map((params: Params) => convertToParamMap(params))); data = this.dataSubject.asObservable(); @@ -35,17 +35,17 @@ export class ActivatedRouteStub { return this._testParams; } - set testParams(params: {}) { + set testParams(params: Params) { this._testParams = params; this.subject.next(params); } // Test data get testData() { - return this._testParams; + return this._testData; } - set testData(data: {}) { + set testData(data: Data) { this._testData = data; this.dataSubject.next(data); } diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index e8d0bf9757..957716d84b 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -1074,7 +1074,7 @@ "collection.listelement.badge": "Collection", - "collection.page.browse.recent.head": "Search", + "collection.page.browse.search.head": "Search", "collection.page.edit": "Edit this collection", @@ -1148,6 +1148,8 @@ "communityList.showMore": "Show More", + "community.subcoms-cols.breadcrumbs": "Subcommunities and Collections", + "community.create.head": "Create a Community", "community.create.notifications.success": "Successfully created the Community",