-
Notifications
You must be signed in to change notification settings - Fork 20
/
individual_events.go
101 lines (81 loc) 路 2.8 KB
/
individual_events.go
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
package html
import (
"github.com/elliotchance/gedcom"
"github.com/elliotchance/gedcom/html/core"
"io"
"sort"
)
// IndividualEvents is the table of events show in the "Events" section of the
// individuals page.
type IndividualEvents struct {
document *gedcom.Document
individual *gedcom.IndividualNode
visibility LivingVisibility
}
func newIndividualEvents(document *gedcom.Document, individual *gedcom.IndividualNode, visibility LivingVisibility) *IndividualEvents {
return &IndividualEvents{
document: document,
individual: individual,
visibility: visibility,
}
}
func (c *IndividualEvents) WriteHTMLTo(w io.Writer) (int64, error) {
events := []core.Component{}
for _, event := range c.individual.AllEvents() {
date := gedcom.String(gedcom.First(gedcom.Dates(event)))
place := gedcom.String(gedcom.First(gedcom.Places(event)))
e := NewIndividualEvent(date, place, core.NewEmpty(), c.individual, event)
events = append(events, e)
}
for _, family := range c.individual.Families() {
marriage := gedcom.First(gedcom.NodesWithTag(family, gedcom.TagMarriage))
if marriage == nil {
continue
}
date := gedcom.First(gedcom.NodesWithTag(marriage, gedcom.TagDate))
if date == nil {
continue
}
place := ""
if p := gedcom.First(gedcom.NodesWithTag(marriage, gedcom.TagPlace)); p != nil {
place = p.Value()
}
var description core.Component = core.NewEmpty()
if family.Husband().IsIndividual(c.individual) {
description = core.NewHTML(UnknownEmphasis)
if wife := family.Wife(); wife != nil {
description = NewIndividualLink(c.document, wife.Individual(), c.visibility)
}
}
if family.Wife().IsIndividual(c.individual) {
description = core.NewHTML(UnknownEmphasis)
if husband := family.Husband(); husband != nil {
description = NewIndividualLink(c.document, husband.Individual(), c.visibility)
}
}
// Empty description means that the individual is a child so this is not
// an event we want to show.
if _, ok := description.(*core.Empty); !ok {
event := NewIndividualEvent(date.Value(), place,
description, c.individual, marriage)
events = append(events, event)
}
}
// Sort events by age.
sort.Slice(events, func(i, j int) bool {
a := events[i].(*IndividualEvent)
b := events[j].(*IndividualEvent)
if !a.event.Tag().Is(b.event.Tag()) {
return a.event.Tag().SortValue() < b.event.Tag().SortValue()
}
aStart, _ := c.individual.AgeAt(a.event)
bStart, _ := c.individual.AgeAt(b.event)
return aStart.Years() < bStart.Years()
})
tableHead := core.NewTableHead("Age", "Type", "Date", "Place", "Description")
components := core.NewComponents(events...)
s := core.NewTable("text-center", tableHead, components)
return core.NewRow(core.NewColumn(core.EntireRow,
core.NewCard(core.NewText("Events"), len(events), s),
)).WriteHTMLTo(w)
}