Skip to content

Commit

Permalink
Avoid creating empty birth/death events
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub committed Oct 19, 2023
1 parent 7909a44 commit 4d5e3c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/components/GrampsjsFormSelectDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import '@material/mwc-select'
import '@material/mwc-list/mwc-list-item'

import {sharedStyles} from '../SharedStyles.js'
import {getSortval} from '../util.js'
import {getSortval, dateIsEmpty} from '../util.js'
import {GrampsjsTranslateMixin} from '../mixins/GrampsjsTranslateMixin.js'

const modifiers = {
Expand Down Expand Up @@ -494,6 +494,10 @@ class GrampsjsFormSelectDate extends GrampsjsTranslateMixin(LitElement) {
return true
}

isEmpty() {
return dateIsEmpty(this.data)
}

_openDatePicker1() {
this.renderRoot.getElementById('input-date1').showPicker()
}
Expand Down
17 changes: 17 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,3 +577,20 @@ export function clickKeyHandler(event) {
event.stopPropagation()
}
}

export function dateIsEmpty(date) {
if (date.modifier === 6) {
// Text Only Date is never empty
return false
}
if (JSON.stringify(date.dateval.slice(0, 4)) !== '[0,0,0,false]') {
return false
}
if (
date.dateval.len > 4 &&
JSON.stringify(date.dateval.slice(4)) !== '[0,0,0,false]'
) {
return false
}
return true
}
6 changes: 3 additions & 3 deletions src/views/GrampsjsViewNewPerson.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {GrampsjsViewNewObject} from './GrampsjsViewNewObject.js'
import '../components/GrampsjsFormName.js'
import '../components/GrampsjsFormPrivate.js'
import '../components/GrampsjsFormSelectObjectList.js'
import {makeHandle} from '../util.js'
import {makeHandle, dateIsEmpty} from '../util.js'
import {apiPost} from '../api.js'

const gender = {
Expand Down Expand Up @@ -135,8 +135,8 @@ export class GrampsjsViewNewPerson extends GrampsjsViewNewObject {
const birthString = this.translateTypeName(false, 'event_types', 'Birth')
const deathString = this.translateTypeName(false, 'event_types', 'Death')
const {birth, death, ...person} = this.data
const hasBirth = birth.place || birth?.date?._class
const hasDeath = death.place || death?.date?._class
const hasBirth = birth.place || (birth?.date && !dateIsEmpty(birth.date))
const hasDeath = death.place || (death?.date && !dateIsEmpty(birth.date))
if (!hasBirth && !hasDeath) {
return [person]
}
Expand Down

0 comments on commit 4d5e3c8

Please sign in to comment.