working recursive filters with tree reconstruction

This commit is contained in:
BroodjeAap 2022-09-03 14:52:37 +00:00
parent afc2dbea08
commit 27695ebdf3
3 changed files with 24 additions and 27 deletions

32
main.go
View file

@ -60,8 +60,9 @@ func (web Web) deleteWatch(c *gin.Context) {
} }
type FilterDepth struct { type FilterDepth struct {
Filter *Filter Filter *Filter
Depth int Depth []struct{}
RevDepth []struct{}
} }
func FilterPrint(filter *Filter, depth int) { func FilterPrint(filter *Filter, depth int) {
@ -105,7 +106,7 @@ func (web Web) viewWatch(c *gin.Context) {
filter := currentLayerFilters[0] filter := currentLayerFilters[0]
bftFilters = append(bftFilters, FilterDepth{ bftFilters = append(bftFilters, FilterDepth{
Filter: filter, Filter: filter,
Depth: depth, Depth: make([]struct{}, depth),
}) })
for _, filter := range filter.Filters { for _, filter := range filter.Filters {
nextLayerFilters = append(nextLayerFilters, &filter) nextLayerFilters = append(nextLayerFilters, &filter)
@ -116,28 +117,11 @@ func (web Web) viewWatch(c *gin.Context) {
currentLayerFilters = nextLayerFilters currentLayerFilters = nextLayerFilters
nextLayerFilters = []*Filter{} nextLayerFilters = []*Filter{}
} }
/*
nextFilters := []*Filter{}
depth := 0
for len(queuedFilters) > 0 {
for _, f1 := range queuedFilters {
bftFilters = append(bftFilters, FilterDepth{
Filter: *f1,
Depth: depth,
})
for _, f2 := range f1.Filters {
nextFilters = append(nextFilters, &f2)
}
}
queuedFilters = nextFilters
nextFilters = []*Filter{}
depth += 1
}
for _, f := range bftFilters { for i := range bftFilters {
FilterPrint(&f.Filter, 0) fd := &bftFilters[i]
} fd.RevDepth = make([]struct{}, depth-len(fd.Depth))
*/ }
c.HTML(http.StatusOK, "viewWatch", gin.H{ c.HTML(http.StatusOK, "viewWatch", gin.H{
"Watch": watch, "Watch": watch,
"Filters": bftFilters, "Filters": bftFilters,

View file

@ -23,5 +23,5 @@ type Filter struct {
Var2 *string `form:"var2" yaml:"var2"` Var2 *string `form:"var2" yaml:"var2"`
Var3 *string `form:"var3" yaml:"var3"` Var3 *string `form:"var3" yaml:"var3"`
Filters []Filter `gorm:"-:all"` Filters []Filter `gorm:"-:all"`
results []string `gorm:"-:all"` Results []string `gorm:"-:all"`
} }

View file

@ -10,13 +10,26 @@
</div> </div>
</div> </div>
<table class="table-sm"> <table class="table">
<thead>
<tr>
<th colspan="{{ .MaxDepth }}">ID</th>
<th>ID</th>
<th>ParentID</th>
<th>Name</th>
</tr>
</thead>
{{ range .Filters }} {{ range .Filters }}
<tr> <tr>
<td>{{ .Depth }}</td> {{ range .Depth }}
<td></td>
{{ end }}
<td>{{ .Filter.ID }}</td> <td>{{ .Filter.ID }}</td>
<td>{{ .Filter.ParentID }}</td> <td>{{ .Filter.ParentID }}</td>
<td>{{ .Filter.Name }}</td> <td>{{ .Filter.Name }}</td>
{{ range .RevDepth }}
<td></td>
{{ end }}
</tr> </tr>
{{ end }} {{ end }}
</table> </table>