diff --git a/gogs.go b/gogs.go index 28abaa3ee62e..0014b76f9024 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.4.5.0706 Alpha" +const APP_VER = "0.4.5.0707 Alpha" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/models.go b/models/models.go index 070784f13757..ded8b05984e7 100644 --- a/models/models.go +++ b/models/models.go @@ -148,9 +148,9 @@ type Statistic struct { } func GetStatistic() (stats Statistic) { - stats.Counter.User, _ = x.Count(new(User)) + stats.Counter.User = CountUsers() + stats.Counter.Repo = CountRepositories() stats.Counter.PublicKey, _ = x.Count(new(PublicKey)) - stats.Counter.Repo, _ = x.Count(new(Repository)) stats.Counter.Watch, _ = x.Count(new(Watch)) stats.Counter.Action, _ = x.Count(new(Action)) stats.Counter.Access, _ = x.Count(new(Access)) diff --git a/models/repo.go b/models/repo.go index 35e4427577ee..396e536e4b61 100644 --- a/models/repo.go +++ b/models/repo.go @@ -589,6 +589,12 @@ func CreateRepository(u *User, name, desc, lang, license string, private, mirror return repo, nil } +// CountRepositories returns number of repositories. +func CountRepositories() int64 { + count, _ := x.Count(new(Repository)) + return count +} + // GetRepositoriesWithUsers returns given number of repository objects with offset. // It also auto-gets corresponding users. func GetRepositoriesWithUsers(num, offset int) ([]*Repository, error) { diff --git a/models/user.go b/models/user.go index b98e81babe1b..47f1d45f0e7f 100644 --- a/models/user.go +++ b/models/user.go @@ -212,6 +212,12 @@ func CreateUser(u *User) (*User, error) { return u, err } +// CountUsers returns number of users. +func CountUsers() int64 { + count, _ := x.Where("type=0").Count(new(User)) + return count +} + // GetUsers returns given number of user objects with offset. func GetUsers(num, offset int) ([]User, error) { users := make([]User, 0, num) diff --git a/modules/base/tool.go b/modules/base/tool.go index 5b066b2b9f70..9635f13e0f5a 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -458,6 +458,16 @@ func (f StrTo) Int64() (int64, error) { return int64(v), err } +func (f StrTo) MustInt() int { + v, _ := f.Int() + return v +} + +func (f StrTo) MustInt64() int64 { + v, _ := f.Int64() + return v +} + func (f StrTo) String() string { if f.Exist() { return string(f) diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 50a3823a0fad..2a40792a186a 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -30,7 +30,9 @@ const ( MONITOR_CRON base.TplName = "admin/monitor/cron" ) -var startTime = time.Now() +var ( + startTime = time.Now() +) var sysStatus struct { Uptime string @@ -157,8 +159,24 @@ func Users(ctx *middleware.Context) { ctx.Data["Title"] = "User Management" ctx.Data["PageIsUsers"] = true + p := base.StrTo(ctx.Query("p")).MustInt() + if p < 1 { + p = 1 + } + pageNum := 100 + count := models.CountUsers() + curCount := int64((p-1)*pageNum + pageNum) + if curCount > count { + p = int(count) / pageNum + } else if count > curCount { + ctx.Data["NextPageNum"] = p + 1 + } + if p > 1 { + ctx.Data["LastPageNum"] = p - 1 + } + var err error - ctx.Data["Users"], err = models.GetUsers(200, 0) + ctx.Data["Users"], err = models.GetUsers(pageNum, (p-1)*pageNum) if err != nil { ctx.Handle(500, "admin.Users(GetUsers)", err) return @@ -170,8 +188,24 @@ func Repositories(ctx *middleware.Context) { ctx.Data["Title"] = "Repository Management" ctx.Data["PageIsRepos"] = true + p := base.StrTo(ctx.Query("p")).MustInt() + if p < 1 { + p = 1 + } + pageNum := 2 + count := models.CountRepositories() + curCount := int64((p-1)*pageNum + pageNum) + if curCount > count { + p = int(count) / pageNum + } else if count > curCount { + ctx.Data["NextPageNum"] = p + 1 + } + if p > 1 { + ctx.Data["LastPageNum"] = p - 1 + } + var err error - ctx.Data["Repos"], err = models.GetRepositoriesWithUsers(200, 0) + ctx.Data["Repos"], err = models.GetRepositoriesWithUsers(pageNum, (p-1)*pageNum) if err != nil { ctx.Handle(500, "admin.Repositories", err) return diff --git a/templates/VERSION b/templates/VERSION index 9821ab4ed5b4..636217884b34 100644 --- a/templates/VERSION +++ b/templates/VERSION @@ -1 +1 @@ -0.4.5.0706 Alpha \ No newline at end of file +0.4.5.0707 Alpha \ No newline at end of file diff --git a/templates/admin/repos.tmpl b/templates/admin/repos.tmpl index f6f3a7be9822..373348b9d13e 100644 --- a/templates/admin/repos.tmpl +++ b/templates/admin/repos.tmpl @@ -37,6 +37,10 @@ {{end}} +
diff --git a/templates/admin/users.tmpl b/templates/admin/users.tmpl index 14fddf33c46a..0efe90929666 100644 --- a/templates/admin/users.tmpl +++ b/templates/admin/users.tmpl @@ -38,6 +38,10 @@ {{end}} +