-
Notifications
You must be signed in to change notification settings - Fork 2
/
index_builder.go
57 lines (53 loc) · 1.25 KB
/
index_builder.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
package structexplorer
import (
"fmt"
"html/template"
"sort"
"strings"
)
type indexDataBuilder struct {
data indexData
seq int
}
func newIndexDataBuilder() *indexDataBuilder {
b := new(indexDataBuilder)
b.data = indexData{
Script: template.JS(scriptJS),
Style: template.CSS(styleCSS),
}
return b
}
func (b *indexDataBuilder) build(row, column int, access objectAccess, value any) {
// check room
for len(b.data.Rows) <= row {
b.data.Rows = append(b.data.Rows, tableRow{})
}
for len(b.data.Rows[row].Cells) <= column {
b.data.Rows[row].Cells = append(b.data.Rows[row].Cells, fieldList{})
}
// replace
fields := newFields(value)
sort.Slice(fields, func(i, j int) bool {
return fields[i].displayKey() < fields[j].displayKey()
})
// copy fields into entries
entries := make([]fieldEntry, len(fields))
for i, each := range fields {
entries[i] = fieldEntry{
fieldAccess: each,
hideZero: access.hideZeros,
}
}
b.data.Rows[row].Cells[column] = fieldList{
Row: row,
Column: column,
Path: strings.Join(access.path, "."),
Label: access.label,
Fields: entries,
Type: access.typeName,
IsRoot: access.isRoot,
SelectSize: len(fields),
SelectID: fmt.Sprintf("id%d", b.seq),
}
b.seq++
}