From 02830596fb251120bc3db91ac30d3c307f200284 Mon Sep 17 00:00:00 2001 From: Magomedcoder Date: Sat, 11 Oct 2025 18:42:09 +0300 Subject: [PATCH] Refactor: move maintenance operations from dashboard to a separate page --- routers/web/admin/admin.go | 40 +++++++----- routers/web/web.go | 5 +- services/forms/admin.go | 6 +- templates/admin/dashboard.tmpl | 67 -------------------- templates/admin/maintenance_operations.tmpl | 70 +++++++++++++++++++++ templates/admin/navbar.tmpl | 5 +- 6 files changed, 104 insertions(+), 89 deletions(-) create mode 100644 templates/admin/maintenance_operations.tmpl diff --git a/routers/web/admin/admin.go b/routers/web/admin/admin.go index 0cd13acf6012b..5a8d76267242f 100644 --- a/routers/web/admin/admin.go +++ b/routers/web/admin/admin.go @@ -32,15 +32,16 @@ import ( ) const ( - tplDashboard templates.TplName = "admin/dashboard" - tplSystemStatus templates.TplName = "admin/system_status" - tplSelfCheck templates.TplName = "admin/self_check" - tplCron templates.TplName = "admin/cron" - tplQueue templates.TplName = "admin/queue" - tplPerfTrace templates.TplName = "admin/perftrace" - tplStacktrace templates.TplName = "admin/stacktrace" - tplQueueManage templates.TplName = "admin/queue_manage" - tplStats templates.TplName = "admin/stats" + tplDashboard templates.TplName = "admin/dashboard" + tplSystemStatus templates.TplName = "admin/system_status" + tplMaintenanceOperations templates.TplName = "admin/maintenance_operations" + tplSelfCheck templates.TplName = "admin/self_check" + tplCron templates.TplName = "admin/cron" + tplQueue templates.TplName = "admin/queue" + tplPerfTrace templates.TplName = "admin/perftrace" + tplStacktrace templates.TplName = "admin/stacktrace" + tplQueueManage templates.TplName = "admin/queue_manage" + tplStats templates.TplName = "admin/stats" ) var sysStatus struct { @@ -151,13 +152,18 @@ func SystemStatus(ctx *context.Context) { ctx.HTML(http.StatusOK, tplSystemStatus) } -// DashboardPost run an admin operation -func DashboardPost(ctx *context.Context) { - form := web.GetForm(ctx).(*forms.AdminDashboardForm) - ctx.Data["Title"] = ctx.Tr("admin.dashboard") - ctx.Data["PageIsAdminDashboard"] = true - updateSystemStatus() - ctx.Data["SysStatus"] = sysStatus +// MaintenanceOperations show admin panel maintenance operations +func MaintenanceOperations(ctx *context.Context) { + ctx.Data["Title"] = ctx.Tr("admin.dashboard.maintenance_operations") + ctx.Data["PageIsAdminMaintenanceOperations"] = true + ctx.HTML(http.StatusOK, tplMaintenanceOperations) +} + +// MaintenanceOperationsPost run an admin maintenance operations +func MaintenanceOperationsPost(ctx *context.Context) { + form := web.GetForm(ctx).(*forms.AdminMaintenanceOperationsForm) + ctx.Data["Title"] = ctx.Tr("admin.dashboard.maintenance_operations") + ctx.Data["PageIsAdminMaintenanceOperations"] = true // Run operation. if form.Op != "" { @@ -189,7 +195,7 @@ func DashboardPost(ctx *context.Context) { if form.From == "monitor" { ctx.Redirect(setting.AppSubURL + "/-/admin/monitor/cron") } else { - ctx.Redirect(setting.AppSubURL + "/-/admin") + ctx.Redirect(setting.AppSubURL + "/-/admin/maintenance-operations") } } diff --git a/routers/web/web.go b/routers/web/web.go index 5ee211b576a0c..34770a20643ae 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -719,8 +719,11 @@ func registerWebRoutes(m *web.Router) { // ***** START: Admin ***** m.Group("/-/admin", func() { m.Get("", admin.Dashboard) + m.Get("/system_status", admin.SystemStatus) - m.Post("", web.Bind(forms.AdminDashboardForm{}), admin.DashboardPost) + + m.Get("/maintenance-operations", admin.MaintenanceOperations) + m.Post("/maintenance-operations", web.Bind(forms.AdminMaintenanceOperationsForm{}), admin.MaintenanceOperationsPost) m.Get("/self_check", admin.SelfCheck) m.Post("/self_check", admin.SelfCheckPost) diff --git a/services/forms/admin.go b/services/forms/admin.go index 81276f8f46f9c..2cb2ea391015f 100644 --- a/services/forms/admin.go +++ b/services/forms/admin.go @@ -60,14 +60,14 @@ func (f *AdminEditUserForm) Validate(req *http.Request, errs binding.Errors) bin return middleware.Validate(errs, ctx.Data, f, ctx.Locale) } -// AdminDashboardForm form for admin dashboard operations -type AdminDashboardForm struct { +// AdminMaintenanceOperationsForm form for admin maintenance operations +type AdminMaintenanceOperationsForm struct { Op string `binding:"required"` From string } // Validate validates form fields -func (f *AdminDashboardForm) Validate(req *http.Request, errs binding.Errors) binding.Errors { +func (f *AdminMaintenanceOperationsForm) Validate(req *http.Request, errs binding.Errors) binding.Errors { ctx := context.GetValidateContext(req) return middleware.Validate(errs, ctx.Data, f, ctx.Locale) } diff --git a/templates/admin/dashboard.tmpl b/templates/admin/dashboard.tmpl index 2426a43b154d9..a3c80ec4ef818 100644 --- a/templates/admin/dashboard.tmpl +++ b/templates/admin/dashboard.tmpl @@ -5,73 +5,6 @@

{{ctx.Locale.Tr "admin.dashboard.new_version_hint" .RemoteVersion AppVer "https://blog.gitea.com"}}

{{end}} -

- {{ctx.Locale.Tr "admin.dashboard.maintenance_operations"}} -

-
-
- {{.CsrfTokenHtml}} - - - - - - - - - - - - - - - - - - - {{if and (not .SSH.Disabled) (not .SSH.StartBuiltinServer)}} - - - - - - - - - {{end}} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{{ctx.Locale.Tr "admin.dashboard.delete_inactive_accounts"}}
{{ctx.Locale.Tr "admin.dashboard.delete_repo_archives"}}
{{ctx.Locale.Tr "admin.dashboard.delete_missing_repos"}}
{{ctx.Locale.Tr "admin.dashboard.git_gc_repos"}}
{{ctx.Locale.Tr "admin.dashboard.resync_all_sshkeys"}}
{{ctx.Locale.Tr "admin.dashboard.resync_all_sshprincipals"}}
{{ctx.Locale.Tr "admin.dashboard.resync_all_hooks"}}
{{ctx.Locale.Tr "admin.dashboard.reinit_missing_repos"}}
{{ctx.Locale.Tr "admin.dashboard.sync_external_users"}}
{{ctx.Locale.Tr "admin.dashboard.repo_health_check"}}
{{ctx.Locale.Tr "admin.dashboard.delete_generated_repository_avatars"}}
{{ctx.Locale.Tr "admin.dashboard.sync_repo_branches"}}
{{ctx.Locale.Tr "admin.dashboard.sync_repo_tags"}}
-
-
-

{{ctx.Locale.Tr "admin.dashboard.system_status"}}

diff --git a/templates/admin/maintenance_operations.tmpl b/templates/admin/maintenance_operations.tmpl new file mode 100644 index 0000000000000..125a28df54df8 --- /dev/null +++ b/templates/admin/maintenance_operations.tmpl @@ -0,0 +1,70 @@ +{{template "admin/layout_head" (dict "ctxData" . "pageClass" "admin maintenance operations")}} +
+

+ {{ctx.Locale.Tr "admin.dashboard.maintenance_operations"}} +

+
+
+ {{.CsrfTokenHtml}} + + + + + + + + + + + + + + + + + + + {{if and (not .SSH.Disabled) (not .SSH.StartBuiltinServer)}} + + + + + + + + + {{end}} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{ctx.Locale.Tr "admin.dashboard.delete_inactive_accounts"}}
{{ctx.Locale.Tr "admin.dashboard.delete_repo_archives"}}
{{ctx.Locale.Tr "admin.dashboard.delete_missing_repos"}}
{{ctx.Locale.Tr "admin.dashboard.git_gc_repos"}}
{{ctx.Locale.Tr "admin.dashboard.resync_all_sshkeys"}}
{{ctx.Locale.Tr "admin.dashboard.resync_all_sshprincipals"}}
{{ctx.Locale.Tr "admin.dashboard.resync_all_hooks"}}
{{ctx.Locale.Tr "admin.dashboard.reinit_missing_repos"}}
{{ctx.Locale.Tr "admin.dashboard.sync_external_users"}}
{{ctx.Locale.Tr "admin.dashboard.repo_health_check"}}
{{ctx.Locale.Tr "admin.dashboard.delete_generated_repository_avatars"}}
{{ctx.Locale.Tr "admin.dashboard.sync_repo_branches"}}
{{ctx.Locale.Tr "admin.dashboard.sync_repo_tags"}}
+
+
+
+{{template "admin/layout_footer" .}} diff --git a/templates/admin/navbar.tmpl b/templates/admin/navbar.tmpl index 72584ec799cc3..a7b3ab095f7b4 100644 --- a/templates/admin/navbar.tmpl +++ b/templates/admin/navbar.tmpl @@ -2,12 +2,15 @@