Skip to content

Commit

Permalink
Merge pull request #683 from geonetwork/backport/679-to-2.0.x
Browse files Browse the repository at this point in the history
[Backport 2.0.x] Datahub (fix): Display UpdateFrequencyCustom correctly
  • Loading branch information
jahow authored Nov 13, 2023
2 parents 67c862f + ddb0857 commit 37ce8f0
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@
{{ metadata.recordUpdated && metadata.recordUpdated.toLocaleString() }}
</p>
</div>
<div *ngIf="metadata.updateFrequency">
<div *ngIf="updateFrequency">
<p class="text-sm" translate>record.metadata.updateFrequency</p>
<p class="text-primary font-medium mt-[4px]" translate>
domain.record.updateFrequency.{{ metadata.updateFrequency }}
<p
class="text-primary font-medium mt-[4px] updateFrequency"
translate
[translateParams]="{ count: updatedTimes }"
>
{{ updateFrequency }}
</p>
</div>
<div *ngIf="metadata.status">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,28 @@ import { TranslateModule } from '@ngx-translate/core'
import { ContentGhostComponent } from '../content-ghost/content-ghost.component'
import { MetadataInfoComponent } from './metadata-info.component'
import { DATASET_RECORDS } from '@geonetwork-ui/common/fixtures'
import { TranslateTestingModule } from '@geonetwork-ui/util/i18n'
import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler'

