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 27, 2024
1 parent 6e19d67 commit b3c6e02
Show file tree
Hide file tree
Showing 21 changed files with 210 additions and 50 deletions.
4 changes: 4 additions & 0 deletions libs/feature/editor/src/lib/+state/editor.selectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ describe('Editor Selectors', () => {
},
{
config: DEFAULT_FIELDS[8],
value: DATASET_RECORDS[0].overviews,
},
{
config: DEFAULT_FIELDS[9],
value: DATASET_RECORDS[0].keywords,
},
])
Expand Down
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,14 +10,35 @@ 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'
import { BehaviorSubject } from 'rxjs'
import { EditorFacade } from '@geonetwork-ui/feature/editor'

Check failure on line 15 in libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.spec.ts

View workflow job for this annotation

GitHub Actions / Format check, lint, unit tests

Projects should use relative imports to import from other files within the same project. Use "./path/to/file" instead of import from "@geonetwork-ui/feature/editor"
import { DATASET_RECORDS } from '@geonetwork-ui/common/fixtures'
import { NO_ERRORS_SCHEMA } from '@angular/core'
import { HttpClientTestingModule } from '@angular/common/http/testing'

class EditorFacadeMock {
record$ = new BehaviorSubject(DATASET_RECORDS[0])
}

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

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [FormFieldComponent, TranslateModule.forRoot()],
imports: [
FormFieldComponent,
TranslateModule.forRoot(),
HttpClientTestingModule,
],
schemas: [NO_ERRORS_SCHEMA],
providers: [
{
provide: EditorFacade,
useClass: EditorFacadeMock,
},
],
}).compileComponents()

fixture = TestBed.createComponent(FormFieldComponent)
Expand Down Expand Up @@ -150,4 +171,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 @@ -162,6 +162,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 @@ -172,6 +173,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 @@ -261,10 +263,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 @@ -364,11 +364,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
Loading

0 comments on commit b3c6e02

Please sign in to comment.