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
|
package user
import "net/http"
import "time"
import "soko/pkg/app/layout"
import "soko/pkg/app/utils"
import "soko/pkg/config"
import "soko/pkg/models"
var viewTabs = []layout.SubTab{
{
Name: "General",
Link: "/user/preferences/general",
Icon: "fa fa-globe mr-1",
},
{
Name: "Packages",
Link: "/user/preferences/packages",
Icon: "fa fa-cube mr-1",
},
{
Name: "Maintainers",
Link: "/user/preferences/maintainers",
Icon: "fa fa-users mr-1",
},
}
templ show(currentSubTab string, preferences models.UserPreferences) {
<div class="container mb-5">
switch currentSubTab {
case "General":
@general(preferences.General)
case "Maintainers":
@maintainers(preferences.Maintainers)
}
</div>
<script src="/assets/userpref.js"></script>
}
templ sortableScript() {
<script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
<script>
if(document.getElementById("example1") != null && document.getElementById("example2") != null) {
new Sortable(example1, {
group: 'shared',
animation: 150,
ghostClass: 'bg-info'
});
new Sortable(example2, {
group: 'shared',
animation: 150,
ghostClass: 'bg-info'
});
}
</script>
}
func Preferences(currentSubTab string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
layout.TabbedLayout("User", layout.About, "Preferences", "fa fa-fw fa-cog", "You can customize the page contents to your needs here", viewTabs,
currentSubTab, show(currentSubTab, utils.GetUserPreferences(r))).Render(r.Context(), w)
}
}
// addCookie will apply a new cookie to the response of a http request
// with the key/value specified.
func addCookie(w http.ResponseWriter, name, path, value string, ttl time.Duration) {
expire := time.Now().Add(ttl)
cookie := http.Cookie{
Name: name,
Path: path,
Value: value,
Expires: expire,
HttpOnly: true,
Secure: config.DevMode() == "false",
}
http.SetCookie(w, &cookie)
}
|