-
Notifications
You must be signed in to change notification settings - Fork 4
/
grouping.go
58 lines (53 loc) · 2.25 KB
/
grouping.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
package view
import (
"fmt"
"projectforge.dev/projectforge/app/file"
"projectforge.dev/projectforge/app/project/export/files/helper"
"projectforge.dev/projectforge/app/project/export/golang"
"projectforge.dev/projectforge/app/project/export/model"
)
func Grouping(m *model.Model, grp *model.Column, addHeader bool, linebreak string) (*file.File, error) {
g := golang.NewGoTemplate([]string{"views", "v" + m.Package}, fmt.Sprintf("%s.html", grp.ProperPlural()))
g.AddImport(helper.ImpApp, helper.ImpAppUtil, helper.ImpComponents, helper.ImpCutil, helper.ImpLayout)
g.AddBlocks(exportViewGroupedClass(grp), exportViewGroupedBody(m, grp))
return g.Render(addHeader, linebreak)
}
func exportViewGroupedClass(grp *model.Column) *golang.Block {
ret := golang.NewBlock(grp.ProperPlural(), "struct")
ret.W("{%%%% code type %s struct {", grp.ProperPlural())
ret.W(" layout.Basic")
ret.W(" %s []*util.KeyValInt", grp.ProperPlural())
ret.W("} %%}")
return ret
}
func exportViewGroupedBody(m *model.Model, grp *model.Column) *golang.Block {
ret := golang.NewBlock(fmt.Sprintf("%sBody", grp.ProperPlural()), "func")
ret.W("{%%%% func (p *%s) Body(as *app.State, ps *cutil.PageState) %%%%}", grp.ProperPlural())
ret.W(" <div class=\"card\">")
ret.W(" <h3>{%%%%= components.SVGRefIcon(`%s`, ps) %%%%} %s %s</h3>", m.Icon, m.Title(), grp.ProperPlural())
ret.W(" <div class=\"mt\">")
ret.W(" {%%- if len(p." + grp.ProperPlural() + ") == 0 -%%}")
ret.W(" <em>No %s available</em>", grp.Plural())
ret.W(" {%%- else -%%}")
ret.W(" <table>")
ret.W(" <thead>")
ret.W(" <tr>")
ret.W(" <th>%s</th>", grp.Proper())
ret.W(" <th>%s Count</th>", m.Title())
ret.W(" </tr>")
ret.W(" </thead>")
ret.W(" <tbody>")
ret.W(" {%%- for _, x := range p." + grp.ProperPlural() + " -%%}")
ret.W(" <tr>")
ret.W(" <td><a href=\"/" + m.Camel() + "/" + grp.Camel() + "/{%%s x.Key %%}\">{%%s x.Key %%}</a></td>")
ret.W(" <td>{%%d x.Count %%}</td>")
ret.W(" </tr>")
ret.W(" {%%- endfor -%%}")
ret.W(" </tbody>")
ret.W(" </table>")
ret.W(" {%%- endif -%%}")
ret.W(" </div>")
ret.W(" </div>")
ret.W("{%% endfunc %%}")
return ret
}