Skip to content

Commit

Permalink
feat: getting record logo as fallback if it is set in contact
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas committed Jul 11, 2023
1 parent 70e0784 commit 0b6a439
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
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 @@ -132,7 +132,7 @@ export class OrganisationsFromGroupsService
const groupId = parseInt(selectField(source, 'groupOwner'))
const resourceContacts = getAsArray(
selectField(source, 'contactForResource')
).map((contact) => mapContact(contact))
).map((contact) => mapContact(contact, source))
return this.groups$.pipe(
map((groups) => {
const group = groups.find((g) => g.id === groupId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,17 @@ export class OrganisationsFromMetadataService
}

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

Expand Down Expand Up @@ -202,11 +205,11 @@ export class OrganisationsFromMetadataService
...record,
resourceContacts: [
...getAsArray(selectField(source, 'contactForResource')).map(
(contact) => mapContact(contact)
(contact) => mapContact(contact, source)
),
],
contact: {
...mapContact(getFirstValue(selectField(source, 'contact'))),
...mapContact(getFirstValue(selectField(source, 'contact')), source),
},
}

Expand All @@ -218,10 +221,13 @@ export class OrganisationsFromMetadataService
)[0]

if (org) {
const contactFromOrg = this.mapContactFromOrganisation(org)
const contactFromOrg = this.mapContactFromOrganisation(
org,
metadataRecord.contact
)
metadataRecord.contact = contactFromOrg
metadataRecord.resourceContacts = [
contactFromOrg,
contactFromOrg, // FIXME: this should go into an organization field
...metadataRecord.resourceContacts,
]
}
Expand Down
7 changes: 4 additions & 3 deletions libs/util/shared/src/lib/utils/atomic-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ export const getAsUrl = (field) => {
}

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

export const mapContact = (
sourceContact: SourceWithUnknownProps
sourceContact: SourceWithUnknownProps,
sourceRecord: SourceWithUnknownProps
): MetadataContact => {
const website = getAsUrl(selectField<string>(sourceContact, 'website'))
const logoUrl = mapLogo(sourceContact)
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 0b6a439

Please sign in to comment.