-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-func-maps.go
More file actions
executable file
·79 lines (66 loc) · 2.52 KB
/
template-func-maps.go
File metadata and controls
executable file
·79 lines (66 loc) · 2.52 KB
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
package user
import (
"encoding/json"
"fmt"
"html/template"
"strconv"
"github.com/go-bolo/bolo"
)
type HTMLBootstrapConfig struct {
AppName string `json:"appName"`
AppLogo string `json:"appLogo"`
ENV string `json:"env"`
Site string `json:"site"`
Hostname string `json:"hostname"`
QueryDefaultLimit int `json:"queryDefaultLimit"`
QueryMaxLimit int `json:"queryMaxLimit"`
Locales []string `json:"locales"`
DefaultLocale string `json:"defaultLocale"`
Date clientSideDateFormat `json:"date"`
Plugins []string `json:"plugins"`
User map[string]string `json:"authenticatedUser"`
UserRoles []string `json:"userRoles"`
ActiveLocale string `json:"activeLocale"`
}
func renderClientAppConfigs(tplCtx bolo.TemplateCTX) template.HTML {
ctx := tplCtx.Ctx.(*bolo.RequestContext)
app := bolo.GetApp()
cfgs := bolo.GetConfiguration()
queryDefaultLimit, _ := strconv.Atoi(cfgs.GetF("PAGER_LIMIT", "20"))
queryMaxLimit, _ := strconv.Atoi(cfgs.GetF("PAGER_LIMIT_MAX", "50"))
keys := make([]string, 0, len(app.GetPlugins()))
for _, p := range app.GetPlugins() {
keys = append(keys, p.GetName())
}
data := HTMLBootstrapConfig{
AppName: cfgs.GetF("SITE_NAME", "App"),
ENV: ctx.ENV,
Hostname: ctx.AppOrigin,
ActiveLocale: cfgs.GetF("DEFAULT_LOCALE", "en-us"),
DefaultLocale: cfgs.GetF("DEFAULT_LOCALE", "en-us"),
Date: clientSideDateFormat{DefaultFormat: "L HH:mm"},
QueryDefaultLimit: queryDefaultLimit,
QueryMaxLimit: queryMaxLimit,
Locales: []string{"pt-br"},
Plugins: keys,
UserRoles: *ctx.GetAuthenticatedRoles(),
}
if ctx.IsAuthenticated {
data.User = make(map[string]string)
data.User["id"] = ctx.AuthenticatedUser.GetID()
data.User["displayName"] = ctx.AuthenticatedUser.GetDisplayName()
// TODO! add all user authenticated data
AUserLang := ctx.AuthenticatedUser.GetLanguage()
if AUserLang != "" {
data.ActiveLocale = AUserLang
}
}
for _, role := range data.UserRoles {
ctx.BodyClass = append(ctx.BodyClass, "ur-"+role)
}
jsonStringData, err := json.Marshal(data)
if err != nil {
fmt.Printf("Error: %s", err)
}
return template.HTML("<script>window.CATUPIRI_BOOTSTRAP_CONFIG=" + string(jsonStringData) + ";</script>")
}