-
Notifications
You must be signed in to change notification settings - Fork 4
/
page.go
73 lines (65 loc) · 2.33 KB
/
page.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
// Content managed by Project Forge, see [projectforge.md] for details.
package cutil
import (
"context"
"fmt"
"github.com/valyala/fasthttp"
"go.uber.org/zap"
"projectforge.dev/projectforge/app/lib/menu"
"projectforge.dev/projectforge/app/lib/telemetry"
"projectforge.dev/projectforge/app/lib/user"
"projectforge.dev/projectforge/app/util"
)
type PageState struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Method string `json:"method,omitempty"`
URI *fasthttp.URI `json:"-"`
Menu menu.Items `json:"menu,omitempty"`
Breadcrumbs Breadcrumbs `json:"breadcrumbs,omitempty"`
Flashes []string `json:"flashes,omitempty"`
Session util.ValueMap `json:"-"`
Profile *user.Profile `json:"profile,omitempty"`
Accounts user.Accounts `json:"accounts,omitempty"`
Authed bool `json:"authed,omitempty"`
Admin bool `json:"admin,omitempty"`
Icons []string `json:"icons,omitempty"`
RootIcon string `json:"rootIcon,omitempty"`
RootPath string `json:"rootPath,omitempty"`
RootTitle string `json:"rootTitle,omitempty"`
SearchPath string `json:"searchPath,omitempty"`
ProfilePath string `json:"profilePath,omitempty"`
HideMenu bool `json:"hideMenu,omitempty"`
ForceRedirect string `json:"forceRedirect,omitempty"`
HeaderContent string `json:"headerContent,omitempty"`
Data any `json:"data,omitempty"`
Logger *zap.SugaredLogger `json:"-"`
Context context.Context `json:"-"`
Span *telemetry.Span `json:"-"`
RenderElapsed float64 `json:"renderElapsed,omitempty"`
}
func (p *PageState) AddIcon(n string) {
for _, icon := range p.Icons {
if icon == n {
return
}
}
p.Icons = append(p.Icons, n)
}
func (p *PageState) TitleString() string {
if p.Title == "" {
return util.AppName
}
return fmt.Sprintf("%s - %s", p.Title, util.AppName)
}
func (p *PageState) User() string {
if len(p.Accounts) == 0 {
return "anonymous"
}
return p.Accounts[0].Email
}
func (p *PageState) Close() {
if p.Span != nil {
p.Span.Complete()
}
}