Skip to content

Commit

Permalink
feature(metadata-editor): added FormFieldOverviews component to the F…
Browse files Browse the repository at this point in the history
…ormFieldComponent.
  • Loading branch information
Romuald Caplier committed Jun 26, 2024
1 parent c6911e8 commit 648d4b8
Show file tree
Hide file tree
Showing 20 changed files with 185 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[maxSizeMB]="5"
[previewUrl]="resourceUrl"
[altText]="imageAltText"
[formControl]="formControl"
(fileChange)="handleFileChange($event)"
(urlChange)="handleUrlChange($event)"
(delete)="handleDelete()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
EventEmitter,
Input,
OnInit,
Output,
} from '@angular/core'
import { CommonModule } from '@angular/common'
import { RecordsApiService } from '@geonetwork-ui/data-access/gn4'
import { UiInputsModule } from '@geonetwork-ui/ui/inputs'
import { FormControl } from '@angular/forms'
import { GraphicOverview } from '@geonetwork-ui/common/domain/model/record'

@Component({
selector: 'gn-ui-overview-upload',
Expand All @@ -19,6 +23,8 @@ import { UiInputsModule } from '@geonetwork-ui/ui/inputs'
})
export class OverviewUploadComponent implements OnInit {
@Input() metadataUuid: string
@Input() formControl!: FormControl
@Output() overViewChange = new EventEmitter<GraphicOverview | null>()

imageAltText: string
resourceUrl: string
Expand All @@ -34,6 +40,10 @@ export class OverviewUploadComponent implements OnInit {
.subscribe((resources) => {
this.imageAltText = resources[0]?.filename
this.resourceUrl = resources[0]?.url

this.resourceUrl = this.formControl.value?.[0]?.url.href
this.imageAltText = this.formControl.value?.[0]?.description

this.cd.markForCheck()
})
}
Expand All @@ -44,6 +54,12 @@ export class OverviewUploadComponent implements OnInit {
.subscribe((resource) => {
this.imageAltText = resource.filename
this.resourceUrl = resource.url

this.overViewChange.emit({
url: new URL(resource.url),
description: resource.filename,
})

this.cd.markForCheck()
})
}
Expand All @@ -54,6 +70,12 @@ export class OverviewUploadComponent implements OnInit {
.subscribe((resource) => {
this.imageAltText = resource.filename
this.resourceUrl = resource.url

this.overViewChange.emit({
url: new URL(resource.url),
description: resource.filename,
})

this.cd.markForCheck()
})
}
Expand All @@ -64,6 +86,9 @@ export class OverviewUploadComponent implements OnInit {
.subscribe(() => {
this.imageAltText = null
this.resourceUrl = null

this.overViewChange.emit(null)

this.cd.markForCheck()
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<gn-ui-overview-upload
[metadataUuid]="metadataUuid"
[formControl]="control"
(overViewChange)="handleOverViewChange($event)"
></gn-ui-overview-upload>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'

import { FormFieldOverviewsComponent } from './form-field-overviews.component'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { TranslateModule } from '@ngx-translate/core'
import { FormControl } from '@angular/forms'

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

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
FormFieldOverviewsComponent,
HttpClientTestingModule,
TranslateModule.forRoot(),
],
}).compileComponents()

fixture = TestBed.createComponent(FormFieldOverviewsComponent)
component = fixture.componentInstance
component.metadataUuid = '8505d991-e38f-4704-a47a-e7d335dfbef5'
const control = new FormControl()
control.setValue([
{
description: 'doge.jpg',
url: new URL(
'http://localhost:8080/geonetwork/srv/api/0.1/records/8505d991-e38f-4704-a47a-e7d335dfbef5/attachments/doge.jpg'
),
},
])
component.control = control
fixture.detectChanges()
})

