Skip to content

Commit

Permalink
Merge pull request #511 from geonetwork/org-thumbnail
Browse files Browse the repository at this point in the history
feat: adding organisations thumbnails to records
  • Loading branch information
f-necas authored Jul 17, 2023
2 parents c69e0f0 + 8c212f6 commit 0c09970
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class OrganisationsComponent {
return index
}

getOrganisationUrl(organisation: Organisation) {
getOrganisationUrl(organisation: Organisation): string {
if (!this.urlTemplate) return null
return this.urlTemplate.replace('${name}', organisation.name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
selectField,
SourceWithUnknownProps,
} from '@geonetwork-ui/util/shared'
import { combineLatest, forkJoin, Observable, of } from 'rxjs'
import { forkJoin, Observable, of } from 'rxjs'
import { map, shareReplay } from 'rxjs/operators'
import { OrganisationsServiceInterface } from './organisations.service.interface'
import { TranslateService } from '@ngx-translate/core'
Expand Down 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 @@ -29,6 +29,14 @@ const sampleOrgB: Organisation = {
recordCount: 1,
description: null,
}
const sampleOrgC: Organisation = {
emails: ['[email protected]'],
email: '[email protected]',
logoUrl: '/geonetwork/images/harvesting/ifremer.png',
name: 'Ifremer',
recordCount: 1,
description: null,
}

const organisationsAggregationMock = {
aggregations: {
Expand Down Expand Up @@ -67,6 +75,20 @@ const organisationsAggregationMock = {
],
},
},
{
key: 'Ifremer',
doc_count: 1,
mail: {
doc_count_error_upper_bound: 0,
sum_other_doc_count: 0,
buckets: [
{
key: '[email protected]',
doc_count: 1,
},
],
},
},
],
},
},
Expand Down Expand Up @@ -181,6 +203,13 @@ describe('OrganisationsFromMetadataService', () => {
name: 'BAKOM',
recordCount: 1,
},
{
description: null,
emails: ['[email protected]'],
logoUrl: null,
name: 'Ifremer',
recordCount: 1,
},
])
})
})
Expand All @@ -192,7 +221,7 @@ describe('OrganisationsFromMetadataService', () => {
.subscribe((orgs) => (organisations = orgs))
})
it('get organisations hydrated from groups via name or email mapping', () => {
expect(organisations).toEqual([sampleOrgA, sampleOrgB])
expect(organisations).toEqual([sampleOrgA, sampleOrgB, sampleOrgC])
})
})
})
Expand Down Expand Up @@ -245,12 +274,12 @@ describe('OrganisationsFromMetadataService', () => {
let filters
beforeEach(async () => {
filters = await firstValueFrom(
service.getFiltersForOrgs([sampleOrgA, sampleOrgB])
service.getFiltersForOrgs([sampleOrgA, sampleOrgB, sampleOrgC])
)
})
it('generates filters', () => {
expect(filters).toEqual({
OrgForResource: { ARE: true, BAKOM: true },
OrgForResource: { ARE: true, BAKOM: true, Ifremer: true },
})
})
})
Expand Down Expand Up @@ -288,14 +317,18 @@ describe('OrganisationsFromMetadataService', () => {
title: 'Surval - Données par paramètre',
uuid: 'cf5048f6-5bbf-4e44-ba74-e6f429af51ea',
contact: {
name: "Cellule d'administration Quadrige",
organisation: 'Ifremer',
email: '[email protected]',
website: 'https://www.ifremer.fr/',
logoUrl:
'http://localhost/geonetwork/images/logos/81e8a591-7815-4d2f-a7da-5673192e74c9.png',
name: 'Ifremer',
email: '[email protected]',
logoUrl: 'http://localhost/geonetwork/images/harvesting/ifremer.png',
},
resourceContacts: [
{
email: '[email protected]',
logoUrl:
'http://localhost/geonetwork/images/harvesting/ifremer.png',
name: 'Ifremer',
organisation: 'Ifremer',
},
{
email: '[email protected]',
logoUrl:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ 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 { filter, map, shareReplay, startWith } from 'rxjs/operators'
import { filter, map, shareReplay, startWith, takeLast } from 'rxjs/operators'
import { OrganisationsServiceInterface } from './organisations.service.interface'

const IMAGE_URL = '/geonetwork/images/harvesting/'
Expand Down Expand Up @@ -161,6 +163,21 @@ export class OrganisationsFromMetadataService
})
}

private mapContactFromOrganisation(
organisation: Organisation,
contact: MetadataContact
): MetadataContact {
const logoUrl = organisation.logoUrl
? getAsUrl(`${organisation.logoUrl}`)
: contact.logoUrl
return {
name: organisation.name,
organisation: organisation.name,
email: organisation.email,
logoUrl: logoUrl,
} as MetadataContact
}

getFiltersForOrgs(organisations: Organisation[]): Observable<SearchFilters> {
return of({
OrgForResource: organisations.reduce(
Expand All @@ -184,17 +201,39 @@ export class OrganisationsFromMetadataService
source: SourceWithUnknownProps,
record: MetadataRecord
): Observable<MetadataRecord> {
return of({
const metadataRecord = {
...record,
resourceContacts: [
...getAsArray(selectField(source, 'contactForResource')).map(
(contact) => mapContact(contact, source)
),
],
contact: mapContact(
getFirstValue(selectField(source, 'contact')),
source
),
})
contact: {
...mapContact(getFirstValue(selectField(source, 'contact')), source),
},
}

return this.organisations$.pipe(
takeLast(1),
map((organisations) => {
const org = organisations.filter(
(o) => o.name === metadataRecord.resourceContacts[0]?.organisation
)[0]

if (org) {
const contactFromOrg = this.mapContactFromOrganisation(
org,
metadataRecord.contact
)
metadataRecord.contact = contactFromOrg
metadataRecord.resourceContacts = [
contactFromOrg, // FIXME: this should go into an organization field
...metadataRecord.resourceContacts,
]
}

return metadataRecord
})
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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
19 changes: 19 additions & 0 deletions libs/util/shared/src/lib/fixtures/groups.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,23 @@ export const GROUPS_FIXTURE = deepFreeze([
eng: 'Municipality of Köniz',
},
},
{
logo: 'ifremer.png',
website: 'www.ifremer.ch',
defaultCategory: null,
allowedCategories: [],
enableAllowedCategories: false,
id: 348385324,
email: '[email protected]',
referrer: null,
description: '',
name: 'Ifremer',
label: {
ger: 'Ifremer',
ita: 'Ifremer',
fre: 'Ifremer',
roh: 'Ifremer',
eng: 'Ifremer',
},
},
])
4 changes: 2 additions & 2 deletions libs/util/shared/src/lib/utils/atomic-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const getAsUrl = (field) => {
}

export const mapLogo = (source: SourceWithUnknownProps) => {
const logo = selectField(source, 'logo')
const logo = selectFallbackFields(source, 'logoUrl', 'logo')
return logo ? getAsUrl(`/geonetwork${logo}`) : null
}

Expand All @@ -59,7 +59,7 @@ export const mapContact = (
sourceRecord: SourceWithUnknownProps
): MetadataContact => {
const website = getAsUrl(selectField<string>(sourceContact, 'website'))
const logoUrl = mapLogo(sourceRecord)
const logoUrl = mapLogo(sourceContact) || mapLogo(sourceRecord)
const address = selectField<string>(sourceContact, 'address')
const phone = selectField<string>(sourceContact, 'phone')
return {
Expand Down

0 comments on commit 0c09970

Please sign in to comment.