/
browsers.go
75 lines (66 loc) · 2.18 KB
/
browsers.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
// Copyright © Martin Tournoij – This file is part of GoatCounter and published
// under the terms of a slightly modified EUPL v1.2 license, which can be found
// in the LICENSE file or at https://license.goatcounter.com
package widgets
import (
"context"
"html/template"
"zgo.at/goatcounter/v2"
"zgo.at/z18n"
)
type Browsers struct {
id int
loaded bool
err error
html template.HTML
s goatcounter.WidgetSettings
Limit int
Detail string
Stats goatcounter.HitStats
}
func (w Browsers) Name() string { return "browsers" }
func (w Browsers) Type() string { return "hchart" }
func (w Browsers) Label(ctx context.Context) string {
return z18n.T(ctx, "label/browser-stats|Browser stats")
}
func (w *Browsers) SetHTML(h template.HTML) { w.html = h }
func (w Browsers) HTML() template.HTML { return w.html }
func (w *Browsers) SetErr(h error) { w.err = h }
func (w Browsers) Err() error { return w.err }
func (w Browsers) ID() int { return w.id }
func (w Browsers) Settings() goatcounter.WidgetSettings { return w.s }
func (w *Browsers) SetSettings(s goatcounter.WidgetSettings) {
if x := s["limit"].Value; x != nil {
w.Limit = int(x.(float64))
}
if x := s["key"].Value; x != nil {
w.Detail = x.(string)
}
w.s = s
}
func (w *Browsers) GetData(ctx context.Context, a Args) (more bool, err error) {
if w.Detail != "" {
err = w.Stats.ListBrowser(ctx, w.Detail, a.Rng, a.PathFilter, w.Limit, a.Offset)
} else {
err = w.Stats.ListBrowsers(ctx, a.Rng, a.PathFilter, w.Limit, a.Offset)
}
w.loaded = true
return w.Stats.More, err
}
func (w Browsers) RenderHTML(ctx context.Context, shared SharedData) (string, any) {
return "_dashboard_hchart.gohtml", struct {
Context context.Context
ID int
RowsOnly bool
HasSubMenu bool
Loaded bool
Err error
IsCollected bool
Header string
TotalUTC int
Stats goatcounter.HitStats
Detail string
}{ctx, w.id, shared.RowsOnly, w.Detail == "", w.loaded, w.err, isCol(ctx, goatcounter.CollectUserAgent),
z18n.T(ctx, "header/browsers|Browsers"),
shared.TotalUTC, w.Stats, w.Detail}
}