1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

new watchers, stars and forks UI

This commit is contained in:
Unknwon
2015-11-16 23:28:46 -05:00
parent e06558e208
commit 9ab96172fc
12 changed files with 216 additions and 256 deletions

View File

@@ -1,44 +0,0 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package repo
import (
"github.com/Unknwon/paginater"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware"
)
const (
STARS base.TplName = "repo/stars"
)
func Stars(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repos.stars")
page := ctx.QueryInt("page")
if page <= 0 {
page = 1
}
ctx.Data["Page"] = paginater.New(ctx.Repo.Repository.NumStars, models.ItemsPerPage, page, 5)
stars, err := ctx.Repo.Repository.GetStars(ctx.QueryInt("page"))
if err != nil {
ctx.Handle(500, "GetStars", err)
return
}
if (ctx.QueryInt("page")-1)*models.ItemsPerPage > ctx.Repo.Repository.NumStars {
ctx.Handle(404, "ctx.Repo.Repository.NumStars", nil)
return
}
ctx.Data["Stars"] = stars
ctx.HTML(200, STARS)
}

View File

@@ -11,6 +11,8 @@ import (
"path/filepath"
"strings"
"github.com/Unknwon/paginater"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/git"
@@ -20,7 +22,8 @@ import (
)
const (
HOME base.TplName = "repo/home"
HOME base.TplName = "repo/home"
WATCHERS base.TplName = "repo/watchers"
)
func Home(ctx *middleware.Context) {
@@ -245,3 +248,33 @@ func Home(ctx *middleware.Context) {
ctx.Data["BranchLink"] = branchLink
ctx.HTML(200, HOME)
}
func renderItems(ctx *middleware.Context, total int, getter func(page int) ([]*models.User, error)) {
page := ctx.QueryInt("page")
if page <= 0 {
page = 1
}
pager := paginater.New(total, models.ItemsPerPage, page, 5)
ctx.Data["Page"] = pager
items, err := getter(pager.Current())
if err != nil {
ctx.Handle(500, "getter", err)
return
}
ctx.Data["Watchers"] = items
ctx.HTML(200, WATCHERS)
}
func Watchers(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repo.watchers")
ctx.Data["PageIsWatchers"] = true
renderItems(ctx, ctx.Repo.Repository.NumWatches, ctx.Repo.Repository.GetWatchers)
}
func Stars(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repo.stargazers")
ctx.Data["PageIsStargazers"] = true
renderItems(ctx, ctx.Repo.Repository.NumStars, ctx.Repo.Repository.GetStargazers)
}

View File

@@ -1,44 +0,0 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package repo
import (
"github.com/Unknwon/paginater"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware"
)
const (
WATCHERS base.TplName = "repo/watchers"
)
func Watchers(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repos.watches")
page := ctx.QueryInt("page")
if page <= 0 {
page = 1
}
ctx.Data["Page"] = paginater.New(ctx.Repo.Repository.NumWatches, models.ItemsPerPage, page, 5)
watchers, err := ctx.Repo.Repository.GetWatchers(ctx.QueryInt("page"))
if err != nil {
ctx.Handle(500, "GetWatchers", err)
return
}
if (ctx.QueryInt("page")-1)*models.ItemsPerPage > ctx.Repo.Repository.NumWatches {
ctx.Handle(404, "ctx.Repo.Repository.NumWatches", nil)
return
}
ctx.Data["Watchers"] = watchers
ctx.HTML(200, WATCHERS)
}