-
Notifications
You must be signed in to change notification settings - Fork 0
/
fill_up_table.go
203 lines (175 loc) · 5.27 KB
/
fill_up_table.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// generated code - do not edit
package probe
import (
"fmt"
"log"
"sort"
gongtable "github.com/fullstack-lang/gongtable/go/models"
"github.com/fullstack-lang/maticons/maticons"
"github.com/fullstack-lang/gongleaflet/go/models"
"github.com/fullstack-lang/gongleaflet/go/orm"
)
func fillUpTablePointerToGongstruct[T models.PointerToGongstruct](
probe *Probe,
) {
var typedInstance T
switch any(typedInstance).(type) {
// insertion point
case *models.Circle:
fillUpTable[models.Circle](probe)
case *models.DivIcon:
fillUpTable[models.DivIcon](probe)
case *models.LayerGroup:
fillUpTable[models.LayerGroup](probe)
case *models.LayerGroupUse:
fillUpTable[models.LayerGroupUse](probe)
case *models.MapOptions:
fillUpTable[models.MapOptions](probe)
case *models.Marker:
fillUpTable[models.Marker](probe)
case *models.UserClick:
fillUpTable[models.UserClick](probe)
case *models.VLine:
fillUpTable[models.VLine](probe)
case *models.VisualTrack:
fillUpTable[models.VisualTrack](probe)
default:
log.Println("unknow type")
}
}
func fillUpTable[T models.Gongstruct](
probe *Probe,
) {
probe.tableStage.Reset()
probe.tableStage.Commit()
table := new(gongtable.Table).Stage(probe.tableStage)
table.Name = "Table"
table.HasColumnSorting = true
table.HasFiltering = true
table.HasPaginator = true
table.HasCheckableRows = false
table.HasSaveButton = false
fields := models.GetFields[T]()
reverseFields := models.GetReverseFields[T]()
table.NbOfStickyColumns = 3
// refresh the stage of interest
probe.stageOfInterest.Checkout()
setOfStructs := (*models.GetGongstructInstancesSet[T](probe.stageOfInterest))
sliceOfGongStructsSorted := make([]*T, len(setOfStructs))
i := 0
for k := range setOfStructs {
sliceOfGongStructsSorted[i] = k
i++
}
sort.Slice(sliceOfGongStructsSorted, func(i, j int) bool {
return orm.GetID(
probe.stageOfInterest,
probe.backRepoOfInterest,
sliceOfGongStructsSorted[i],
) <
orm.GetID(
probe.stageOfInterest,
probe.backRepoOfInterest,
sliceOfGongStructsSorted[j],
)
})
column := new(gongtable.DisplayedColumn).Stage(probe.tableStage)
column.Name = "ID"
table.DisplayedColumns = append(table.DisplayedColumns, column)
column = new(gongtable.DisplayedColumn).Stage(probe.tableStage)
column.Name = "Delete"
table.DisplayedColumns = append(table.DisplayedColumns, column)
for _, fieldName := range fields {
column := new(gongtable.DisplayedColumn).Stage(probe.tableStage)
column.Name = fieldName
table.DisplayedColumns = append(table.DisplayedColumns, column)
}
for _, reverseField := range reverseFields {
column := new(gongtable.DisplayedColumn).Stage(probe.tableStage)
column.Name = "(" + reverseField.GongstructName + ") -> " + reverseField.Fieldname
table.DisplayedColumns = append(table.DisplayedColumns, column)
}
fieldIndex := 0
for _, structInstance := range sliceOfGongStructsSorted {
row := new(gongtable.Row).Stage(probe.tableStage)
row.Name = models.GetFieldStringValue[T](*structInstance, "Name")
updater := NewRowUpdate[T](structInstance, probe)
updater.Instance = structInstance
row.Impl = updater
table.Rows = append(table.Rows, row)
cell := (&gongtable.Cell{
Name: "ID",
}).Stage(probe.tableStage)
row.Cells = append(row.Cells, cell)
cellInt := (&gongtable.CellInt{
Name: "ID",
Value: orm.GetID(
probe.stageOfInterest,
probe.backRepoOfInterest,
structInstance,
),
}).Stage(probe.tableStage)
cell.CellInt = cellInt
cell = (&gongtable.Cell{
Name: "Delete Icon",
}).Stage(probe.tableStage)
row.Cells = append(row.Cells, cell)
cellIcon := (&gongtable.CellIcon{
Name: "Delete Icon",
Icon: string(maticons.BUTTON_delete),
}).Stage(probe.tableStage)
cellIcon.Impl = NewCellDeleteIconImpl[T](structInstance, probe)
cell.CellIcon = cellIcon
for _, fieldName := range fields {
value := models.GetFieldStringValue[T](*structInstance, fieldName)
name := fmt.Sprintf("%d", fieldIndex) + " " + value
fieldIndex++
// log.Println(fieldName, value)
cell := (&gongtable.Cell{
Name: name,
}).Stage(probe.tableStage)
row.Cells = append(row.Cells, cell)
cellString := (&gongtable.CellString{
Name: name,
Value: value,
}).Stage(probe.tableStage)
cell.CellString = cellString
}
for _, reverseField := range reverseFields {
value := orm.GetReverseFieldOwnerName[T](
probe.stageOfInterest,
probe.backRepoOfInterest,
structInstance,
&reverseField)
name := fmt.Sprintf("%d", fieldIndex) + " " + value
fieldIndex++
// log.Println(fieldName, value)
cell := (&gongtable.Cell{
Name: name,
}).Stage(probe.tableStage)
row.Cells = append(row.Cells, cell)
cellString := (&gongtable.CellString{
Name: name,
Value: value,
}).Stage(probe.tableStage)
cell.CellString = cellString
}
}
}
func NewRowUpdate[T models.Gongstruct](
Instance *T,
probe *Probe,
) (rowUpdate *RowUpdate[T]) {
rowUpdate = new(RowUpdate[T])
rowUpdate.Instance = Instance
rowUpdate.probe = probe
return
}
type RowUpdate[T models.Gongstruct] struct {
Instance *T
probe *Probe
}
func (rowUpdate *RowUpdate[T]) RowUpdated(stage *gongtable.StageStruct, row, updatedRow *gongtable.Row) {
log.Println("RowUpdate: RowUpdated", updatedRow.Name)
FillUpFormFromGongstruct(rowUpdate.Instance, rowUpdate.probe)
}