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.ts b/libs/feature/editor/src/lib/components/overview-upload/overview-upload.component.ts index ce32eddf0f..179196933b 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 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'),