From 0af02bc13ecdefcdc5d9d2e758cb34082fd1804f Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Fri, 5 Apr 2024 16:20:02 +0200 Subject: [PATCH] feat(home): implement 'routing' to datahub --- apps/home/src/app/app.component.html | 4 ++-- apps/home/src/app/app.module.ts | 14 ------------ apps/home/src/app/app.router.service.ts | 20 ----------------- .../home-header/home-header.component.html | 5 +++-- .../home/home-header/home-header.component.ts | 22 ++++++++++++++----- .../app/home/home-page/home-page.component.ts | 2 +- libs/mel/src/index.ts | 1 + .../results-list/results-list.component.ts | 13 +++++++---- libs/mel/src/lib/route.utils.ts | 13 +++++++++++ package.json | 2 +- 10 files changed, 46 insertions(+), 50 deletions(-) delete mode 100644 apps/home/src/app/app.router.service.ts create mode 100644 libs/mel/src/lib/route.utils.ts diff --git a/apps/home/src/app/app.component.html b/apps/home/src/app/app.component.html index 4be75efb..2df188fa 100644 --- a/apps/home/src/app/app.component.html +++ b/apps/home/src/app/app.component.html @@ -1,6 +1,6 @@
-
- +
+
diff --git a/apps/home/src/app/app.module.ts b/apps/home/src/app/app.module.ts index c56d2029..6bd1b383 100644 --- a/apps/home/src/app/app.module.ts +++ b/apps/home/src/app/app.module.ts @@ -1,9 +1,7 @@ import { importProvidersFrom, isDevMode, NgModule } from '@angular/core' import { BrowserModule } from '@angular/platform-browser' -import { RouterModule } from '@angular/router' import { AppComponent } from './app.component' import { - DefaultRouterModule, FeatureAuthModule, FeatureCatalogModule, FeatureRecordModule, @@ -20,7 +18,6 @@ import { UiInputsModule, UiWidgetsModule, UiMapModule, - RouterService, } from 'geonetwork-ui' import { TranslateLoader, @@ -41,7 +38,6 @@ import { MatTooltipModule } from '@angular/material/tooltip' import { MelModule, MelEmbeddedTranslateLoader } from '@mel-dataplatform/mel' import { HomeHeaderComponent } from './home/home-header/home-header.component' import { HomePageComponent } from './home/home-page/home-page.component' -import { AppRouterService } from './app.router.service' @NgModule({ declarations: [AppComponent, HomeHeaderComponent, HomePageComponent], @@ -85,21 +81,11 @@ import { AppRouterService } from './app.router.service' ), EffectsModule.forRoot([]), StoreDevtoolsModule.instrument({ logOnly: !isDevMode() }), - DefaultRouterModule.forRoot({ - searchStateId: 'mainSearch', - searchRouteComponent: HomePageComponent, - recordRouteComponent: HomePageComponent, - }), - RouterModule.forRoot([], { - initialNavigation: 'enabledBlocking', - scrollPositionRestoration: 'enabled', - }), ], providers: [ importProvidersFrom(FeatureAuthModule), provideGn4(), provideRepositoryUrl(() => '/geonetwork/srv/api'), - { provide: RouterService, useClass: AppRouterService }, { provide: LOGIN_URL, useFactory: () => '${current_url}?login', diff --git a/apps/home/src/app/app.router.service.ts b/apps/home/src/app/app.router.service.ts deleted file mode 100644 index a3a5f7be..00000000 --- a/apps/home/src/app/app.router.service.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Injectable } from '@angular/core' -import { Routes } from '@angular/router' -import { RouterService } from 'geonetwork-ui' -import { HomePageComponent } from './home/home-page/home-page.component' - -@Injectable() -export class AppRouterService extends RouterService { - override buildRoutes(): Routes { - return [ - { - path: '', - component: HomePageComponent, - data: { - shouldDetach: true, - }, - }, - { path: '**', redirectTo: '', pathMatch: 'full' }, - ] - } -} diff --git a/apps/home/src/app/home/home-header/home-header.component.html b/apps/home/src/app/home/home-header/home-header.component.html index 47dbe395..dee8fd1a 100644 --- a/apps/home/src/app/home/home-header/home-header.component.html +++ b/apps/home/src/app/home/home-header/home-header.component.html @@ -6,11 +6,12 @@

-
+
@@ -23,7 +24,7 @@

>

- + ) {} @@ -57,10 +58,14 @@ export class ResultsListComponent implements OnInit, OnDestroy { } onInfoKeywordClick(keyword: Keyword) { - this.routerFacade.updateSearch({ q: keyword.label }) + this.routerFacade + ? this.routerFacade.updateSearch({ q: keyword.label }) + : goFromHomeToSearch(keyword.label) } onMetadataSelection(metadata: CatalogRecord): void { - this.routerFacade.goToMetadata(metadata) + this.routerFacade + ? this.routerFacade.goToMetadata(metadata) + : goFromHomeToRecord(metadata) } } diff --git a/libs/mel/src/lib/route.utils.ts b/libs/mel/src/lib/route.utils.ts new file mode 100644 index 00000000..3bdfb7c0 --- /dev/null +++ b/libs/mel/src/lib/route.utils.ts @@ -0,0 +1,13 @@ +import { CatalogRecord } from 'geonetwork-ui/libs/common/domain/src/lib/model/record' + +export const DATAHUB_ROOT = '/catalogue' +export const DATAHUB_ROUTE_DATASET = 'dataset' +export const DATAHUB_ROUTE_SEARCH = 'search' + +export function goFromHomeToRecord(record: CatalogRecord) { + window.location.href = `${DATAHUB_ROOT}/${DATAHUB_ROUTE_DATASET}/${record.uniqueIdentifier}` +} + +export function goFromHomeToSearch(query: string) { + window.location.href = `${DATAHUB_ROOT}/${DATAHUB_ROUTE_SEARCH}?q=${query}` +} diff --git a/package.json b/package.json index 24b1c14a..aa123fbb 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "license": "MIT", "scripts": { "start": "nx serve mel-datahub", - "home": "nx serve home", + "home": "nx serve home --port 4201", "format": "nx format:write", "format:check": "nx format:check", "lint:all": "nx run-many --target=lint",