Items per page field of a profile is zero by default. Related form input in profile page does not accept values lower than 1. This makes the profile form impossible to submit without changing the value. Fill the form with the default value from configuration.
Signed-off-by: Franciszek Stachura <[email protected]> --- pkg/web/profile.go | 11 ++++++++++- pkg/web/profile.templ | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/web/profile.go b/pkg/web/profile.go index 78b017b..d573293 100644 --- a/pkg/web/profile.go +++ b/pkg/web/profile.go @@ -28,6 +28,7 @@ type profileData struct { Token string MaintainerProjects []db.Project ContributorProjects []db.Project + ItemsPerPage int } type linkedEmail struct { @@ -93,6 +94,11 @@ func (h *webHandler) ProfilePage(w http.ResponseWriter, r *http.Request) { OrderExpr("project.name ASC"). Scan(ctx) + itemsPerPage := user.ItemsPerPage + if itemsPerPage == 0 { + itemsPerPage = h.cfg.Http.WebPageSize + } + data := profileData{ PC: pc, User: user, @@ -101,6 +107,7 @@ func (h *webHandler) ProfilePage(w http.ResponseWriter, r *http.Request) { Token: token, MaintainerProjects: maintainerProjects, ContributorProjects: contributorProjects, + ItemsPerPage: itemsPerPage, } profilePage(data).Render(ctx, w) } @@ -120,7 +127,9 @@ func (h *webHandler) ProfileUpdate(w http.ResponseWriter, r *http.Request) { r.ParseForm() itemsPerPage, _ := strconv.Atoi(r.FormValue("items_per_page")) - if itemsPerPage < 1 { + if itemsPerPage == h.cfg.Http.WebPageSize { + itemsPerPage = 0 + } else if itemsPerPage < 1 { itemsPerPage = 100 } showIds := r.FormValue("show_ids") == "on" diff --git a/pkg/web/profile.templ b/pkg/web/profile.templ index 87d7927..dd03830 100644 --- a/pkg/web/profile.templ +++ b/pkg/web/profile.templ @@ -109,7 +109,7 @@ templ profilePage(d profileData) { <table> <tr> <th>Items per page</th> - <td><input type="number" name="items_per_page" value={ fmt.Sprintf("%d", d.User.ItemsPerPage) } min="1"/></td> + <td><input type="number" name="items_per_page" value={ fmt.Sprintf("%d", d.ItemsPerPage) } min="1"/></td> </tr> <tr> <th>Show patch IDs</th> -- 2.56.0 _______________________________________________ Patchwork mailing list [email protected] https://lists.ozlabs.org/listinfo/patchwork
