diff options
author | 2024-04-18 19:43:18 +0300 | |
---|---|---|
committer | 2024-04-18 19:48:11 +0300 | |
commit | 962af6a0d694c19b516690cea2fe8d22dbb49055 (patch) | |
tree | a5b64aa0a3e21ee510294d297394c8dc893a17f0 | |
parent | bump go to go 1.22.2 (diff) | |
download | soko-962af6a0d694c19b516690cea2fe8d22dbb49055.tar.gz soko-962af6a0d694c19b516690cea2fe8d22dbb49055.tar.bz2 soko-962af6a0d694c19b516690cea2fe8d22dbb49055.zip |
user perf: drop useflags preferences
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r-- | assets/pgo5.png | bin | 17468 -> 0 bytes | |||
-rw-r--r-- | assets/pgo6.png | bin | 112793 -> 0 bytes | |||
-rw-r--r-- | pkg/app/handler/useflags/index.go | 19 | ||||
-rw-r--r-- | pkg/app/handler/user/preferences.templ | 7 | ||||
-rw-r--r-- | pkg/app/handler/user/useflags.templ | 89 | ||||
-rw-r--r-- | pkg/app/serve.go | 7 | ||||
-rw-r--r-- | pkg/app/utils/userdata.go | 9 | ||||
-rw-r--r-- | pkg/models/userpreferences.go | 12 |
8 files changed, 2 insertions, 141 deletions
diff --git a/assets/pgo5.png b/assets/pgo5.png Binary files differdeleted file mode 100644 index 933d2aa..0000000 --- a/assets/pgo5.png +++ /dev/null diff --git a/assets/pgo6.png b/assets/pgo6.png Binary files differdeleted file mode 100644 index a889239..0000000 --- a/assets/pgo6.png +++ /dev/null diff --git a/pkg/app/handler/useflags/index.go b/pkg/app/handler/useflags/index.go deleted file mode 100644 index d08d62b..0000000 --- a/pkg/app/handler/useflags/index.go +++ /dev/null @@ -1,19 +0,0 @@ -// Used to display the landing page of the USE flag section - -package useflags - -import ( - "net/http" - "soko/pkg/app/utils" -) - -// Index renders a template to show the index page of the USE flags -// section containing a bubble chart of popular USE flags -func Default(w http.ResponseWriter, r *http.Request) { - userPreferences := utils.GetUserPreferences(r) - if userPreferences.Useflags.Layout == "bubble" { - http.Redirect(w, r, "/useflags/popular", http.StatusSeeOther) - } else { - http.Redirect(w, r, "/useflags/search", http.StatusSeeOther) - } -} diff --git a/pkg/app/handler/user/preferences.templ b/pkg/app/handler/user/preferences.templ index b0277ce..5119635 100644 --- a/pkg/app/handler/user/preferences.templ +++ b/pkg/app/handler/user/preferences.templ @@ -23,11 +23,6 @@ var viewTabs = []layout.SubTab{ Link: "/user/preferences/maintainers", Icon: "fa fa-users mr-1", }, - { - Name: "USE flags", - Link: "/user/preferences/useflags", - Icon: "fa fa-sliders mr-1", - }, } templ show(currentSubTab string, preferences models.UserPreferences) { @@ -39,8 +34,6 @@ templ show(currentSubTab string, preferences models.UserPreferences) { @packages(preferences.Packages) case "Maintainers": @maintainers(preferences.Maintainers) - case "USE flags": - @useflags(preferences.Useflags) } </div> <script src="/assets/userpref.js"></script> diff --git a/pkg/app/handler/user/useflags.templ b/pkg/app/handler/user/useflags.templ deleted file mode 100644 index d47f931..0000000 --- a/pkg/app/handler/user/useflags.templ +++ /dev/null @@ -1,89 +0,0 @@ -package user - -import "encoding/base64" -import "encoding/json" -import "net/http" -import "time" -import "soko/pkg/app/utils" -import "soko/pkg/models" - -templ useflags(preferences models.UseflagsPreferences) { - <form method="post" action="/user/preferences/useflags/edit"> - <div class="row"> - <div class="col-5 offset-1 mt-1"> - <div class="card" style="background: transparent;"> - <div class="card-body"> - <img id="img1" alt="Popular USE flags (default)" src="/assets/pgo6.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="BubbleUseflagDefaultPage" - name="useflag-default-page" - value="bubble" - checked?={ preferences.Layout == "bubble" } - /> - <label class="form-check-label ml-1" for="BubbleUseflagDefaultPage" style="overflow:hidden;text-overflow: ellipsis;" title="Popular USE flags (default)">Popular USE flags <i>(default)</i></label> - </div> - </div> - </div> - <div class="col-5 mt-1"> - <div class="card" style="background: transparent;"> - <div class="card-body"> - <img id="img2" alt="USE flags search" src="/assets/pgo5.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="SearchUseflagDefaultPage" - name="useflag-default-page" - value="search" - checked?={ preferences.Layout == "search" } - /> - <label class="form-check-label ml-1" for="SearchUseflagDefaultPage" style="overflow:hidden;text-overflow: ellipsis;" title="USE flags search">USE flags search</label> - </div> - </div> - </div> - <div class="col-10 offset-1 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/useflags/reset">Reset to Defaults</a> - </div> - </div> - </form> - <div id="myModal" class="modal"> - <span class="close">×</span> - <img class="modal-content" id="img01"/> - <div id="caption"></div> - </div> -} - -func Useflags(w http.ResponseWriter, r *http.Request) { - userPreferences := utils.GetUserPreferences(r) - r.ParseForm() - // default use flag page - layout := r.Form.Get("useflag-default-page") - if layout == "bubble" || layout == "search" { - userPreferences.Useflags.Layout = layout - } - // store cookie - encodedUserPreferences, err := json.Marshal(&userPreferences.Useflags) - if err == nil { - sEnc := base64.StdEncoding.EncodeToString(encodedUserPreferences) - addCookie(w, "userpref_useflags", "/", sEnc, 365*24*time.Hour) - } - http.Redirect(w, r, "/user/preferences/useflags", http.StatusSeeOther) -} - -func ResetUseflags(w http.ResponseWriter, r *http.Request) { - userPreferences := utils.GetDefaultUserPreferences() - encodedUserPreferences, err := json.Marshal(&userPreferences.Useflags) - if err == nil { - sEnc := base64.StdEncoding.EncodeToString(encodedUserPreferences) - addCookie(w, "userpref_useflags", "/", sEnc, 365*24*time.Hour) - } - http.Redirect(w, r, "/user/preferences/useflags", http.StatusSeeOther) -} diff --git a/pkg/app/serve.go b/pkg/app/serve.go index 1f09b17..b54d4f2 100644 --- a/pkg/app/serve.go +++ b/pkg/app/serve.go @@ -44,6 +44,7 @@ func Serve() { setRoute("GET /categories/{category}/stabilization.list", categories.ShowStabilizationFile) setRoute("GET /categories/{category}/stabilization.xml", categories.ShowStabilizationFile) + redirect("GET /useflags", "/useflags/popular") setRoute("GET /useflags/popular.json", useflags.Popular) setRoute("GET /useflags/suggest.json", useflags.Suggest) setRoute("GET /useflags/search", useflags.Search) @@ -51,7 +52,6 @@ func Serve() { setRoute("GET /useflags/local", useflags.Local) setRoute("GET /useflags/expand", useflags.Expand) setRoute("GET /useflags/popular", useflags.PopularPage) - setRoute("GET /useflags", useflags.Default) setRoute("GET /useflags/{useflag}", useflags.Show) redirect("GET /arches", "/arches/amd64/keyworded") @@ -110,8 +110,6 @@ func Serve() { setRoute("GET /user/preferences/general", user.Preferences("General")) setRoute("GET /user/preferences/packages", user.Preferences("Packages")) setRoute("GET /user/preferences/maintainers", user.Preferences("Maintainers")) - setRoute("GET /user/preferences/useflags", user.Preferences("USE flags")) - setRoute("GET /user/preferences/arches", user.Preferences("Architectures")) setRoute("/user/preferences/general/layout", user.General) setRoute("/user/preferences/general/reset", user.ResetGeneral) @@ -119,9 +117,6 @@ func Serve() { setRoute("/user/preferences/packages/edit", user.EditPackagesPreferences) setRoute("/user/preferences/packages/reset", user.ResetPackages) - setRoute("/user/preferences/useflags/edit", user.Useflags) - setRoute("/user/preferences/useflags/reset", user.ResetUseflags) - setRoute("/user/preferences/maintainers/edit", user.Maintainers) setRoute("/user/preferences/maintainers/reset", user.ResetMaintainers) diff --git a/pkg/app/utils/userdata.go b/pkg/app/utils/userdata.go index acff520..dc4258b 100644 --- a/pkg/app/utils/userdata.go +++ b/pkg/app/utils/userdata.go @@ -38,14 +38,7 @@ func GetUserPreferences(r *http.Request) models.UserPreferences { } } - cookie, err = r.Cookie("userpref_useflags") - if err == nil { - cookieValue, err := b64.StdEncoding.DecodeString(cookie.Value) - if err == nil { - json.Unmarshal(cookieValue, &userPreferences.Useflags) - } - } - + // old cookie: userpref_useflags // old cookie: userpref_arches userPreferences.Sanitize() diff --git a/pkg/models/userpreferences.go b/pkg/models/userpreferences.go index 803c66c..91d95ee 100644 --- a/pkg/models/userpreferences.go +++ b/pkg/models/userpreferences.go @@ -6,7 +6,6 @@ type UserPreferences struct { General GeneralPreferences Packages PackagesPreferences Maintainers MaintainersPreferences - Useflags UseflagsPreferences } type GeneralPreferences struct { @@ -27,10 +26,6 @@ type MaintainersPreferences struct { ExcludedProjects []string } -type UseflagsPreferences struct { - Layout string -} - var ArchesToShow = [...]string{"amd64", "x86", "alpha", "arm", "arm64", "hppa", "ia64", "ppc", "ppc64", "riscv", "sparc"} var AllArches = [...]string{"alpha", "amd64", "arm", "arm64", "hppa", "ia64", "mips", "ppc", "ppc64", "riscv", "s390", "sparc", "x86"} @@ -40,15 +35,12 @@ func GetDefaultUserPreferences() UserPreferences { userPreferences.Packages = PackagesPreferences{} userPreferences.Packages.Overview = PackagesOverviewPreferences{} userPreferences.Maintainers = MaintainersPreferences{} - userPreferences.Useflags = UseflagsPreferences{} userPreferences.General.LandingPageLayout = "classic" userPreferences.Packages.Overview.Layout = "minimal" userPreferences.Packages.Overview.EAPI = "none" - userPreferences.Useflags.Layout = "bubble" - userPreferences.Maintainers.IncludeProjectPackages = false userPreferences.Maintainers.ExcludedProjects = []string{} @@ -69,8 +61,4 @@ func (u *UserPreferences) Sanitize() { if !(u.Packages.Overview.EAPI == "none" || u.Packages.Overview.EAPI == "column" || u.Packages.Overview.EAPI == "inline") { u.Packages.Overview.EAPI = defaultUserPreferences.Packages.Overview.EAPI } - - if !(u.Useflags.Layout == "bubble" || u.Useflags.Layout == "search") { - u.Useflags.Layout = defaultUserPreferences.Useflags.Layout - } } |