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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
package user
import "encoding/base64"
import "encoding/json"
import "net/http"
import "time"
import "soko/pkg/app/utils"
import "soko/pkg/models"
templ packages(preferences models.PackagesPreferences) {
<div class="row">
<form method="post" action="/user/preferences/packages/edit">
<h4 class="mb-1">Layout</h4>
<div class="row">
<div class="col-6 mt-1">
<div class="card" style="background: transparent;">
<div class="card-body">
<img id="img1" alt="Versions + Metadata (default)" src="/assets/pgo2.png" style="width: 100%;cursor: pointer;"/>
</div>
</div>
<div class="text-center mt-2">
<div class="form-check text-center form-check-inline" style="text-overflow: ellipsis;overflow: hidden;">
<input
type="radio"
id="minimalOverviewLayout"
name="overview-layout"
value="minimal"
checked?={ preferences.Overview.Layout == "minimal" }
/>
<label class="form-check-label ml-1" for="minimalOverviewLayout" style="overflow:hidden;text-overflow: ellipsis;" title="Versions + Metadata (default)">Versions + Metadata <i>(default)</i></label>
</div>
</div>
</div>
<div class="col-6 mt-1">
<div class="card" style="background: transparent;">
<div class="card-body">
<img id="img2" alt="Versions + Metadata + Changelog" src="/assets/pgo1.png" onclick="document.getElementById('fullOverviewLayout').checked = true;" style="width: 100%;cursor: pointer;"/>
</div>
</div>
<div class="text-center mt-2">
<div class="form-check text-center form-check-inline" style="text-overflow: ellipsis;overflow: hidden;">
<input
type="radio"
id="fullOverviewLayout"
name="overview-layout"
value="full"
checked?={ preferences.Overview.Layout == "full" }
/>
<label class="form-check-label ml-1" for="fullOverviewLayout" style="overflow:hidden;text-overflow: ellipsis;" title="Versions + Metadata + Changelog">Versions + Metadata + Changelog</label>
</div>
</div>
</div>
</div>
<h4 class="mt-4 mb-1">EAPI version</h4>
<div class="card">
<div class="card-body">
Show
<select class="form-control form-control-sm ml-2" style="max-width: 100px;display: inline;" name="overview-eapi" id="overview-eapi">
<option
value="none"
selected?={ preferences.Overview.EAPI == "none" }
>none</option>
<option
value="column"
selected?={ preferences.Overview.EAPI == "column" }
>in column</option>
<option
value="inline"
selected?={ preferences.Overview.EAPI == "inline" }
>inline</option>
</select>
</div>
</div>
<div class="row">
<div class="col-12 mt-4">
<button type="submit" class="float-right btn btn-sm btn-primary">Save</button>
<a class="float-right btn btn-sm btn-outline-danger mr-2" href="/user/preferences/packages/reset">Reset to Defaults</a>
</div>
</div>
</form>
</div>
<div id="myModal" class="modal">
<span class="close">×</span>
<img class="modal-content" id="img01"/>
<div id="caption"></div>
</div>
}
func EditPackagesPreferences(w http.ResponseWriter, r *http.Request) {
userPreferences := utils.GetUserPreferences(r)
r.ParseForm()
// Overview: Layout
overviewLayout := r.Form.Get("overview-layout")
if overviewLayout == "minimal" || overviewLayout == "full" {
userPreferences.Packages.Overview.Layout = overviewLayout
}
// EAPI
showEAPI := r.Form.Get("overview-eapi")
if showEAPI == "none" || showEAPI == "column" || showEAPI == "inline" {
userPreferences.Packages.Overview.EAPI = showEAPI
}
//
// Store cookie
//
encodedUserPreferences, err := json.Marshal(&userPreferences.Packages)
if err == nil {
sEnc := base64.StdEncoding.EncodeToString(encodedUserPreferences)
addCookie(w, "userpref_packages", "/", sEnc, 365*24*time.Hour)
}
http.Redirect(w, r, "/user/preferences/packages", http.StatusSeeOther)
}
func ResetPackages(w http.ResponseWriter, r *http.Request) {
userPreferences := utils.GetDefaultUserPreferences()
encodedUserPreferences, err := json.Marshal(&userPreferences.Packages)
if err == nil {
sEnc := base64.StdEncoding.EncodeToString(encodedUserPreferences)
addCookie(w, "userpref_packages", "/", sEnc, 365*24*time.Hour)
}
http.Redirect(w, r, "/user/preferences/packages", http.StatusSeeOther)
}
|