From e23c1f7b5d1d0851c2f339e64f44e583ba9559cf Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Thu, 15 Feb 2024 21:00:06 +0100 Subject: [PATCH] 110889: Replaced recently added component with search comcol section --- .../collection-page-routing.module.ts | 4 +- .../collection-page/collection-page.module.ts | 2 - .../collection-recently-added.component.html | 18 ---- ...ollection-recently-added.component.spec.ts | 53 ------------ .../collection-recently-added.component.ts | 82 ------------------- src/app/shared/comcol/comcol.module.ts | 2 + .../comcol-search-section.component.html} | 0 .../comcol-search-section.component.scss | 0 .../comcol-search-section.component.spec.ts | 23 ++++++ .../comcol-search-section.component.ts | 9 ++ src/assets/i18n/en.json5 | 4 +- 11 files changed, 37 insertions(+), 160 deletions(-) delete mode 100644 src/app/collection-page/sections/recently-added/collection-recently-added.component.html delete mode 100644 src/app/collection-page/sections/recently-added/collection-recently-added.component.spec.ts delete mode 100644 src/app/collection-page/sections/recently-added/collection-recently-added.component.ts rename src/app/{collection-page/sections/recently-added/collection-recently-added.component.scss => shared/comcol/sections/comcol-search-section/comcol-search-section.component.html} (100%) create mode 100644 src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.scss create mode 100644 src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.spec.ts create mode 100644 src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.ts diff --git a/src/app/collection-page/collection-page-routing.module.ts b/src/app/collection-page/collection-page-routing.module.ts index 5ddef6ca68..ed0c77c2f8 100644 --- a/src/app/collection-page/collection-page-routing.module.ts +++ b/src/app/collection-page/collection-page-routing.module.ts @@ -25,7 +25,7 @@ import { DSOEditMenuResolver } from '../shared/dso-page/dso-edit-menu.resolver'; import { ComcolBrowseByComponent } from '../shared/comcol/sections/comcol-browse-by/comcol-browse-by.component'; import { BrowseByGuard } from '../browse-by/browse-by-guard'; import { BrowseByI18nBreadcrumbResolver } from '../browse-by/browse-by-i18n-breadcrumb.resolver'; -import { CollectionRecentlyAddedComponent } from './sections/recently-added/collection-recently-added.component'; +import { ComcolSearchSectionComponent } from '../shared/comcol/sections/comcol-search-section/comcol-search-section.component'; @NgModule({ imports: [ @@ -73,7 +73,7 @@ import { CollectionRecentlyAddedComponent } from './sections/recently-added/coll { path: '', pathMatch: 'full', - component: CollectionRecentlyAddedComponent, + component: ComcolSearchSectionComponent, }, { path: 'browse/:id', diff --git a/src/app/collection-page/collection-page.module.ts b/src/app/collection-page/collection-page.module.ts index 8782be0a45..5db85d48e9 100644 --- a/src/app/collection-page/collection-page.module.ts +++ b/src/app/collection-page/collection-page.module.ts @@ -19,7 +19,6 @@ import { ComcolModule } from '../shared/comcol/comcol.module'; import { DsoSharedModule } from '../dso-shared/dso-shared.module'; import { DsoPageModule } from '../shared/dso-page/dso-page.module'; import { BrowseByPageModule } from '../browse-by/browse-by-page.module'; -import { CollectionRecentlyAddedComponent } from './sections/recently-added/collection-recently-added.component'; const DECLARATIONS = [ CollectionPageComponent, @@ -29,7 +28,6 @@ const DECLARATIONS = [ EditItemTemplatePageComponent, ThemedEditItemTemplatePageComponent, CollectionItemMapperComponent, - CollectionRecentlyAddedComponent, ]; @NgModule({ diff --git a/src/app/collection-page/sections/recently-added/collection-recently-added.component.html b/src/app/collection-page/sections/recently-added/collection-recently-added.component.html deleted file mode 100644 index 002b8cceda..0000000000 --- a/src/app/collection-page/sections/recently-added/collection-recently-added.component.html +++ /dev/null @@ -1,18 +0,0 @@ - -
-

{{'collection.page.browse.recent.head' | translate}}

- - -
- - - -
diff --git a/src/app/collection-page/sections/recently-added/collection-recently-added.component.spec.ts b/src/app/collection-page/sections/recently-added/collection-recently-added.component.spec.ts deleted file mode 100644 index 4acc24e3f5..0000000000 --- a/src/app/collection-page/sections/recently-added/collection-recently-added.component.spec.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { CollectionRecentlyAddedComponent } from './collection-recently-added.component'; -import { APP_CONFIG } from '../../../../config/app-config.interface'; -import { environment } from '../../../../environments/environment.test'; -import { ActivatedRoute } from '@angular/router'; -import { ActivatedRouteStub } from '../../../shared/testing/active-router.stub'; -import { PaginationService } from '../../../core/pagination/pagination.service'; -import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub'; -import { SearchServiceStub } from '../../../shared/testing/search-service.stub'; -import { SearchService } from '../../../core/shared/search/search.service'; -import { VarDirective } from '../../../shared/utils/var.directive'; -import { TranslateModule } from '@ngx-translate/core'; -import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; - -describe('CollectionRecentlyAddedComponent', () => { - let component: CollectionRecentlyAddedComponent; - let fixture: ComponentFixture; - - let activatedRoute: ActivatedRouteStub; - let paginationService: PaginationServiceStub; - let searchService: SearchServiceStub; - - beforeEach(async () => { - activatedRoute = new ActivatedRouteStub(); - paginationService = new PaginationServiceStub(); - searchService = new SearchServiceStub(); - - await TestBed.configureTestingModule({ - declarations: [ - CollectionRecentlyAddedComponent, - VarDirective, - ], - imports: [ - TranslateModule.forRoot(), - ], - providers: [ - { provide: ActivatedRoute, useValue: activatedRoute }, - { provide: APP_CONFIG, useValue: environment }, - { provide: PaginationService, useValue: paginationService }, - { provide: SearchService, useValue: SearchServiceStub }, - ], - schemas: [CUSTOM_ELEMENTS_SCHEMA], - }).compileComponents(); - - fixture = TestBed.createComponent(CollectionRecentlyAddedComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/collection-page/sections/recently-added/collection-recently-added.component.ts b/src/app/collection-page/sections/recently-added/collection-recently-added.component.ts deleted file mode 100644 index 65af77a63b..0000000000 --- a/src/app/collection-page/sections/recently-added/collection-recently-added.component.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { Component, OnInit, Inject, OnDestroy } from '@angular/core'; -import { Observable, combineLatest as observableCombineLatest } from 'rxjs'; -import { RemoteData } from '../../../core/data/remote-data'; -import { PaginatedList } from '../../../core/data/paginated-list.model'; -import { Item } from '../../../core/shared/item.model'; -import { switchMap, map, startWith, take } from 'rxjs/operators'; -import { getFirstSucceededRemoteData, toDSpaceObjectListRD } from '../../../core/shared/operators'; -import { PaginatedSearchOptions } from '../../../shared/search/models/paginated-search-options.model'; -import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model'; -import { BROWSE_LINKS_TO_FOLLOW } from '../../../core/browse/browse.service'; -import { PaginationService } from '../../../core/pagination/pagination.service'; -import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; -import { SortOptions, SortDirection } from '../../../core/cache/models/sort-options.model'; -import { APP_CONFIG, AppConfig } from '../../../../config/app-config.interface'; -import { SearchService } from '../../../core/shared/search/search.service'; -import { Collection } from '../../../core/shared/collection.model'; -import { ActivatedRoute, Data } from '@angular/router'; -import { fadeIn } from '../../../shared/animations/fade'; - -@Component({ - selector: 'ds-collection-recently-added', - templateUrl: './collection-recently-added.component.html', - styleUrls: ['./collection-recently-added.component.scss'], - animations: [fadeIn], -}) -export class CollectionRecentlyAddedComponent implements OnInit, OnDestroy { - - paginationConfig: PaginationComponentOptions; - - sortConfig: SortOptions; - - collectionRD$: Observable>; - - itemRD$: Observable>>; - - constructor( - @Inject(APP_CONFIG) protected appConfig: AppConfig, - protected paginationService: PaginationService, - protected route: ActivatedRoute, - protected searchService: SearchService, - ) { - this.paginationConfig = Object.assign(new PaginationComponentOptions(), { - id: 'cp', - currentPage: 1, - pageSize: this.appConfig.browseBy.pageSize, - }); - - this.sortConfig = new SortOptions('dc.date.accessioned', SortDirection.DESC); - } - - ngOnInit(): void { - this.collectionRD$ = this.route.data.pipe( - map((data: Data) => data.dso as RemoteData), - take(1), - ); - - this.itemRD$ = observableCombineLatest([ - this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig), - this.paginationService.getCurrentSort(this.paginationConfig.id, this.sortConfig), - ]).pipe( - switchMap(([currentPagination, currentSort]: [PaginationComponentOptions, SortOptions]) => this.collectionRD$.pipe( - getFirstSucceededRemoteData(), - map((rd: RemoteData) => rd.payload.id), - switchMap((id: string) => this.searchService.search( - new PaginatedSearchOptions({ - scope: id, - pagination: currentPagination, - sort: currentSort, - dsoTypes: [DSpaceObjectType.ITEM] - }), null, true, true, ...BROWSE_LINKS_TO_FOLLOW).pipe( - toDSpaceObjectListRD() - ) as Observable>>), - startWith(undefined), // Make sure switching pages shows loading component - )), - ); - } - - ngOnDestroy(): void { - this.paginationService.clearPagination(this.paginationConfig.id); - } - -} diff --git a/src/app/shared/comcol/comcol.module.ts b/src/app/shared/comcol/comcol.module.ts index 7ce48a3a55..172931fbad 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 { ComcolSearchSectionComponent } from './sections/comcol-search-section/comcol-search-section.component'; const COMPONENTS = [ ComcolPageContentComponent, @@ -33,6 +34,7 @@ const COMPONENTS = [ ComcolRoleComponent, ThemedComcolPageHandleComponent, ComcolBrowseByComponent, + ComcolSearchSectionComponent, ]; @NgModule({ diff --git a/src/app/collection-page/sections/recently-added/collection-recently-added.component.scss b/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.html similarity index 100% rename from src/app/collection-page/sections/recently-added/collection-recently-added.component.scss rename to src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.html diff --git a/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.scss b/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.scss new file mode 100644 index 0000000000..e69de29bb2 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 new file mode 100644 index 0000000000..0aa89175f2 --- /dev/null +++ b/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComcolSearchSectionComponent } from './comcol-search-section.component'; + +describe('ComcolSearchSectionComponent', () => { + let component: ComcolSearchSectionComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ + ComcolSearchSectionComponent, + ], + }).compileComponents(); + + fixture = TestBed.createComponent(ComcolSearchSectionComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); 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 new file mode 100644 index 0000000000..e953861bd3 --- /dev/null +++ b/src/app/shared/comcol/sections/comcol-search-section/comcol-search-section.component.ts @@ -0,0 +1,9 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'ds-comcol-search-section', + templateUrl: './comcol-search-section.component.html', + styleUrls: ['./comcol-search-section.component.scss'], +}) +export class ComcolSearchSectionComponent { +} diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 0346f9cd1f..e8d0bf9757 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -1074,9 +1074,7 @@ "collection.listelement.badge": "Collection", - "collection.page.browse.recent.head": "Recent Submissions", - - "collection.page.browse.recent.empty": "No items to show", + "collection.page.browse.recent.head": "Search", "collection.page.edit": "Edit this collection",