-
Notifications
You must be signed in to change notification settings - Fork 246
Expand file tree
/
Copy pathGrampsjsPerson.js
More file actions
174 lines (158 loc) · 4.38 KB
/
Copy pathGrampsjsPerson.js
File metadata and controls
174 lines (158 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import {html, css} from 'lit'
import '@material/web/button/outlined-button'
import {mdiFamilyTree, mdiDna} from '@mdi/js'
import {GrampsjsObject} from './GrampsjsObject.js'
import {asteriskIcon, crossIcon} from '../icons.js'
import './GrampsJsImage.js'
import './GrampsjsEditGender.js'
import './GrampsjsPersonRelationship.js'
import {fireEvent} from '../util.js'
export class GrampsjsPerson extends GrampsjsObject {
static get styles() {
return [super.styles, css``]
}
static get properties() {
return {
homePersonDetails: {type: Object},
}
}
constructor() {
super()
this.homePersonDetails = {}
this._objectsName = 'People'
this._objectEndpoint = 'people'
this._objectIcon = 'person'
this._showReferences = false
this._showPersonTimeline = true
}
renderProfile() {
return html`
<h2>
<grampsjs-edit-gender
?edit="${this.edit}"
gender="${this.data.gender}"
></grampsjs-edit-gender>
${this._displayName()}
</h2>
${this._renderBirth()} ${this._renderDeath()} ${this._renderRelation()}
<p class="button-list">
${this._renderTreeBtn()} ${this._renderDnaBtn()}
</p>
`
}
_displayName() {
if (!this.data.profile) {
return ''
}
const nameDisplay = this.data.profile?.name_display
if (nameDisplay) {
return html`${nameDisplay}`
}
const surname = this.data.profile.name_surname || '…'
const suffix = this.data.profile.name_suffix || ''
const call = this.data?.primary_name?.call
let given = this.data.profile.name_given || call || '…'
const callIndex = call && call !== given ? given.search(call) : -1
given =
callIndex > -1
? html`
${given.substring(0, callIndex)}
<span class="given-name"
>${given.substring(callIndex, callIndex + call.length)}</span
>
${given.substring(callIndex + call.length)}
`
: given
return html`${given} ${surname} ${suffix}`
}
_renderBirth() {
const obj = this.data?.profile?.birth
if (obj === undefined || Object.keys(obj).length === 0) {
return ''
}
return html`
<span class="event">
<i>${asteriskIcon}</i>
${obj.date || ''} ${obj.place ? this._('in') : ''}
${obj.place_name || obj.place || ''}
</span>
`
}
_renderDeath() {
const obj = this.data?.profile?.death
if (obj === undefined || Object.keys(obj).length === 0) {
return ''
}
return html`
<span class="event">
<i>${crossIcon}</i>
${obj.date || ''} ${obj.place ? this._('in') : ''}
${obj.place_name || obj.place || ''}
</span>
`
}
_renderRelation() {
if (!this.homePersonDetails.handle) {
// no home person set
return ''
}
return html`
<dl>
<dt>${this._('Relationship to home person')}</dt>
<dd>
<grampsjs-person-relationship
person1="${this.homePersonDetails.handle}"
person2="${this.data.handle}"
.appState="${this.appState}"
></grampsjs-person-relationship>
</dd>
</dl>
`
}
_renderTreeBtn() {
return html`
<md-outlined-button @click="${this._handleTreeButtonClick}">
${this._('Show in tree')}
<grampsjs-icon
path="${mdiFamilyTree}"
color="var(--mdc-theme-primary)"
slot="icon"
>
</grampsjs-icon>
</md-outlined-button>
`
}
_renderDnaBtn() {
if (!this.data?.person_ref_list?.filter(ref => ref.rel === 'DNA').length) {
// no DNA data
return ''
}
return html`
<md-outlined-button
@click="${this._handleDnaButtonClick}"
class="dna-btn"
>
${this._('DNA matches')}
<grampsjs-icon
path="${mdiDna}"
color="var(--mdc-theme-primary)"
slot="icon"
></grampsjs-icon>
</md-outlined-button>
`
}
_handleTreeButtonClick() {
this.dispatchEvent(
new CustomEvent('pedigree:person-selected', {
bubbles: true,
composed: true,
detail: {grampsId: this.data.gramps_id},
})
)
fireEvent(this, 'nav', {path: 'tree'})
}
_handleDnaButtonClick() {
fireEvent(this, 'nav', {path: `dna-matches/${this.data.gramps_id}`})
}
}
window.customElements.define('grampsjs-person', GrampsjsPerson)