From 3a6c33f7c89d69a68cdc237980b5adc53cc81489 Mon Sep 17 00:00:00 2001 From: Olivia Guyot Date: Tue, 2 Jul 2024 13:13:20 +0200 Subject: [PATCH] docs: add remote debug port to gn, document --- .../model/metadataResource.api.model.ts | 2 +- .../overview-upload.component.spec.ts | 35 +++++++--- .../overview-upload.component.ts | 66 +++++++++---------- .../form-field/form-field.component.spec.ts | 2 +- .../form-field/form-field.component.ts | 1 + libs/feature/editor/src/lib/fields.config.ts | 25 ++++--- 6 files changed, 71 insertions(+), 60 deletions(-) diff --git a/libs/data-access/gn4/src/openapi/model/metadataResource.api.model.ts b/libs/data-access/gn4/src/openapi/model/metadataResource.api.model.ts index 206f8f87d2..b7d69cb4a2 100644 --- a/libs/data-access/gn4/src/openapi/model/metadataResource.api.model.ts +++ b/libs/data-access/gn4/src/openapi/model/metadataResource.api.model.ts @@ -19,7 +19,7 @@ export interface MetadataResourceApiModel { metadataResourceExternalManagementProperties?: MetadataResourceExternalManagementPropertiesApiModel lastModification?: string version?: string - url?: URL + url?: string filename?: string id?: string size?: number diff --git a/libs/feature/editor/src/lib/components/overview-upload/overview-upload.component.spec.ts b/libs/feature/editor/src/lib/components/overview-upload/overview-upload.component.spec.ts index d07b71b57e..5ff2d480a6 100644 --- a/libs/feature/editor/src/lib/components/overview-upload/overview-upload.component.spec.ts +++ b/libs/feature/editor/src/lib/components/overview-upload/overview-upload.component.spec.ts @@ -5,13 +5,27 @@ import { TranslateModule } from '@ngx-translate/core' import { of } from 'rxjs' import { OverviewUploadComponent } from './overview-upload.component' +const imageFileName = 'doge.jpg' +const imageUrl = + 'http://localhost:8080/geonetwork/srv/api/records/8698bf0b-fceb-4f0f-989b-111e7c4af0a4/attachments/doge.jpg' + class RecordsApiServiceMock { getAllResources = jest.fn(() => - of([{ filename: 'filenameGet', url: 'urlGet' }]) + of([ + { + filename: imageFileName, + url: imageUrl, + }, + ]) + ) + putResource = jest.fn(() => + of({ + filename: imageFileName, + url: imageUrl, + }) ) - putResource = jest.fn(() => of({ filename: 'filenamePut', url: 'urlPut' })) putResourceFromURL = jest.fn(() => - of({ filename: 'filenamePutUrl', url: 'urlPutUrl' }) + of({ filename: imageFileName, url: imageUrl }) ) delResource = jest.fn(() => of(void 0)) } @@ -51,8 +65,9 @@ describe('OverviewUploadComponent', () => { it('should get all resources corresponding to the metadata UUID on init', () => { expect(recordsApiService.getAllResources).toHaveBeenCalledWith(metadataUuid) - expect(component.imageAltText).toEqual('filenameGet') - expect(component.resourceUrl).toEqual('urlGet') + expect(component.imageAltText).toEqual(imageFileName) + expect(component.ressourceFileName).toEqual(imageFileName) + expect(component.resourceUrl.href).toEqual(imageUrl) }) it('should put the file resource on file change', () => { @@ -63,8 +78,8 @@ describe('OverviewUploadComponent', () => { someFile, 'public' ) - expect(component.imageAltText).toEqual('filenamePut') - expect(component.resourceUrl).toEqual('urlPut') + expect(component.imageAltText).toEqual(imageFileName) + expect(component.resourceUrl.href).toEqual(imageUrl) }) it('should put the resource from URL on URL change', () => { @@ -74,8 +89,8 @@ describe('OverviewUploadComponent', () => { 'someUrl', 'public' ) - expect(component.imageAltText).toEqual('filenamePutUrl') - expect(component.resourceUrl).toEqual('urlPutUrl') + expect(component.imageAltText).toEqual(imageFileName) + expect(component.resourceUrl.href).toEqual(imageUrl) }) it('should delete the resource corresponding to the metadata UUID on delete', () => { @@ -83,7 +98,7 @@ describe('OverviewUploadComponent', () => { component.handleDelete() expect(recordsApiService.delResource).toHaveBeenCalledWith( metadataUuid, - 'filenameDelete' + imageFileName ) expect(component.imageAltText).toBeNull() expect(component.resourceUrl).toBeNull() diff --git a/libs/feature/editor/src/lib/components/overview-upload/overview-upload.component.ts b/libs/feature/editor/src/lib/components/overview-upload/overview-upload.component.ts index ce32eddf0f..a71cc4ec22 100644 --- a/libs/feature/editor/src/lib/components/overview-upload/overview-upload.component.ts +++ b/libs/feature/editor/src/lib/components/overview-upload/overview-upload.component.ts @@ -13,14 +13,11 @@ 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' -import { Subject, takeUntil } from 'rxjs' - -const extractFileNameFormUrl = (url: URL, metadataUuid: string): string => { - const pattern = new RegExp( - `records/${metadataUuid}/attachments/([^/?#]+)(?:[/?#]|$)`, - 'i' - ) - const match = url.href.match(pattern) +import { Subject } from 'rxjs' + +const extractFileNameFormUrl = (url: string): string => { + const pattern = new RegExp(`attachments/([^/?#]+)(?:[/?#]|$)`, 'i') + const match = url.match(pattern) return match ? match[1] : '' } @@ -37,7 +34,8 @@ export class OverviewUploadComponent implements OnInit, OnDestroy { @Input() formControl!: FormControl @Output() overviewChange = new EventEmitter() - imageAltText: string + imageAltText: string // = ressourceFileName by default + ressourceFileName: string resourceUrl: URL private destroy$ = new Subject() @@ -48,32 +46,33 @@ export class OverviewUploadComponent implements OnInit, OnDestroy { ) {} ngOnInit(): void { - this.recordsApiService - .getAllResources(this.metadataUuid) - .pipe(takeUntil(this.destroy$)) - .subscribe({ - next: (resources) => { - if (resources && resources.length > 0) { - this.resourceUrl = new URL(resources[0]?.url) - this.imageAltText = resources[0].filename - } else if (this.formControl.value[0]) { - this.resourceUrl = new URL(this.formControl.value[0].url.href) - this.imageAltText = this.formControl.value[0].description - } else { - this.resourceUrl = null - this.imageAltText = '' - } - - this.cd.markForCheck() - }, - error: this.errorHandle, - }) + this.recordsApiService.getAllResources(this.metadataUuid).subscribe({ + next: (resources) => { + if (resources && resources.length > 0) { + this.resourceUrl = new URL(resources[0]?.url) + this.imageAltText = resources[0].filename + this.ressourceFileName = extractFileNameFormUrl(resources[0]?.url) + } else if (this.formControl.value[0]) { + this.resourceUrl = new URL(this.formControl.value[0].url.href) + this.imageAltText = this.formControl.value[0].description + this.ressourceFileName = extractFileNameFormUrl( + this.formControl.value[0].url.href + ) + } else { + this.resourceUrl = null + this.imageAltText = '' + this.ressourceFileName = '' + } + + this.cd.markForCheck() + }, + error: this.errorHandle, + }) } handleFileChange(file: File) { this.recordsApiService .putResource(this.metadataUuid, file, 'public') - .pipe(takeUntil(this.destroy$)) .subscribe({ next: (resource) => { this.resourceUrl = new URL(resource.url) @@ -93,7 +92,6 @@ export class OverviewUploadComponent implements OnInit, OnDestroy { handleUrlChange(url: string) { this.recordsApiService .putResourceFromURL(this.metadataUuid, url, 'public') - .pipe(takeUntil(this.destroy$)) .subscribe({ next: (resource) => { this.resourceUrl = new URL(resource.url) @@ -111,11 +109,8 @@ export class OverviewUploadComponent implements OnInit, OnDestroy { } handleDelete() { - const fileName = extractFileNameFormUrl(this.resourceUrl, this.metadataUuid) - this.recordsApiService - .delResource(this.metadataUuid, fileName) - .pipe(takeUntil(this.destroy$)) + .delResource(this.metadataUuid, this.ressourceFileName) .subscribe({ next: () => { this.imageAltText = null @@ -134,6 +129,7 @@ export class OverviewUploadComponent implements OnInit, OnDestroy { this.resourceUrl = null this.imageAltText = '' + this.ressourceFileName = '' this.overviewChange.emit(null) diff --git a/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.spec.ts b/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.spec.ts index 77561c4f1a..2596d65e6f 100644 --- a/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.spec.ts +++ b/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.spec.ts @@ -179,7 +179,7 @@ describe('FormFieldComponent', () => { By.directive(FormFieldOverviewsComponent) ).componentInstance }) - it('creates an array form field', () => { + it('creates an overview upload form field', () => { expect(formField).toBeTruthy() }) }) diff --git a/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.ts b/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.ts index d4b20e4fe9..db576ccb2d 100644 --- a/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.ts +++ b/libs/feature/editor/src/lib/components/record-form/form-field/form-field.component.ts @@ -31,6 +31,7 @@ import { FormFieldKeywordsComponent } from './form-field-keywords/form-field-key import { FormFieldOverviewsComponent } from './form-field-overviews/form-field-overviews.component' import { map, take } from 'rxjs/operators' import { EditorFacade } from '../../../+state/editor.facade' +import { FormFieldConfig } from '../../../models' @Component({ selector: 'gn-ui-form-field', diff --git a/libs/feature/editor/src/lib/fields.config.ts b/libs/feature/editor/src/lib/fields.config.ts index cf72fef64d..1614eb1e05 100644 --- a/libs/feature/editor/src/lib/fields.config.ts +++ b/libs/feature/editor/src/lib/fields.config.ts @@ -83,6 +83,13 @@ export const RECORD_ABSTRACT_FIELD: EditorField = { }, } +export const RECORD_GRAPHICAL_OVERVIEW_FIELD: EditorField = { + model: 'overviews', + formFieldConfig: { + labelKey: marker('editor.record.form.field.overviews'), + }, +} + /************************************************************ *************** SECTIONS ***************** ************************************************************ @@ -90,7 +97,11 @@ export const RECORD_ABSTRACT_FIELD: EditorField = { export const TITLE_SECTION: EditorSection = { hidden: false, - fields: [RECORD_TITLE_FIELD, RECORD_ABSTRACT_FIELD], + fields: [ + RECORD_TITLE_FIELD, + RECORD_ABSTRACT_FIELD, + RECORD_GRAPHICAL_OVERVIEW_FIELD, + ], } export const ABOUT_SECTION: EditorSection = { @@ -167,18 +178,6 @@ export const DEFAULT_CONFIGURATION: EditorConfig = { { labelKey: marker('editor.record.form.page.description'), sections: [TITLE_SECTION, ABOUT_SECTION, GEOGRAPHICAL_COVERAGE_SECTION], - { - model: 'overviews', - formFieldConfig: { - labelKey: marker('editor.record.form.overviews'), - type: 'list', - }, - }, - { - model: 'keywords', - formFieldConfig: { - labelKey: marker('editor.record.form.keywords'), - type: 'list', }, { labelKey: marker('editor.record.form.page.ressources'),