From fa2e34928d56598268bbf37e175a291a4b40e92c Mon Sep 17 00:00:00 2001 From: zeripath Date: Thu, 24 Dec 2020 15:26:19 +0000 Subject: [PATCH] Ensure that search term and page are not lost on adoption page-turn (#14133) Fix #14111 Signed-off-by: Andrew Thornton Co-authored-by: Lunny Xiao --- routers/admin/repos.go | 11 ++++++++++- templates/admin/repo/unadopted.tmpl | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/routers/admin/repos.go b/routers/admin/repos.go index 54b6c8e7c..46d0b60f2 100644 --- a/routers/admin/repos.go +++ b/routers/admin/repos.go @@ -5,6 +5,8 @@ package admin import ( + "net/url" + "strconv" "strings" "code.gitea.io/gitea/models" @@ -71,6 +73,8 @@ func UnadoptedRepos(ctx *context.Context) { opts.Page = 1 } + ctx.Data["CurrentPage"] = opts.Page + doSearch := ctx.QueryBool("search") ctx.Data["search"] = doSearch @@ -79,6 +83,7 @@ func UnadoptedRepos(ctx *context.Context) { if !doSearch { pager := context.NewPagination(0, opts.PageSize, opts.Page, 5) pager.SetDefaultParams(ctx) + pager.AddParam(ctx, "search", "search") ctx.Data["Page"] = pager ctx.HTML(200, tplUnadoptedRepos) return @@ -92,6 +97,7 @@ func UnadoptedRepos(ctx *context.Context) { ctx.Data["Dirs"] = repoNames pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5) pager.SetDefaultParams(ctx) + pager.AddParam(ctx, "search", "search") ctx.Data["Page"] = pager ctx.HTML(200, tplUnadoptedRepos) } @@ -100,6 +106,9 @@ func UnadoptedRepos(ctx *context.Context) { func AdoptOrDeleteRepository(ctx *context.Context) { dir := ctx.Query("id") action := ctx.Query("action") + page := ctx.QueryInt("page") + q := ctx.Query("q") + dirSplit := strings.SplitN(dir, "/", 2) if len(dirSplit) != 2 { ctx.Redirect(setting.AppSubURL + "/admin/repos") @@ -148,5 +157,5 @@ func AdoptOrDeleteRepository(ctx *context.Context) { } ctx.Flash.Success(ctx.Tr("repo.delete_preexisting_success", dir)) } - ctx.Redirect(setting.AppSubURL + "/admin/repos/unadopted") + ctx.Redirect(setting.AppSubURL + "/admin/repos/unadopted?search=true&q=" + url.QueryEscape(q) + "&page=" + strconv.Itoa(page)) } diff --git a/templates/admin/repo/unadopted.tmpl b/templates/admin/repo/unadopted.tmpl index 206ae91f0..bd47dd026 100644 --- a/templates/admin/repo/unadopted.tmpl +++ b/templates/admin/repo/unadopted.tmpl @@ -41,6 +41,8 @@ {{$.CsrfTokenHtml}} + +
{{svg "octicon-trashcan" 16 "mr-2"}} @@ -66,6 +68,8 @@ {{$.CsrfTokenHtml}} + +
{{svg "octicon-trashcan" 16 "mr-2"}}