From 19d91b4d2f1abf5ab8630e9615836aa72f8d0ccc Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Wed, 22 Jun 2022 16:04:01 +0200 Subject: [PATCH 01/20] refactor(dh:home-page): split search page into home and search page --- .../home/home-page/home-page.component.html | 10 +++++++ .../home-page/home-page.component.scss} | 0 .../home-page/home-page.component.spec.ts | 27 +++++++++++++++++++ .../app/home/home-page/home-page.component.ts | 9 +++++++ .../search-page/search-page.component.html | 11 ++++++++ .../search-page/search-page.component.scss | 0 .../search-page/search-page.component.spec.ts | 0 .../search-page/search-page.component.ts | 2 +- .../search-page/search-page.component.html | 22 --------------- 9 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 apps/datahub/src/app/home/home-page/home-page.component.html rename apps/datahub/src/app/{search/search-page/search-page.component.scss => home/home-page/home-page.component.scss} (100%) create mode 100644 apps/datahub/src/app/home/home-page/home-page.component.spec.ts create mode 100644 apps/datahub/src/app/home/home-page/home-page.component.ts create mode 100644 apps/datahub/src/app/home/search/search-page/search-page.component.html create mode 100644 apps/datahub/src/app/home/search/search-page/search-page.component.scss rename apps/datahub/src/app/{ => home}/search/search-page/search-page.component.spec.ts (100%) rename apps/datahub/src/app/{ => home}/search/search-page/search-page.component.ts (96%) delete mode 100644 apps/datahub/src/app/search/search-page/search-page.component.html 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..bf5f1dfe0e --- /dev/null +++ b/apps/datahub/src/app/home/home-page/home-page.component.html @@ -0,0 +1,10 @@ +
+ + + + + +
+ +
+
diff --git a/apps/datahub/src/app/search/search-page/search-page.component.scss b/apps/datahub/src/app/home/home-page/home-page.component.scss similarity index 100% rename from apps/datahub/src/app/search/search-page/search-page.component.scss rename to apps/datahub/src/app/home/home-page/home-page.component.scss 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..bc29991a3a --- /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.scss'], + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class HomePageComponent {} 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..b2f73a0a3c --- /dev/null +++ b/apps/datahub/src/app/home/search/search-page/search-page.component.html @@ -0,0 +1,11 @@ +
+
+ +
+
+ +
+
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 100% 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 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 96% 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..f6de246fd2 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, } 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 @@ -
- - - - - -
-
-
- -
-
- -
-
-
-
From 431854f6d493f5bcbd4fd9bab349dc67e6986a41 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Wed, 22 Jun 2022 16:04:21 +0200 Subject: [PATCH 02/20] feat(dh:home-header): rename search header into home header and introduce new tabs --- .../home-header/home-header.component.css} | 0 .../home-header/home-header.component.html} | 15 ++-- .../home-header.component.spec.ts} | 10 +-- .../home/home-header/home-header.component.ts | 70 +++++++++++++++++++ .../search-header/search-header.component.ts | 34 --------- 5 files changed, 84 insertions(+), 45 deletions(-) rename apps/datahub/src/app/{search/search-header/search-header.component.css => home/home-header/home-header.component.css} (100%) rename apps/datahub/src/app/{search/search-header/search-header.component.html => home/home-header/home-header.component.html} (62%) rename apps/datahub/src/app/{search/search-header/search-header.component.spec.ts => home/home-header/home-header.component.spec.ts} (86%) create mode 100644 apps/datahub/src/app/home/home-header/home-header.component.ts delete mode 100644 apps/datahub/src/app/search/search-header/search-header.component.ts 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 62% 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..1d5937de02 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 @@ -29,21 +29,24 @@ -->
- - - +
Organisations
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 86% 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..02733a4c38 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 @@ -6,7 +6,7 @@ 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: () => ({ @@ -29,13 +29,13 @@ 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: [ { @@ -47,7 +47,7 @@ describe('HeaderComponent', () => { }) beforeEach(() => { - fixture = TestBed.createComponent(SearchHeaderComponent) + fixture = TestBed.createComponent(HomeHeaderComponent) component = fixture.componentInstance fixture.detectChanges() }) diff --git a/apps/datahub/src/app/home/home-header/home-header.component.ts b/apps/datahub/src/app/home/home-header/home-header.component.ts new file mode 100644 index 0000000000..7c0ed247d1 --- /dev/null +++ b/apps/datahub/src/app/home/home-header/home-header.component.ts @@ -0,0 +1,70 @@ +import { ChangeDetectionStrategy, Component, Input } from '@angular/core' +import { marker } from '@biesbjerg/ngx-translate-extract-marker' +import { RouterFacade } from '@geonetwork-ui/feature/router' +import { SearchFacade } 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_HOME, + ROUTER_ROUTE_NEWS, + ROUTER_ROUTE_ORGANISATION, + ROUTER_ROUTE_SEARCH, +} from '../../router/constants' + +marker('datahub.header.myfavorites') +marker('datahub.header.connex') +marker('datahub.header.lastRecords') +marker('datahub.header.popularRecords') + +@Component({ + selector: 'datahub-home-header', + templateUrl: './home-header.component.html', + styleUrls: ['./home-header.component.css'], + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class HomeHeaderComponent { + @Input() expandRatio: number + + searchInputRouteValue$ = this.routerFacade.anySearch$.pipe( + map((any) => ({ title: any })) + ) + currentRoute$ = this.routerFacade.currentRoute$.pipe( + map((route) => route.routeConfig.path) + ) + backgroundCss = + getThemeConfig().HEADER_BACKGROUND || + `center /cover url('assets/img/header_bg.webp')` + + constructor( + public routerFacade: RouterFacade, + private searchFacade: SearchFacade + ) {} + + onFuzzySearchSelection(record: MetadataRecord) { + this.routerFacade.goToMetadata(record) + } + + onNewsClick(): void { + this.routerFacade.go({ path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_NEWS}` }) + this.resetSearch() + } + + onDatasetsClick(): void { + this.routerFacade.go({ + path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_SEARCH}`, + }) + this.resetSearch() + } + + onOrganisationsClick(): void { + this.routerFacade.go({ + path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_ORGANISATION}`, + }) + this.resetSearch() + } + + private resetSearch(): void { + this.searchFacade.setFilters({}) + } +} diff --git a/apps/datahub/src/app/search/search-header/search-header.component.ts b/apps/datahub/src/app/search/search-header/search-header.component.ts deleted file mode 100644 index 58421d03eb..0000000000 --- a/apps/datahub/src/app/search/search-header/search-header.component.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { ChangeDetectionStrategy, Component, Input } from '@angular/core' -import { marker } from '@biesbjerg/ngx-translate-extract-marker' -import { RouterFacade } from '@geonetwork-ui/feature/router' -import { getThemeConfig } from '@geonetwork-ui/util/app-config' -import { MetadataRecord } from '@geonetwork-ui/util/shared' -import { map } from 'rxjs/operators' - -marker('datahub.header.myfavorites') -marker('datahub.header.connex') -marker('datahub.header.lastRecords') -marker('datahub.header.popularRecords') - -@Component({ - selector: 'datahub-search-header', - templateUrl: './search-header.component.html', - styleUrls: ['./search-header.component.css'], - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class SearchHeaderComponent { - @Input() expandRatio: number - - searchInputRouteValue$ = this.routerFacade.anySearch$.pipe( - map((any) => ({ title: any })) - ) - backgroundCss = - getThemeConfig().HEADER_BACKGROUND || - `center /cover url('assets/img/header_bg.webp')` - - constructor(private routerFacade: RouterFacade) {} - - onFuzzySearchSelection(record: MetadataRecord) { - this.routerFacade.goToMetadata(record) - } -} From bb00fa94b85938880b3a7f7338ba24aa2c4aebab Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Wed, 22 Jun 2022 16:04:36 +0200 Subject: [PATCH 03/20] refactor(dh:search-page): move search page subcomponents --- apps/datahub/src/app/app.config.ts | 2 +- .../src/app/home/home-header/home-header.component.ts | 6 ++++-- .../record-preview-datahub.component.css | 0 .../record-preview-datahub.component.html | 0 .../record-preview-datahub.component.spec.ts | 0 .../record-preview-datahub.component.ts | 0 .../search/search-summary/search-summary.component.css | 0 .../search/search-summary/search-summary.component.html | 0 .../search/search-summary/search-summary.component.spec.ts | 0 .../search/search-summary/search-summary.component.ts | 0 10 files changed, 5 insertions(+), 3 deletions(-) rename apps/datahub/src/app/{ => home}/search/record-preview-datahub/record-preview-datahub.component.css (100%) rename apps/datahub/src/app/{ => home}/search/record-preview-datahub/record-preview-datahub.component.html (100%) rename apps/datahub/src/app/{ => home}/search/record-preview-datahub/record-preview-datahub.component.spec.ts (100%) rename apps/datahub/src/app/{ => home}/search/record-preview-datahub/record-preview-datahub.component.ts (100%) rename apps/datahub/src/app/{ => home}/search/search-summary/search-summary.component.css (100%) rename apps/datahub/src/app/{ => home}/search/search-summary/search-summary.component.html (100%) rename apps/datahub/src/app/{ => home}/search/search-summary/search-summary.component.spec.ts (100%) rename apps/datahub/src/app/{ => home}/search/search-summary/search-summary.component.ts (100%) 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/home/home-header/home-header.component.ts b/apps/datahub/src/app/home/home-header/home-header.component.ts index 7c0ed247d1..3378af7606 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.ts +++ b/apps/datahub/src/app/home/home-header/home-header.component.ts @@ -1,6 +1,9 @@ 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 { SearchFacade } from '@geonetwork-ui/feature/search' import { getThemeConfig } from '@geonetwork-ui/util/app-config' import { MetadataRecord } from '@geonetwork-ui/util/shared' @@ -9,7 +12,6 @@ import { ROUTER_ROUTE_HOME, ROUTER_ROUTE_NEWS, ROUTER_ROUTE_ORGANISATION, - ROUTER_ROUTE_SEARCH, } from '../../router/constants' marker('datahub.header.myfavorites') diff --git a/apps/datahub/src/app/search/record-preview-datahub/record-preview-datahub.component.css b/apps/datahub/src/app/home/search/record-preview-datahub/record-preview-datahub.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/search/record-preview-datahub/record-preview-datahub.component.css 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 100% 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 diff --git a/apps/datahub/src/app/search/search-summary/search-summary.component.css b/apps/datahub/src/app/home/search/search-summary/search-summary.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/search/search-summary/search-summary.component.css 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 100% 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 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 From f640437a07e36c674ef9a782a30b381b515ee62d Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Wed, 22 Jun 2022 16:04:40 +0200 Subject: [PATCH 04/20] feat(dh:news-page): generate empty news page --- .../home/news-page/news-page.component.css | 0 .../home/news-page/news-page.component.html | 1 + .../news-page/news-page.component.spec.ts | 22 +++++++++++++++++++ .../app/home/news-page/news-page.component.ts | 13 +++++++++++ 4 files changed, 36 insertions(+) create mode 100644 apps/datahub/src/app/home/news-page/news-page.component.css create mode 100644 apps/datahub/src/app/home/news-page/news-page.component.html create mode 100644 apps/datahub/src/app/home/news-page/news-page.component.spec.ts create mode 100644 apps/datahub/src/app/home/news-page/news-page.component.ts diff --git a/apps/datahub/src/app/home/news-page/news-page.component.css b/apps/datahub/src/app/home/news-page/news-page.component.css new file mode 100644 index 0000000000..e69de29bb2 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..9088c76fcf --- /dev/null +++ b/apps/datahub/src/app/home/news-page/news-page.component.ts @@ -0,0 +1,13 @@ +import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core' + +@Component({ + selector: 'datahub-news-page', + templateUrl: './news-page.component.html', + styleUrls: ['./news-page.component.css'], + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class NewsPageComponent implements OnInit { + constructor() {} + + ngOnInit(): void {} +} From b319fd3189f35c965470622c872d5a00a73918e0 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Wed, 22 Jun 2022 16:04:44 +0200 Subject: [PATCH 05/20] feat(dh:organisations-page): generate empty organisations page --- .../organisations-page.component.css | 0 .../organisations-page.component.html | 1 + .../organisations-page.component.spec.ts | 22 +++++++++++++++++++ .../organisations-page.component.ts | 13 +++++++++++ 4 files changed, 36 insertions(+) create mode 100644 apps/datahub/src/app/home/organisations-page/organisations-page.component.css create mode 100644 apps/datahub/src/app/home/organisations-page/organisations-page.component.html create mode 100644 apps/datahub/src/app/home/organisations-page/organisations-page.component.spec.ts create mode 100644 apps/datahub/src/app/home/organisations-page/organisations-page.component.ts diff --git a/apps/datahub/src/app/home/organisations-page/organisations-page.component.css b/apps/datahub/src/app/home/organisations-page/organisations-page.component.css new file mode 100644 index 0000000000..e69de29bb2 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..2f0e83c7a7 --- /dev/null +++ b/apps/datahub/src/app/home/organisations-page/organisations-page.component.ts @@ -0,0 +1,13 @@ +import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core' + +@Component({ + selector: 'datahub-organisations-page', + templateUrl: './organisations-page.component.html', + styleUrls: ['./organisations-page.component.css'], + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class OrganisationsPageComponent implements OnInit { + constructor() {} + + ngOnInit(): void {} +} From 0496431fe28272e27be0eceb80ef469cbe4c3ba9 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Wed, 22 Jun 2022 16:04:47 +0200 Subject: [PATCH 06/20] feat(dh:router-init): add new routes via init from dh --- apps/datahub/src/app/router/constants.ts | 18 ++++++ ...atahub-router-init-service.service.spec.ts | 16 +++++ .../datahub-router-init-service.service.ts | 59 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 apps/datahub/src/app/router/constants.ts create mode 100644 apps/datahub/src/app/router/datahub-router-init-service.service.spec.ts create mode 100644 apps/datahub/src/app/router/datahub-router-init-service.service.ts diff --git a/apps/datahub/src/app/router/constants.ts b/apps/datahub/src/app/router/constants.ts new file mode 100644 index 0000000000..133285d23e --- /dev/null +++ b/apps/datahub/src/app/router/constants.ts @@ -0,0 +1,18 @@ +// import { InjectionToken, Type } from '@angular/core' + +export const ROUTER_ROUTE_HOME = 'home' +export const ROUTER_ROUTE_NEWS = 'news' +export const ROUTER_ROUTE_ORGANISATION = 'organisations' + +// export interface RouterConfigModel { +// searchStateId: string +// homeRouteComponent: Type +// newsRouteComponent: Type +// searchRouteComponent: Type +// organisationsRouteComponent: Type +// recordRouteComponent: Type +// } + +// export const DATAHUB_ROUTER_CONFIG = new InjectionToken( +// 'router.config' +// ) diff --git a/apps/datahub/src/app/router/datahub-router-init-service.service.spec.ts b/apps/datahub/src/app/router/datahub-router-init-service.service.spec.ts new file mode 100644 index 0000000000..a2212122ca --- /dev/null +++ b/apps/datahub/src/app/router/datahub-router-init-service.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { DatahubRouterInitServiceService } from './datahub-router-init-service.service'; + +describe('DatahubRouterInitServiceService', () => { + let service: DatahubRouterInitServiceService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(DatahubRouterInitServiceService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/apps/datahub/src/app/router/datahub-router-init-service.service.ts b/apps/datahub/src/app/router/datahub-router-init-service.service.ts new file mode 100644 index 0000000000..27abf379b6 --- /dev/null +++ b/apps/datahub/src/app/router/datahub-router-init-service.service.ts @@ -0,0 +1,59 @@ +import { Inject, Injectable } from '@angular/core' +import { Router, Routes } from '@angular/router' +import { + RouterConfigModel, + ROUTER_CONFIG, + ROUTER_ROUTE_DATASET, + ROUTER_ROUTE_SEARCH, +} from '@geonetwork-ui/feature/router' +import { + ROUTER_ROUTE_HOME, + ROUTER_ROUTE_NEWS, + ROUTER_ROUTE_ORGANISATION, +} from './constants' + +@Injectable({ + providedIn: 'root', +}) +export class DatahubRouterInitServiceService { + constructor( + @Inject(ROUTER_CONFIG) private routerConfig: RouterConfigModel, + 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}`, + component: this.routerConfig.homeRouteComponent, + children: [ + { + path: ROUTER_ROUTE_NEWS, + component: this.routerConfig.newsRouteComponent, + }, + { + path: ROUTER_ROUTE_SEARCH, + component: this.routerConfig.searchRouteComponent, + }, + { + path: ROUTER_ROUTE_ORGANISATION, + component: this.routerConfig.organisationsRouteComponent, + }, + ], + }, + { + path: `${ROUTER_ROUTE_DATASET}/:metadataUuid`, + component: this.routerConfig.recordRouteComponent, + }, + ] + } +} From c5e8ff37077484c932eab79de784f9eb633b4159 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Wed, 22 Jun 2022 16:04:50 +0200 Subject: [PATCH 07/20] refactor(dh:app-module): update app module --- apps/datahub/src/app/app.module.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/apps/datahub/src/app/app.module.ts b/apps/datahub/src/app/app.module.ts index 49ab6ddfc8..8720cc62f1 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, + RouterInitService, ROUTER_ROUTE_DATASET, } from '@geonetwork-ui/feature/router' import { FeatureSearchModule } from '@geonetwork-ui/feature/search' @@ -37,14 +38,19 @@ 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 { DatahubRouterInitServiceService } from './router/datahub-router-init-service.service' +import { OrganisationsPageComponent } from './home/organisations-page/organisations-page.component' +import { SearchPageComponent } from './home/search/search-page/search-page.component' +// import { DATAHUB_ROUTER_CONFIG } from './router/constants' export const metaReducers: MetaReducer[] = !environment.production ? [] : [] // https://github.com/nrwl/nx/issues/191 @@ -52,14 +58,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, @@ -83,7 +92,10 @@ export const metaReducers: MetaReducer[] = !environment.production ? [] : [] FeatureSearchModule, DefaultRouterModule.forRoot({ searchStateId: 'mainSearch', + homeRouteComponent: HomePageComponent, + newsRouteComponent: NewsPageComponent, searchRouteComponent: SearchPageComponent, + organisationsRouteComponent: OrganisationsPageComponent, recordRouteComponent: RecordPageComponent, }), FeatureRecordModule, @@ -96,6 +108,8 @@ export const metaReducers: MetaReducer[] = !environment.production ? [] : [] ], providers: [ { provide: RESULTS_LAYOUT_CONFIG, useValue: DATAHUB_RESULTS_LAYOUT_CONFIG }, + { provide: RouterInitService, useClass: DatahubRouterInitServiceService }, + // { provide: ROUTER_CONFIG, useValue: DATAHUB_ROUTER_CONFIG }, { provide: Configuration, useFactory: () => From a7c2aef2579c3118e0146d3cbd0454d873618330 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Mon, 27 Jun 2022 11:59:02 +0200 Subject: [PATCH 08/20] refactor(dh-router): init router with default config, override in dh service --- apps/datahub/src/app/app.module.ts | 5 ---- apps/datahub/src/app/router/constants.ts | 15 ----------- .../datahub-router-init-service.service.ts | 26 +++++++++---------- 3 files changed, 13 insertions(+), 33 deletions(-) diff --git a/apps/datahub/src/app/app.module.ts b/apps/datahub/src/app/app.module.ts index 8720cc62f1..1ddf60c26f 100644 --- a/apps/datahub/src/app/app.module.ts +++ b/apps/datahub/src/app/app.module.ts @@ -50,7 +50,6 @@ import { NewsPageComponent } from './home/news-page/news-page.component' import { DatahubRouterInitServiceService } from './router/datahub-router-init-service.service' import { OrganisationsPageComponent } from './home/organisations-page/organisations-page.component' import { SearchPageComponent } from './home/search/search-page/search-page.component' -// import { DATAHUB_ROUTER_CONFIG } from './router/constants' export const metaReducers: MetaReducer[] = !environment.production ? [] : [] // https://github.com/nrwl/nx/issues/191 @@ -92,10 +91,7 @@ export const metaReducers: MetaReducer[] = !environment.production ? [] : [] FeatureSearchModule, DefaultRouterModule.forRoot({ searchStateId: 'mainSearch', - homeRouteComponent: HomePageComponent, - newsRouteComponent: NewsPageComponent, searchRouteComponent: SearchPageComponent, - organisationsRouteComponent: OrganisationsPageComponent, recordRouteComponent: RecordPageComponent, }), FeatureRecordModule, @@ -109,7 +105,6 @@ export const metaReducers: MetaReducer[] = !environment.production ? [] : [] providers: [ { provide: RESULTS_LAYOUT_CONFIG, useValue: DATAHUB_RESULTS_LAYOUT_CONFIG }, { provide: RouterInitService, useClass: DatahubRouterInitServiceService }, - // { provide: ROUTER_CONFIG, useValue: DATAHUB_ROUTER_CONFIG }, { provide: Configuration, useFactory: () => diff --git a/apps/datahub/src/app/router/constants.ts b/apps/datahub/src/app/router/constants.ts index 133285d23e..bc4dc12779 100644 --- a/apps/datahub/src/app/router/constants.ts +++ b/apps/datahub/src/app/router/constants.ts @@ -1,18 +1,3 @@ -// import { InjectionToken, Type } from '@angular/core' - export const ROUTER_ROUTE_HOME = 'home' export const ROUTER_ROUTE_NEWS = 'news' export const ROUTER_ROUTE_ORGANISATION = 'organisations' - -// export interface RouterConfigModel { -// searchStateId: string -// homeRouteComponent: Type -// newsRouteComponent: Type -// searchRouteComponent: Type -// organisationsRouteComponent: Type -// recordRouteComponent: Type -// } - -// export const DATAHUB_ROUTER_CONFIG = new InjectionToken( -// 'router.config' -// ) diff --git a/apps/datahub/src/app/router/datahub-router-init-service.service.ts b/apps/datahub/src/app/router/datahub-router-init-service.service.ts index 27abf379b6..2449a23d34 100644 --- a/apps/datahub/src/app/router/datahub-router-init-service.service.ts +++ b/apps/datahub/src/app/router/datahub-router-init-service.service.ts @@ -1,11 +1,14 @@ -import { Inject, Injectable } from '@angular/core' +import { Injectable } from '@angular/core' import { Router, Routes } from '@angular/router' import { - RouterConfigModel, - ROUTER_CONFIG, 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, @@ -16,10 +19,7 @@ import { providedIn: 'root', }) export class DatahubRouterInitServiceService { - constructor( - @Inject(ROUTER_CONFIG) private routerConfig: RouterConfigModel, - private router: Router - ) {} + constructor(private router: Router) {} initRoutes() { this.router.resetConfig(this.buildRoutes()) @@ -33,26 +33,26 @@ export class DatahubRouterInitServiceService { pathMatch: 'full', }, { - path: `${ROUTER_ROUTE_HOME}`, - component: this.routerConfig.homeRouteComponent, + path: ROUTER_ROUTE_HOME, + component: HomePageComponent, children: [ { path: ROUTER_ROUTE_NEWS, - component: this.routerConfig.newsRouteComponent, + component: NewsPageComponent, }, { path: ROUTER_ROUTE_SEARCH, - component: this.routerConfig.searchRouteComponent, + component: SearchPageComponent, }, { path: ROUTER_ROUTE_ORGANISATION, - component: this.routerConfig.organisationsRouteComponent, + component: OrganisationsPageComponent, }, ], }, { path: `${ROUTER_ROUTE_DATASET}/:metadataUuid`, - component: this.routerConfig.recordRouteComponent, + component: RecordPageComponent, }, ] } From 3bc3b737d396acb1845bb5638595d09b8c7b1975 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Mon, 27 Jun 2022 12:00:08 +0200 Subject: [PATCH 09/20] refactor(router): add getSearchRoute method for router facade --- .../app/router/datahub-router-init-service.service.ts | 4 ++++ .../router/src/lib/default/router-init.service.ts | 4 ++++ .../router/src/lib/default/state/router.facade.ts | 10 +++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/datahub/src/app/router/datahub-router-init-service.service.ts b/apps/datahub/src/app/router/datahub-router-init-service.service.ts index 2449a23d34..510e21052d 100644 --- a/apps/datahub/src/app/router/datahub-router-init-service.service.ts +++ b/apps/datahub/src/app/router/datahub-router-init-service.service.ts @@ -56,4 +56,8 @@ export class DatahubRouterInitServiceService { }, ] } + + getSearchRoute(): string { + return `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_SEARCH}` + } } diff --git a/libs/feature/router/src/lib/default/router-init.service.ts b/libs/feature/router/src/lib/default/router-init.service.ts index ea256a575f..4678e28992 100644 --- a/libs/feature/router/src/lib/default/router-init.service.ts +++ b/libs/feature/router/src/lib/default/router-init.service.ts @@ -34,4 +34,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..b50917f53a 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 { RouterInitService } from '../router-init.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: RouterInitService + ) {} 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 }), }) } From 4d0da8e14f4734cf8feb4169edbea4c3135ba05e Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Mon, 27 Jun 2022 12:08:19 +0200 Subject: [PATCH 10/20] refactor(router): rename router-init.service to router.service, in lib and dh --- apps/datahub/src/app/app.module.ts | 6 +++--- .../datahub-router-init-service.service.spec.ts | 16 ---------------- .../app/router/datahub-router.service.spec.ts | 16 ++++++++++++++++ ...vice.service.ts => datahub-router.service.ts} | 2 +- libs/feature/router/src/lib/default/index.ts | 2 +- .../router/src/lib/default/router.module.ts | 6 +++--- ...it.service.spec.ts => router.service.spec.ts} | 2 +- ...{router-init.service.ts => router.service.ts} | 4 ++-- .../src/lib/default/state/router.facade.ts | 4 ++-- 9 files changed, 29 insertions(+), 29 deletions(-) delete mode 100644 apps/datahub/src/app/router/datahub-router-init-service.service.spec.ts create mode 100644 apps/datahub/src/app/router/datahub-router.service.spec.ts rename apps/datahub/src/app/router/{datahub-router-init-service.service.ts => datahub-router.service.ts} (97%) rename libs/feature/router/src/lib/default/{router-init.service.spec.ts => router.service.spec.ts} (96%) rename libs/feature/router/src/lib/default/{router-init.service.ts => router.service.ts} (95%) diff --git a/apps/datahub/src/app/app.module.ts b/apps/datahub/src/app/app.module.ts index 1ddf60c26f..52d4ab2e94 100644 --- a/apps/datahub/src/app/app.module.ts +++ b/apps/datahub/src/app/app.module.ts @@ -7,7 +7,7 @@ import { Configuration } from '@geonetwork-ui/data-access/gn4' import { FeatureRecordModule } from '@geonetwork-ui/feature/record' import { DefaultRouterModule, - RouterInitService, + RouterService, ROUTER_ROUTE_DATASET, } from '@geonetwork-ui/feature/router' import { FeatureSearchModule } from '@geonetwork-ui/feature/search' @@ -47,7 +47,7 @@ import { SearchSummaryComponent } from './home/search/search-summary/search-summ 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 { DatahubRouterInitServiceService } from './router/datahub-router-init-service.service' +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' @@ -104,7 +104,7 @@ export const metaReducers: MetaReducer[] = !environment.production ? [] : [] ], providers: [ { provide: RESULTS_LAYOUT_CONFIG, useValue: DATAHUB_RESULTS_LAYOUT_CONFIG }, - { provide: RouterInitService, useClass: DatahubRouterInitServiceService }, + { provide: RouterService, useClass: DatahubRouterService }, { provide: Configuration, useFactory: () => diff --git a/apps/datahub/src/app/router/datahub-router-init-service.service.spec.ts b/apps/datahub/src/app/router/datahub-router-init-service.service.spec.ts deleted file mode 100644 index a2212122ca..0000000000 --- a/apps/datahub/src/app/router/datahub-router-init-service.service.spec.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { DatahubRouterInitServiceService } from './datahub-router-init-service.service'; - -describe('DatahubRouterInitServiceService', () => { - let service: DatahubRouterInitServiceService; - - beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(DatahubRouterInitServiceService); - }); - - it('should be created', () => { - expect(service).toBeTruthy(); - }); -}); 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..053194a3e6 --- /dev/null +++ b/apps/datahub/src/app/router/datahub-router.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing' + +import { DatahubRouterService } from './datahub-router.service' + +describe('DatahubRouterInitServiceService', () => { + let service: DatahubRouterService + + beforeEach(() => { + TestBed.configureTestingModule({}) + service = TestBed.inject(DatahubRouterService) + }) + + it('should be created', () => { + expect(service).toBeTruthy() + }) +}) diff --git a/apps/datahub/src/app/router/datahub-router-init-service.service.ts b/apps/datahub/src/app/router/datahub-router.service.ts similarity index 97% rename from apps/datahub/src/app/router/datahub-router-init-service.service.ts rename to apps/datahub/src/app/router/datahub-router.service.ts index 510e21052d..5faafa2403 100644 --- a/apps/datahub/src/app/router/datahub-router-init-service.service.ts +++ b/apps/datahub/src/app/router/datahub-router.service.ts @@ -18,7 +18,7 @@ import { @Injectable({ providedIn: 'root', }) -export class DatahubRouterInitServiceService { +export class DatahubRouterService { constructor(private router: Router) {} initRoutes() { 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 96% 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..e27fd744b6 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 { RouterInitService } from './router.service' const SearchRouteComponent = { name: 'searchRoute', 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 95% rename from libs/feature/router/src/lib/default/router-init.service.ts rename to libs/feature/router/src/lib/default/router.service.ts index 4678e28992..90f4c992f2 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 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 b50917f53a..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,6 +1,6 @@ import { Injectable } from '@angular/core' import { MdViewActions } from '@geonetwork-ui/feature/record' -import { RouterInitService } from '../router-init.service' +import { RouterService } from '../router.service' import { MetadataRecord } from '@geonetwork-ui/util/shared' import { RouterReducerState } from '@ngrx/router-store' import { select, Store } from '@ngrx/store' @@ -45,7 +45,7 @@ export class RouterFacade { constructor( private store: Store, - private routerService: RouterInitService + private routerService: RouterService ) {} goToMetadata(metadata: MetadataRecord) { From 18497bfa64dc3301e3d6886f3bea23262f1f3c16 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Mon, 27 Jun 2022 14:37:52 +0200 Subject: [PATCH 11/20] feat(dh:home-header): do not reset search on tab navigation --- .../app/home/home-header/home-header.component.ts | 12 +++--------- .../home/search/search-page/search-page.component.ts | 4 ---- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/apps/datahub/src/app/home/home-header/home-header.component.ts b/apps/datahub/src/app/home/home-header/home-header.component.ts index 3378af7606..23c5a56a65 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.ts +++ b/apps/datahub/src/app/home/home-header/home-header.component.ts @@ -4,7 +4,7 @@ import { RouterFacade, ROUTER_ROUTE_SEARCH, } from '@geonetwork-ui/feature/router' -import { SearchFacade } from '@geonetwork-ui/feature/search' +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' @@ -40,7 +40,7 @@ export class HomeHeaderComponent { constructor( public routerFacade: RouterFacade, - private searchFacade: SearchFacade + private searchService: SearchService ) {} onFuzzySearchSelection(record: MetadataRecord) { @@ -49,24 +49,18 @@ export class HomeHeaderComponent { onNewsClick(): void { this.routerFacade.go({ path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_NEWS}` }) - this.resetSearch() } onDatasetsClick(): void { this.routerFacade.go({ path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_SEARCH}`, }) - this.resetSearch() + this.searchService.updateSearch({}) } onOrganisationsClick(): void { this.routerFacade.go({ path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_ORGANISATION}`, }) - this.resetSearch() - } - - private resetSearch(): void { - this.searchFacade.setFilters({}) } } diff --git a/apps/datahub/src/app/home/search/search-page/search-page.component.ts b/apps/datahub/src/app/home/search/search-page/search-page.component.ts index f6de246fd2..ba37ca349a 100644 --- a/apps/datahub/src/app/home/search/search-page/search-page.component.ts +++ b/apps/datahub/src/app/home/search/search-page/search-page.component.ts @@ -27,8 +27,4 @@ export class SearchPageComponent implements OnInit { onMetadataSelection(metadata: MetadataRecord): void { this.searchRouter.goToMetadata(metadata) } - - resetSearch(): void { - this.searchFacade.setFilters({}) - } } From 19d43aee17a97d67e96a285082c29f54cf94da5c Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Mon, 27 Jun 2022 14:38:43 +0200 Subject: [PATCH 12/20] feat(dh:home-header): fix header style and translate tab labels --- .../home-header/home-header.component.html | 40 ++++++++++++++----- translations/de.json | 5 ++- translations/en.json | 5 ++- translations/es.json | 5 ++- translations/fr.json | 5 ++- translations/it.json | 5 ++- translations/nl.json | 5 ++- translations/pt.json | 5 ++- 8 files changed, 50 insertions(+), 25 deletions(-) diff --git a/apps/datahub/src/app/home/home-header/home-header.component.html b/apps/datahub/src/app/home/home-header/home-header.component.html index 1d5937de02..6dc867d552 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.html +++ b/apps/datahub/src/app/home/home-header/home-header.component.html @@ -1,5 +1,5 @@
-
+
-->
-
Fil d'activité
+ datahub.header.news +
+
- datasets + datahub.header.datasets +
+
+ datahub.header.organisations
-
Organisations
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": "", From 20c2013d25254454a853771242f72aff1d55c298 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Mon, 27 Jun 2022 14:44:04 +0200 Subject: [PATCH 13/20] feat(dh:router): add a redirect for /home --- apps/datahub/src/app/router/datahub-router.service.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/datahub/src/app/router/datahub-router.service.ts b/apps/datahub/src/app/router/datahub-router.service.ts index 5faafa2403..d61d0143dd 100644 --- a/apps/datahub/src/app/router/datahub-router.service.ts +++ b/apps/datahub/src/app/router/datahub-router.service.ts @@ -32,6 +32,11 @@ export class DatahubRouterService { 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, From 415db6bbc705d7e2b6edb0d400dec8962e233bb4 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Mon, 27 Jun 2022 14:59:47 +0200 Subject: [PATCH 14/20] fix(dh): fix lint --- .../datahub/src/app/home/news-page/news-page.component.ts | 8 ++------ .../organisations-page/organisations-page.component.ts | 8 ++------ .../record-preview-datahub.component.ts | 7 +++++-- .../search-summary/search-summary.component.spec.ts | 4 ++-- .../header-badge-button/header-badge-button.component.ts | 1 - 5 files changed, 11 insertions(+), 17 deletions(-) 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 index 9088c76fcf..e41532bc6d 100644 --- a/apps/datahub/src/app/home/news-page/news-page.component.ts +++ b/apps/datahub/src/app/home/news-page/news-page.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core' +import { ChangeDetectionStrategy, Component } from '@angular/core' @Component({ selector: 'datahub-news-page', @@ -6,8 +6,4 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core' styleUrls: ['./news-page.component.css'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class NewsPageComponent implements OnInit { - constructor() {} - - ngOnInit(): void {} -} +export class NewsPageComponent {} 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 index 2f0e83c7a7..802df579e1 100644 --- a/apps/datahub/src/app/home/organisations-page/organisations-page.component.ts +++ b/apps/datahub/src/app/home/organisations-page/organisations-page.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core' +import { ChangeDetectionStrategy, Component } from '@angular/core' @Component({ selector: 'datahub-organisations-page', @@ -6,8 +6,4 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core' styleUrls: ['./organisations-page.component.css'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class OrganisationsPageComponent implements OnInit { - constructor() {} - - ngOnInit(): void {} -} +export class OrganisationsPageComponent {} diff --git a/apps/datahub/src/app/home/search/record-preview-datahub/record-preview-datahub.component.ts b/apps/datahub/src/app/home/search/record-preview-datahub/record-preview-datahub.component.ts index 534b1cd784..914b4d6b5e 100644 --- a/apps/datahub/src/app/home/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-summary/search-summary.component.spec.ts b/apps/datahub/src/app/home/search/search-summary/search-summary.component.spec.ts index 1c1e6b0833..e31810f571 100644 --- a/apps/datahub/src/app/home/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/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, From 71c6cab92e39a396b089476ea67b7bf053cc8366 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Mon, 27 Jun 2022 19:56:59 +0200 Subject: [PATCH 15/20] test(dh/router): rework tests --- .../home-header/home-header.component.spec.ts | 50 ++++++++++++++- .../search-page/search-page.component.spec.ts | 28 ++++++--- .../app/router/datahub-router.service.spec.ts | 62 ++++++++++++++++++- .../src/lib/default/router.service.spec.ts | 8 +-- 4 files changed, 133 insertions(+), 15 deletions(-) diff --git a/apps/datahub/src/app/home/home-header/home-header.component.spec.ts b/apps/datahub/src/app/home/home-header/home-header.component.spec.ts index 02733a4c38..5d8a5b069b 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.spec.ts +++ b/apps/datahub/src/app/home/home-header/home-header.component.spec.ts @@ -1,10 +1,19 @@ 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 { + RouterFacade, + ROUTER_ROUTE_SEARCH, +} 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 { + ROUTER_ROUTE_HOME, + ROUTER_ROUTE_NEWS, + ROUTER_ROUTE_ORGANISATION, +} from '../../router/constants' import { HomeHeaderComponent } from './home-header.component' @@ -15,8 +24,14 @@ jest.mock('@geonetwork-ui/util/app-config', () => ({ })) const routerFacadeMock = { + go: jest.fn(), goToMetadata: jest.fn(), anySearch$: new BehaviorSubject('scot'), + currentRoute$: new BehaviorSubject('search'), +} + +const searchServiceMock = { + updateSearch: jest.fn(), } /* eslint-disable */ @Component({ @@ -42,6 +57,10 @@ describe('HeaderComponent', () => { provide: RouterFacade, useValue: routerFacadeMock, }, + { + provide: SearchService, + useValue: searchServiceMock, + }, ], }).compileComponents() }) @@ -56,7 +75,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 +92,31 @@ describe('HeaderComponent', () => { expect(fuzzyCpt.value).toEqual({ title: 'river' }) }) }) + describe('tabs navigation', () => { + it('calls routerFacade go with correct route when clicking news', () => { + component.onNewsClick() + expect(routerFacadeMock.go).toHaveBeenCalledWith({ + path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_NEWS}`, + }) + }) + it('calls routerFacade go with correct route when clicking organisations', () => { + component.onOrganisationsClick() + expect(routerFacadeMock.go).toHaveBeenCalledWith({ + path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_ORGANISATION}`, + }) + }) + describe('click datasets tab', () => { + beforeEach(() => { + component.onDatasetsClick() + }) + it('calls routerFacade go with correct route when clicking datasets', () => { + expect(routerFacadeMock.go).toHaveBeenCalledWith({ + path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_SEARCH}`, + }) + }) + it('calls searchService updateSearch with empty object', () => { + expect(searchServiceMock.updateSearch).toHaveBeenCalledWith({}) + }) + }) + }) }) diff --git a/apps/datahub/src/app/home/search/search-page/search-page.component.spec.ts b/apps/datahub/src/app/home/search/search-page/search-page.component.spec.ts index a0a3931137..8acf011fb9 100644 --- a/apps/datahub/src/app/home/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/router/datahub-router.service.spec.ts b/apps/datahub/src/app/router/datahub-router.service.spec.ts index 053194a3e6..d8ea2c7946 100644 --- a/apps/datahub/src/app/router/datahub-router.service.spec.ts +++ b/apps/datahub/src/app/router/datahub-router.service.spec.ts @@ -1,16 +1,74 @@ 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' -describe('DatahubRouterInitServiceService', () => { +const RouterMock = { + resetConfig: jest.fn(), +} + +const expectedRoutes = [ + { + path: '', + redirectTo: 'home/search', + pathMatch: 'full', + }, + { + path: 'home', + redirectTo: 'home/search', + pathMatch: 'full', + }, + { + path: 'home', + component: HomePageComponent, + children: [ + { + path: 'news', + component: NewsPageComponent, + }, + { + path: 'search', + component: SearchPageComponent, + }, + { + path: 'organisations', + component: OrganisationsPageComponent, + }, + ], + }, + { + path: `dataset/:metadataUuid`, + component: RecordPageComponent, + }, +] +describe('DatahubRouterService', () => { let service: DatahubRouterService beforeEach(() => { - TestBed.configureTestingModule({}) + 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/libs/feature/router/src/lib/default/router.service.spec.ts b/libs/feature/router/src/lib/default/router.service.spec.ts index e27fd744b6..04e57eaed3 100644 --- a/libs/feature/router/src/lib/default/router.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.service' +import { RouterService } from './router.service' const SearchRouteComponent = { name: 'searchRoute', @@ -39,8 +39,8 @@ const expectedRoutes = [ path: 'dataset/:metadataUuid', }, ] -describe('RouterInitService', () => { - let service: RouterInitService +describe('RouterService', () => { + let service: RouterService beforeEach(() => { TestBed.configureTestingModule({ @@ -55,7 +55,7 @@ describe('RouterInitService', () => { }, ], }) - service = TestBed.inject(RouterInitService) + service = TestBed.inject(RouterService) }) it('should be created', () => { From 416ad8437e06abeaf4421d771f7c8e1129aa0569 Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Tue, 28 Jun 2022 09:28:00 +0200 Subject: [PATCH 16/20] refactor(review): consider comments --- .../home-header/home-header.component.html | 23 +++++-------- .../home-header/home-header.component.spec.ts | 32 ++----------------- .../home/home-header/home-header.component.ts | 25 ++++----------- ...component.scss => home-page.component.css} | 0 .../home/home-page/home-page.component.html | 4 ++- .../app/home/home-page/home-page.component.ts | 2 +- .../search-page/search-page.component.html | 18 +++++------ apps/datahub/src/app/router/constants.ts | 2 +- .../src/app/router/datahub-router.service.ts | 4 +-- 9 files changed, 31 insertions(+), 79 deletions(-) rename apps/datahub/src/app/home/home-page/{home-page.component.scss => home-page.component.css} (100%) diff --git a/apps/datahub/src/app/home/home-header/home-header.component.html b/apps/datahub/src/app/home/home-header/home-header.component.html index 6dc867d552..b66f9ba313 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.html +++ b/apps/datahub/src/app/home/home-header/home-header.component.html @@ -35,32 +35,25 @@ >
datahub.header.news
datahub.header.datasets
datahub.header.organisations diff --git a/apps/datahub/src/app/home/home-header/home-header.component.spec.ts b/apps/datahub/src/app/home/home-header/home-header.component.spec.ts index 5d8a5b069b..46593f5a6a 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.spec.ts +++ b/apps/datahub/src/app/home/home-header/home-header.component.spec.ts @@ -1,20 +1,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, - ROUTER_ROUTE_SEARCH, -} from '@geonetwork-ui/feature/router' +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 { - ROUTER_ROUTE_HOME, - ROUTER_ROUTE_NEWS, - ROUTER_ROUTE_ORGANISATION, -} from '../../router/constants' - import { HomeHeaderComponent } from './home-header.component' jest.mock('@geonetwork-ui/util/app-config', () => ({ @@ -24,10 +15,8 @@ jest.mock('@geonetwork-ui/util/app-config', () => ({ })) const routerFacadeMock = { - go: jest.fn(), goToMetadata: jest.fn(), anySearch$: new BehaviorSubject('scot'), - currentRoute$: new BehaviorSubject('search'), } const searchServiceMock = { @@ -93,26 +82,9 @@ describe('HeaderComponent', () => { }) }) describe('tabs navigation', () => { - it('calls routerFacade go with correct route when clicking news', () => { - component.onNewsClick() - expect(routerFacadeMock.go).toHaveBeenCalledWith({ - path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_NEWS}`, - }) - }) - it('calls routerFacade go with correct route when clicking organisations', () => { - component.onOrganisationsClick() - expect(routerFacadeMock.go).toHaveBeenCalledWith({ - path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_ORGANISATION}`, - }) - }) describe('click datasets tab', () => { beforeEach(() => { - component.onDatasetsClick() - }) - it('calls routerFacade go with correct route when clicking datasets', () => { - expect(routerFacadeMock.go).toHaveBeenCalledWith({ - path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_SEARCH}`, - }) + component.updateSearch() }) it('calls searchService updateSearch with empty object', () => { expect(searchServiceMock.updateSearch).toHaveBeenCalledWith({}) diff --git a/apps/datahub/src/app/home/home-header/home-header.component.ts b/apps/datahub/src/app/home/home-header/home-header.component.ts index 23c5a56a65..85417957d2 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.ts +++ b/apps/datahub/src/app/home/home-header/home-header.component.ts @@ -9,9 +9,8 @@ import { getThemeConfig } from '@geonetwork-ui/util/app-config' import { MetadataRecord } from '@geonetwork-ui/util/shared' import { map } from 'rxjs/operators' import { - ROUTER_ROUTE_HOME, ROUTER_ROUTE_NEWS, - ROUTER_ROUTE_ORGANISATION, + ROUTER_ROUTE_ORGANISATIONS, } from '../../router/constants' marker('datahub.header.myfavorites') @@ -31,13 +30,14 @@ export class HomeHeaderComponent { searchInputRouteValue$ = this.routerFacade.anySearch$.pipe( map((any) => ({ title: any })) ) - currentRoute$ = this.routerFacade.currentRoute$.pipe( - map((route) => route.routeConfig.path) - ) backgroundCss = getThemeConfig().HEADER_BACKGROUND || `center /cover url('assets/img/header_bg.webp')` + ROUTE_NEWS = `${ROUTER_ROUTE_NEWS}` + ROUTE_SEARCH = `${ROUTER_ROUTE_SEARCH}` + ROUTE_ORGANISATIONS = `${ROUTER_ROUTE_ORGANISATIONS}` + constructor( public routerFacade: RouterFacade, private searchService: SearchService @@ -47,20 +47,7 @@ export class HomeHeaderComponent { this.routerFacade.goToMetadata(record) } - onNewsClick(): void { - this.routerFacade.go({ path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_NEWS}` }) - } - - onDatasetsClick(): void { - this.routerFacade.go({ - path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_SEARCH}`, - }) + updateSearch(): void { this.searchService.updateSearch({}) } - - onOrganisationsClick(): void { - this.routerFacade.go({ - path: `${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_ORGANISATION}`, - }) - } } diff --git a/apps/datahub/src/app/home/home-page/home-page.component.scss b/apps/datahub/src/app/home/home-page/home-page.component.css similarity index 100% rename from apps/datahub/src/app/home/home-page/home-page.component.scss 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 index bf5f1dfe0e..b496f56f62 100644 --- a/apps/datahub/src/app/home/home-page/home-page.component.html +++ b/apps/datahub/src/app/home/home-page/home-page.component.html @@ -5,6 +5,8 @@
- +
+ +
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 index bc29991a3a..53436ec20a 100644 --- a/apps/datahub/src/app/home/home-page/home-page.component.ts +++ b/apps/datahub/src/app/home/home-page/home-page.component.ts @@ -3,7 +3,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core' @Component({ selector: 'datahub-home-page', templateUrl: './home-page.component.html', - styleUrls: ['./home-page.component.scss'], + styleUrls: ['./home-page.component.css'], changeDetection: ChangeDetectionStrategy.OnPush, }) export class HomePageComponent {} 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 index b2f73a0a3c..edcd38a829 100644 --- 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 @@ -1,11 +1,9 @@ -
-
- -
-
- -
+
+ +
+
+
diff --git a/apps/datahub/src/app/router/constants.ts b/apps/datahub/src/app/router/constants.ts index bc4dc12779..2c962b5eca 100644 --- a/apps/datahub/src/app/router/constants.ts +++ b/apps/datahub/src/app/router/constants.ts @@ -1,3 +1,3 @@ export const ROUTER_ROUTE_HOME = 'home' export const ROUTER_ROUTE_NEWS = 'news' -export const ROUTER_ROUTE_ORGANISATION = 'organisations' +export const ROUTER_ROUTE_ORGANISATIONS = 'organisations' diff --git a/apps/datahub/src/app/router/datahub-router.service.ts b/apps/datahub/src/app/router/datahub-router.service.ts index d61d0143dd..148060f77b 100644 --- a/apps/datahub/src/app/router/datahub-router.service.ts +++ b/apps/datahub/src/app/router/datahub-router.service.ts @@ -12,7 +12,7 @@ import { RecordPageComponent } from '../record/record-page/record-page.component import { ROUTER_ROUTE_HOME, ROUTER_ROUTE_NEWS, - ROUTER_ROUTE_ORGANISATION, + ROUTER_ROUTE_ORGANISATIONS, } from './constants' @Injectable({ @@ -50,7 +50,7 @@ export class DatahubRouterService { component: SearchPageComponent, }, { - path: ROUTER_ROUTE_ORGANISATION, + path: ROUTER_ROUTE_ORGANISATIONS, component: OrganisationsPageComponent, }, ], From 42ca55d2dfb839e44b3180a3688ef0ff8627db2a Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Tue, 28 Jun 2022 09:40:19 +0200 Subject: [PATCH 17/20] refactor(dh:home-header): fix routerLink syntax --- .../src/app/home/home-header/home-header.component.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/datahub/src/app/home/home-header/home-header.component.html b/apps/datahub/src/app/home/home-header/home-header.component.html index b66f9ba313..c44417ceae 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.html +++ b/apps/datahub/src/app/home/home-header/home-header.component.html @@ -36,7 +36,7 @@
datahub.header.news @@ -44,7 +44,7 @@
@@ -53,7 +53,7 @@
datahub.header.organisations From db14c7b4deee18a65208b36fc9f685f04d4821a5 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 28 Jun 2022 17:11:57 +0200 Subject: [PATCH 18/20] refactor(router): shouldDetach in route data easier configuration of shouldDetach than match on route path --- .../src/lib/default/SearchRouteReuseStrategy.spec.ts | 10 ++++++++-- .../router/src/lib/default/SearchRouteReuseStrategy.ts | 5 ++--- .../router/src/lib/default/router.service.spec.ts | 3 +++ libs/feature/router/src/lib/default/router.service.ts | 3 +++ 4 files changed, 16 insertions(+), 5 deletions(-) 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/router.service.spec.ts b/libs/feature/router/src/lib/default/router.service.spec.ts index 04e57eaed3..2b18c9ccc3 100644 --- a/libs/feature/router/src/lib/default/router.service.spec.ts +++ b/libs/feature/router/src/lib/default/router.service.spec.ts @@ -31,6 +31,9 @@ const expectedRoutes = [ name: 'searchRoute', }, path: 'search', + data: { + shouldDetach: true, + }, }, { component: { diff --git a/libs/feature/router/src/lib/default/router.service.ts b/libs/feature/router/src/lib/default/router.service.ts index 90f4c992f2..e185361cd1 100644 --- a/libs/feature/router/src/lib/default/router.service.ts +++ b/libs/feature/router/src/lib/default/router.service.ts @@ -26,6 +26,9 @@ export class RouterService { { path: '', redirectTo: `/${ROUTER_ROUTE_SEARCH}`, pathMatch: 'full' }, { path: ROUTER_ROUTE_SEARCH, + data: { + shouldDetach: true, + }, component: this.routerConfig.searchRouteComponent, }, { From e8d0e603e6eae6ba3088017dd3d12746fba919aa Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 28 Jun 2022 17:12:24 +0200 Subject: [PATCH 19/20] feat(detahub): detach all home routes this fix infinite scroll issue --- .../src/app/router/datahub-router.service.spec.ts | 12 ++++++++++++ .../datahub/src/app/router/datahub-router.service.ts | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/apps/datahub/src/app/router/datahub-router.service.spec.ts b/apps/datahub/src/app/router/datahub-router.service.spec.ts index d8ea2c7946..c7269f2305 100644 --- a/apps/datahub/src/app/router/datahub-router.service.spec.ts +++ b/apps/datahub/src/app/router/datahub-router.service.spec.ts @@ -26,18 +26,30 @@ const expectedRoutes = [ { 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, + }, }, ], }, diff --git a/apps/datahub/src/app/router/datahub-router.service.ts b/apps/datahub/src/app/router/datahub-router.service.ts index 148060f77b..6a373a4082 100644 --- a/apps/datahub/src/app/router/datahub-router.service.ts +++ b/apps/datahub/src/app/router/datahub-router.service.ts @@ -40,18 +40,30 @@ export class DatahubRouterService { { 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, + }, }, ], }, From c869b80fb902cbfd4864be7c84e5a6ff4324daa9 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 28 Jun 2022 17:27:45 +0200 Subject: [PATCH 20/20] fix(navigation-bar): test --- .../app/record/navigation-bar/navigation-bar.component.spec.ts | 2 ++ 1 file changed, 2 insertions(+) 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() })