mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-12-07 14:09:47 +00:00
feat(ui): improve admin dashboard cron list (#10270)
* in both `/admin` and `/admin/cron`: use new buttons, they are slightly more compact, which i think fits this place well as currently rows here feel too tall
* in `/admin/cron`: use `octicon-play` consistently with `/admin` instead of `octicon-triangle-right`
* in `/admin`: replace verbose template HTML with Range-based generator
* added integration test to verify page content
<!--start release-notes-assistant-->
## Release notes
<!--URL:https://codeberg.org/forgejo/forgejo-->
- User Interface features
- [PR](https://codeberg.org/forgejo/forgejo/pulls/10270): <!--number 10270 --><!--line 0 --><!--description ZmVhdCh1aSk6IGltcHJvdmUgYWRtaW4gZGFzaGJvYXJkIGNyb24gbGlzdA==-->feat(ui): improve admin dashboard cron list<!--description-->
<!--end release-notes-assistant-->
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10270
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Reviewed-by: Otto <otto@codeberg.org>
Co-authored-by: 0ko <0ko@noreply.codeberg.org>
Co-committed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
parent
e31d67e0aa
commit
3f207017a8
4 changed files with 108 additions and 53 deletions
|
|
@ -135,7 +135,27 @@ func Dashboard(ctx *context.Context) {
|
|||
ctx.Data["RemoteVersion"] = updatechecker.GetRemoteVersion(ctx)
|
||||
updateSystemStatus()
|
||||
ctx.Data["SysStatus"] = sysStatus
|
||||
ctx.Data["SSH"] = setting.SSH
|
||||
|
||||
entries := []string{
|
||||
"delete_inactive_accounts",
|
||||
"delete_repo_archives",
|
||||
"delete_missing_repos",
|
||||
"git_gc_repos",
|
||||
}
|
||||
if !setting.SSH.Disabled && !setting.SSH.StartBuiltinServer {
|
||||
entries = append(entries, "resync_all_sshkeys", "resync_all_sshprincipals")
|
||||
}
|
||||
entries = append(entries, []string{
|
||||
"resync_all_hooks",
|
||||
"reinit_missing_repos",
|
||||
"sync_external_users",
|
||||
"repo_health_check",
|
||||
"delete_generated_repository_avatars",
|
||||
"sync_repo_branches",
|
||||
"sync_repo_tags",
|
||||
}...)
|
||||
ctx.Data["Entries"] = entries
|
||||
|
||||
prepareDeprecatedWarningsAlert(ctx)
|
||||
ctx.HTML(http.StatusOK, tplDashboard)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
<tbody>
|
||||
{{range .Entries}}
|
||||
<tr>
|
||||
<td><button type="submit" class="ui primary button" name="op" value="{{.Name}}" title="{{ctx.Locale.Tr "admin.dashboard.operation_run"}}">{{svg "octicon-triangle-right"}}</button></td>
|
||||
<td><button type="submit" class="primary button" name="op" value="{{.Name}}" title="{{ctx.Locale.Tr "admin.dashboard.operation_run"}}">{{svg "octicon-play"}}</button></td>
|
||||
<td>{{ctx.Locale.Tr (printf "admin.dashboard.%s" .Name)}}</td>
|
||||
<td>{{.Spec}}</td>
|
||||
<td>{{DateUtils.FullTime .Next}}</td>
|
||||
|
|
|
|||
|
|
@ -12,60 +12,16 @@
|
|||
<form method="post" action="{{AppSubUrl}}/admin">
|
||||
<table class="ui very basic table tw-mt-0 tw-px-4">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{{ctx.Locale.Tr "admin.dashboard.delete_inactive_accounts"}}</td>
|
||||
<td class="text right"><button type="submit" class="ui primary button" name="op" value="delete_inactive_accounts">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ctx.Locale.Tr "admin.dashboard.delete_repo_archives"}}</td>
|
||||
<td class="text right"><button type="submit" class="ui primary button" name="op" value="delete_repo_archives">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ctx.Locale.Tr "admin.dashboard.delete_missing_repos"}}</td>
|
||||
<td class="text right"><button type="submit" class="ui primary button" name="op" value="delete_missing_repos">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ctx.Locale.Tr "admin.dashboard.git_gc_repos"}}</td>
|
||||
<td class="text right"><button type="submit" class="ui primary button" name="op" value="git_gc_repos">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
|
||||
</tr>
|
||||
{{if and (not .SSH.Disabled) (not .SSH.StartBuiltinServer)}}
|
||||
{{range .Entries}}
|
||||
<tr>
|
||||
<td>{{ctx.Locale.Tr "admin.dashboard.resync_all_sshkeys"}}</td>
|
||||
<td class="text right"><button type="submit" class="ui primary button" name="op" value="resync_all_sshkeys">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ctx.Locale.Tr "admin.dashboard.resync_all_sshprincipals"}}</td>
|
||||
<td class="text right"><button type="submit" class="ui primary button" name="op" value="resync_all_sshprincipals">{{svg "octicon-play" 16}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
|
||||
<td>{{ctx.Locale.Tr (printf "admin.dashboard.%s" .)}}</td>
|
||||
<td class="text right">
|
||||
<button type="submit" class="primary button" name="op" value="{{.}}">
|
||||
{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
<tr>
|
||||
<td>{{ctx.Locale.Tr "admin.dashboard.resync_all_hooks"}}</td>
|
||||
<td class="text right"><button type="submit" class="ui primary button" name="op" value="resync_all_hooks">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ctx.Locale.Tr "admin.dashboard.reinit_missing_repos"}}</td>
|
||||
<td class="text right"><button type="submit" class="ui primary button" name="op" value="reinit_missing_repos">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ctx.Locale.Tr "admin.dashboard.sync_external_users"}}</td>
|
||||
<td class="text right"><button type="submit" class="ui primary button" name="op" value="sync_external_users">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ctx.Locale.Tr "admin.dashboard.repo_health_check"}}</td>
|
||||
<td class="text right"><button type="submit" class="ui primary button" name="op" value="repo_health_check">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ctx.Locale.Tr "admin.dashboard.delete_generated_repository_avatars"}}</td>
|
||||
<td class="text right"><button type="submit" class="ui primary button" name="op" value="delete_generated_repository_avatars">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ctx.Locale.Tr "admin.dashboard.sync_repo_branches"}}</td>
|
||||
<td class="text right"><button type="submit" class="ui primary button" name="op" value="sync_repo_branches">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ctx.Locale.Tr "admin.dashboard.sync_repo_tags"}}</td>
|
||||
<td class="text right"><button type="submit" class="ui primary button" name="op" value="sync_repo_tags">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
|
|
|
|||
79
tests/integration/admin_dashboard_test.go
Normal file
79
tests/integration/admin_dashboard_test.go
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"forgejo.org/modules/setting"
|
||||
"forgejo.org/modules/test"
|
||||
"forgejo.org/modules/translation"
|
||||
"forgejo.org/tests"
|
||||
)
|
||||
|
||||
var commonEntries = []string{
|
||||
"delete_inactive_accounts",
|
||||
"delete_repo_archives",
|
||||
"delete_missing_repos",
|
||||
"git_gc_repos",
|
||||
"resync_all_hooks",
|
||||
"reinit_missing_repos",
|
||||
"sync_external_users",
|
||||
"repo_health_check",
|
||||
"delete_generated_repository_avatars",
|
||||
"sync_repo_branches",
|
||||
"sync_repo_tags",
|
||||
}
|
||||
|
||||
var sshEntries = []string{
|
||||
"resync_all_sshkeys",
|
||||
"resync_all_sshprincipals",
|
||||
}
|
||||
|
||||
func testAssertAdminDashboardEntries(t *testing.T, page *HTMLDoc, locale translation.Locale, expectSSH bool) {
|
||||
for _, entry := range commonEntries {
|
||||
page.AssertSelection(t, page.FindByText("table tr td", locale.TrString(fmt.Sprintf("admin.dashboard.%s", entry))), true)
|
||||
page.AssertSelection(t, page.Find(fmt.Sprintf("table tr td button[value='%s']", entry)), true)
|
||||
}
|
||||
for _, entry := range sshEntries {
|
||||
page.AssertSelection(t, page.FindByText("table tr td", locale.TrString(fmt.Sprintf("admin.dashboard.%s", entry))), expectSSH)
|
||||
page.AssertSelection(t, page.Find(fmt.Sprintf("table tr td button[value='%s']", entry)), expectSSH)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminDashboard(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
session := loginUser(t, "user1")
|
||||
locale := translation.NewLocale("en-US")
|
||||
url := "/admin"
|
||||
|
||||
t.Run("SSH disabled", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
defer test.MockVariableValue(&setting.SSH.Disabled, true)()
|
||||
|
||||
page := NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", url), http.StatusOK).Body)
|
||||
testAssertAdminDashboardEntries(t, page, locale, false)
|
||||
})
|
||||
|
||||
t.Run("SSH enabled, but built-in", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
defer test.MockVariableValue(&setting.SSH.Disabled, false)()
|
||||
defer test.MockVariableValue(&setting.SSH.StartBuiltinServer, true)()
|
||||
|
||||
page := NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", url), http.StatusOK).Body)
|
||||
testAssertAdminDashboardEntries(t, page, locale, false)
|
||||
})
|
||||
|
||||
t.Run("SSH enabled and external", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
defer test.MockVariableValue(&setting.SSH.Disabled, false)()
|
||||
defer test.MockVariableValue(&setting.SSH.StartBuiltinServer, false)()
|
||||
|
||||
page := NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", url), http.StatusOK).Body)
|
||||
testAssertAdminDashboardEntries(t, page, locale, true)
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue