Skip to content

Commit

Permalink
Merge pull request #622 from geonetwork/advanced-filters
Browse files Browse the repository at this point in the history
Enlarge advanced filters behavior
  • Loading branch information
fgravin authored Sep 21, 2023
2 parents f6374e3 + 190d8c8 commit 175dbb0
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
QueryList,
ViewChildren,
} from '@angular/core'
import { marker } from '@biesbjerg/ngx-translate-extract-marker'
import {
FieldsService,
FilterDropdownComponent,
Expand Down Expand Up @@ -53,52 +52,10 @@ export class SearchFiltersComponent implements OnInit {
return false
}
})
.map((filter) => {
switch (filter) {
case 'publisher':
return {
fieldName: filter,
title: marker('search.filters.byOrganisation'),
}
case 'format':
return {
fieldName: filter,
title: marker('search.filters.byFormat'),
}
case 'standard':
return {
fieldName: filter,
title: marker('search.filters.byStandard'),
}
case 'inspireKeyword':
return {
fieldName: filter,
title: marker('search.filters.byInspireKeyword'),
}
case 'topic':
return {
fieldName: filter,
title: marker('search.filters.byTopic'),
}
case 'publicationYear':
return {
fieldName: filter,
title: marker('search.filters.byPublicationYear'),
}
case 'isSpatial':
return {
fieldName: filter,
title: marker('search.filters.isSpatial'),
}
case 'license':
return {
fieldName: filter,
title: marker('search.filters.byLicense'),
}
default:
return { fieldName: filter, title: filter }
}
})
.map((filter) => ({
fieldName: filter,
title: `search.filters.${filter}`,
}))
}

open() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ describe('FieldsService', () => {
expect(service.supportedFields).toEqual([
'publisher',
'format',
'resourceType',
'representationType',
'publicationYear',
'topic',
'inspireKeyword',
Expand Down Expand Up @@ -151,6 +153,8 @@ describe('FieldsService', () => {
publicationYear: [],
publisher: ['orgB'],
q: [],
representationType: [],
resourceType: [],
topic: [],
})
})
Expand Down
25 changes: 23 additions & 2 deletions libs/feature/search/src/lib/utils/service/fields.service.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,55 @@
import { Injectable, Injector } from '@angular/core'
import {
AbstractSearchField,
GnUiTranslationSearchField,
FieldValue,
FullTextSearchField,
IsSpatialSearchField,
LicenseSearchField,
OrganizationSearchField,
SimpleSearchField,
TopicSearchField,
} from './fields'
import { forkJoin, Observable, of } from 'rxjs'
import { map } from 'rxjs/operators'
import { FieldFilters } from '@geonetwork-ui/common/domain/search'
import { marker } from '@biesbjerg/ngx-translate-extract-marker'

// key is the field name
export type FieldValues = Record<string, FieldValue[] | FieldValue>

marker('search.filters.format')
marker('search.filters.inspireKeyword')
marker('search.filters.isSpatial')
marker('search.filters.license')
marker('search.filters.publisher')
marker('search.filters.representationType')
marker('search.filters.resourceType')
marker('search.filters.standard')
marker('search.filters.topic')

@Injectable({
providedIn: 'root',
})
export class FieldsService {
private fields = {
publisher: new OrganizationSearchField(this.injector),
format: new SimpleSearchField('format', 'asc', this.injector),
resourceType: new GnUiTranslationSearchField(
'resourceType',
'asc',
this.injector
),
representationType: new GnUiTranslationSearchField(
'cl_spatialRepresentationType.key',
'asc',
this.injector
),
publicationYear: new SimpleSearchField(
'publicationYearForResource',
'desc',
this.injector
),
topic: new TopicSearchField(this.injector),
topic: new GnUiTranslationSearchField('cl_topic.key', 'asc', this.injector),
inspireKeyword: new SimpleSearchField(
'th_httpinspireeceuropaeutheme-theme_tree.default',
'asc',
Expand Down
8 changes: 6 additions & 2 deletions libs/feature/search/src/lib/utils/service/fields.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { lastValueFrom, of } from 'rxjs'
import {
AbstractSearchField,
FullTextSearchField,
GnUiTranslationSearchField,
IsSpatialSearchField,
LicenseSearchField,
OrganizationSearchField,
SimpleSearchField,
TopicSearchField,
} from './fields'
import { TestBed } from '@angular/core/testing'
import { Injector } from '@angular/core'
Expand Down Expand Up @@ -292,7 +292,11 @@ describe('search fields implementations', () => {

describe('TopicSearchField', () => {
beforeEach(() => {
searchField = new TopicSearchField(injector)
searchField = new GnUiTranslationSearchField(
'cl_topic.key',
'asc',
injector
)
})
describe('#getAvailableValues', () => {
let values
Expand Down
28 changes: 18 additions & 10 deletions libs/feature/search/src/lib/utils/service/fields.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { firstValueFrom, Observable, of, switchMap } from 'rxjs'
import { ToolsApiService } from '@geonetwork-ui/data-access/gn4'
import { map, shareReplay } from 'rxjs/operators'
import { catchError, map, shareReplay } from 'rxjs/operators'
import { Injector } from '@angular/core'
import { TranslateService } from '@ngx-translate/core'
import { marker } from '@biesbjerg/ngx-translate-extract-marker'
Expand Down Expand Up @@ -35,7 +35,7 @@ export class SimpleSearchField implements AbstractSearchField {

constructor(
protected esFieldName: string,
private order: 'asc' | 'desc' = 'asc',
protected order: 'asc' | 'desc' = 'asc',
protected injector: Injector
) {}

Expand Down Expand Up @@ -87,24 +87,32 @@ export class SimpleSearchField implements AbstractSearchField {
}
}

export class TopicSearchField extends SimpleSearchField {
export class GnUiTranslationSearchField extends SimpleSearchField {
private toolsApiService = this.injector.get(ToolsApiService)
allTranslations = this.toolsApiService
.getTranslationsPackage1('gnui')
.pipe(shareReplay(1))
allTranslations = this.toolsApiService.getTranslationsPackage1('gnui').pipe(
catchError(() => {
console.warn('Error while loading gnui language package')
return of({})
}),
shareReplay(1)
)

constructor(injector: Injector) {
super('cl_topic.key', 'asc', injector)
constructor(
esFieldName: string,
order: 'asc' | 'desc' = 'asc',
injector: Injector
) {
super(esFieldName, order, injector)
}

private async getTopicTranslation(topicKey: string) {
private async getTranslation(topicKey: string) {
return firstValueFrom(
this.allTranslations.pipe(map((translations) => translations[topicKey]))
)
}

protected async getBucketLabel(bucket: TermBucket) {
return (await this.getTopicTranslation(bucket.term)) || bucket.term
return (await this.getTranslation(bucket.term)) || bucket.term
}

getAvailableValues(): Observable<FieldAvailableValue[]> {
Expand Down
16 changes: 9 additions & 7 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,15 @@
"search.error.receivedError": "Ein Fehler wurde empfangen",
"search.error.recordNotFound": "Der Datensatz mit der Kennung \"{ id }\" konnte nicht gefunden werden.",
"search.field.any.placeholder": "Suche nach Datensätzen, Diensten und Karten ...",
"search.field.location.placeholder": "",
"search.field.sortBy": "Sortieren nach:",
"search.filters.byFormat": "Formate",
"search.filters.byInspireKeyword": "INSPIRE-Schlüsselwort",
"search.filters.byLicense": "Lizenz",
"search.filters.byOrganisation": "Organisationen",
"search.filters.byPublicationYear": "Veröffentlichungsjahr",
"search.filters.byStandard": "Standard",
"search.filters.byTopic": "Thema",
"search.filters.clear": "Zurücksetzen",
"search.filters.format": "Formate",
"search.filters.inspireKeyword": "INSPIRE-Schlüsselwort",
"search.filters.isSpatial": "Ist räumliche Daten",
"search.filters.isSpatial.no": "nicht räumlich",
"search.filters.isSpatial.yes": "räumlich",
"search.filters.license": "Lizenz",
"search.filters.license.cc-by": "Creative Commons CC-BY",
"search.filters.license.cc-by-sa": "Creative Commons CC-BY-SA",
"search.filters.license.cc-zero": "Creative Commons CC-0",
Expand All @@ -234,7 +231,12 @@
"search.filters.license.unknown": "Unbekannt oder nicht vorhanden",
"search.filters.maximize": "Erweitern",
"search.filters.minimize": "Minimieren",
"search.filters.publisher": "Organisationen",
"search.filters.representationType": "",
"search.filters.resourceType": "",
"search.filters.standard": "Standard",
"search.filters.title": "Ergebnisse filtern",
"search.filters.topic": "Thema",
"search.filters.useSpatialFilter": "Zuerst Datensätze im Interessenbereich anzeigen",
"search.filters.useSpatialFilterHelp": "Wenn diese Option aktiviert ist, werden Datensätze im Bereich des Katalogs zuerst angezeigt. Datensätze außerhalb dieses Bereichs werden nicht angezeigt.",
"share.tab.permalink": "Teilen",
Expand Down
16 changes: 9 additions & 7 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,15 @@
"search.error.receivedError": "An error was received",
"search.error.recordNotFound": "The record with identifier \"{ id }\" could not be found.",
"search.field.any.placeholder": "Search datasets, services and maps ...",
"search.field.location.placeholder": "",
"search.field.sortBy": "Sort by:",
"search.filters.byFormat": "Formats",
"search.filters.byInspireKeyword": "INSPIRE keyword",
"search.filters.byLicense": "License",
"search.filters.byOrganisation": "Organisations",
"search.filters.byPublicationYear": "Publication year",
"search.filters.byStandard": "Standard",
"search.filters.byTopic": "Topic",
"search.filters.clear": "Reset",
"search.filters.format": "Formats",
"search.filters.inspireKeyword": "INSPIRE keyword",
"search.filters.isSpatial": "Is spatial data",
"search.filters.isSpatial.no": "non spatial",
"search.filters.isSpatial.yes": "spatial",
"search.filters.license": "",
"search.filters.license.cc-by": "Creative Commons CC-BY",
"search.filters.license.cc-by-sa": "Creative Commons CC-BY-SA",
"search.filters.license.cc-zero": "Creative Commons CC-0",
Expand All @@ -234,7 +231,12 @@
"search.filters.license.unknown": "Unknown or absent",
"search.filters.maximize": "Expand",
"search.filters.minimize": "Minimize",
"search.filters.publisher": "Organizations",
"search.filters.representationType": "Representation type",
"search.filters.resourceType": "Resource type",
"search.filters.standard": "Standard",
"search.filters.title": "Filter your results",
"search.filters.topic": "Topic",
"search.filters.useSpatialFilter": "Show records in the area of interest first",
"search.filters.useSpatialFilterHelp": "When this is enabled, records situated in the catalog's area of interest are shown first; records outside of this area will not show up.",
"share.tab.permalink": "Share",
Expand Down
16 changes: 9 additions & 7 deletions translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,15 @@
"search.error.receivedError": "",
"search.error.recordNotFound": "",
"search.field.any.placeholder": "",
"search.field.location.placeholder": "",
"search.field.sortBy": "",
"search.filters.byFormat": "",
"search.filters.byInspireKeyword": "",
"search.filters.byLicense": "",
"search.filters.byOrganisation": "",
"search.filters.byPublicationYear": "",
"search.filters.byStandard": "",
"search.filters.byTopic": "",
"search.filters.clear": "",
"search.filters.format": "",
"search.filters.inspireKeyword": "",
"search.filters.isSpatial": "",
"search.filters.isSpatial.no": "",
"search.filters.isSpatial.yes": "",
"search.filters.license": "",
"search.filters.license.cc-by": "",
"search.filters.license.cc-by-sa": "",
"search.filters.license.cc-zero": "",
Expand All @@ -234,7 +231,12 @@
"search.filters.license.unknown": "",
"search.filters.maximize": "",
"search.filters.minimize": "",
"search.filters.publisher": "",
"search.filters.representationType": "",
"search.filters.resourceType": "",
"search.filters.standard": "",
"search.filters.title": "",
"search.filters.topic": "",
"search.filters.useSpatialFilter": "",
"search.filters.useSpatialFilterHelp": "",
"share.tab.permalink": "",
Expand Down
28 changes: 15 additions & 13 deletions translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,30 +211,32 @@
"search.error.receivedError": "Erreur retournée",
"search.error.recordNotFound": "Cette donnée n'a pu être trouvée.",
"search.field.any.placeholder": "Rechercher une fiche de métadonnée...",
"search.field.location.placeholder": "",
"search.field.sortBy": "Trier par :",
"search.filters.byFormat": "Formats",
"search.filters.byInspireKeyword": "Mot-clé INSPIRE",
"search.filters.byLicense": "Licence",
"search.filters.byOrganisation": "Organisations",
"search.filters.byPublicationYear": "Année de publication",
"search.filters.byStandard": "",
"search.filters.byTopic": "Thème",
"search.filters.clear": "Réinitialiser",
"search.filters.format": "Formats",
"search.filters.inspireKeyword": "Mot-clé INSPIRE",
"search.filters.isSpatial": "Données spatiales",
"search.filters.isSpatial.no": "non-géolocalisées",
"search.filters.isSpatial.yes": "géolocalisées",
"search.filters.license.cc-by": "",
"search.filters.license.cc-by-sa": "",
"search.filters.license.cc-zero": "",
"search.filters.license": "Licence",
"search.filters.license.cc-by": "cc-by",
"search.filters.license.cc-by-sa": "cc-by-sa",
"search.filters.license.cc-zero": "cc-zero",
"search.filters.license.etalab": "Licence Ouverte (Etalab)",
"search.filters.license.etalab-v2": "Licence Ouverte v2.0 (Etalab)",
"search.filters.license.odbl": "",
"search.filters.license.odc-by": "",
"search.filters.license.pddl": "",
"search.filters.license.odbl": "odbl",
"search.filters.license.odc-by": "odc-by",
"search.filters.license.pddl": "pddl",
"search.filters.license.unknown": "Non-reconnue ou absente",
"search.filters.maximize": "Agrandir",
"search.filters.minimize": "Réduire",
"search.filters.publisher": "Organisations",
"search.filters.representationType": "Type de représentation",
"search.filters.resourceType": "Type de ressource",
"search.filters.standard": "Standard",
"search.filters.title": "Affiner votre recherche",
"search.filters.topic": "Thème",
"search.filters.useSpatialFilter": "Mettre en avant les résultats sur la zone d'intérêt",
"search.filters.useSpatialFilterHelp": "Si cette option est activée, les fiches portant sur la zone d'intérêt du catalogue seront montrées en premier; les fiches en dehors de cette zone n'apparaitront pas dans les résultats.",
"share.tab.permalink": "Partager",
Expand Down
Loading

0 comments on commit 175dbb0

Please sign in to comment.