diff --git a/apps/metadata-editor/src/app/records/records-list.component.ts b/apps/metadata-editor/src/app/records/records-list.component.ts index 86c49509a6..e11c1f9dbb 100644 --- a/apps/metadata-editor/src/app/records/records-list.component.ts +++ b/apps/metadata-editor/src/app/records/records-list.component.ts @@ -15,6 +15,7 @@ const includes = [ 'userinfo', 'cl_status', 'isPublishedToAll', + 'link', ] @Component({ diff --git a/libs/feature/record/src/lib/data-downloads/data-downloads.component.ts b/libs/feature/record/src/lib/data-downloads/data-downloads.component.ts index c2af94335f..890e4ea6fe 100644 --- a/libs/feature/record/src/lib/data-downloads/data-downloads.component.ts +++ b/libs/feature/record/src/lib/data-downloads/data-downloads.component.ts @@ -1,6 +1,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core' import { DataService } from '@geonetwork-ui/feature/dataviz' -import { getFileFormat, sortPriority } from '@geonetwork-ui/util/shared' +import { getFileFormat, getLinkPriority } from '@geonetwork-ui/util/shared' import { combineLatest, of } from 'rxjs' import { catchError, map, switchMap } from 'rxjs/operators' import { MdViewFacade } from '../state' @@ -92,5 +92,5 @@ const removeDuplicateLinks = (wfsDownloadLinks) => const sortLinks = (allLinks) => allLinks.sort((a: DatasetDistribution, b: DatasetDistribution): number => { - return sortPriority(b) - sortPriority(a) + return getLinkPriority(b) - getLinkPriority(a) }) diff --git a/libs/ui/search/src/lib/record-table/record-table.component.html b/libs/ui/search/src/lib/record-table/record-table.component.html index ad143820cb..53365b9bb3 100644 --- a/libs/ui/search/src/lib/record-table/record-table.component.html +++ b/libs/ui/search/src/lib/record-table/record-table.component.html @@ -38,10 +38,28 @@
{{ record.title }}
-
- {{ - getStatus(record.extras?.isPublishedToAll) - }} +
+ + {{ formats[0] }} + + + {{ formats[1] }} + +
+ +{{ formats.slice(2).length }} +
person diff --git a/libs/ui/search/src/lib/record-table/record-table.component.spec.ts b/libs/ui/search/src/lib/record-table/record-table.component.spec.ts index f1db185839..195690ea21 100644 --- a/libs/ui/search/src/lib/record-table/record-table.component.spec.ts +++ b/libs/ui/search/src/lib/record-table/record-table.component.spec.ts @@ -1,4 +1,5 @@ import { ComponentFixture, TestBed } from '@angular/core/testing' +import { DATASET_RECORDS } from '@geonetwork-ui/common/fixtures' import { RecordTableComponent } from './record-table.component' @@ -19,4 +20,23 @@ describe('RecordTableComponent', () => { it('should create', () => { expect(component).toBeTruthy() }) + + describe('get a list of formats and sorts them depending on priority', () => { + it('returns a list of unique formats', () => { + expect(component.getRecordFormats(DATASET_RECORDS[0])).toEqual([ + 'geojson', + 'shp', + 'pdf', + ]) + }) + }) + describe('get the badge color for given format', () => { + it('returns the color for its format', () => { + expect( + component.getBadgeColor( + component.getRecordFormats(DATASET_RECORDS[0])[0] + ) + ).toEqual('#1e5180') // geojson + }) + }) }) diff --git a/libs/ui/search/src/lib/record-table/record-table.component.ts b/libs/ui/search/src/lib/record-table/record-table.component.ts index 0a15c75366..cf71e88ff5 100644 --- a/libs/ui/search/src/lib/record-table/record-table.component.ts +++ b/libs/ui/search/src/lib/record-table/record-table.component.ts @@ -1,6 +1,11 @@ -import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' -import { DATASET_RECORDS } from '@geonetwork-ui/common/fixtures' +import { Component, EventEmitter, Input, Output } from '@angular/core' import { CatalogRecord } from '@geonetwork-ui/common/domain/record' +import { + FileFormat, + getBadgeColor, + getFileFormat, + getFormatPriority, +} from '@geonetwork-ui/util/shared' @Component({ selector: 'gn-ui-record-table', @@ -8,7 +13,7 @@ import { CatalogRecord } from '@geonetwork-ui/common/domain/record' styleUrls: ['./record-table.component.css'], }) export class RecordTableComponent { - @Input() records: CatalogRecord[] = DATASET_RECORDS + @Input() records: CatalogRecord[] = [] @Input() totalHits?: number @Output() recordSelect = new EventEmitter() @@ -32,4 +37,21 @@ export class RecordTableComponent { } return undefined } + + getRecordFormats(record: CatalogRecord): FileFormat[] { + if (record.kind === 'service' || !('distributions' in record)) { + return [] + } + const formats = Array.from( + new Set( + record.distributions.map((distribution) => getFileFormat(distribution)) + ) + ).filter((format) => !!format) + formats.sort((a, b) => getFormatPriority(b) - getFormatPriority(a)) + return formats + } + + getBadgeColor(format: FileFormat): string { + return getBadgeColor(format) + } } diff --git a/libs/util/shared/src/lib/links/link-utils.spec.ts b/libs/util/shared/src/lib/links/link-utils.spec.ts index 96cd1f001b..cebd11e3e9 100644 --- a/libs/util/shared/src/lib/links/link-utils.spec.ts +++ b/libs/util/shared/src/lib/links/link-utils.spec.ts @@ -7,7 +7,7 @@ import { getFileFormat, getLinkLabel, mimeTypeToFormat, - sortPriority, + getLinkPriority, } from './link-utils' describe('link utils', () => { @@ -171,7 +171,7 @@ describe('link utils', () => { const nFormats = Object.keys(FORMATS).length it(`returns ${nFormats - 1}`, () => { expect( - sortPriority({ + getLinkPriority({ description: 'Data in CSV format', name: 'abc.csv', url: new URL('https://my.server/files/abc.csv'), @@ -181,7 +181,7 @@ describe('link utils', () => { }) it(`returns ${nFormats - 5}`, () => { expect( - sortPriority({ + getLinkPriority({ description: 'Data in KML format', name: 'abc.kml', url: new URL('https://my.server/files/abc.kml'), diff --git a/libs/util/shared/src/lib/links/link-utils.ts b/libs/util/shared/src/lib/links/link-utils.ts index c8136070ad..de8015953d 100644 --- a/libs/util/shared/src/lib/links/link-utils.ts +++ b/libs/util/shared/src/lib/links/link-utils.ts @@ -84,10 +84,9 @@ export const FORMATS = { }, } as const -type FileFormat = keyof typeof FORMATS +export type FileFormat = keyof typeof FORMATS -export function sortPriority(link: DatasetDistribution): number { - const linkFormat = getFileFormat(link) +export function getFormatPriority(linkFormat: FileFormat): number { for (const format in FORMATS) { for (const ext of FORMATS[format].extensions) { if (new RegExp(`${ext}`, 'i').test(linkFormat)) { @@ -99,6 +98,10 @@ export function sortPriority(link: DatasetDistribution): number { return 0 } +export function getLinkPriority(link: DatasetDistribution): number { + return getFormatPriority(getFileFormat(link)) +} + export function extensionToFormat(extension: string): FileFormat { for (const format in FORMATS) { for (const alias of FORMATS[format].extensions) {