Skip to content

Commit

Permalink
docs: add remote debug port to gn, document
Browse files Browse the repository at this point in the history
  • Loading branch information
jahow authored and Romuald Caplier committed Jul 29, 2024
1 parent 21acdd2 commit b88db78
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface MetadataResourceApiModel {
metadataResourceExternalManagementProperties?: MetadataResourceExternalManagementPropertiesApiModel
lastModification?: string
version?: string
url?: URL
url?: string
filename?: string
id?: string
size?: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -74,16 +89,16 @@ 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', () => {
component.imageAltText = 'filenameDelete'
component.handleDelete()
expect(recordsApiService.delResource).toHaveBeenCalledWith(
metadataUuid,
'filenameDelete'
imageFileName
)
expect(component.imageAltText).toBeNull()
expect(component.resourceUrl).toBeNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 extractFileNameFromUrl = (url: string): string => {
const pattern = new RegExp(`attachments/([^/?#]+)(?:[/?#]|$)`, 'i')
const match = url.match(pattern)
return match ? match[1] : ''
}

Expand All @@ -37,7 +34,8 @@ export class OverviewUploadComponent implements OnInit, OnDestroy {
@Input() formControl!: FormControl
@Output() overviewChange = new EventEmitter<GraphicOverview | null>()

imageAltText: string
imageAltText: string // = ressourceFileName by default
ressourceFileName: string
resourceUrl: URL

private destroy$ = new Subject<void>()
Expand All @@ -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 = extractFileNameFromUrl(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 = extractFileNameFromUrl(
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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -134,6 +129,7 @@ export class OverviewUploadComponent implements OnInit, OnDestroy {

this.resourceUrl = null
this.imageAltText = ''
this.ressourceFileName = ''

this.overviewChange.emit(null)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
25 changes: 12 additions & 13 deletions libs/feature/editor/src/lib/fields.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,25 @@ export const RECORD_ABSTRACT_FIELD: EditorField = {
},
}

export const RECORD_GRAPHICAL_OVERVIEW_FIELD: EditorField = {
model: 'overviews',
formFieldConfig: {
labelKey: marker('editor.record.form.field.overviews'),
},
}

/************************************************************
*************** SECTIONS *****************
************************************************************
*/

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 = {
Expand Down Expand Up @@ -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'),
Expand Down
24 changes: 8 additions & 16 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,16 @@
"editor.record.form.bottomButtons.comeBackLater": "",
"editor.record.form.bottomButtons.next": "",
"editor.record.form.bottomButtons.previous": "",
"editor.record.form.field.abstract": "",
"editor.record.form.field.abstract": "Kurzbeschreibung",
"editor.record.form.field.keywords": "Schlagwörter",
"editor.record.form.field.license": "Lizenz",
"editor.record.form.field.recordUpdated": "",
"editor.record.form.field.resourceUpdated": "",
"editor.record.form.field.temporalExtents": "",
"editor.record.form.field.title": "",
"editor.record.form.field.uniqueIdentifier": "",
"editor.record.form.field.updateFrequency": "",
"editor.record.form.abstract": "Kurzbeschreibung",
"editor.record.form.keywords": "Schlüsselwörter",
"editor.record.form.license": "Lizenz",
"editor.record.form.field.overviews": "",
"editor.record.form.field.recordUpdated": "Datensatz zuletzt aktualisiert",
"editor.record.form.field.resourceUpdated": "Letztes Aktualisierungsdatum",
"editor.record.form.field.temporalExtents": "Zeitlicher Umfang",
"editor.record.form.field.title": "Metadaten-Titel",
"editor.record.form.field.uniqueIdentifier": "Eindeutige Kennung (ID)",
"editor.record.form.field.updateFrequency": "Aktualisierungshäufigkeit",
"editor.record.form.license.cc-by": "Creative Commons CC-BY",
"editor.record.form.license.cc-by-sa": "Creative Commons CC-BY-SA",
"editor.record.form.license.cc-zero": "Creative Commons CC-0",
Expand All @@ -205,16 +203,10 @@
"editor.record.form.section.dataPointOfContact.label": "",
"editor.record.form.section.geographicalCoverage.label": "",
"editor.record.form.section.useAndAccessConditions.label": "",
"editor.record.form.metadata.title": "Metadaten-Titel",
"editor.record.form.record.updated": "Datensatz zuletzt aktualisiert",
"editor.record.form.resourceUpdated": "Letztes Aktualisierungsdatum",
"editor.record.form.temporalExtents": "Zeitlicher Umfang",
"editor.record.form.temporalExtents.addDate": "Zeitpunkt",
"editor.record.form.temporalExtents.addRange": "Zeitraum",
"editor.record.form.temporalExtents.date": "Datum",
"editor.record.form.temporalExtents.range": "Datumsbereich",
"editor.record.form.unique.identifier": "Eindeutige Kennung (ID)",
"editor.record.form.updateFrequency": "Aktualisierungshäufigkeit",
"editor.record.form.updateFrequency.planned": "Die Daten sollten regelmäßig aktualisiert werden.",
"editor.record.loadError.body": "Der Datensatz konnte nicht geladen werden:",
"editor.record.loadError.closeMessage": "Verstanden",
Expand Down
10 changes: 1 addition & 9 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,13 @@
"editor.record.form.field.abstract": "Abstract",
"editor.record.form.field.keywords": "Keywords",
"editor.record.form.field.license": "License",
"editor.record.form.field.overviews": "Overviews",
"editor.record.form.field.recordUpdated": "Record Updated",
"editor.record.form.field.resourceUpdated": "Resource Updated",
"editor.record.form.field.temporalExtents": "Temporal extents",
"editor.record.form.field.title": "Metadata title",
"editor.record.form.field.uniqueIdentifier": "Unique identifier",
"editor.record.form.field.updateFrequency": "Update frequency",
"editor.record.form.abstract": "Abstract",
"editor.record.form.keywords": "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",
"editor.record.form.license.cc-zero": "Creative Commons CC-0",
Expand All @@ -205,16 +203,10 @@
"editor.record.form.section.dataPointOfContact.label": "Data point of contact",
"editor.record.form.section.geographicalCoverage.label": "Geographical coverage",
"editor.record.form.section.useAndAccessConditions.label": "Use and access conditions",
"editor.record.form.metadata.title": "Metadata title",
"editor.record.form.record.updated": "Record updated",
"editor.record.form.resourceUpdated": "Last update date",
"editor.record.form.temporalExtents": "Temporal extent",
"editor.record.form.temporalExtents.addDate": "Time instant",
"editor.record.form.temporalExtents.addRange": "Time period",
"editor.record.form.temporalExtents.date": "Date",
"editor.record.form.temporalExtents.range": "Date range",
"editor.record.form.unique.identifier": "Unique identifier",
"editor.record.form.updateFrequency": "Update frequency",
"editor.record.form.updateFrequency.planned": "The data should be updated regularly.",
"editor.record.loadError.body": "The record could not be loaded:",
"editor.record.loadError.closeMessage": "Understood",
Expand Down
10 changes: 1 addition & 9 deletions translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,13 @@
"editor.record.form.field.abstract": "",
"editor.record.form.field.keywords": "",
"editor.record.form.field.license": "",
"editor.record.form.field.overviews": "",
"editor.record.form.field.recordUpdated": "",
"editor.record.form.field.resourceUpdated": "",
"editor.record.form.field.temporalExtents": "",
"editor.record.form.field.title": "",
"editor.record.form.field.uniqueIdentifier": "",
"editor.record.form.field.updateFrequency": "",
"editor.record.form.abstract": "",
"editor.record.form.keywords": "",
"editor.record.form.license": "",
"editor.record.form.license.cc-by": "",
"editor.record.form.license.cc-by-sa": "",
"editor.record.form.license.cc-zero": "",
Expand All @@ -205,16 +203,10 @@
"editor.record.form.section.dataPointOfContact.label": "",
"editor.record.form.section.geographicalCoverage.label": "",
"editor.record.form.section.useAndAccessConditions.label": "",
"editor.record.form.metadata.title": "",
"editor.record.form.record.updated": "",
"editor.record.form.resourceUpdated": "",
"editor.record.form.temporalExtents": "",
"editor.record.form.temporalExtents.addDate": "",
"editor.record.form.temporalExtents.addRange": "",
"editor.record.form.temporalExtents.date": "",
"editor.record.form.temporalExtents.range": "",
"editor.record.form.unique.identifier": "",
"editor.record.form.updateFrequency": "",
"editor.record.form.updateFrequency.planned": "",
"editor.record.loadError.body": "",
"editor.record.loadError.closeMessage": "",
Expand Down
Loading

0 comments on commit b88db78

Please sign in to comment.