Merged
Overzicht: max 10 repos/groepen, groepen op laatste push
timfa
wants to merge
1 commit
from
cursor/dash-limit
into
stage
Overview Commits 1 Pipelines 1 Changes 7
Dashboard toont max 10 repos en 10 groepen met Alles tonen (?all=repos / ?all=groups). Groepen gesorteerd op de laatste push in een repo van de groep (BlueGit kent geen subgroepen), zonder push onderaan, dan op naam. Tooltips + i18n.
Activity
- timfa opened this merge request 27 October 2026
- timfa Pipeline #422 is Passed 27 October 2026
- timfa merged this merge request 27 October 2026
Commits
Pipelines
- #422 Passed
Changes
@@ -0,0 +1,8 @@
1
package i18n
2
3
func init() {
4
addCatalog(en, map[string]string{"dash.showAll": "Show all (%d more)", "dash.moreTip": "The overview shows the 10 most recently pushed.", "dash.groupsTip": "Sorted by the most recent push in a repository of the group; groups without pushes come last."})
5
addCatalog(nl, map[string]string{"dash.showAll": "Alles tonen (nog %d)", "dash.moreTip": "Het overzicht toont de 10 waarin het laatst gepusht is.", "dash.groupsTip": "Gesorteerd op de laatste push in een repository van de groep; groepen zonder push staan onderaan."})
6
addCatalog(de, map[string]string{"dash.showAll": "Alle anzeigen (%d weitere)", "dash.moreTip": "Die Übersicht zeigt die 10 mit dem jüngsten Push.", "dash.groupsTip": "Nach dem letzten Push in einem Repository der Gruppe sortiert; Gruppen ohne Push stehen unten."})
7
addCatalog(fr, map[string]string{"dash.showAll": "Tout afficher (%d de plus)", "dash.moreTip": "L'aperçu montre les 10 avec le push le plus récent.", "dash.groupsTip": "Trié par dernier push dans un dépôt du groupe ; les groupes sans push sont en bas."})
8
}
@@ -0,0 +1,8 @@1
package i18n2
3
func init() {4
addCatalog(en, map[string]string{"dash.showAll": "Show all (%d more)", "dash.moreTip": "The overview shows the 10 most recently pushed.", "dash.groupsTip": "Sorted by the most recent push in a repository of the group; groups without pushes come last."})5
addCatalog(nl, map[string]string{"dash.showAll": "Alles tonen (nog %d)", "dash.moreTip": "Het overzicht toont de 10 waarin het laatst gepusht is.", "dash.groupsTip": "Gesorteerd op de laatste push in een repository van de groep; groepen zonder push staan onderaan."})6
addCatalog(de, map[string]string{"dash.showAll": "Alle anzeigen (%d weitere)", "dash.moreTip": "Die Übersicht zeigt die 10 mit dem jüngsten Push.", "dash.groupsTip": "Nach dem letzten Push in einem Repository der Gruppe sortiert; Gruppen ohne Push stehen unten."})7
addCatalog(fr, map[string]string{"dash.showAll": "Tout afficher (%d de plus)", "dash.moreTip": "L'aperçu montre les 10 avec le push le plus récent.", "dash.groupsTip": "Trié par dernier push dans un dépôt du groupe ; les groupes sans push sont en bas."})8
}@@ -106,6 +106,11 @@ func (s *Server) home(w http.ResponseWriter, r *http.Request) {
106
106
return
107
107
}
108
108
store.SortReposByPush(repos)
109
all := r.URL.Query().Get("all")
110
if len(repos) > dashLimit && all != "repos" {
111
v.MoreRepos = len(repos) - dashLimit
112
repos = repos[:dashLimit]
113
}
109
114
v.Repos = repos
110
115
v.ReleaseRepos = s.releaseOnlyRepos(r, v.User.ID)
111
116
groups, err := s.Store.ListGroups(r.Context(), v.User.ID)
@@ -113,6 +118,13 @@ func (s *Server) home(w http.ResponseWriter, r *http.Request) {
113
118
http.Error(w, s.tr(r, "err.overview"), http.StatusInternalServerError)
114
119
return
115
120
}
121
if at, err := s.Store.GroupPushTimes(r.Context()); err == nil {
122
store.SortGroupsByPush(groups, at)
123
}
124
if len(groups) > dashLimit && all != "groups" {
125
v.MoreGroups = len(groups) - dashLimit
126
groups = groups[:dashLimit]
127
}
116
128
v.Groups = groups
117
129
v.Title = s.tr(r, "nav.dashboard")
118
130
v.Page = "dashboard"
@@ -253,3 +265,6 @@ func parseID(s string, dest *int64) (int64, error) {
253
265
}
254
266
255
267
var errBadID = http.ErrMissingFile
268
269
// dashLimit is het aantal repos en groepen op het overzicht.
270
const dashLimit = 10
@@ -106,6 +106,11 @@ func (s *Server) home(w http.ResponseWriter, r *http.Request) {106
return106
return107
}107
}108
store.SortReposByPush(repos)108
store.SortReposByPush(repos)109
all := r.URL.Query().Get("all")110
if len(repos) > dashLimit && all != "repos" {111
v.MoreRepos = len(repos) - dashLimit112
repos = repos[:dashLimit]113
}109
v.Repos = repos114
v.Repos = repos110
v.ReleaseRepos = s.releaseOnlyRepos(r, v.User.ID)115
v.ReleaseRepos = s.releaseOnlyRepos(r, v.User.ID)111
groups, err := s.Store.ListGroups(r.Context(), v.User.ID)116
groups, err := s.Store.ListGroups(r.Context(), v.User.ID)@@ -113,6 +118,13 @@ func (s *Server) home(w http.ResponseWriter, r *http.Request) {113
http.Error(w, s.tr(r, "err.overview"), http.StatusInternalServerError)118
http.Error(w, s.tr(r, "err.overview"), http.StatusInternalServerError)114
return119
return115
}120
}121
if at, err := s.Store.GroupPushTimes(r.Context()); err == nil {122
store.SortGroupsByPush(groups, at)123
}124
if len(groups) > dashLimit && all != "groups" {125
v.MoreGroups = len(groups) - dashLimit126
groups = groups[:dashLimit]127
}116
v.Groups = groups128
v.Groups = groups117
v.Title = s.tr(r, "nav.dashboard")129
v.Title = s.tr(r, "nav.dashboard")118
v.Page = "dashboard"130
v.Page = "dashboard"@@ -253,3 +265,6 @@ func parseID(s string, dest *int64) (int64, error) {253
}265
}254
266
255
var errBadID = http.ErrMissingFile267
var errBadID = http.ErrMissingFile268
269
// dashLimit is het aantal repos en groepen op het overzicht.270
const dashLimit = 10@@ -0,0 +1,92 @@
1
package server
2
3
import (
4
"context"
5
"fmt"
6
"net/http"
7
"net/http/cookiejar"
8
"net/http/httptest"
9
"os/exec"
10
"path/filepath"
11
"strings"
12
"testing"
13
"time"
14
15
"gitlab.com/Timfa/bluegit/internal/auth"
16
"gitlab.com/Timfa/bluegit/internal/config"
17
"gitlab.com/Timfa/bluegit/internal/store"
18
)
19
20
func TestDashboardLimitsToTen(t *testing.T) {
21
if _, err := exec.LookPath("git"); err != nil {
22
t.Skip("git ontbreekt")
23
}
24
storage := t.TempDir()
25
st, err := store.Open(filepath.Join(storage, "bluegit.db"), bytes32())
26
if err != nil {
27
t.Fatal(err)
28
}
29
t.Cleanup(func() { _ = st.Close() })
30
ctx := context.Background()
31
ada, err := st.UpsertUser(ctx, 1, "ada", "", false)
32
if err != nil {
33
t.Fatal(err)
34
}
35
dev, err := st.UpsertUser(ctx, 2, "dev", "", false)
36
if err != nil {
37
t.Fatal(err)
38
}
39
issue := func(u store.User) string {
40
plain, _, err := st.IssueToken(ctx, u.ID, store.TokenRequest{Name: u.Username, Scopes: "api", ExpiresAt: time.Time{}})
41
if err != nil {
42
t.Fatal(err)
43
}
44
return plain
45
}
46
adaTok, devTok := issue(ada), issue(dev)
47
cfg := config.Config{
48
BaseURL: "http://127.0.0.1:9", StoragePath: storage,
49
Auth: config.Auth{Mode: "dev", DevUser: "ada", DevAuthID: 1},
50
Git: config.Git{Binary: "git", DefaultBranch: "master"},
51
}
52
srv := &Server{Cfg: cfg, Store: st, Auth: auth.Dev{Username: "ada", AuthID: 1}, Dev: true, Git: "git", HookBin: "/bin/true", StateDir: t.TempDir()}
53
ts := httptest.NewServer(srv.Handler())
54
t.Cleanup(ts.Close)
55
56
for i := 0; i < 12; i++ {
57
r, err := st.CreateRepo(ctx, "user", ada.ID, fmt.Sprintf("r%02d", i), "", "master", "private")
58
if err != nil {
59
t.Fatal(err)
60
}
61
_ = st.TouchPushed(ctx, r.ID, time.Date(2026, 1, 1+i, 0, 0, 0, 0, time.UTC))
62
}
63
_, _ = devTok, adaTok
64
jar, _ := cookiejar.New(nil)
65
client := &http.Client{Jar: jar}
66
res, err := client.Get(ts.URL + "/login")
67
if err != nil {
68
t.Fatal(err)
69
}
70
_ = read(t, res)
71
get := func(path string) string {
72
res, err := client.Get(ts.URL + path)
73
if err != nil {
74
t.Fatal(err)
75
}
76
return read(t, res)
77
}
78
dash := get("/")
79
if n := strings.Count(dash, `class="reponame" href="/ada/r`); n != 10 {
80
t.Fatalf("dashboard toont %d repos", n)
81
}
82
if !strings.Contains(dash, `href="/?all=repos"`) || !strings.Contains(dash, "(2 more)") {
83
t.Fatal("alles-tonen-link ontbreekt")
84
}
85
if strings.Index(dash, `href="/ada/r11"`) > strings.Index(dash, `href="/ada/r10"`) || strings.Contains(dash, `href="/ada/r01"`) {
86
t.Fatal("volgorde of afkapping klopt niet")
87
}
88
full := get("/?all=repos")
89
if n := strings.Count(full, `class="reponame" href="/ada/r`); n != 12 {
90
t.Fatalf("alles tonen geeft %d", n)
91
}
92
}
@@ -0,0 +1,92 @@1
package server2
3
import (4
"context"5
"fmt"6
"net/http"7
"net/http/cookiejar"8
"net/http/httptest"9
"os/exec"10
"path/filepath"11
"strings"12
"testing"13
"time"14
15
"gitlab.com/Timfa/bluegit/internal/auth"16
"gitlab.com/Timfa/bluegit/internal/config"17
"gitlab.com/Timfa/bluegit/internal/store"18
)19
20
func TestDashboardLimitsToTen(t *testing.T) {21
if _, err := exec.LookPath("git"); err != nil {22
t.Skip("git ontbreekt")23
}24
storage := t.TempDir()25
st, err := store.Open(filepath.Join(storage, "bluegit.db"), bytes32())26
if err != nil {27
t.Fatal(err)28
}29
t.Cleanup(func() { _ = st.Close() })30
ctx := context.Background()31
ada, err := st.UpsertUser(ctx, 1, "ada", "", false)32
if err != nil {33
t.Fatal(err)34
}35
dev, err := st.UpsertUser(ctx, 2, "dev", "", false)36
if err != nil {37
t.Fatal(err)38
}39
issue := func(u store.User) string {40
plain, _, err := st.IssueToken(ctx, u.ID, store.TokenRequest{Name: u.Username, Scopes: "api", ExpiresAt: time.Time{}})41
if err != nil {42
t.Fatal(err)43
}44
return plain45
}46
adaTok, devTok := issue(ada), issue(dev)47
cfg := config.Config{48
BaseURL: "http://127.0.0.1:9", StoragePath: storage,49
Auth: config.Auth{Mode: "dev", DevUser: "ada", DevAuthID: 1},50
Git: config.Git{Binary: "git", DefaultBranch: "master"},51
}52
srv := &Server{Cfg: cfg, Store: st, Auth: auth.Dev{Username: "ada", AuthID: 1}, Dev: true, Git: "git", HookBin: "/bin/true", StateDir: t.TempDir()}53
ts := httptest.NewServer(srv.Handler())54
t.Cleanup(ts.Close)55
56
for i := 0; i < 12; i++ {57
r, err := st.CreateRepo(ctx, "user", ada.ID, fmt.Sprintf("r%02d", i), "", "master", "private")58
if err != nil {59
t.Fatal(err)60
}61
_ = st.TouchPushed(ctx, r.ID, time.Date(2026, 1, 1+i, 0, 0, 0, 0, time.UTC))62
}63
_, _ = devTok, adaTok64
jar, _ := cookiejar.New(nil)65
client := &http.Client{Jar: jar}66
res, err := client.Get(ts.URL + "/login")67
if err != nil {68
t.Fatal(err)69
}70
_ = read(t, res)71
get := func(path string) string {72
res, err := client.Get(ts.URL + path)73
if err != nil {74
t.Fatal(err)75
}76
return read(t, res)77
}78
dash := get("/")79
if n := strings.Count(dash, `class="reponame" href="/ada/r`); n != 10 {80
t.Fatalf("dashboard toont %d repos", n)81
}82
if !strings.Contains(dash, `href="/?all=repos"`) || !strings.Contains(dash, "(2 more)") {83
t.Fatal("alles-tonen-link ontbreekt")84
}85
if strings.Index(dash, `href="/ada/r11"`) > strings.Index(dash, `href="/ada/r10"`) || strings.Contains(dash, `href="/ada/r01"`) {86
t.Fatal("volgorde of afkapping klopt niet")87
}88
full := get("/?all=repos")89
if n := strings.Count(full, `class="reponame" href="/ada/r`); n != 12 {90
t.Fatalf("alles tonen geeft %d", n)91
}92
}@@ -709,6 +709,8 @@ type View struct {
709
709
Query string
710
710
SortDir string
711
711
SortBy string
712
MoreRepos int
713
MoreGroups int
712
714
FlipDir string
713
715
Cards []RepoCard
714
716
Head *CommitRow
@@ -709,6 +709,8 @@ type View struct {709
Query string709
Query string710
SortDir string710
SortDir string711
SortBy string711
SortBy string712
MoreRepos int713
MoreGroups int712
FlipDir string714
FlipDir string713
Cards []RepoCard715
Cards []RepoCard714
Head *CommitRow716
Head *CommitRow@@ -97,13 +97,15 @@
97
97
<ul class="repolist">
98
98
{{range .Repos}}<li>{{template "namemark" .}}<div class="grown"><a class="reponame" href="/{{.FullPath}}" title="{{pushedLabel .}}">{{.FullPath}}</a> <span class="pill">{{visName .Visibility}}</span>{{if .Description}}<div class="muted">{{.Description}}</div>{{end}}</div></li>{{end}}
99
99
</ul>
100
{{if .MoreRepos}}<p><a class="btn ghost tiny" href="/?all=repos" data-tip="{{t "dash.moreTip"}}">{{t "dash.showAll" .MoreRepos}}</a></p>{{end}}
100
101
</section>
101
102
<section class="panel">
102
<h2>{{t "dash.groups"}}</h2>
103
<h2><span data-tip="{{t "dash.groupsTip"}}">{{t "dash.groups"}}</span></h2>
103
104
{{if not .Groups}}<p class="muted">{{t "dash.noGroups"}}</p>{{end}}
104
105
<ul class="repolist">
105
106
{{range .Groups}}<li>{{template "namemark" .}}<div class="grown"><a class="reponame" href="/groups/{{.Path}}">{{.Name}}</a> <span class="muted">{{.Path}}</span></div></li>{{end}}
106
107
</ul>
108
{{if .MoreGroups}}<p><a class="btn ghost tiny" href="/?all=groups" data-tip="{{t "dash.moreTip"}}">{{t "dash.showAll" .MoreGroups}}</a></p>{{end}}
107
109
</section>
108
110
</div>
109
111
{{template "releaserepos" .}}
@@ -97,13 +97,15 @@97
<ul class="repolist">97
<ul class="repolist">98
{{range .Repos}}<li>{{template "namemark" .}}<div class="grown"><a class="reponame" href="/{{.FullPath}}" title="{{pushedLabel .}}">{{.FullPath}}</a> <span class="pill">{{visName .Visibility}}</span>{{if .Description}}<div class="muted">{{.Description}}</div>{{end}}</div></li>{{end}}98
{{range .Repos}}<li>{{template "namemark" .}}<div class="grown"><a class="reponame" href="/{{.FullPath}}" title="{{pushedLabel .}}">{{.FullPath}}</a> <span class="pill">{{visName .Visibility}}</span>{{if .Description}}<div class="muted">{{.Description}}</div>{{end}}</div></li>{{end}}99
</ul>99
</ul>100
{{if .MoreRepos}}<p><a class="btn ghost tiny" href="/?all=repos" data-tip="{{t "dash.moreTip"}}">{{t "dash.showAll" .MoreRepos}}</a></p>{{end}}100
</section>101
</section>101
<section class="panel">102
<section class="panel">102
<h2>{{t "dash.groups"}}</h2>103
<h2><span data-tip="{{t "dash.groupsTip"}}">{{t "dash.groups"}}</span></h2>103
{{if not .Groups}}<p class="muted">{{t "dash.noGroups"}}</p>{{end}}104
{{if not .Groups}}<p class="muted">{{t "dash.noGroups"}}</p>{{end}}104
<ul class="repolist">105
<ul class="repolist">105
{{range .Groups}}<li>{{template "namemark" .}}<div class="grown"><a class="reponame" href="/groups/{{.Path}}">{{.Name}}</a> <span class="muted">{{.Path}}</span></div></li>{{end}}106
{{range .Groups}}<li>{{template "namemark" .}}<div class="grown"><a class="reponame" href="/groups/{{.Path}}">{{.Name}}</a> <span class="muted">{{.Path}}</span></div></li>{{end}}106
</ul>107
</ul>108
{{if .MoreGroups}}<p><a class="btn ghost tiny" href="/?all=groups" data-tip="{{t "dash.moreTip"}}">{{t "dash.showAll" .MoreGroups}}</a></p>{{end}}107
</section>109
</section>108
</div>110
</div>109
{{template "releaserepos" .}}111
{{template "releaserepos" .}}@@ -67,3 +67,28 @@ func TestReposSortedByLastPush(t *testing.T) {
67
67
t.Fatalf("groep %+v", gl)
68
68
}
69
69
}
70
71
func TestGroupsSortedByLastPush(t *testing.T) {
72
s := openStore(t)
73
ctx := context.Background()
74
tim, _ := s.UpsertUser(ctx, 1, "tim", "", false)
75
a, _ := s.CreateGroup(ctx, tim.ID, "Alpha", "alpha", "", access.RoleDeveloper)
76
b, _ := s.CreateGroup(ctx, tim.ID, "Beta", "beta", "", access.RoleDeveloper)
77
c, _ := s.CreateGroup(ctx, tim.ID, "Gamma", "gamma", "", access.RoleDeveloper)
78
ra, _ := s.CreateRepo(ctx, "group", a.ID, "x", "", "master", "public")
79
rc, _ := s.CreateRepo(ctx, "group", c.ID, "y", "", "master", "public")
80
rc2, _ := s.CreateRepo(ctx, "group", c.ID, "z", "", "master", "public")
81
base := time.Date(2026, 10, 1, 0, 0, 0, 0, time.UTC)
82
_ = s.TouchPushed(ctx, ra.ID, base)
83
_ = s.TouchPushed(ctx, rc.ID, base.Add(-time.Hour))
84
_ = s.TouchPushed(ctx, rc2.ID, base.Add(time.Hour))
85
at, err := s.GroupPushTimes(ctx)
86
if err != nil {
87
t.Fatal(err)
88
}
89
list := []Group{a, b, c}
90
SortGroupsByPush(list, at)
91
if list[0].ID != c.ID || list[1].ID != a.ID || list[2].ID != b.ID {
92
t.Fatalf("volgorde %s %s %s", list[0].Name, list[1].Name, list[2].Name)
93
}
94
}
@@ -67,3 +67,28 @@ func TestReposSortedByLastPush(t *testing.T) {67
t.Fatalf("groep %+v", gl)67
t.Fatalf("groep %+v", gl)68
}68
}69
}69
}70
71
func TestGroupsSortedByLastPush(t *testing.T) {72
s := openStore(t)73
ctx := context.Background()74
tim, _ := s.UpsertUser(ctx, 1, "tim", "", false)75
a, _ := s.CreateGroup(ctx, tim.ID, "Alpha", "alpha", "", access.RoleDeveloper)76
b, _ := s.CreateGroup(ctx, tim.ID, "Beta", "beta", "", access.RoleDeveloper)77
c, _ := s.CreateGroup(ctx, tim.ID, "Gamma", "gamma", "", access.RoleDeveloper)78
ra, _ := s.CreateRepo(ctx, "group", a.ID, "x", "", "master", "public")79
rc, _ := s.CreateRepo(ctx, "group", c.ID, "y", "", "master", "public")80
rc2, _ := s.CreateRepo(ctx, "group", c.ID, "z", "", "master", "public")81
base := time.Date(2026, 10, 1, 0, 0, 0, 0, time.UTC)82
_ = s.TouchPushed(ctx, ra.ID, base)83
_ = s.TouchPushed(ctx, rc.ID, base.Add(-time.Hour))84
_ = s.TouchPushed(ctx, rc2.ID, base.Add(time.Hour))85
at, err := s.GroupPushTimes(ctx)86
if err != nil {87
t.Fatal(err)88
}89
list := []Group{a, b, c}90
SortGroupsByPush(list, at)91
if list[0].ID != c.ID || list[1].ID != a.ID || list[2].ID != b.ID {92
t.Fatalf("volgorde %s %s %s", list[0].Name, list[1].Name, list[2].Name)93
}94
}@@ -908,3 +908,37 @@ func SortReposByPush(list []Repo) {
908
908
return a.ID < b.ID
909
909
})
910
910
}
911
912
// GroupPushTimes geeft per groep de laatste push in een van haar repos.
913
// Groepen zonder push ontbreken in de map.
914
func (s *Store) GroupPushTimes(ctx context.Context) (map[int64]time.Time, error) {
915
rows, err := s.db.QueryContext(ctx, `SELECT owner_id, MAX(pushed_at) FROM repos WHERE owner_kind = 'group' AND pushed_at <> '' GROUP BY owner_id`)
916
if err != nil {
917
return nil, err
918
}
919
defer rows.Close()
920
out := map[int64]time.Time{}
921
for rows.Next() {
922
var id int64
923
var at string
924
if err := rows.Scan(&id, &at); err != nil {
925
return nil, err
926
}
927
out[id] = parseTime(at)
928
}
929
return out, rows.Err()
930
}
931
932
// SortGroupsByPush: laatste push eerst, groepen zonder push onderaan, dan op naam.
933
func SortGroupsByPush(list []Group, at map[int64]time.Time) {
934
sort.SliceStable(list, func(i, j int) bool {
935
a, b := at[list[i].ID], at[list[j].ID]
936
if a.IsZero() != b.IsZero() {
937
return !a.IsZero()
938
}
939
if !a.Equal(b) {
940
return a.After(b)
941
}
942
return strings.ToLower(list[i].Name) < strings.ToLower(list[j].Name)
943
})
944
}
@@ -908,3 +908,37 @@ func SortReposByPush(list []Repo) {908
return a.ID < b.ID908
return a.ID < b.ID909
})909
})910
}910
}911
912
// GroupPushTimes geeft per groep de laatste push in een van haar repos.913
// Groepen zonder push ontbreken in de map.914
func (s *Store) GroupPushTimes(ctx context.Context) (map[int64]time.Time, error) {915
rows, err := s.db.QueryContext(ctx, `SELECT owner_id, MAX(pushed_at) FROM repos WHERE owner_kind = 'group' AND pushed_at <> '' GROUP BY owner_id`)916
if err != nil {917
return nil, err918
}919
defer rows.Close()920
out := map[int64]time.Time{}921
for rows.Next() {922
var id int64923
var at string924
if err := rows.Scan(&id, &at); err != nil {925
return nil, err926
}927
out[id] = parseTime(at)928
}929
return out, rows.Err()930
}931
932
// SortGroupsByPush: laatste push eerst, groepen zonder push onderaan, dan op naam.933
func SortGroupsByPush(list []Group, at map[int64]time.Time) {934
sort.SliceStable(list, func(i, j int) bool {935
a, b := at[list[i].ID], at[list[j].ID]936
if a.IsZero() != b.IsZero() {937
return !a.IsZero()938
}939
if !a.Equal(b) {940
return a.After(b)941
}942
return strings.ToLower(list[i].Name) < strings.ToLower(list[j].Name)943
})944
}