-
Notifications
You must be signed in to change notification settings - Fork 19
/
individual_list_page.go
108 lines (91 loc) 路 2.89 KB
/
individual_list_page.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
102
103
104
105
106
107
108
package html
import (
"fmt"
"github.com/elliotchance/gedcom"
"github.com/elliotchance/gedcom/html/core"
"io"
"sort"
)
// IndividualListPage is the page that lists of all the individuals.
type IndividualListPage struct {
document *gedcom.Document
selectedLetter rune
googleAnalyticsID string
options *PublishShowOptions
indexLetters []rune
}
func NewIndividualListPage(document *gedcom.Document, selectedLetter rune, googleAnalyticsID string, options *PublishShowOptions, indexLetters []rune) *IndividualListPage {
return &IndividualListPage{
document: document,
selectedLetter: selectedLetter,
googleAnalyticsID: googleAnalyticsID,
options: options,
indexLetters: indexLetters,
}
}
func (c *IndividualListPage) WriteHTMLTo(w io.Writer) (int64, error) {
table := []core.Component{
core.NewTableHead("Name", "Birth", "Death"),
}
individuals := gedcom.IndividualNodes{}
for _, individual := range c.document.Individuals() {
if surnameStartsWith(individual, c.selectedLetter) {
individuals = append(individuals, individual)
}
}
// Sort individuals by name.
sort.Slice(individuals, func(i, j int) bool {
left := individuals[i].Name().Format(gedcom.NameFormatIndex)
right := individuals[j].Name().Format(gedcom.NameFormatIndex)
return left < right
})
livingCount := 0
lastSurname := ""
for _, i := range individuals {
if i.IsLiving() {
switch c.options.LivingVisibility {
case LivingVisibilityShow:
// Proceed.
case LivingVisibilityHide, LivingVisibilityPlaceholder:
livingCount += 1
continue
}
}
if newSurname := i.Name().Surname(); newSurname != lastSurname {
heading := core.NewComponents(
core.NewAnchor(newSurname),
core.NewHeading(3, "", core.NewText(newSurname)),
)
table = append(table, core.NewTableRow(
core.NewTableCell(heading),
core.NewTableCell(core.NewText("")),
core.NewTableCell(core.NewText("")),
))
lastSurname = newSurname
}
table = append(table, NewIndividualInList(c.document, i, c.options.LivingVisibility))
}
livingRow := core.NewRow(
core.NewColumn(core.EntireRow, core.NewText(fmt.Sprintf(
"%d individuals are hidden because they are living.",
livingCount,
))),
)
if livingCount == 0 ||
c.options.LivingVisibility == LivingVisibilityHide ||
c.options.LivingVisibility == LivingVisibilityShow {
livingRow = nil
}
return core.NewPage("Individuals", core.NewComponents(
NewPublishHeader(c.document, "", selectedIndividualsTab, c.options, c.indexLetters),
livingRow,
core.NewSpace(),
NewIndividualIndexHeader(c.document, c.selectedLetter, c.options.LivingVisibility, c.indexLetters),
core.NewSpace(),
NewSurnameIndex(c.document, c.selectedLetter, c.options.LivingVisibility),
core.NewSpace(),
core.NewRow(
core.NewColumn(core.EntireRow, core.NewTable("", table...)),
),
), c.googleAnalyticsID).WriteHTMLTo(w)
}