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] Display and Edit Resource Creation date #1053

Merged
merged 3 commits into from
Dec 9, 2024
Merged
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
30 changes: 28 additions & 2 deletions apps/metadata-editor-e2e/src/e2e/edit.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,37 @@ describe('editor form', () => {
.should('eq', 'Test - resource identifier')
})
})
describe('resource updated', () => {
describe('resource created', () => {
beforeEach(() => {
cy.get('@aboutSection')
.find('gn-ui-form-field-date-updated')
.find('gn-ui-form-field-date')
.eq(0)
.as('resourceCreatedField')
})
it('shows the resource creation date', () => {
cy.get('@resourceCreatedField')
.find('input')
.invoke('val')
.should('eq', '1/1/2005')
})
it('edits and saves the resource creation date', () => {
cy.editor_wrapPreviousDraft()
cy.get('@resourceCreatedField')
.find('input')
.type('{selectall}{del}01/01/2019{enter}')
cy.editor_publishAndReload()
cy.get('@saveStatus').should('eq', 'record_up_to_date')
cy.get('@resourceCreatedField')
.find('input')
.invoke('val')
.should('eq', '1/1/2019')
})
})
describe('resource updated', () => {
beforeEach(() => {
cy.get('@aboutSection')
.find('gn-ui-form-field-date')
.eq(1)
.as('resourceUpdatedField')
})
it('shows the resource update date', () => {
Expand Down
10 changes: 10 additions & 0 deletions libs/common/fixtures/src/lib/editor/editor.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const editorSectionAboutFixture = () => ({
fields: [
editorFieldTitleFixture(),
editorFieldAbstractFixture(),
editorFieldResourceCreatedFixture(),
editorFieldResourceUpdatedFixture(),
editorFieldRecordUpdatedFixture(),
editorFieldUpdateFrequencyFixture(),
Expand Down Expand Up @@ -71,6 +72,14 @@ export const editorFieldAbstractFixture = () => ({
},
})

export const editorFieldResourceCreatedFixture = () => ({
model: 'resourceCreated',
hidden: false,
formFieldConfig: {
labelKey: 'editor.record.form.field.resourceCreated',
},
})

export const editorFieldResourceUpdatedFixture = () => ({
model: 'resourceUpdated',
hidden: false,
Expand Down Expand Up @@ -144,6 +153,7 @@ export const editorFieldsFixture = () => [
editorFieldTitleFixture(),
editorFieldAbstractFixture(),
editorFieldResourceUpdatedFixture(),
editorFieldResourceCreatedFixture(),
editorFieldRecordUpdatedFixture(),
editorFieldUpdateFrequencyFixture(),
editorFieldTemporalExtentsFixture(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { FormControl } from '@angular/forms'
import { FormFieldDateUpdatedComponent } from './form-field-date-updated.component'
import { FormFieldDateComponent } from './form-field-date.component'

describe('FormFieldResourceUpdatedComponent', () => {
let component: FormFieldDateUpdatedComponent
let fixture: ComponentFixture<FormFieldDateUpdatedComponent>
let component: FormFieldDateComponent
let fixture: ComponentFixture<FormFieldDateComponent>

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [FormFieldDateUpdatedComponent],
imports: [FormFieldDateComponent],
}).compileComponents()

fixture = TestBed.createComponent(FormFieldDateUpdatedComponent)
fixture = TestBed.createComponent(FormFieldDateComponent)
component = fixture.componentInstance
const control = new FormControl()
control.setValue(new Date())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
import { DatePickerComponent } from '@geonetwork-ui/ui/inputs'

@Component({
selector: 'gn-ui-form-field-date-updated',
templateUrl: './form-field-date-updated.component.html',
styleUrls: ['./form-field-date-updated.component.css'],
selector: 'gn-ui-form-field-date',
templateUrl: './form-field-date.component.html',
styleUrls: ['./form-field-date.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [DatePickerComponent],
})
export class FormFieldDateUpdatedComponent {
export class FormFieldDateComponent {
@Input() value: Date
@Output() valueChange: EventEmitter<Date> = new EventEmitter()
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@
(valueChange)="valueChange.emit($event)"
></gn-ui-form-field-simple>
</ng-container>
<ng-container *ngSwitchCase="'resourceCreated'">
<gn-ui-form-field-date
[value]="valueAsDate"
(valueChange)="valueChange.emit($event)"
></gn-ui-form-field-date>
</ng-container>
<ng-container *ngSwitchCase="'resourceUpdated'">
<gn-ui-form-field-date-updated
<gn-ui-form-field-date
[value]="valueAsDate"
(valueChange)="valueChange.emit($event)"
></gn-ui-form-field-date-updated>
></gn-ui-form-field-date>
</ng-container>
<ng-container *ngSwitchCase="'updateFrequency'">
<gn-ui-form-field-update-frequency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TranslateModule } from '@ngx-translate/core'
import { MockBuilder } from 'ng-mocks'
import { FormFieldLicenseComponent } from './form-field-license/form-field-license.component'
import { FormFieldOverviewsComponent } from './form-field-overviews/form-field-overviews.component'
import { FormFieldDateUpdatedComponent } from './form-field-date-updated/form-field-date-updated.component'
import { FormFieldDateComponent } from './form-field-date/form-field-date.component'
import { FormFieldRichComponent } from './form-field-rich/form-field-rich.component'
import { FormFieldSpatialExtentComponent } from './form-field-spatial-extent/form-field-spatial-extent.component'
import { FormFieldTemporalExtentsComponent } from './form-field-temporal-extents/form-field-temporal-extents.component'
Expand Down Expand Up @@ -63,13 +63,26 @@ describe('FormFieldComponent', () => {
expect(formField).toBeTruthy()
})
})
describe('resource created field', () => {
let formField
beforeEach(() => {
component.model = 'resourceCreated'
fixture.detectChanges()
formField = fixture.debugElement.query(
By.directive(FormFieldDateComponent)
).componentInstance
})
it('creates a resource created form field', () => {
expect(formField).toBeTruthy()
})
})
describe('resource updated field', () => {
let formField
beforeEach(() => {
component.model = 'resourceUpdated'
fixture.detectChanges()
formField = fixture.debugElement.query(
By.directive(FormFieldDateUpdatedComponent)
By.directive(FormFieldDateComponent)
).componentInstance
})
it('creates a resource updated form field', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { EditableLabelDirective } from '@geonetwork-ui/ui/inputs'
import { FormFieldWrapperComponent } from '@geonetwork-ui/ui/layout'
import { TranslateModule } from '@ngx-translate/core'
import {
FormFieldDateUpdatedComponent,
FormFieldDateComponent,
FormFieldLicenseComponent,
FormFieldTemporalExtentsComponent,
} from '.'
Expand Down Expand Up @@ -66,7 +66,7 @@ import { TextFieldModule } from '@angular/cdk/text-field'
MatTooltipModule,
FormFieldWrapperComponent,
FormFieldLicenseComponent,
FormFieldDateUpdatedComponent,
FormFieldDateComponent,
FormFieldUpdateFrequencyComponent,
FormFieldTemporalExtentsComponent,
FormFieldSimpleComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './form-field-keywords/form-field-keywords.component'
export * from './form-field-license/form-field-license.component'
export * from './form-field-date-updated/form-field-date-updated.component'
export * from './form-field-date/form-field-date.component'
export * from './form-field-temporal-extents/form-field-temporal-extents.component'
export * from './form-field-simple/form-field-simple.component'
export * from './form-field-file/form-field-file.component'
Expand Down
9 changes: 9 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,14 @@ export const RECORD_KEYWORDS_FIELD: EditorField = {
},
}

export const RECORD_RESOURCE_CREATED_FIELD: EditorField = {
model: 'resourceCreated',
formFieldConfig: {
labelKey: marker('editor.record.form.field.resourceCreated'),
},
gridColumnSpan: 1,
}

export const RESOURCE_IDENTIFIER_FIELD: EditorField = {
model: 'resourceIdentifier',
formFieldConfig: {
Expand Down Expand Up @@ -184,6 +192,7 @@ export const ABOUT_SECTION: EditorSection = {
fields: [
RECORD_UNIQUE_IDENTIFIER_FIELD,
RESOURCE_IDENTIFIER_FIELD,
RECORD_RESOURCE_CREATED_FIELD,
RECORD_RESOURCE_UPDATED_FIELD,
RECORD_UPDATED_FIELD,
RECORD_UPDATE_FREQUENCY_FIELD,
Expand Down
1 change: 1 addition & 0 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,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.resourceCreated": "",
"editor.record.form.field.resourceIdentifier": "",
"editor.record.form.field.resourceUpdated": "Letztes Aktualisierungsdatum",
"editor.record.form.field.securityConstraints": "Sicherheitseinschränkung",
Expand Down
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,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.resourceCreated": "Resource Created",
"editor.record.form.field.resourceIdentifier": "Identifier",
"editor.record.form.field.resourceUpdated": "Resource Updated",
"editor.record.form.field.securityConstraints": "Security constraint",
Expand Down
1 change: 1 addition & 0 deletions translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
"editor.record.form.field.otherConstraints": "",
"editor.record.form.field.overviews": "",
"editor.record.form.field.recordUpdated": "",
"editor.record.form.field.resourceCreated": "",
"editor.record.form.field.resourceIdentifier": "",
"editor.record.form.field.resourceUpdated": "",
"editor.record.form.field.securityConstraints": "",
Expand Down
1 change: 1 addition & 0 deletions translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,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.resourceCreated": "",
"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é",
Expand Down
1 change: 1 addition & 0 deletions translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
"editor.record.form.field.otherConstraints": "",
"editor.record.form.field.overviews": "",
"editor.record.form.field.recordUpdated": "",
"editor.record.form.field.resourceCreated": "",
"editor.record.form.field.resourceIdentifier": "",
"editor.record.form.field.resourceUpdated": "",
"editor.record.form.field.securityConstraints": "",
Expand Down
1 change: 1 addition & 0 deletions translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
"editor.record.form.field.otherConstraints": "",
"editor.record.form.field.overviews": "",
"editor.record.form.field.recordUpdated": "",
"editor.record.form.field.resourceCreated": "",
"editor.record.form.field.resourceIdentifier": "",
"editor.record.form.field.resourceUpdated": "",
"editor.record.form.field.securityConstraints": "",
Expand Down
1 change: 1 addition & 0 deletions translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
"editor.record.form.field.otherConstraints": "",
"editor.record.form.field.overviews": "",
"editor.record.form.field.recordUpdated": "",
"editor.record.form.field.resourceCreated": "",
"editor.record.form.field.resourceIdentifier": "",
"editor.record.form.field.resourceUpdated": "",
"editor.record.form.field.securityConstraints": "",
Expand Down
1 change: 1 addition & 0 deletions translations/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
"editor.record.form.field.otherConstraints": "",
"editor.record.form.field.overviews": "",
"editor.record.form.field.recordUpdated": "",
"editor.record.form.field.resourceCreated": "",
"editor.record.form.field.resourceIdentifier": "",
"editor.record.form.field.resourceUpdated": "",
"editor.record.form.field.securityConstraints": "",
Expand Down
Loading