it('should create', () => {
expect(component).toBeTruthy()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CommonModule } from '@angular/common'
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'
import { OverviewUploadComponent } from '../../../overview-upload/overview-upload.component'
import { FormControl } from '@angular/forms'
import { GraphicOverview } from '@geonetwork-ui/common/domain/model/record'

@Component({
selector: 'gn-ui-form-field-overviews',
templateUrl: './form-field-overviews.component.html',
styleUrls: ['./form-field-overviews.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [CommonModule, OverviewUploadComponent],
})
export class FormFieldOverviewsComponent {
@Input() metadataUuid: string
@Input() control!: FormControl

handleOverViewChange(overView: GraphicOverview | null) {
this.control.setValue(overView ? [overView] : [])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@
<ng-container *ngIf="isSpatialExtentField">
<gn-ui-form-field-spatial-extent></gn-ui-form-field-spatial-extent>
</ng-container>
<ng-container *ngIf="isGraphicOverview">
<gn-ui-form-field-overviews
[control]="formControl"
[metadataUuid]="metadataUuid$ | async"
></gn-ui-form-field-overviews>
</ng-container>
<ng-container *ngIf="isKeywords">
<gn-ui-form-field-keywords
[control]="formControl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FormFieldSpatialExtentComponent } from './form-field-spatial-extent/for
import { FormFieldUpdateFrequencyComponent } from './form-field-update-frequency/form-field-update-frequency.component'
import { FormFieldComponent } from './form-field.component'
import { FormFieldTemporalExtentsComponent } from './form-field-temporal-extents/form-field-temporal-extents.component'
import { FormFieldOverviewsComponent } from './form-field-overviews/form-field-overviews.component'

describe('FormFieldComponent', () => {
let component: FormFieldComponent
Expand Down Expand Up @@ -150,4 +151,17 @@ describe('FormFieldComponent', () => {
expect(formField).toBeTruthy()
})
})
describe('overviews field', () => {
let formField
beforeEach(() => {
component.model = 'overviews'
fixture.detectChanges()
formField = fixture.debugElement.query(
By.directive(FormFieldOverviewsComponent)
).componentInstance
})
it('creates an array form field', () => {
expect(formField).toBeTruthy()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import { FormFieldConfig } from './form-field.model'
import { FormFieldUpdateFrequencyComponent } from './form-field-update-frequency/form-field-update-frequency.component'
import { CatalogRecordKeys } from '@geonetwork-ui/common/domain/model/record'
import { FormFieldKeywordsComponent } from './form-field-keywords/form-field-keywords.component'
import { FormFieldOverviewsComponent } from './form-field-overviews/form-field-overviews.component'
import { map, take } from 'rxjs/operators'
import { EditorFacade } from '../../../+state/editor.facade'

@Component({
selector: 'gn-ui-form-field',
Expand All @@ -55,6 +58,7 @@ import { FormFieldKeywordsComponent } from './form-field-keywords/form-field-key
FormFieldArrayComponent,
FormFieldKeywordsComponent,
TranslateModule,
FormFieldOverviewsComponent,
],
})
export class FormFieldComponent {
Expand All @@ -69,9 +73,14 @@ export class FormFieldComponent {

@ViewChild('titleInput') titleInput: ElementRef

metadataUuid$ = this.facade.record$.pipe(
take(1),
map((record) => record.uniqueIdentifier)
)

formControl = new FormControl()

constructor() {
constructor(private facade: EditorFacade) {
this.valueChange = this.formControl.valueChanges
}

Expand Down Expand Up @@ -100,6 +109,9 @@ export class FormFieldComponent {
get isSpatialExtentField() {
return this.model === 'spatialExtents'
}
get isGraphicOverview() {
return this.model === 'overviews'
}
get isSimpleField() {
return this.model === 'uniqueIdentifier' || this.model === 'recordUpdated'
}
Expand Down
7 changes: 7 additions & 0 deletions libs/feature/editor/src/lib/fields.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ export const DEFAULT_FIELDS: EditorFieldsConfig = [
type: 'list',
},
},
{
model: 'overviews',
formFieldConfig: {
labelKey: marker('editor.record.form.overviews'),
type: 'list',
},
},
{
model: 'keywords',
formFieldConfig: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</gn-ui-button>
</div>
<input
[formControl]="formControl"
*ngIf="showAltTextInput"
type="text"
class="py-3 px-2 border-2 border-gray-300 rounded-lg text-sm font-medium"
Expand Down
3 changes: 3 additions & 0 deletions libs/ui/inputs/src/lib/image-input/image-input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ButtonComponent } from '../button/button.component'
import { FilesDropDirective } from '../files-drop/files-drop.directive'
import { TranslateModule } from '@ngx-translate/core'
import { marker } from '@biesbjerg/ngx-translate-extract-marker'
import { FormControl, ReactiveFormsModule } from '@angular/forms'

@Component({
selector: 'gn-ui-image-input',
Expand All @@ -30,9 +31,11 @@ import { marker } from '@biesbjerg/ngx-translate-extract-marker'
FilesDropDirective,
MatProgressSpinnerModule,
TranslateModule,
ReactiveFormsModule,
],
})
export class ImageInputComponent {
@Input() formControl!: FormControl
@Input() maxSizeMB: number
@Input() previewUrl?: string
@Input() altText?: string
Expand Down
12 changes: 6 additions & 6 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Add Layer As": "",
"button.login": "",
"catalog.figures.datasets": "{count, plural, =0{Datensätze} one{Datensatz} other{Datensätze}}",
"catalog.figures.organizations": "{count, plural, =0{Organisationen} one{Organisation} other{Organisationen}}",
"catalog.figures.organisations": "",
"chart.aggregation.average": "Durchschnitt",
"chart.aggregation.count": "Anzahl",
"chart.aggregation.max": "Maximum",
Expand Down Expand Up @@ -153,6 +153,7 @@
"downloads.format.unknown": "unbekannt",
"downloads.wfs.featuretype.not.found": "Der Layer wurde nicht gefunden",
"dropFile": "Datei ablegen",
"editor.record.form.keywords": "",
"editor.record.form.license": "Lizenz",
"editor.record.form.license.cc-by": "",
"editor.record.form.license.cc-by-sa": "",
Expand All @@ -163,6 +164,7 @@
"editor.record.form.license.odc-by": "",
"editor.record.form.license.pddl": "",
"editor.record.form.license.unknown": "Unbekannt oder nicht vorhanden",
"editor.record.form.overviews": "Vorschau",
"editor.record.form.resourceUpdated": "",
"editor.record.form.temporalExtents": "",
"editor.record.form.temporalExtents.addDate": "",
Expand Down Expand Up @@ -252,10 +254,8 @@
"organisations.sortBy.nameDesc": "Name Z → A",
"organisations.sortBy.recordCountAsc": "Veröffentlichungen 0 → 9",
"organisations.sortBy.recordCountDesc": "Veröffentlichungen 9 → 0",
"organization.header.recordCount": "{count, plural, =0{} one{} other{}}",
"organization.details.publishedDataset": "{count, plural, =0{} one{} other{}}",
"organization.details.mailContact": "",
"organization.datasets": "",
"organization.header.recordCount": "{count, plural, =0{} one{} other{}}",
"organization.lastPublishedDatasets": "",
"organization.lastPublishedDatasets.searchAllButton": "",
"pagination.nextPage": "Nächste Seite",
Expand Down Expand Up @@ -355,11 +355,11 @@
"results.sortBy.relevancy": "Relevanz",
"search.autocomplete.error": "Vorschläge konnten nicht abgerufen werden:",
"search.error.couldNotReachApi": "Die API konnte nicht erreicht werden",
"search.error.organizationHasNoDataset": "",
"search.error.organizationNotFound": "",
"search.error.receivedError": "Ein Fehler ist aufgetreten",
"search.error.recordHasnolink": "",
"search.error.recordNotFound": "Der Datensatz mit der Kennung \"{ id }\" konnte nicht gefunden werden.",
"search.error.organizationNotFound": "",
"search.error.organizationHasNoDataset": "",
"search.field.any.placeholder": "Suche Datensätze ...",
"search.field.sortBy": "Sortieren nach:",
"search.filters.clear": "Zurücksetzen",
Expand Down
12 changes: 6 additions & 6 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Add Layer As": "",
"button.login": "Log in",
"catalog.figures.datasets": "{count, plural, =0{datasets} one{dataset} other{datasets}}",
"catalog.figures.organizations": "{count, plural, =0{organisations} one{organisation} other{organisations}}",
"catalog.figures.organisations": "",
"chart.aggregation.average": "average",
"chart.aggregation.count": "count",
"chart.aggregation.max": "max",
Expand Down Expand Up @@ -153,6 +153,7 @@
"downloads.format.unknown": "unknown",
"downloads.wfs.featuretype.not.found": "The layer was not found",
"dropFile": "drop file",
"editor.record.form.keywords": "",
"editor.record.form.license": "License",
"editor.record.form.license.cc-by": "Creative Commons CC-BY",
"editor.record.form.license.cc-by-sa": "Creative Commons CC-BY-SA",
Expand All @@ -163,6 +164,7 @@
"editor.record.form.license.odc-by": "Open Data Commons ODC-By",
"editor.record.form.license.pddl": "Open Data Commons PDDL",
"editor.record.form.license.unknown": "Unknown or absent",
"editor.record.form.overviews": "Preview",
"editor.record.form.resourceUpdated": "Last update date",
"editor.record.form.temporalExtents": "Temporal extent",
"editor.record.form.temporalExtents.addDate": "Time instant",
Expand Down Expand Up @@ -252,10 +254,8 @@
"organisations.sortBy.nameDesc": "Name Z → A",
"organisations.sortBy.recordCountAsc": "Publications 0 → 9",
"organisations.sortBy.recordCountDesc": "Publications 9 → 0",
"organization.header.recordCount": "{count, plural, =0{data} one{data} other{datas}}",
"organization.details.publishedDataset": "{count, plural, =0{published dataset} one{published dataset} other{published datasets}}",
"organization.details.mailContact": "Contact by email",
"organization.datasets": "Datasets",
"organization.header.recordCount": "{count, plural, =0{data} one{data} other{datas}}",
"organization.lastPublishedDatasets": "Last published datasets",
"organization.lastPublishedDatasets.searchAllButton": "Search all",
"pagination.nextPage": "Next page",
Expand Down Expand Up @@ -355,11 +355,11 @@
"results.sortBy.relevancy": "Relevancy",
"search.autocomplete.error": "Suggestions could not be fetched:",
"search.error.couldNotReachApi": "The API could not be reached",
"search.error.organizationHasNoDataset": "This organization has no dataset yet.",
"search.error.organizationNotFound": "This organization could not be found.",
"search.error.receivedError": "An error was received",
"search.error.recordHasnolink": "This record currently has no link yet, please come back later.",
"search.error.recordNotFound": "The record with identifier \"{ id }\" could not be found.",
"search.error.organizationNotFound": "This organization could not be found.",
"search.error.organizationHasNoDataset": "This organization has no dataset yet.",
"search.field.any.placeholder": "Search datasets ...",
"search.field.sortBy": "Sort by:",
"search.filters.clear": "Reset",
Expand Down
Loading

0 comments on commit 648d4b8

Please sign in to comment.