Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Support resource identifier edition #1045

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/metadata-editor/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ body {
.mat-mdc-button-base {
line-height: normal;
}

.input-as-button {
@apply border-2 border-gray-300 hover:border-main bg-transparent gn-ui-text-input hover:text-main py-[11.5px] pl-[14px] pr-2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class DcatApConverter extends BaseConverter<string> {
spatialExtents: readSpatialExtents,
keywords: readKeywords,
topics: readTopics,
resourceIdentifier: () => undefined,
recordUpdated: readRecordUpdated,
recordCreated: readRecordCreated,
resourceUpdated: readResourceUpdated,
Expand Down Expand Up @@ -93,6 +94,7 @@ export class DcatApConverter extends BaseConverter<string> {
recordUpdated: () => undefined,
recordCreated: () => undefined,
recordPublished: () => undefined,
resourceIdentifier: () => undefined,
resourceUpdated: () => undefined,
resourceCreated: () => undefined,
resourcePublished: () => undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@
<gmd:title>
<gco:CharacterString>A very interesting dataset (un jeu de données très intéressant)</gco:CharacterString>
</gmd:title>
<gmd:identifier>
<gmd:MD_Identifier>
<gmd:code>
<gco:CharacterString>https://www.geoportail-urbanisme.gouv.fr/document/60036_PLU_20220329</gco:CharacterString>
</gmd:code>
</gmd:MD_Identifier>
</gmd:identifier>
<gmd:date>
<gmd:CI_Date>
<gmd:date>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,6 @@ Ce lot de données produit en 2019, a été numérisé à partir du PCI Vecteur
defaultLanguage: 'fr',
otherLanguages: [],
translations: {},
resourceIdentifier:
'https://www.geoportail-urbanisme.gouv.fr/document/60036_PLU_20220329',
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const GEOCAT_CH_DATASET_RECORD: DatasetRecord = {
abstract: `Perimeter der Alpenkonvention in der Schweiz. Die Alpenkonvention ist ein völkerrechtlicher Vertrag zwischen den acht Alpenländern Deutschland, Frankreich, Italien, Liechtenstein, Monaco, Österreich, Schweiz, Slowenien sowie der Europäischen Union. Das Ziel des Übereinkommens ist der Schutz der Alpen durch eine sektorübergreifende, ganzheitliche und nachhaltige Politik.`,
overviews: [],
topics: ['planningCadastre', 'planningCadastre_Planning'],
resourceIdentifier: 'ch.are.alpenkonvention',
keywords: [
{
thesaurus: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
readOwnerOrganization,
readRecordUpdated,
readResourceCreated,
readResourceIdentifier,
readResourcePublished,
readResourceUpdated,
readSecurityConstraints,
Expand Down Expand Up @@ -61,6 +62,7 @@ import {
writeOtherConstraints,
writeRecordUpdated,
writeResourceCreated,
writeResourceIdentifier,
writeResourcePublished,
writeResourceUpdated,
writeSecurityConstraints,
Expand All @@ -85,6 +87,7 @@ export class Iso19139Converter extends BaseConverter<string> {
recordUpdated: readRecordUpdated,
recordCreated: () => undefined, // not supported in ISO19139
recordPublished: () => undefined, // not supported in ISO19139
resourceIdentifier: readResourceIdentifier,
resourceUpdated: readResourceUpdated,
resourceCreated: readResourceCreated,
resourcePublished: readResourcePublished,
Expand Down Expand Up @@ -124,6 +127,7 @@ export class Iso19139Converter extends BaseConverter<string> {
recordUpdated: writeRecordUpdated,
recordCreated: () => undefined, // not supported in ISO19139
recordPublished: () => undefined, // not supported in ISO19139
resourceIdentifier: writeResourceIdentifier,
resourceUpdated: writeResourceUpdated,
resourceCreated: writeResourceCreated,
resourcePublished: writeResourcePublished,
Expand Down Expand Up @@ -232,6 +236,7 @@ export class Iso19139Converter extends BaseConverter<string> {
const onlineResources = this.readers['onlineResources'](rootEl, tr)
const otherLanguages = this.readers['otherLanguages'](rootEl, tr)
const defaultLanguage = this.readers['defaultLanguage'](rootEl, tr)
const resourceIdentifier = this.readers['resourceIdentifier'](rootEl, tr)

if (kind === 'dataset') {
const status = this.readers['status'](rootEl, tr)
Expand All @@ -246,6 +251,7 @@ export class Iso19139Converter extends BaseConverter<string> {

return this.afterRecordRead({
uniqueIdentifier,
...(resourceIdentifier && { resourceIdentifier }),
kind,
otherLanguages,
defaultLanguage,
Expand Down Expand Up @@ -280,6 +286,7 @@ export class Iso19139Converter extends BaseConverter<string> {
} else {
return this.afterRecordRead({
uniqueIdentifier,
...(resourceIdentifier && { resourceIdentifier }),
kind,
otherLanguages,
defaultLanguage,
Expand Down Expand Up @@ -370,6 +377,8 @@ export class Iso19139Converter extends BaseConverter<string> {
this.writers['otherConstraints'](record, rootEl)
fieldChanged('onlineResources') &&
this.writers['onlineResources'](record, rootEl)
fieldChanged('resourceIdentifier') &&
this.writers['resourceIdentifier'](record, rootEl)

if (record.kind === 'dataset') {
fieldChanged('status') && this.writers['status'](record, rootEl)
Expand Down
25 changes: 25 additions & 0 deletions libs/api/metadata-converter/src/lib/iso19139/read-parts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
readContacts,
readOnlineResources,
readOwnerOrganization,
readResourceIdentifier,
readSpatialExtents,
readTemporalExtents,
} from './read-parts'
Expand Down Expand Up @@ -790,6 +791,30 @@ describe('read parts', () => {
])
})
})

describe('read resource identifier', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I remove this test to avoid too many tests as this is a simple field?

beforeEach(() => {
const mdIdentificationInfo = getRootElement(
parseXmlString(`
<gmd:identifier>
<gmd:MD_Identifier>
<gmd:code>
<gco:CharacterString>fr-200053742/2021/scot</gco:CharacterString>
</gmd:code>
</gmd:MD_Identifier>
</gmd:identifier>`)
)
pipe(
removeChildrenByName('gmd:MD_Metadata.identificationInfo'),
appendChildren(() => mdIdentificationInfo)
)(recordRootEl)
})
it('returns the resource identifier', () => {
expect(readResourceIdentifier(recordRootEl)).toEqual(
'fr-200053742/2021/scot'
)
})
})
})
})
})
14 changes: 14 additions & 0 deletions libs/api/metadata-converter/src/lib/iso19139/read-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1124,3 +1124,17 @@ export function readDefaultLanguage(rootEl: XmlElement): LanguageCode {
map((lang) => (lang ? LANG_3_TO_2_MAPPER[lang.toLowerCase()] : null))
)(rootEl)
}

export function readResourceIdentifier(rootEl: XmlElement): string {
return pipe(
findIdentification(),
findNestedElement(
'gmd:citation',
'gmd:CI_Citation',
'gmd:identifier',
'gmd:MD_Identifier',
'gmd:code'
),
extractCharacterString()
)(rootEl)
}
17 changes: 17 additions & 0 deletions libs/api/metadata-converter/src/lib/iso19139/write-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1463,3 +1463,20 @@ export function writeDefaultLanguage(
writeAttribute('codeListValue', lang3)
)(rootEl)
}

export function writeResourceIdentifier(
record: DatasetRecord,
rootEl: XmlElement
) {
pipe(
findOrCreateIdentification(),
findNestedChildOrCreate('gmd:citation', 'gmd:CI_Citation'),
removeChildrenByName('gmd:identifier'),
record.resourceIdentifier
? pipe(
createNestedChild('gmd:identifier', 'gmd:MD_Identifier', 'gmd:code'),
writeCharacterString(record.resourceIdentifier)
)
: noop
)(rootEl)
}
1 change: 1 addition & 0 deletions libs/common/domain/src/lib/model/record/metadata.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export interface BaseRecord {
updateFrequency?: UpdateFrequency

// information related to the resource (dataset, service)
resourceIdentifier?: string
contactsForResource: Array<Individual>
resourceCreated?: Date
resourcePublished?: Date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[choices]="licenceOptions"
[selected]="selectedLicence"
(selectValue)="handleLicenceSelection($event)"
[extraBtnClass]="'input-as-button'"
>
</gn-ui-dropdown-selector>
</div>
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
<input
*ngIf="!isSelect"
[type]="inputType"
[type]="type"
[readonly]="readonly"
[placeholder]="placeholder"
[value]="value"
(valueChange)="valueChange.emit($event)"
class="border rounded-md p-3 w-full bg-white transition-colors"
[ngClass]="{
'border-pink-500': invalid,
'border-gray-200': !invalid,
'text-gray-600': readonly
}"
[ngModel]="value"
(ngModelChange)="valueChange.emit($event)"
class="gn-ui-text-input border-gray-300 hover:border-main"
/>
<select
*ngIf="isSelect"
[value]="value"
(valueChange)="valueChange.emit($event)"
class="border rounded-md p-3 w-full bg-white transition-colors"
[ngClass]="{
'border-pink-500': invalid,
'border-gray-200': !invalid,
'text-gray-600': readonly
}"
>
<option *ngFor="let option of options" [value]="option.value">
{{ option.label }}
</option>
</select>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'

import { FormFieldSimpleComponent } from './form-field-simple.component'
import { FormControl } from '@angular/forms'

describe('FormFieldSimpleComponent', () => {
let component: FormFieldSimpleComponent
Expand All @@ -14,7 +13,6 @@ describe('FormFieldSimpleComponent', () => {

fixture = TestBed.createComponent(FormFieldSimpleComponent)
component = fixture.componentInstance
component.control = new FormControl()
fixture.detectChanges()
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,22 @@ import {
Input,
Output,
} from '@angular/core'
import { FormsModule } from '@angular/forms'

@Component({
selector: 'gn-ui-form-field-simple',
templateUrl: './form-field-simple.component.html',
styleUrls: ['./form-field-simple.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [CommonModule],
imports: [CommonModule, FormsModule],
})
export class FormFieldSimpleComponent {
@Input() type: 'date' | 'url' | 'text' | 'number' | 'list' | 'toggle'
@Input() type: 'text' | 'number'
@Input() readonly = false
@Input() invalid = false
@Input() placeholder = ''
@Input() options?: { label: string; value: unknown }[]
@Input() value: unknown

@Output() valueChange: EventEmitter<unknown> = new EventEmitter()

get inputType() {
switch (this.type) {
case 'url':
case 'text':
return 'text'
case 'date':
return 'datetime-local'
case 'number':
return 'number'
case 'toggle':
return 'checkbox'
default:
return ''
}
}

get isSelect() {
return this.type === 'list'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
[selected]="selectedFrequency"
(selectValue)="onSelectFrequencyValue($event)"
[disabled]="!planned"
[extraBtnClass]="'input-as-button'"
>
</gn-ui-dropdown-selector>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@
(valueChange)="valueChange.emit($event)"
></gn-ui-form-field-overviews>
</ng-container>
<ng-container *ngSwitchCase="'resourceIdentifier'">
<gn-ui-form-field-simple
[type]="'text'"
[value]="valueAsString"
(valueChange)="valueChange.emit($event)"
></gn-ui-form-field-simple>
</ng-container>
<ng-container *ngSwitchCase="'resourceUpdated'">
<gn-ui-form-field-date-updated
[value]="valueAsDate"
Expand Down
8 changes: 8 additions & 0 deletions libs/feature/editor/src/lib/fields.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export const RECORD_KEYWORDS_FIELD: EditorField = {
},
}

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

export const RECORD_RESOURCE_UPDATED_FIELD: EditorField = {
model: 'resourceUpdated',
formFieldConfig: {
Expand Down Expand Up @@ -176,6 +183,7 @@ export const ABOUT_SECTION: EditorSection = {
hidden: false,
fields: [
RECORD_UNIQUE_IDENTIFIER_FIELD,
RESOURCE_IDENTIFIER_FIELD,
RECORD_RESOURCE_UPDATED_FIELD,
RECORD_UPDATED_FIELD,
RECORD_UPDATE_FREQUENCY_FIELD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
<gn-ui-button
type="outline"
class="grow min-w-0"
extraClass="bg-background !p-[8px] !pl-[16px] flex flex-row w-full {{
extraBtnClass
}}"
[style.--gn-ui-button-padding]="'8px 8px 8px 16px'"
extraClass="bg-background flex flex-row w-full {{ extraBtnClass }}"
[title]="title"
[attr.aria-owns]="id"
(buttonClick)="openOverlay()"
Expand Down
1 change: 1 addition & 0 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
"editor.record.form.field.otherConstraints": "Allgemeine Einschränkung",
"editor.record.form.field.overviews": "",
"editor.record.form.field.recordUpdated": "Datensatz zuletzt aktualisiert",
"editor.record.form.field.resourceIdentifier": "",
"editor.record.form.field.resourceUpdated": "Letztes Aktualisierungsdatum",
"editor.record.form.field.securityConstraints": "Sicherheitseinschränkung",
"editor.record.form.field.spatialExtents": "",
Expand Down
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
"editor.record.form.field.otherConstraints": "Other constraint",
"editor.record.form.field.overviews": "Overviews",
"editor.record.form.field.recordUpdated": "Record Updated",
"editor.record.form.field.resourceIdentifier": "Identifier",
"editor.record.form.field.resourceUpdated": "Resource Updated",
"editor.record.form.field.securityConstraints": "Security constraint",
"editor.record.form.field.spatialExtents": "Spatial extents",
Expand Down
1 change: 1 addition & 0 deletions translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
"editor.record.form.field.otherConstraints": "",
"editor.record.form.field.overviews": "",
"editor.record.form.field.recordUpdated": "",
"editor.record.form.field.resourceIdentifier": "",
"editor.record.form.field.resourceUpdated": "",
"editor.record.form.field.securityConstraints": "",
"editor.record.form.field.spatialExtents": "",
Expand Down
1 change: 1 addition & 0 deletions translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
"editor.record.form.field.otherConstraints": "Contrainte générale",
"editor.record.form.field.overviews": "Aperçus",
"editor.record.form.field.recordUpdated": "Date de dernière révision",
"editor.record.form.field.resourceIdentifier": "",
"editor.record.form.field.resourceUpdated": "Date de dernière révision",
"editor.record.form.field.securityConstraints": "Contrainte de sécurité",
"editor.record.form.field.spatialExtents": "Étendue spatiale",
Expand Down
Loading
Loading