Show all WireGuard configs in admin without pagination.

This commit is contained in:
2026-07-29 09:57:50 +03:00
parent 3a864b41a7
commit d9ad81f35a
2 changed files with 7 additions and 18 deletions
+4 -13
View File
@@ -176,22 +176,14 @@ func generateToken(n int) (string, error) {
func (a *App) AdminWG(w http.ResponseWriter, r *http.Request) { func (a *App) AdminWG(w http.ResponseWriter, r *http.Request) {
u := a.Auth.CurrentUser(r) u := a.Auth.CurrentUser(r)
page, _ := strconv.Atoi(r.URL.Query().Get("page"))
if page < 1 {
page = 1
}
const perPage = 10
var total int var total int
_ = a.DB.QueryRow(r.Context(), `SELECT COUNT(*) FROM wg_configs`).Scan(&total) _ = a.DB.QueryRow(r.Context(), `SELECT COUNT(*) FROM wg_configs`).Scan(&total)
totalPages := (total + perPage - 1) / perPage
if totalPages < 1 {
totalPages = 1
}
offset := (page - 1) * perPage
rows, err := a.DB.Query(r.Context(), ` rows, err := a.DB.Query(r.Context(), `
SELECT id, COALESCE(token,''), original_filename, created_at SELECT id, COALESCE(token,''), original_filename, created_at
FROM wg_configs ORDER BY created_at DESC LIMIT $1 OFFSET $2`, perPage, offset) FROM wg_configs
ORDER BY created_at DESC`)
if err != nil { if err != nil {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
return return
@@ -214,8 +206,7 @@ func (a *App) AdminWG(w http.ResponseWriter, r *http.Request) {
a.render(w, "admin_wg.html", map[string]any{ a.render(w, "admin_wg.html", map[string]any{
"User": u, "User": u,
"Configs": configs, "Configs": configs,
"Page": page, "Total": total,
"TotalPages": totalPages,
"Message": msg, "Message": msg,
"MessageType": msgType, "MessageType": msgType,
"NewToken": token, "NewToken": token,
+3 -5
View File
@@ -46,7 +46,9 @@
</div> </div>
<div class="card"> <div class="card">
<h1 style="font-size:1.1rem;margin-bottom:1rem">Конфиги</h1> <h1 style="font-size:1.1rem;margin-bottom:0.35rem">Конфиги</h1>
<p class="muted" style="margin-bottom:1rem">Всего: {{.Total}}</p>
<div style="overflow-x:auto;max-height:70vh;overflow-y:auto">
<table class="table"> <table class="table">
<thead> <thead>
<tr><th>ID</th><th>Токен</th><th>Файл</th><th>Дата</th><th>Ссылка</th><th></th></tr> <tr><th>ID</th><th>Токен</th><th>Файл</th><th>Дата</th><th>Ссылка</th><th></th></tr>
@@ -71,10 +73,6 @@
{{end}} {{end}}
</tbody> </tbody>
</table> </table>
<div class="pager">
{{if gt .Page 1}}<a class="btn btn-ghost" href="/admin/wg?page={{sub .Page 1}}"></a>{{end}}
<span class="muted">стр. {{.Page}} / {{.TotalPages}}</span>
{{if lt .Page .TotalPages}}<a class="btn btn-ghost" href="/admin/wg?page={{add .Page 1}}"></a>{{end}}
</div> </div>
</div> </div>
</div> </div>