From 243f4848624561c4659fcd98d1f1f66e92935dda Mon Sep 17 00:00:00 2001 From: Florian Necas Date: Thu, 22 Jun 2023 16:52:15 +0200 Subject: [PATCH] feat: adding organisations thumbnails to records --- .../catalog/src/lib/feature-catalog.module.ts | 3 +- .../organisations-from-groups.service.ts | 2 +- ...rganisations-from-metadata.service.spec.ts | 10 ++++ .../organisations-from-metadata.service.ts | 60 ++++++++++++++----- .../record-preview-row.component.html | 2 +- 5 files changed, 60 insertions(+), 17 deletions(-) diff --git a/libs/feature/catalog/src/lib/feature-catalog.module.ts b/libs/feature/catalog/src/lib/feature-catalog.module.ts index 948f12e005..be3c110458 100644 --- a/libs/feature/catalog/src/lib/feature-catalog.module.ts +++ b/libs/feature/catalog/src/lib/feature-catalog.module.ts @@ -41,7 +41,8 @@ const organizationsServiceFactory = ( : new OrganisationsFromMetadataService( esService, searchApiService, - groupsApiService + groupsApiService, + translateService ) @NgModule({ diff --git a/libs/feature/catalog/src/lib/organisations/service/organisations-from-groups.service.ts b/libs/feature/catalog/src/lib/organisations/service/organisations-from-groups.service.ts index d59a016f79..3753435292 100644 --- a/libs/feature/catalog/src/lib/organisations/service/organisations-from-groups.service.ts +++ b/libs/feature/catalog/src/lib/organisations/service/organisations-from-groups.service.ts @@ -114,7 +114,7 @@ export class OrganisationsFromGroupsService lang3: string ): MetadataContact { const website = getAsUrl(group.website) - const logoUrl = getAsUrl(`/geonetwork/images/harvesting/${group.logo}`) + const logoUrl = getAsUrl(`${IMAGE_URL}${group.logo}`) return { name: group.label[lang3], organisation: group.label[lang3], diff --git a/libs/feature/catalog/src/lib/organisations/service/organisations-from-metadata.service.spec.ts b/libs/feature/catalog/src/lib/organisations/service/organisations-from-metadata.service.spec.ts index ec7cfa8ac8..c6ba489de4 100644 --- a/libs/feature/catalog/src/lib/organisations/service/organisations-from-metadata.service.spec.ts +++ b/libs/feature/catalog/src/lib/organisations/service/organisations-from-metadata.service.spec.ts @@ -11,6 +11,7 @@ import { GROUPS_FIXTURE, } from '@geonetwork-ui/util/shared/fixtures' import { MetadataRecord, Organisation } from '@geonetwork-ui/util/shared' +import { TranslateService } from '@ngx-translate/core' const sampleOrgA: Organisation = { description: 'A description for ARE', @@ -81,6 +82,11 @@ class GoupsApiServiceMock { getGroups = jest.fn(() => of(GROUPS_FIXTURE)) } +class TranslateServiceMock { + currentLang = 'fr' + get = jest.fn((key) => of(key)) +} + describe('OrganisationsFromMetadataService', () => { let service: OrganisationsFromMetadataService let searchService: SearchApiService @@ -97,6 +103,10 @@ describe('OrganisationsFromMetadataService', () => { provide: SearchApiService, useClass: SearchApiServiceMock, }, + { + provide: TranslateService, + useClass: TranslateServiceMock, + }, ], }) service = TestBed.inject(OrganisationsFromMetadataService) diff --git a/libs/feature/catalog/src/lib/organisations/service/organisations-from-metadata.service.ts b/libs/feature/catalog/src/lib/organisations/service/organisations-from-metadata.service.ts index 1753710589..70d306b5fa 100644 --- a/libs/feature/catalog/src/lib/organisations/service/organisations-from-metadata.service.ts +++ b/libs/feature/catalog/src/lib/organisations/service/organisations-from-metadata.service.ts @@ -7,17 +7,21 @@ import { import { ElasticsearchService, getAsArray, + getAsUrl, getFirstValue, mapContact, + MetadataContact, MetadataRecord, Organisation, SearchFilters, selectField, SourceWithUnknownProps, } from '@geonetwork-ui/util/shared' -import { combineLatest, Observable, of } from 'rxjs' +import { combineLatest, forkJoin, Observable, of } from 'rxjs' import { filter, map, shareReplay, startWith } from 'rxjs/operators' import { OrganisationsServiceInterface } from './organisations.service.interface' +import { TranslateService } from '@ngx-translate/core' +import { LANG_2_TO_3_MAPPER } from '@geonetwork-ui/util/i18n' const IMAGE_URL = '/geonetwork/images/harvesting/' @@ -74,7 +78,8 @@ export class OrganisationsFromMetadataService constructor( private esService: ElasticsearchService, private searchApiService: SearchApiService, - private groupsApiService: GroupsApiService + private groupsApiService: GroupsApiService, + private translateService: TranslateService ) {} equalsNormalizedStrings( @@ -161,6 +166,19 @@ export class OrganisationsFromMetadataService }) } + private mapContactFromOrganisation( + organisation: Organisation, + lang3: string + ): MetadataContact { + const logoUrl = getAsUrl(`${organisation.logoUrl}`) + return { + name: organisation.name[lang3], + organisation: organisation.name[lang3], + email: organisation.email, + ...(organisation.logoUrl && logoUrl && { logoUrl }), + } as MetadataContact + } + getFiltersForOrgs(organisations: Organisation[]): Observable { return of({ OrgForResource: organisations.reduce( @@ -184,17 +202,31 @@ export class OrganisationsFromMetadataService source: SourceWithUnknownProps, record: MetadataRecord ): Observable { - return of({ - ...record, - resourceContacts: [ - ...getAsArray(selectField(source, 'contactForResource')).map( - (contact) => mapContact(contact, source) - ), - ], - contact: mapContact( - getFirstValue(selectField(source, 'contact')), - source - ), - }) + return forkJoin([ + of({ + ...record, + resourceContacts: [ + ...getAsArray(selectField(source, 'contactForResource')).map( + (contact) => mapContact(contact, source) + ), + ], + contact: { + ...mapContact(getFirstValue(selectField(source, 'contact')), source), + }, + }), + this.organisations$, + ]).pipe( + map(([record, organisations]) => { + const org = organisations.filter( + (o) => o.name === record.contact.organisation + )[0] + if (org) { + const lang3 = LANG_2_TO_3_MAPPER[this.translateService.currentLang] + record.contact = this.mapContactFromOrganisation(org, lang3) + record.resourceContacts = [record.contact, ...record.resourceContacts] + } + return record + }) + ) } } diff --git a/libs/ui/search/src/lib/record-preview-row/record-preview-row.component.html b/libs/ui/search/src/lib/record-preview-row/record-preview-row.component.html index 77c8379fbc..5b42c4aab8 100644 --- a/libs/ui/search/src/lib/record-preview-row/record-preview-row.component.html +++ b/libs/ui/search/src/lib/record-preview-row/record-preview-row.component.html @@ -8,7 +8,7 @@ >