describe('MetadataInfoComponent', () => {
let component: MetadataInfoComponent
let fixture: ComponentFixture<MetadataInfoComponent>

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), UtilSharedModule],
imports: [
TranslateModule.forRoot(),
UtilSharedModule,
TranslateTestingModule.withTranslations({
en: {
'domain.record.updateFrequency.notPlanned': 'Not planned',
'domain.record.updateFrequency.month':
'{count, plural, =0{0 times} one{once} other{{count} times}} per month',
},
})
.withDefaultLanguage('en')
.withCompiler(new TranslateMessageFormatCompiler()),
],
declarations: [MetadataInfoComponent, ContentGhostComponent],
}).compileComponents()
})
Expand Down Expand Up @@ -73,4 +87,35 @@ describe('MetadataInfoComponent', () => {
expect(displayedElement).toBeTruthy()
})
})
describe('updateFrequency', () => {
describe('updateFrequency as UpdateFrequencyCode', () => {
beforeEach(() => {
fixture = TestBed.createComponent(MetadataInfoComponent)
component = fixture.componentInstance
component.metadata = {
...DATASET_RECORDS[0],
updateFrequency: 'notPlanned',
}
fixture.detectChanges()
})
it('should display the updateFrequency code correctly', () => {
const displayedElement =
fixture.nativeElement.querySelector('.updateFrequency')
expect(displayedElement.textContent).toEqual(' Not planned ')
})
})
describe('updateFrequency as UpdateFrequencyCustom', () => {
beforeEach(() => {
fixture = TestBed.createComponent(MetadataInfoComponent)
component = fixture.componentInstance
component.metadata = DATASET_RECORDS[0]
fixture.detectChanges()
})
it('should display the updateFrequency object correctly', () => {
const displayedElement =
fixture.nativeElement.querySelector('.updateFrequency')
expect(displayedElement.textContent).toEqual(' 3 times per month ')
})
})
})
})
10 changes: 10 additions & 0 deletions libs/ui/elements/src/lib/metadata-info/metadata-info.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class MetadataInfoComponent {
@Input() metadata: Partial<DatasetRecord>
@Input() incomplete: boolean
@Output() keyword = new EventEmitter<string>()
updatedTimes: number

get hasUsage() {
return (
Expand All @@ -37,6 +38,15 @@ export class MetadataInfoComponent {
return array
}

get updateFrequency(): string {
if (this.metadata.updateFrequency instanceof Object) {
this.updatedTimes = this.metadata.updateFrequency.updatedTimes
return `domain.record.updateFrequency.${this.metadata.updateFrequency.per}`
} else {
return `domain.record.updateFrequency.${this.metadata.updateFrequency}`
}
}

fieldReady(propName: string) {
return !this.incomplete || propName in this.metadata
}
Expand Down
8 changes: 4 additions & 4 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@
"domain.record.status.under_development": "In Erstellung",
"domain.record.updateFrequency.asNeeded": "Bei Bedarf",
"domain.record.updateFrequency.continual": "Kontinuierlich",
"domain.record.updateFrequency.day": "Tag",
"domain.record.updateFrequency.day": "{count, plural, =0{0} one{Ein} other{{count}}} mal am Tag",
"domain.record.updateFrequency.irregular": "Unregelmässig",
"domain.record.updateFrequency.month": "Monat",
"domain.record.updateFrequency.month": "{count, plural, =0{0} one{Ein} other{{count}}} mal im Monat",
"domain.record.updateFrequency.notPlanned": "Nicht geplant",
"domain.record.updateFrequency.periodic": "Regelmässig",
"domain.record.updateFrequency.unknown": "Unbekannt",
"domain.record.updateFrequency.week": "Woche",
"domain.record.updateFrequency.year": "Jahr",
"domain.record.updateFrequency.week": "{count, plural, =0{0} one{Ein} other{{count}}} mal in der Woche",
"domain.record.updateFrequency.year": "{count, plural, =0{0} one{Ein} other{{count}}} mal im Jahr",
"downloads.format.unknown": "unbekannt",
"downloads.wfs.featuretype.not.found": "Die Schicht wurde nicht gefunden",
"dropFile": "Datei ablegen",
Expand Down
8 changes: 4 additions & 4 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@
"domain.record.status.under_development": "Under development",
"domain.record.updateFrequency.asNeeded": "As needed",
"domain.record.updateFrequency.continual": "Continual",
"domain.record.updateFrequency.day": "day",
"domain.record.updateFrequency.day": "{count, plural, =0{0 times} one{Once} other{{count} times}} per day",
"domain.record.updateFrequency.irregular": "Irregular",
"domain.record.updateFrequency.month": "month",
"domain.record.updateFrequency.month": "{count, plural, =0{0 times} one{Once} other{{count} times}} per month",
"domain.record.updateFrequency.notPlanned": "Not planned",
"domain.record.updateFrequency.periodic": "Periodic",
"domain.record.updateFrequency.unknown": "Unknown",
"domain.record.updateFrequency.week": "week",
"domain.record.updateFrequency.year": "year",
"domain.record.updateFrequency.week": "{count, plural, =0{0 times} one{Once} other{{count} times}} per week",
"domain.record.updateFrequency.year": "{count, plural, =0{0 times} one{Once} other{{count} times}} per year",
"downloads.format.unknown": "unknown",
"downloads.wfs.featuretype.not.found": "The layer was not found",
"dropFile": "drop file",
Expand Down
8 changes: 4 additions & 4 deletions translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@
"domain.record.status.under_development": "En cours de création",
"domain.record.updateFrequency.asNeeded": "Lorsque nécessaire",
"domain.record.updateFrequency.continual": "Continue",
"domain.record.updateFrequency.day": "jour",
"domain.record.updateFrequency.day": "{count, plural, =0{0} one{Une} other{{count}}} fois par jour",
"domain.record.updateFrequency.irregular": "Irrégulière",
"domain.record.updateFrequency.month": "mois",
"domain.record.updateFrequency.month": "{count, plural, =0{0} one{Une} other{{count}}} fois par mois",
"domain.record.updateFrequency.notPlanned": "Non planifiée",
"domain.record.updateFrequency.periodic": "Récurrente",
"domain.record.updateFrequency.unknown": "Inconnue",
"domain.record.updateFrequency.week": "semaine",
"domain.record.updateFrequency.year": "an",
"domain.record.updateFrequency.week": "{count, plural, =0{0} one{Une} other{{count}}} fois par semaine",
"domain.record.updateFrequency.year": "{count, plural, =0{0} one{Une} other{{count}}} fois par an",
"downloads.format.unknown": "inconnu",
"downloads.wfs.featuretype.not.found": "La couche n'a pas été retrouvée",
"dropFile": "Faites glisser votre fichier",
Expand Down

0 comments on commit 37ce8f0

Please sign in to comment.