Skip to content

Commit

Permalink
feat: adding organisations thumbnails to records
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas committed Jul 3, 2023
1 parent a8f7c55 commit 243f484
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 17 deletions.
3 changes: 2 additions & 1 deletion libs/feature/catalog/src/lib/feature-catalog.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const organizationsServiceFactory = (
: new OrganisationsFromMetadataService(
esService,
searchApiService,
groupsApiService
groupsApiService,
translateService
)

@NgModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand All @@ -97,6 +103,10 @@ describe('OrganisationsFromMetadataService', () => {
provide: SearchApiService,
useClass: SearchApiServiceMock,
},
{
provide: TranslateService,
useClass: TranslateServiceMock,
},
],
})
service = TestBed.inject(OrganisationsFromMetadataService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/'

Expand Down Expand Up @@ -74,7 +78,8 @@ export class OrganisationsFromMetadataService
constructor(
private esService: ElasticsearchService,
private searchApiService: SearchApiService,
private groupsApiService: GroupsApiService
private groupsApiService: GroupsApiService,
private translateService: TranslateService
) {}

equalsNormalizedStrings(
Expand Down Expand Up @@ -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<SearchFilters> {
return of({
OrgForResource: organisations.reduce(
Expand All @@ -184,17 +202,31 @@ export class OrganisationsFromMetadataService
source: SourceWithUnknownProps,
record: MetadataRecord
): Observable<MetadataRecord> {
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
})
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
>
<gn-ui-thumbnail
class="relative h-full w-full object-cover object-left-top"
[thumbnailUrl]="record.thumbnailUrl"
[thumbnailUrl]="record.thumbnailUrl || contact.logoUrl"
></gn-ui-thumbnail>
</div>
</div>
Expand Down

0 comments on commit 243f484

Please sign in to comment.