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 24, 2024
1 parent 21acdd2 commit 3a6c33f
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 60 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 extractFileNameFormUrl = (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 = 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)
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

0 comments on commit 3a6c33f

Please sign in to comment.