diff --git a/apps/datahub/src/app/app.config.ts b/apps/datahub/src/app/app.config.ts index f207d11eba..1ff50e8358 100644 --- a/apps/datahub/src/app/app.config.ts +++ b/apps/datahub/src/app/app.config.ts @@ -2,7 +2,7 @@ import { ResultsLayoutConfigItem, ResultsLayoutConfigModel, } from '@geonetwork-ui/ui/search' -import { RecordPreviewDatahubComponent } from './search/record-preview-datahub/record-preview-datahub.component' +import { RecordPreviewDatahubComponent } from './home/search/record-preview-datahub/record-preview-datahub.component' export const DATAHUB_RESULTS_LAYOUT_CONFIG: ResultsLayoutConfigModel = { DATAHUB: new ResultsLayoutConfigItem( diff --git a/apps/datahub/src/app/app.module.ts b/apps/datahub/src/app/app.module.ts index 49ab6ddfc8..52d4ab2e94 100644 --- a/apps/datahub/src/app/app.module.ts +++ b/apps/datahub/src/app/app.module.ts @@ -7,6 +7,7 @@ import { Configuration } from '@geonetwork-ui/data-access/gn4' import { FeatureRecordModule } from '@geonetwork-ui/feature/record' import { DefaultRouterModule, + RouterService, ROUTER_ROUTE_DATASET, } from '@geonetwork-ui/feature/router' import { FeatureSearchModule } from '@geonetwork-ui/feature/search' @@ -37,14 +38,18 @@ import { DATAHUB_RESULTS_LAYOUT_CONFIG } from './app.config' import { HeaderBadgeButtonComponent } from './record/header-badge-button/header-badge-button.component' import { HeaderRecordComponent } from './record/header-record/header-record.component' import { RecordPageComponent } from './record/record-page/record-page.component' -import { RecordPreviewDatahubComponent } from './search/record-preview-datahub/record-preview-datahub.component' -import { SearchHeaderComponent } from './search/search-header/search-header.component' -import { SearchPageComponent } from './search/search-page/search-page.component' +import { RecordPreviewDatahubComponent } from './home/search/record-preview-datahub/record-preview-datahub.component' +import { HomeHeaderComponent } from './home/home-header/home-header.component' +import { HomePageComponent } from './home/home-page/home-page.component' import { UiLayoutModule } from '@geonetwork-ui/ui/layout' import { FeatureCatalogModule } from '@geonetwork-ui/feature/catalog' -import { SearchSummaryComponent } from './search/search-summary/search-summary.component' +import { SearchSummaryComponent } from './home/search/search-summary/search-summary.component' import { NavigationBarComponent } from './record/navigation-bar/navigation-bar.component' import { THUMBNAIL_PLACEHOLDER } from '@geonetwork-ui/ui/search' +import { NewsPageComponent } from './home/news-page/news-page.component' +import { DatahubRouterService } from './router/datahub-router.service' +import { OrganisationsPageComponent } from './home/organisations-page/organisations-page.component' +import { SearchPageComponent } from './home/search/search-page/search-page.component' export const metaReducers: MetaReducer[] = !environment.production ? [] : [] // https://github.com/nrwl/nx/issues/191 @@ -52,14 +57,17 @@ export const metaReducers: MetaReducer[] = !environment.production ? [] : [] @NgModule({ declarations: [ AppComponent, - SearchPageComponent, + HomePageComponent, RecordPreviewDatahubComponent, - SearchHeaderComponent, + HomeHeaderComponent, HeaderBadgeButtonComponent, HeaderRecordComponent, RecordPageComponent, SearchSummaryComponent, NavigationBarComponent, + NewsPageComponent, + OrganisationsPageComponent, + SearchPageComponent, ], imports: [ BrowserModule, @@ -96,6 +104,7 @@ export const metaReducers: MetaReducer[] = !environment.production ? [] : [] ], providers: [ { provide: RESULTS_LAYOUT_CONFIG, useValue: DATAHUB_RESULTS_LAYOUT_CONFIG }, + { provide: RouterService, useClass: DatahubRouterService }, { provide: Configuration, useFactory: () => diff --git a/apps/datahub/src/app/search/search-header/search-header.component.css b/apps/datahub/src/app/home/home-header/home-header.component.css similarity index 100% rename from apps/datahub/src/app/search/search-header/search-header.component.css rename to apps/datahub/src/app/home/home-header/home-header.component.css diff --git a/apps/datahub/src/app/search/search-header/search-header.component.html b/apps/datahub/src/app/home/home-header/home-header.component.html similarity index 58% rename from apps/datahub/src/app/search/search-header/search-header.component.html rename to apps/datahub/src/app/home/home-header/home-header.component.html index bf8c5e9d11..c44417ceae 100644 --- a/apps/datahub/src/app/search/search-header/search-header.component.html +++ b/apps/datahub/src/app/home/home-header/home-header.component.html @@ -1,5 +1,5 @@
-
+
-->
- - -
diff --git a/apps/datahub/src/app/search/search-header/search-header.component.spec.ts b/apps/datahub/src/app/home/home-header/home-header.component.spec.ts similarity index 68% rename from apps/datahub/src/app/search/search-header/search-header.component.spec.ts rename to apps/datahub/src/app/home/home-header/home-header.component.spec.ts index 78d529f862..46593f5a6a 100644 --- a/apps/datahub/src/app/search/search-header/search-header.component.spec.ts +++ b/apps/datahub/src/app/home/home-header/home-header.component.spec.ts @@ -2,11 +2,11 @@ import { Component, Input, NO_ERRORS_SCHEMA } from '@angular/core' import { ComponentFixture, TestBed } from '@angular/core/testing' import { By } from '@angular/platform-browser' import { RouterFacade } from '@geonetwork-ui/feature/router' +import { SearchService } from '@geonetwork-ui/feature/search' import { MetadataRecord } from '@geonetwork-ui/util/shared' import { TranslateModule } from '@ngx-translate/core' import { BehaviorSubject } from 'rxjs' - -import { SearchHeaderComponent } from './search-header.component' +import { HomeHeaderComponent } from './home-header.component' jest.mock('@geonetwork-ui/util/app-config', () => ({ getThemeConfig: () => ({ @@ -18,6 +18,10 @@ const routerFacadeMock = { goToMetadata: jest.fn(), anySearch$: new BehaviorSubject('scot'), } + +const searchServiceMock = { + updateSearch: jest.fn(), +} /* eslint-disable */ @Component({ selector: 'gn-ui-fuzzy-search', @@ -29,25 +33,29 @@ class FuzzySearchComponentMock { /* eslint-enable */ describe('HeaderComponent', () => { - let component: SearchHeaderComponent - let fixture: ComponentFixture + let component: HomeHeaderComponent + let fixture: ComponentFixture beforeEach(async () => { await TestBed.configureTestingModule({ imports: [TranslateModule.forRoot()], - declarations: [SearchHeaderComponent, FuzzySearchComponentMock], + declarations: [HomeHeaderComponent, FuzzySearchComponentMock], schemas: [NO_ERRORS_SCHEMA], providers: [ { provide: RouterFacade, useValue: routerFacadeMock, }, + { + provide: SearchService, + useValue: searchServiceMock, + }, ], }).compileComponents() }) beforeEach(() => { - fixture = TestBed.createComponent(SearchHeaderComponent) + fixture = TestBed.createComponent(HomeHeaderComponent) component = fixture.componentInstance fixture.detectChanges() }) @@ -56,7 +64,7 @@ describe('HeaderComponent', () => { expect(component).toBeTruthy() }) - describe('search route paramter', () => { + describe('search route parameter', () => { it('passed to fuzzy search as AutoComplete item object', () => { const fuzzyCpt = fixture.debugElement.query( By.directive(FuzzySearchComponentMock) @@ -73,4 +81,14 @@ describe('HeaderComponent', () => { expect(fuzzyCpt.value).toEqual({ title: 'river' }) }) }) + describe('tabs navigation', () => { + describe('click datasets tab', () => { + beforeEach(() => { + component.updateSearch() + }) + it('calls searchService updateSearch with empty object', () => { + expect(searchServiceMock.updateSearch).toHaveBeenCalledWith({}) + }) + }) + }) }) diff --git a/apps/datahub/src/app/search/search-header/search-header.component.ts b/apps/datahub/src/app/home/home-header/home-header.component.ts similarity index 54% rename from apps/datahub/src/app/search/search-header/search-header.component.ts rename to apps/datahub/src/app/home/home-header/home-header.component.ts index 58421d03eb..85417957d2 100644 --- a/apps/datahub/src/app/search/search-header/search-header.component.ts +++ b/apps/datahub/src/app/home/home-header/home-header.component.ts @@ -1,9 +1,17 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core' import { marker } from '@biesbjerg/ngx-translate-extract-marker' -import { RouterFacade } from '@geonetwork-ui/feature/router' +import { + RouterFacade, + ROUTER_ROUTE_SEARCH, +} from '@geonetwork-ui/feature/router' +import { SearchService } from '@geonetwork-ui/feature/search' import { getThemeConfig } from '@geonetwork-ui/util/app-config' import { MetadataRecord } from '@geonetwork-ui/util/shared' import { map } from 'rxjs/operators' +import { + ROUTER_ROUTE_NEWS, + ROUTER_ROUTE_ORGANISATIONS, +} from '../../router/constants' marker('datahub.header.myfavorites') marker('datahub.header.connex') @@ -11,12 +19,12 @@ marker('datahub.header.lastRecords') marker('datahub.header.popularRecords') @Component({ - selector: 'datahub-search-header', - templateUrl: './search-header.component.html', - styleUrls: ['./search-header.component.css'], + selector: 'datahub-home-header', + templateUrl: './home-header.component.html', + styleUrls: ['./home-header.component.css'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class SearchHeaderComponent { +export class HomeHeaderComponent { @Input() expandRatio: number searchInputRouteValue$ = this.routerFacade.anySearch$.pipe( @@ -26,9 +34,20 @@ export class SearchHeaderComponent { getThemeConfig().HEADER_BACKGROUND || `center /cover url('assets/img/header_bg.webp')` - constructor(private routerFacade: RouterFacade) {} + ROUTE_NEWS = `${ROUTER_ROUTE_NEWS}` + ROUTE_SEARCH = `${ROUTER_ROUTE_SEARCH}` + ROUTE_ORGANISATIONS = `${ROUTER_ROUTE_ORGANISATIONS}` + + constructor( + public routerFacade: RouterFacade, + private searchService: SearchService + ) {} onFuzzySearchSelection(record: MetadataRecord) { this.routerFacade.goToMetadata(record) } + + updateSearch(): void { + this.searchService.updateSearch({}) + } } diff --git a/apps/datahub/src/app/search/record-preview-datahub/record-preview-datahub.component.css b/apps/datahub/src/app/home/home-page/home-page.component.css similarity index 100% rename from apps/datahub/src/app/search/record-preview-datahub/record-preview-datahub.component.css rename to apps/datahub/src/app/home/home-page/home-page.component.css diff --git a/apps/datahub/src/app/home/home-page/home-page.component.html b/apps/datahub/src/app/home/home-page/home-page.component.html new file mode 100644 index 0000000000..b496f56f62 --- /dev/null +++ b/apps/datahub/src/app/home/home-page/home-page.component.html @@ -0,0 +1,12 @@ +
+ + + + + +
+
+ +
+
+
diff --git a/apps/datahub/src/app/home/home-page/home-page.component.spec.ts b/apps/datahub/src/app/home/home-page/home-page.component.spec.ts new file mode 100644 index 0000000000..55a717114f --- /dev/null +++ b/apps/datahub/src/app/home/home-page/home-page.component.spec.ts @@ -0,0 +1,27 @@ +import { NO_ERRORS_SCHEMA } from '@angular/core' +import { ComponentFixture, TestBed } from '@angular/core/testing' +import { HomePageComponent } from './home-page.component' +import { UiLayoutModule } from '@geonetwork-ui/ui/layout' + +describe('HomePageComponent', () => { + let component: HomePageComponent + let fixture: ComponentFixture + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [HomePageComponent], + imports: [UiLayoutModule], + schemas: [NO_ERRORS_SCHEMA], + }).compileComponents() + }) + + beforeEach(() => { + fixture = TestBed.createComponent(HomePageComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) + + it('should create', () => { + expect(component).toBeTruthy() + }) +}) diff --git a/apps/datahub/src/app/home/home-page/home-page.component.ts b/apps/datahub/src/app/home/home-page/home-page.component.ts new file mode 100644 index 0000000000..53436ec20a --- /dev/null +++ b/apps/datahub/src/app/home/home-page/home-page.component.ts @@ -0,0 +1,9 @@ +import { ChangeDetectionStrategy, Component } from '@angular/core' + +@Component({ + selector: 'datahub-home-page', + templateUrl: './home-page.component.html', + styleUrls: ['./home-page.component.css'], + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class HomePageComponent {} diff --git a/apps/datahub/src/app/search/search-page/search-page.component.scss b/apps/datahub/src/app/home/news-page/news-page.component.css similarity index 100% rename from apps/datahub/src/app/search/search-page/search-page.component.scss rename to apps/datahub/src/app/home/news-page/news-page.component.css diff --git a/apps/datahub/src/app/home/news-page/news-page.component.html b/apps/datahub/src/app/home/news-page/news-page.component.html new file mode 100644 index 0000000000..d416fcbb68 --- /dev/null +++ b/apps/datahub/src/app/home/news-page/news-page.component.html @@ -0,0 +1 @@ +

news-page works!

diff --git a/apps/datahub/src/app/home/news-page/news-page.component.spec.ts b/apps/datahub/src/app/home/news-page/news-page.component.spec.ts new file mode 100644 index 0000000000..f9b095de85 --- /dev/null +++ b/apps/datahub/src/app/home/news-page/news-page.component.spec.ts @@ -0,0 +1,22 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing' + +import { NewsPageComponent } from './news-page.component' + +describe('NewsPageComponent', () => { + let component: NewsPageComponent + let fixture: ComponentFixture + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [NewsPageComponent], + }).compileComponents() + + fixture = TestBed.createComponent(NewsPageComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) + + it('should create', () => { + expect(component).toBeTruthy() + }) +}) diff --git a/apps/datahub/src/app/home/news-page/news-page.component.ts b/apps/datahub/src/app/home/news-page/news-page.component.ts new file mode 100644 index 0000000000..e41532bc6d --- /dev/null +++ b/apps/datahub/src/app/home/news-page/news-page.component.ts @@ -0,0 +1,9 @@ +import { ChangeDetectionStrategy, Component } from '@angular/core' + +@Component({ + selector: 'datahub-news-page', + templateUrl: './news-page.component.html', + styleUrls: ['./news-page.component.css'], + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class NewsPageComponent {} diff --git a/apps/datahub/src/app/search/search-summary/search-summary.component.css b/apps/datahub/src/app/home/organisations-page/organisations-page.component.css similarity index 100% rename from apps/datahub/src/app/search/search-summary/search-summary.component.css rename to apps/datahub/src/app/home/organisations-page/organisations-page.component.css diff --git a/apps/datahub/src/app/home/organisations-page/organisations-page.component.html b/apps/datahub/src/app/home/organisations-page/organisations-page.component.html new file mode 100644 index 0000000000..cab0580c41 --- /dev/null +++ b/apps/datahub/src/app/home/organisations-page/organisations-page.component.html @@ -0,0 +1 @@ +

organisations-page works!

diff --git a/apps/datahub/src/app/home/organisations-page/organisations-page.component.spec.ts b/apps/datahub/src/app/home/organisations-page/organisations-page.component.spec.ts new file mode 100644 index 0000000000..f240f6dc5c --- /dev/null +++ b/apps/datahub/src/app/home/organisations-page/organisations-page.component.spec.ts @@ -0,0 +1,22 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing' + +import { OrganisationsPageComponent } from './organisations-page.component' + +describe('OrganisationsPageComponent', () => { + let component: OrganisationsPageComponent + let fixture: ComponentFixture + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [OrganisationsPageComponent], + }).compileComponents() + + fixture = TestBed.createComponent(OrganisationsPageComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) + + it('should create', () => { + expect(component).toBeTruthy() + }) +}) diff --git a/apps/datahub/src/app/home/organisations-page/organisations-page.component.ts b/apps/datahub/src/app/home/organisations-page/organisations-page.component.ts new file mode 100644 index 0000000000..802df579e1 --- /dev/null +++ b/apps/datahub/src/app/home/organisations-page/organisations-page.component.ts @@ -0,0 +1,9 @@ +import { ChangeDetectionStrategy, Component } from '@angular/core' + +@Component({ + selector: 'datahub-organisations-page', + templateUrl: './organisations-page.component.html', + styleUrls: ['./organisations-page.component.css'], + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class OrganisationsPageComponent {} diff --git a/apps/datahub/src/app/home/search/record-preview-datahub/record-preview-datahub.component.css b/apps/datahub/src/app/home/search/record-preview-datahub/record-preview-datahub.component.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/apps/datahub/src/app/search/record-preview-datahub/record-preview-datahub.component.html b/apps/datahub/src/app/home/search/record-preview-datahub/record-preview-datahub.component.html similarity index 100% rename from apps/datahub/src/app/search/record-preview-datahub/record-preview-datahub.component.html rename to apps/datahub/src/app/home/search/record-preview-datahub/record-preview-datahub.component.html diff --git a/apps/datahub/src/app/search/record-preview-datahub/record-preview-datahub.component.spec.ts b/apps/datahub/src/app/home/search/record-preview-datahub/record-preview-datahub.component.spec.ts similarity index 100% rename from apps/datahub/src/app/search/record-preview-datahub/record-preview-datahub.component.spec.ts rename to apps/datahub/src/app/home/search/record-preview-datahub/record-preview-datahub.component.spec.ts diff --git a/apps/datahub/src/app/search/record-preview-datahub/record-preview-datahub.component.ts b/apps/datahub/src/app/home/search/record-preview-datahub/record-preview-datahub.component.ts similarity index 72% rename from apps/datahub/src/app/search/record-preview-datahub/record-preview-datahub.component.ts rename to apps/datahub/src/app/home/search/record-preview-datahub/record-preview-datahub.component.ts index 534b1cd784..914b4d6b5e 100644 --- a/apps/datahub/src/app/search/record-preview-datahub/record-preview-datahub.component.ts +++ b/apps/datahub/src/app/home/search/record-preview-datahub/record-preview-datahub.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component } from '@angular/core' +import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core' import { RecordPreviewComponent } from '@geonetwork-ui/ui/search' import { stripHtml } from '@geonetwork-ui/util/shared' @@ -8,7 +8,10 @@ import { stripHtml } from '@geonetwork-ui/util/shared' styleUrls: ['./record-preview-datahub.component.css'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class RecordPreviewDatahubComponent extends RecordPreviewComponent { +export class RecordPreviewDatahubComponent + extends RecordPreviewComponent + implements OnInit +{ abstract: string ngOnInit() { super.ngOnInit() diff --git a/apps/datahub/src/app/home/search/search-page/search-page.component.html b/apps/datahub/src/app/home/search/search-page/search-page.component.html new file mode 100644 index 0000000000..edcd38a829 --- /dev/null +++ b/apps/datahub/src/app/home/search/search-page/search-page.component.html @@ -0,0 +1,9 @@ +
+ +
+
+ +
diff --git a/apps/datahub/src/app/home/search/search-page/search-page.component.scss b/apps/datahub/src/app/home/search/search-page/search-page.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/apps/datahub/src/app/search/search-page/search-page.component.spec.ts b/apps/datahub/src/app/home/search/search-page/search-page.component.spec.ts similarity index 59% rename from apps/datahub/src/app/search/search-page/search-page.component.spec.ts rename to apps/datahub/src/app/home/search/search-page/search-page.component.spec.ts index a0a3931137..8acf011fb9 100644 --- a/apps/datahub/src/app/search/search-page/search-page.component.spec.ts +++ b/apps/datahub/src/app/home/search/search-page/search-page.component.spec.ts @@ -5,14 +5,15 @@ import { RouterFacade } from '@geonetwork-ui/feature/router' import { SearchPageComponent } from './search-page.component' import { SearchFacade } from '@geonetwork-ui/feature/search' import { UiLayoutModule } from '@geonetwork-ui/ui/layout' +import { RECORDS_SUMMARY_FIXTURE } from '@geonetwork-ui/util/shared' -class RouterFacadeMock { - goToMetadata = jest.fn() +const RouterFacadeMock = { + goToMetadata: jest.fn(), } -class SearchFacadeMock { - setFilters = jest.fn(() => this) - setResultsLayout = jest.fn(() => this) +const SearchFacadeMock = { + setFilters: jest.fn(() => this), + setResultsLayout: jest.fn(() => this), } describe('MainSearchComponent', () => { @@ -27,11 +28,11 @@ describe('MainSearchComponent', () => { providers: [ { provide: RouterFacade, - useClass: RouterFacadeMock, + useValue: RouterFacadeMock, }, { provide: SearchFacade, - useClass: SearchFacadeMock, + useValue: SearchFacadeMock, }, ], }).compileComponents() @@ -46,4 +47,17 @@ describe('MainSearchComponent', () => { it('should create', () => { expect(component).toBeTruthy() }) + + it('should setResultsLayout to DATAHUB', () => { + expect(SearchFacadeMock.setResultsLayout).toHaveBeenCalledWith('DATAHUB') + }) + + describe('navigate to metadata record', () => { + it('calls searchRouter goToMetdata with md record', () => { + component.onMetadataSelection(RECORDS_SUMMARY_FIXTURE[0]) + expect(RouterFacadeMock.goToMetadata).toHaveBeenCalledWith( + RECORDS_SUMMARY_FIXTURE[0] + ) + }) + }) }) diff --git a/apps/datahub/src/app/search/search-page/search-page.component.ts b/apps/datahub/src/app/home/search/search-page/search-page.component.ts similarity index 90% rename from apps/datahub/src/app/search/search-page/search-page.component.ts rename to apps/datahub/src/app/home/search/search-page/search-page.component.ts index 4cd5e233e0..ba37ca349a 100644 --- a/apps/datahub/src/app/search/search-page/search-page.component.ts +++ b/apps/datahub/src/app/home/search/search-page/search-page.component.ts @@ -16,7 +16,7 @@ export class SearchPageComponent implements OnInit { ) {} scrollableOptions: InfiniteScrollModel = { - container: '#search-page', + container: '#home-page', fromRoot: true, } @@ -27,8 +27,4 @@ export class SearchPageComponent implements OnInit { onMetadataSelection(metadata: MetadataRecord): void { this.searchRouter.goToMetadata(metadata) } - - resetSearch(): void { - this.searchFacade.setFilters({}) - } } diff --git a/apps/datahub/src/app/home/search/search-summary/search-summary.component.css b/apps/datahub/src/app/home/search/search-summary/search-summary.component.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/apps/datahub/src/app/search/search-summary/search-summary.component.html b/apps/datahub/src/app/home/search/search-summary/search-summary.component.html similarity index 100% rename from apps/datahub/src/app/search/search-summary/search-summary.component.html rename to apps/datahub/src/app/home/search/search-summary/search-summary.component.html diff --git a/apps/datahub/src/app/search/search-summary/search-summary.component.spec.ts b/apps/datahub/src/app/home/search/search-summary/search-summary.component.spec.ts similarity index 97% rename from apps/datahub/src/app/search/search-summary/search-summary.component.spec.ts rename to apps/datahub/src/app/home/search/search-summary/search-summary.component.spec.ts index 1c1e6b0833..e31810f571 100644 --- a/apps/datahub/src/app/search/search-summary/search-summary.component.spec.ts +++ b/apps/datahub/src/app/home/search/search-summary/search-summary.component.spec.ts @@ -7,10 +7,10 @@ import { BehaviorSubject } from 'rxjs' import { SearchSummaryComponent } from './search-summary.component' const state = { Org: { mel: true } } -const searchFacadeMock: any = { +const searchFacadeMock = { searchFilters$: new BehaviorSubject(state), } -const searchServiceMock: any = { +const searchServiceMock = { updateSearch: jest.fn(), } describe('SearchSummaryComponent', () => { diff --git a/apps/datahub/src/app/search/search-summary/search-summary.component.ts b/apps/datahub/src/app/home/search/search-summary/search-summary.component.ts similarity index 100% rename from apps/datahub/src/app/search/search-summary/search-summary.component.ts rename to apps/datahub/src/app/home/search/search-summary/search-summary.component.ts diff --git a/apps/datahub/src/app/record/header-badge-button/header-badge-button.component.ts b/apps/datahub/src/app/record/header-badge-button/header-badge-button.component.ts index f4de5607e2..54af0f14bb 100644 --- a/apps/datahub/src/app/record/header-badge-button/header-badge-button.component.ts +++ b/apps/datahub/src/app/record/header-badge-button/header-badge-button.component.ts @@ -1,6 +1,5 @@ import { Component, - OnInit, ChangeDetectionStrategy, Input, EventEmitter, diff --git a/apps/datahub/src/app/record/navigation-bar/navigation-bar.component.spec.ts b/apps/datahub/src/app/record/navigation-bar/navigation-bar.component.spec.ts index 55d3199b8e..ab43fa37bb 100644 --- a/apps/datahub/src/app/record/navigation-bar/navigation-bar.component.spec.ts +++ b/apps/datahub/src/app/record/navigation-bar/navigation-bar.component.spec.ts @@ -1,3 +1,4 @@ +import { NO_ERRORS_SCHEMA } from '@angular/core' import { ComponentFixture, TestBed } from '@angular/core/testing' import { NavigationBarComponent } from './navigation-bar.component' @@ -9,6 +10,7 @@ describe('NavigationBarComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [NavigationBarComponent], + schemas: [NO_ERRORS_SCHEMA], }).compileComponents() }) diff --git a/apps/datahub/src/app/router/constants.ts b/apps/datahub/src/app/router/constants.ts new file mode 100644 index 0000000000..2c962b5eca --- /dev/null +++ b/apps/datahub/src/app/router/constants.ts @@ -0,0 +1,3 @@ +export const ROUTER_ROUTE_HOME = 'home' +export const ROUTER_ROUTE_NEWS = 'news' +export const ROUTER_ROUTE_ORGANISATIONS = 'organisations' diff --git a/apps/datahub/src/app/router/datahub-router.service.spec.ts b/apps/datahub/src/app/router/datahub-router.service.spec.ts new file mode 100644 index 0000000000..c7269f2305 --- /dev/null +++ b/apps/datahub/src/app/router/datahub-router.service.spec.ts @@ -0,0 +1,86 @@ +import { TestBed } from '@angular/core/testing' +import { Router } from '@angular/router' +import { HomePageComponent } from '../home/home-page/home-page.component' +import { NewsPageComponent } from '../home/news-page/news-page.component' +import { OrganisationsPageComponent } from '../home/organisations-page/organisations-page.component' +import { SearchPageComponent } from '../home/search/search-page/search-page.component' +import { RecordPageComponent } from '../record/record-page/record-page.component' + +import { DatahubRouterService } from './datahub-router.service' + +const RouterMock = { + resetConfig: jest.fn(), +} + +const expectedRoutes = [ + { + path: '', + redirectTo: 'home/search', + pathMatch: 'full', + }, + { + path: 'home', + redirectTo: 'home/search', + pathMatch: 'full', + }, + { + path: 'home', + component: HomePageComponent, + data: { + shouldDetach: true, + }, + children: [ + { + path: 'news', + component: NewsPageComponent, + data: { + shouldDetach: true, + }, + }, + { + path: 'search', + component: SearchPageComponent, + data: { + shouldDetach: true, + }, + }, + { + path: 'organisations', + component: OrganisationsPageComponent, + data: { + shouldDetach: true, + }, + }, + ], + }, + { + path: `dataset/:metadataUuid`, + component: RecordPageComponent, + }, +] +describe('DatahubRouterService', () => { + let service: DatahubRouterService + + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ + { + provide: Router, + useValue: RouterMock, + }, + ], + }) + service = TestBed.inject(DatahubRouterService) + }) + + it('should be created', () => { + expect(service).toBeTruthy() + }) + it('build routes', () => { + expect(service.buildRoutes()).toEqual(expectedRoutes) + }) + it('reset config', () => { + service.initRoutes() + expect(RouterMock.resetConfig).toHaveBeenCalledWith(expectedRoutes) + }) +}) diff --git a/apps/datahub/src/app/router/datahub-router.service.ts b/apps/datahub/src/app/router/datahub-router.service.ts new file mode 100644 index 0000000000..6a373a4082 --- /dev/null +++ b/apps/datahub/src/app/router/datahub-router.service.ts @@ -0,0 +1,80 @@ +import { Injectable } from '@angular/core' +import { Router, Routes } from '@angular/router' +import { + ROUTER_ROUTE_DATASET, + ROUTER_ROUTE_SEARCH, +} from '@geonetwork-ui/feature/router' +import { HomePageComponent } from '../home/home-page/home-page.component' +import { NewsPageComponent } from '../home/news-page/news-page.component' +import { OrganisationsPageComponent } from '../home/organisations-page/organisations-page.component' +import { SearchPageComponent } from '../home/search/search-page/search-page.component' +import { RecordPageComponent } from '../record/record-page/record-page.component' +import { + ROUTER_ROUTE_HOME, + ROUTER_ROUTE_NEWS, + ROUTER_ROUTE_ORGANISATIONS, +} from './constants' + +@Injectable({ + providedIn: 'root', +}) +export class DatahubRouterService { + constructor(private router: Router) {} + + initRoutes() { + this.router.resetConfig(this.buildRoutes()) + } + + buildRoutes(): Routes { + return [ + { + path: '', + redirectTo: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_SEARCH}`, + pathMatch: 'full', + }, + { + path: ROUTER_ROUTE_HOME, + redirectTo: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_SEARCH}`, + pathMatch: 'full', + }, + { + path: ROUTER_ROUTE_HOME, + component: HomePageComponent, + data: { + shouldDetach: true, + }, + children: [ + { + path: ROUTER_ROUTE_NEWS, + component: NewsPageComponent, + data: { + shouldDetach: true, + }, + }, + { + path: ROUTER_ROUTE_SEARCH, + component: SearchPageComponent, + data: { + shouldDetach: true, + }, + }, + { + path: ROUTER_ROUTE_ORGANISATIONS, + component: OrganisationsPageComponent, + data: { + shouldDetach: true, + }, + }, + ], + }, + { + path: `${ROUTER_ROUTE_DATASET}/:metadataUuid`, + component: RecordPageComponent, + }, + ] + } + + getSearchRoute(): string { + return `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_SEARCH}` + } +} diff --git a/apps/datahub/src/app/search/search-page/search-page.component.html b/apps/datahub/src/app/search/search-page/search-page.component.html deleted file mode 100644 index dfbb296541..0000000000 --- a/apps/datahub/src/app/search/search-page/search-page.component.html +++ /dev/null @@ -1,22 +0,0 @@ -
- - - - - -
-
-
- -
-
- -
-
-
-
diff --git a/libs/feature/router/src/lib/default/SearchRouteReuseStrategy.spec.ts b/libs/feature/router/src/lib/default/SearchRouteReuseStrategy.spec.ts index b54e72a41f..0176fa55d6 100644 --- a/libs/feature/router/src/lib/default/SearchRouteReuseStrategy.spec.ts +++ b/libs/feature/router/src/lib/default/SearchRouteReuseStrategy.spec.ts @@ -13,21 +13,27 @@ describe('SearchRouteReuseStrategy', () => { routeConfig: { path: 'search', }, + data: { + shouldDetach: true, + }, } }) describe('#shouldDetach', () => { - describe('when route is `search`', () => { + describe('when route has shouldDetach = true', () => { it('returns true', () => { expect(reuseStrategy.shouldDetach(route)).toBe(true) }) }) - describe('when route is `dataset`', () => { + describe('when route is shouldDetach is undefined', () => { beforeEach(() => { route = { routeConfig: { path: 'dataset', }, + data: { + shouldDetach: false, + }, } }) it('returns false', () => { diff --git a/libs/feature/router/src/lib/default/SearchRouteReuseStrategy.ts b/libs/feature/router/src/lib/default/SearchRouteReuseStrategy.ts index 51a89735ee..b6891c5f8a 100644 --- a/libs/feature/router/src/lib/default/SearchRouteReuseStrategy.ts +++ b/libs/feature/router/src/lib/default/SearchRouteReuseStrategy.ts @@ -1,15 +1,14 @@ import { - RouteReuseStrategy, ActivatedRouteSnapshot, DetachedRouteHandle, + RouteReuseStrategy, } from '@angular/router' -import { ROUTER_ROUTE_SEARCH } from './constants' export class SearchRouteReuseStrategy implements RouteReuseStrategy { private storedRoutes = new Map() shouldDetach(route: ActivatedRouteSnapshot): boolean { - return route.routeConfig.path === ROUTER_ROUTE_SEARCH + return route.data.shouldDetach === true } store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle): void { diff --git a/libs/feature/router/src/lib/default/index.ts b/libs/feature/router/src/lib/default/index.ts index 6ec95fc880..f9a59a8017 100644 --- a/libs/feature/router/src/lib/default/index.ts +++ b/libs/feature/router/src/lib/default/index.ts @@ -1,5 +1,5 @@ export * from './router.module' export * from './constants' export * from './state' -export * from './router-init.service' +export * from './router.service' export * from './router.mapper' diff --git a/libs/feature/router/src/lib/default/router.module.ts b/libs/feature/router/src/lib/default/router.module.ts index 87ae73e95f..7051bc1bff 100644 --- a/libs/feature/router/src/lib/default/router.module.ts +++ b/libs/feature/router/src/lib/default/router.module.ts @@ -14,7 +14,7 @@ import { import { StoreModule } from '@ngrx/store' import { ROUTER_STATE_KEY } from './constants' import { SearchRouterContainerDirective } from './container/search-router.container.directive' -import { RouterInitService } from './router-init.service' +import { RouterService } from './router.service' import { SearchRouteReuseStrategy } from './SearchRouteReuseStrategy' import { RouterFacade } from './state' import { RouterEffects } from './state/router.effects' @@ -48,8 +48,8 @@ export const ROUTER_CONFIG = new InjectionToken( ], }) export class DefaultRouterModule { - constructor(private routerInit: RouterInitService) { - this.routerInit.initRoutes() + constructor(private routerService: RouterService) { + this.routerService.initRoutes() } static forRoot( diff --git a/libs/feature/router/src/lib/default/router-init.service.spec.ts b/libs/feature/router/src/lib/default/router.service.spec.ts similarity index 86% rename from libs/feature/router/src/lib/default/router-init.service.spec.ts rename to libs/feature/router/src/lib/default/router.service.spec.ts index ce47b0059f..2b18c9ccc3 100644 --- a/libs/feature/router/src/lib/default/router-init.service.spec.ts +++ b/libs/feature/router/src/lib/default/router.service.spec.ts @@ -2,7 +2,7 @@ import { TestBed } from '@angular/core/testing' import { Router } from '@angular/router' import { ROUTER_CONFIG } from './router.module' -import { RouterInitService } from './router-init.service' +import { RouterService } from './router.service' const SearchRouteComponent = { name: 'searchRoute', @@ -31,6 +31,9 @@ const expectedRoutes = [ name: 'searchRoute', }, path: 'search', + data: { + shouldDetach: true, + }, }, { component: { @@ -39,8 +42,8 @@ const expectedRoutes = [ path: 'dataset/:metadataUuid', }, ] -describe('RouterInitService', () => { - let service: RouterInitService +describe('RouterService', () => { + let service: RouterService beforeEach(() => { TestBed.configureTestingModule({ @@ -55,7 +58,7 @@ describe('RouterInitService', () => { }, ], }) - service = TestBed.inject(RouterInitService) + service = TestBed.inject(RouterService) }) it('should be created', () => { diff --git a/libs/feature/router/src/lib/default/router-init.service.ts b/libs/feature/router/src/lib/default/router.service.ts similarity index 83% rename from libs/feature/router/src/lib/default/router-init.service.ts rename to libs/feature/router/src/lib/default/router.service.ts index ea256a575f..e185361cd1 100644 --- a/libs/feature/router/src/lib/default/router-init.service.ts +++ b/libs/feature/router/src/lib/default/router.service.ts @@ -5,13 +5,13 @@ import { ROUTER_ROUTE_DATASET, ROUTER_ROUTE_SEARCH, RouterConfigModel, -} from './' +} from '.' import { Router, Routes } from '@angular/router' @Injectable({ providedIn: 'root', }) -export class RouterInitService { +export class RouterService { constructor( @Inject(ROUTER_CONFIG) private routerConfig: RouterConfigModel, private router: Router @@ -26,6 +26,9 @@ export class RouterInitService { { path: '', redirectTo: `/${ROUTER_ROUTE_SEARCH}`, pathMatch: 'full' }, { path: ROUTER_ROUTE_SEARCH, + data: { + shouldDetach: true, + }, component: this.routerConfig.searchRouteComponent, }, { @@ -34,4 +37,8 @@ export class RouterInitService { }, ] } + + getSearchRoute(): string { + return ROUTER_ROUTE_SEARCH + } } diff --git a/libs/feature/router/src/lib/default/state/router.facade.ts b/libs/feature/router/src/lib/default/state/router.facade.ts index ece26ef147..8cb97f161d 100644 --- a/libs/feature/router/src/lib/default/state/router.facade.ts +++ b/libs/feature/router/src/lib/default/state/router.facade.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core' import { MdViewActions } from '@geonetwork-ui/feature/record' +import { RouterService } from '../router.service' import { MetadataRecord } from '@geonetwork-ui/util/shared' import { RouterReducerState } from '@ngrx/router-store' import { select, Store } from '@ngrx/store' @@ -42,7 +43,10 @@ export class RouterFacade { distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)) ) - constructor(private store: Store) {} + constructor( + private store: Store, + private routerService: RouterService + ) {} goToMetadata(metadata: MetadataRecord) { this.pathParams$ @@ -62,7 +66,7 @@ export class RouterFacade { updateSearch(query?: SearchRouteParams) { this.go({ - path: `${ROUTER_ROUTE_SEARCH}/`, + path: this.routerService.getSearchRoute(), ...(query && { query }), queryParamsHandling: 'merge', }) @@ -70,7 +74,7 @@ export class RouterFacade { setSearch(query?: SearchRouteParams) { this.go({ - path: `${ROUTER_ROUTE_SEARCH}/`, + path: this.routerService.getSearchRoute(), ...(query && { query }), }) } diff --git a/translations/de.json b/translations/de.json index 03031ffe72..c3b94554ef 100644 --- a/translations/de.json +++ b/translations/de.json @@ -73,13 +73,14 @@ "datafeeder.wizardSummarize.createdAt": "", "datafeeder.wizardSummarize.scale": "", "datahub.header.connex": "", + "datahub.header.datasets": "", "datahub.header.lastRecords": "", "datahub.header.myfavorites": "", + "datahub.header.news": "", + "datahub.header.organisations": "", "datahub.header.popularRecords": "", "datahub.header.title.html": "", "datahub.search.back": "", - "datahub.search.filter.all": "", - "datahub.search.filter.others": "", "datahub.search.filter.generatedByWfs": "", "dataset.error.http": "", "dataset.error.network": "", diff --git a/translations/en.json b/translations/en.json index e302e600a0..060949dabf 100644 --- a/translations/en.json +++ b/translations/en.json @@ -73,13 +73,14 @@ "datafeeder.wizardSummarize.createdAt": "Created at", "datafeeder.wizardSummarize.scale": "Scale", "datahub.header.connex": "Beside search", + "datahub.header.datasets": "Datasets", "datahub.header.lastRecords": "The latest", "datahub.header.myfavorites": "My favorites", + "datahub.header.news": "News", + "datahub.header.organisations": "Organisations", "datahub.header.popularRecords": "The most popular", "datahub.header.title.html": "
Discover open
data from my Organization
", "datahub.search.back": "Back to results", - "datahub.search.filter.all": "All", - "datahub.search.filter.others": "Others", "datahub.search.filter.generatedByWfs": "generated by API (WFS)", "dataset.error.http": "The data could not be loaded because of an HTTP error", "dataset.error.network": "The data could not be loaded because of a network error or CORS limitations", diff --git a/translations/es.json b/translations/es.json index 03031ffe72..c3b94554ef 100644 --- a/translations/es.json +++ b/translations/es.json @@ -73,13 +73,14 @@ "datafeeder.wizardSummarize.createdAt": "", "datafeeder.wizardSummarize.scale": "", "datahub.header.connex": "", + "datahub.header.datasets": "", "datahub.header.lastRecords": "", "datahub.header.myfavorites": "", + "datahub.header.news": "", + "datahub.header.organisations": "", "datahub.header.popularRecords": "", "datahub.header.title.html": "", "datahub.search.back": "", - "datahub.search.filter.all": "", - "datahub.search.filter.others": "", "datahub.search.filter.generatedByWfs": "", "dataset.error.http": "", "dataset.error.network": "", diff --git a/translations/fr.json b/translations/fr.json index 8f103233b8..c149801828 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -73,13 +73,14 @@ "datafeeder.wizardSummarize.createdAt": "Créée le", "datafeeder.wizardSummarize.scale": "Échelle", "datahub.header.connex": "recherche connexe", + "datahub.header.datasets": "Datasets", "datahub.header.lastRecords": "les plus récentes", "datahub.header.myfavorites": "mes favoris", + "datahub.header.news": "Fil d'activité", + "datahub.header.organisations": "Organisations", "datahub.header.popularRecords": "les plus appréciées", "datahub.header.title.html": "
Toutes les données
publiques de mon organisation
", "datahub.search.back": "Retour aux résultats", - "datahub.search.filter.all": "Tous", - "datahub.search.filter.others": "Autres", "datahub.search.filter.generatedByWfs": "généré par API (WFS)", "dataset.error.http": "Le chargement des données a échoué en raison d'une erreur HTTP", "dataset.error.network": "Le chargement des données a échoué en raison d'une erreur réseau ou de limitations CORS", diff --git a/translations/it.json b/translations/it.json index f3cb2882dc..88ec616e7c 100644 --- a/translations/it.json +++ b/translations/it.json @@ -73,13 +73,14 @@ "datafeeder.wizardSummarize.createdAt": "", "datafeeder.wizardSummarize.scale": "", "datahub.header.connex": "", + "datahub.header.datasets": "", "datahub.header.lastRecords": "", "datahub.header.myfavorites": "", + "datahub.header.news": "", + "datahub.header.organisations": "", "datahub.header.popularRecords": "", "datahub.header.title.html": "", "datahub.search.back": "", - "datahub.search.filter.all": "", - "datahub.search.filter.others": "", "datahub.search.filter.generatedByWfs": "name", "dataset.error.http": "", "dataset.error.network": "", diff --git a/translations/nl.json b/translations/nl.json index 03031ffe72..c3b94554ef 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -73,13 +73,14 @@ "datafeeder.wizardSummarize.createdAt": "", "datafeeder.wizardSummarize.scale": "", "datahub.header.connex": "", + "datahub.header.datasets": "", "datahub.header.lastRecords": "", "datahub.header.myfavorites": "", + "datahub.header.news": "", + "datahub.header.organisations": "", "datahub.header.popularRecords": "", "datahub.header.title.html": "", "datahub.search.back": "", - "datahub.search.filter.all": "", - "datahub.search.filter.others": "", "datahub.search.filter.generatedByWfs": "", "dataset.error.http": "", "dataset.error.network": "", diff --git a/translations/pt.json b/translations/pt.json index 03031ffe72..c3b94554ef 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -73,13 +73,14 @@ "datafeeder.wizardSummarize.createdAt": "", "datafeeder.wizardSummarize.scale": "", "datahub.header.connex": "", + "datahub.header.datasets": "", "datahub.header.lastRecords": "", "datahub.header.myfavorites": "", + "datahub.header.news": "", + "datahub.header.organisations": "", "datahub.header.popularRecords": "", "datahub.header.title.html": "", "datahub.search.back": "", - "datahub.search.filter.all": "", - "datahub.search.filter.others": "", "datahub.search.filter.generatedByWfs": "", "dataset.error.http": "", "dataset.error.network": "",