Skip to content

Commit

Permalink
feat(home): implement 'routing' to datahub
Browse files Browse the repository at this point in the history
  • Loading branch information
tkohr committed Apr 5, 2024
1 parent 18dbb90 commit 0af02bc
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 50 deletions.
4 changes: 2 additions & 2 deletions apps/home/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="h-full flex flex-col">
<div class="flex-grow" gnUiSearchRouterContainer="mainSearch">
<router-outlet></router-outlet>
<div class="flex-grow" gnUiSearchStateContainer="mainSearch">
<mel-datahub-home-page></mel-datahub-home-page>
</div>
<mel-datahub-footer></mel-datahub-footer>
</div>
14 changes: 0 additions & 14 deletions apps/home/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -20,7 +18,6 @@ import {
UiInputsModule,
UiWidgetsModule,
UiMapModule,
RouterService,
} from 'geonetwork-ui'
import {
TranslateLoader,
Expand All @@ -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],
Expand Down Expand Up @@ -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',
Expand Down
20 changes: 0 additions & 20 deletions apps/home/src/app/app.router.service.ts

This file was deleted.

5 changes: 3 additions & 2 deletions apps/home/src/app/home/home-header/home-header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ <h1 class="flex justify-center mel-page-title" translate="">
<div class="flex justify-center pt-8 pb-24 relative">
<mel-datahub-fuzzy-search
class="mel-fuzzy-search"
(inputSubmitted)="onFuzzySearchSubmit($event)"
(itemSelected)="onFuzzySearchSelection($event)"
[autoFocus]="true"
></mel-datahub-fuzzy-search>
</div>
<div class="max-w-[1182px] mx-auto" gnUiSearchStateContainer="headerHome">
<div class="max-w-[1182px] mx-auto">
<div class="sm:ml-16">
<div class="mel-title-line"></div>
<div class="text-2xl font-title" translate="">
Expand All @@ -23,7 +24,7 @@ <h1 class="flex justify-center mel-page-title" translate="">
></mel-datahub-results-list-carousel>
</div>
<div class="flex justify-end mt-4">
<a routerLink="/search">
<a [href]="HREF_ROUTE_SEARCH">
<mel-datahub-button
[label]="'mel.homepage.visit.catalog' | translate"
[icon]="'arrow'"
Expand Down
22 changes: 16 additions & 6 deletions apps/home/src/app/home/home-header/home-header.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { ChangeDetectionStrategy, Component } from '@angular/core'
import { RouterFacade, SearchService } from 'geonetwork-ui'
import { SearchService } from 'geonetwork-ui'
import {
DATAHUB_ROOT,
DATAHUB_ROUTE_SEARCH,
goFromHomeToRecord,
goFromHomeToSearch,
} from '@mel-dataplatform/mel'
import { CatalogRecord } from 'geonetwork-ui/libs/common/domain/src/lib/model/record'
import { SortByField } from 'geonetwork-ui/libs/common/domain/src/lib/model/search'

Expand All @@ -17,14 +23,18 @@ import { SortByField } from 'geonetwork-ui/libs/common/domain/src/lib/model/sear
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class HomeHeaderComponent {
constructor(
public routerFacade: RouterFacade,
private searchService: SearchService
) {}
HREF_ROUTE_SEARCH = `${DATAHUB_ROOT}/${DATAHUB_ROUTE_SEARCH}`

constructor(private searchService: SearchService) {}

onFuzzySearchSelection(record: CatalogRecord) {
this.routerFacade.goToMetadata(record)
goFromHomeToRecord(record)
}

onFuzzySearchSubmit(query: string) {
goFromHomeToSearch(query)
}

clearSearchAndSort(sort: SortByField | string): void {
this.searchService.setSortAndFilters({}, sort as SortByField)
}
Expand Down
2 changes: 1 addition & 1 deletion apps/home/src/app/home/home-page/home-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ChangeDetectionStrategy, Component } from '@angular/core'

@Component({
selector: 'mel-datahub-home-page',
Expand Down
1 change: 1 addition & 0 deletions libs/mel/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './lib/mel.module'
export * from './lib/embedded.translate.loader'
export * from './lib/route.utils'
13 changes: 9 additions & 4 deletions libs/mel/src/lib/results-list/results-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core'
import { Component, Input, OnDestroy, OnInit, Optional } from '@angular/core'
import { Store } from '@ngrx/store'
import {
FIELDS_BRIEF,
Expand All @@ -13,6 +13,7 @@ import {
Keyword,
} from 'geonetwork-ui/libs/common/domain/src/lib/model/record'
import { Subscription } from 'rxjs'
import { goFromHomeToRecord, goFromHomeToSearch } from '../route.utils'

@Component({
selector: 'mel-datahub-results-list',
Expand All @@ -30,7 +31,7 @@ export class ResultsListComponent implements OnInit, OnDestroy {
constructor(
protected searchService: SearchService,
protected searchFacade: SearchFacade,
protected routerFacade: RouterFacade,
@Optional() protected routerFacade: RouterFacade,
protected favoritesService: FavoritesService,
protected store: Store<SearchState>
) {}
Expand All @@ -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)
}
}
13 changes: 13 additions & 0 deletions libs/mel/src/lib/route.utils.ts
Original file line number Diff line number Diff line change
@@ -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}`
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0af02bc

Please sign in to comment.