Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Angi-Kinas authored and f-necas committed Nov 22, 2023
1 parent 36efb2b commit 021b5f0
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 11 deletions.
2 changes: 1 addition & 1 deletion libs/api/repository/src/lib/gn4/organizations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export type OrganizationsStrategy = 'metadata' | 'groups'
export const ORGANIZATIONS_STRATEGY = new InjectionToken<OrganizationsStrategy>(
'organizations-strategy',
{
factory: () => 'metadata',
factory: () => 'groups',
}
)
99 changes: 98 additions & 1 deletion libs/data-access/gn4/src/openapi/api/tools.api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,24 @@ import {
HttpParameterCodec,
} from '@angular/common/http'
import { CustomHttpParameterCodec } from '../encoder'
import { Observable } from 'rxjs'
import { Observable, map, of, tap } from 'rxjs'

import { BASE_PATH, COLLECTION_FORMATS } from '../variables'
import { Configuration } from '../configuration'

interface thesaurusResponse {
values: string[]
definitions: string[]
coordEast: string
coordWest: string
coordSouth: string
coordNorth: string
thesaurusKey: string
value: string
uri: string
definition: string
}

@Injectable({
providedIn: 'root',
})
Expand Down Expand Up @@ -913,4 +926,88 @@ export class ToolsApiService {
}
)
}

/**
* List database translations (used to overrides client application translations).
* @param esFieldName set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param iso3 set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public getTranslationsFromThesaurus(
thesaurusName: string,
langIso3: string,
observe?: 'body',
reportProgress?: boolean,
options?: { httpHeaderAccept?: 'application/json' }
): Observable<any>
public getTranslationsFromThesaurus(
thesaurusName: string,
langIso3: string,
observe?: 'response',
reportProgress?: boolean,
options?: { httpHeaderAccept?: 'application/json' }
): Observable<thesaurusResponse[]>
public getTranslationsFromThesaurus(
thesaurusName: string,
langIso3: string,
observe?: 'events',
reportProgress?: boolean,
options?: { httpHeaderAccept?: 'application/json' }
): Observable<thesaurusResponse[]>
public getTranslationsFromThesaurus(
thesaurusName: string,
langIso3: string,
observe: any = 'body',
reportProgress: boolean = false,
options?: { httpHeaderAccept?: 'application/json' }
): Observable<any> {
if (
thesaurusName === null ||
thesaurusName === undefined ||
langIso3 === null ||
langIso3 === undefined
) {
throw new Error(
'Required parameter pack was null or undefined when calling getTranslationsFromThesaurus.'
)
}

let headers = this.defaultHeaders

let httpHeaderAcceptSelected: string | undefined =
options && options.httpHeaderAccept
if (httpHeaderAcceptSelected === undefined) {
// to determine the Accept header
const httpHeaderAccepts: string[] = ['application/json']
httpHeaderAcceptSelected =
this.configuration.selectHeaderAccept(httpHeaderAccepts)
}
if (httpHeaderAcceptSelected !== undefined) {
headers = headers.set('Accept', httpHeaderAcceptSelected)
}

let responseType_: 'text' | 'json' = 'json'
if (
httpHeaderAcceptSelected &&
httpHeaderAcceptSelected.startsWith('text')
) {
responseType_ = 'text'
}

return this.httpClient.get<thesaurusResponse[]>(
`${
this.configuration.basePath
}/registries/vocabularies/search?rows=1000&type=CONTAINS&sort=DESC&thesaurus=${encodeURIComponent(
String(thesaurusName)
)}&lang=${encodeURIComponent(langIso3)}`,
{
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress,
}
)
}
}
12 changes: 6 additions & 6 deletions libs/feature/search/src/lib/utils/service/fields.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
OwnerSearchField,
SimpleSearchField,
ContactSearchField,
//GnUiTranslationSearchFieldArray,
ThesaurusTranslationSearchField,
} from './fields'
import { forkJoin, Observable, of } from 'rxjs'
import { map } from 'rxjs/operators'
Expand Down Expand Up @@ -54,16 +54,16 @@ export class FieldsService {
this.injector
),
topic: new GnUiTranslationSearchField('cl_topic.key', 'asc', this.injector),
inspireKeyword: new GnUiTranslationSearchField(
/*inspireKeyword: new GnUiTranslationSearchField(
'th_httpinspireeceuropaeutheme-theme.link',
'asc',
this.injector
),
/*inspireKeyword: new SimpleSearchField(
'th_httpinspireeceuropaeutheme-theme_tree.key', //todo remove default
),*/
inspireKeyword: new SimpleSearchField(
'th_httpinspireeceuropaeutheme-theme_tree.default', //todo remove default
'asc',
this.injector
),*/
),
documentStandard: new SimpleSearchField(
'documentStandard',
'asc',
Expand Down
57 changes: 54 additions & 3 deletions libs/feature/search/src/lib/utils/service/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@geonetwork-ui/common/domain/search'
import { RecordsRepositoryInterface } from '@geonetwork-ui/common/domain/records-repository.interface'
import { ElasticsearchService } from '@geonetwork-ui/api/repository/gn4'
import { LangService } from '@geonetwork-ui/util/i18n'

export type FieldValue = string | number
export interface FieldAvailableValue {
Expand Down Expand Up @@ -107,10 +108,60 @@ export class GnUiTranslationSearchField extends SimpleSearchField {

private async getTranslation(topicKey: string) {
return firstValueFrom(
this.allTranslations.pipe(
tap((val) => console.log(topicKey, val)),
map((translations) => translations[topicKey])
this.allTranslations.pipe(map((translations) => translations[topicKey]))
)
}

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

getAvailableValues(): Observable<FieldAvailableValue[]> {
// sort values by alphabetical order
return super
.getAvailableValues()
.pipe(
map((values) =>
values.sort((a, b) => new Intl.Collator().compare(a.label, b.label))
)
)
}
}

export class ThesaurusTranslationSearchField extends SimpleSearchField {
private toolsApiService = this.injector.get(ToolsApiService)
private langService = this.injector.get(LangService)
allTranslations = this.toolsApiService
.getTranslationsFromThesaurus(this.esFieldName, this.langService.iso3)
.pipe(
map((response) =>
response.map((response) => {
return { [response.uri]: response.value }
})
),
tap((response) => {
console.log('hereres', response)
}),
catchError(() => {
console.warn('Error while loading thesaurus language package')
return of({})
}),
shareReplay(1)
)

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

private async getTranslation(topicKey: string) {
console.log('here ?')
return firstValueFrom(
this.allTranslations.pipe(map((translations) => translations[topicKey]))
)
}

Expand Down

0 comments on commit 021b5f0

Please sign in to comment.