本文整理汇总了Golang中github.com/Unknwon/paginater.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Explore
func Explore(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExploreRepositories"] = true
page := ctx.QueryInt("page")
if page <= 1 {
page = 1
}
ctx.Data["Page"] = paginater.New(int(models.CountRepositories()), setting.ExplorePagingNum, page, 5)
repos, err := models.GetRecentUpdatedRepositories(page)
if err != nil {
ctx.Handle(500, "GetRecentUpdatedRepositories", err)
return
}
for _, repo := range repos {
if err = repo.GetOwner(); err != nil {
ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.ID, err))
return
}
}
ctx.Data["Repos"] = repos
ctx.HTML(200, EXPLORE_REPOS)
}
示例2: 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)
}
示例3: Commits
func Commits(ctx *middleware.Context) {
ctx.Data["PageIsCommits"] = true
commitsCount, err := ctx.Repo.Commit.CommitsCount()
if err != nil {
ctx.Handle(500, "GetCommitsCount", err)
return
}
page := ctx.QueryInt("page")
if page <= 1 {
page = 1
}
ctx.Data["Page"] = paginater.New(int(commitsCount), git.CommitsRangeSize, page, 5)
// Both `git log branchName` and `git log commitId` work.
commits, err := ctx.Repo.Commit.CommitsByRange(page)
if err != nil {
ctx.Handle(500, "CommitsByRange", err)
return
}
commits = RenderIssueLinks(commits, ctx.Repo.RepoLink)
commits = models.ValidateCommitsWithEmails(commits)
ctx.Data["Commits"] = commits
ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
ctx.Data["CommitCount"] = commitsCount
ctx.Data["Branch"] = ctx.Repo.BranchName
ctx.HTML(200, COMMITS)
}
示例4: showOrgProfile
func showOrgProfile(ctx *context.Context) {
ctx.SetParams(":org", ctx.Params(":username"))
context.HandleOrgAssignment(ctx)
if ctx.Written() {
return
}
org := ctx.Org.Organization
ctx.Data["Title"] = org.FullName
page := ctx.QueryInt("page")
if page <= 0 {
page = 1
}
var (
repos []*models.Repository
count int64
err error
)
if ctx.IsSigned && !ctx.User.IsAdmin {
repos, count, err = org.GetUserRepositories(ctx.User.ID, page, setting.UI.User.RepoPagingNum)
if err != nil {
ctx.Handle(500, "GetUserRepositories", err)
return
}
ctx.Data["Repos"] = repos
} else {
showPrivate := ctx.IsSigned && ctx.User.IsAdmin
repos, err = models.GetUserRepositories(org.ID, showPrivate, page, setting.UI.User.RepoPagingNum)
if err != nil {
ctx.Handle(500, "GetRepositories", err)
return
}
ctx.Data["Repos"] = repos
count = models.CountUserRepositories(org.ID, showPrivate)
}
ctx.Data["Page"] = paginater.New(int(count), setting.UI.User.RepoPagingNum, page, 5)
if err := org.GetMembers(); err != nil {
ctx.Handle(500, "GetMembers", err)
return
}
ctx.Data["Members"] = org.Members
ctx.Data["Teams"] = org.Teams
ctx.HTML(200, ORG_HOME)
}
示例5: RenderRepoSearch
func RenderRepoSearch(ctx *context.Context,
counter func() int64, ranger func(int, int) ([]*models.Repository, error),
pagingNum int, orderBy string, tplName base.TplName) {
page := ctx.QueryInt("page")
if page <= 1 {
page = 1
}
var (
repos []*models.Repository
count int64
err error
)
keyword := ctx.Query("q")
if len(keyword) == 0 {
repos, err = ranger(page, pagingNum)
if err != nil {
ctx.Handle(500, "ranger", err)
return
}
count = counter()
} else {
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
Keyword: keyword,
OrderBy: orderBy,
Page: page,
PageSize: pagingNum,
})
if err != nil {
ctx.Handle(500, "SearchRepositoryByName", err)
return
}
}
ctx.Data["Keyword"] = keyword
ctx.Data["Total"] = count
ctx.Data["Page"] = paginater.New(int(count), pagingNum, page, 5)
for _, repo := range repos {
if err = repo.GetOwner(); err != nil {
ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.ID, err))
return
}
}
ctx.Data["Repos"] = repos
ctx.HTML(200, tplName)
}
示例6: RenderRepoSearch
func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
page := ctx.QueryInt("page")
if page <= 0 {
page = 1
}
var (
repos []*models.Repository
count int64
err error
)
keyword := ctx.Query("q")
if len(keyword) == 0 {
repos, err = opts.Ranger(page, opts.PageSize)
if err != nil {
ctx.Handle(500, "opts.Ranger", err)
return
}
count = opts.Counter(opts.Private)
} else {
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
Keyword: keyword,
OrderBy: opts.OrderBy,
Private: opts.Private,
Page: page,
PageSize: opts.PageSize,
})
if err != nil {
ctx.Handle(500, "SearchRepositoryByName", err)
return
}
}
ctx.Data["Keyword"] = keyword
ctx.Data["Total"] = count
ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5)
for _, repo := range repos {
if err = repo.GetOwner(); err != nil {
ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.ID, err))
return
}
}
ctx.Data["Repos"] = repos
ctx.HTML(200, opts.TplName)
}
示例7: renderItems
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)
}
示例8: RenderUserCards
func RenderUserCards(ctx *context.Context, total int, getter func(page int) ([]*models.User, error), tpl base.TplName) {
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["Cards"] = items
ctx.HTML(200, tpl)
}
示例9: Milestones
func Milestones(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repo.milestones")
ctx.Data["PageIsIssueList"] = true
ctx.Data["PageIsMilestones"] = true
isShowClosed := ctx.Query("state") == "closed"
openCount, closedCount := models.MilestoneStats(ctx.Repo.Repository.ID)
ctx.Data["OpenCount"] = openCount
ctx.Data["ClosedCount"] = closedCount
page := ctx.QueryInt("page")
if page <= 1 {
page = 1
}
var total int
if !isShowClosed {
total = int(openCount)
} else {
total = int(closedCount)
}
ctx.Data["Page"] = paginater.New(total, setting.IssuePagingNum, page, 5)
miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed)
if err != nil {
ctx.Handle(500, "GetMilestones", err)
return
}
for _, m := range miles {
m.RenderedContent = string(base.RenderMarkdown([]byte(m.Content), ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
m.CalOpenIssues()
}
ctx.Data["Milestones"] = miles
if isShowClosed {
ctx.Data["State"] = "closed"
} else {
ctx.Data["State"] = "open"
}
ctx.Data["IsShowClosed"] = isShowClosed
ctx.HTML(200, MILESTONE)
}
示例10: Index
func Index(c *middleware.Context) {
var (
p = c.ParamsInt(":p")
)
sites, e := models.SiteList(p)
if e != nil {
color.Red("%s", e)
}
cnt, e := models.SiteCount()
if e != nil {
color.Red("%s", e)
}
c.Data["sites"] = sites
c.Data["sites_count"] = cnt
c.Data["paginater"] = paginater.New(int(cnt), 10, p, 5)
c.HTML(200, "catalog/index")
}
示例11: AllFeed
func AllFeed(c *middleware.Context) {
p := c.ParamsInt(":p")
if p < 1 {
p = 1
}
feed, e := models.GetFeed(p)
if e != nil {
color.Red("%s", e)
}
cnt, e := models.FeedCount()
if e != nil {
color.Red("%s", e)
}
c.Data["feed"] = feed
c.Data["paginater"] = paginater.New(int(cnt), 10, p, 5)
c.HTML(200, "catalog/feed")
}
示例12: RenderUserSearch
func RenderUserSearch(ctx *context.Context, userType models.UserType,
counter func() int64, ranger func(int, int) ([]*models.User, error),
pagingNum int, orderBy string, tplName base.TplName) {
page := ctx.QueryInt("page")
if page <= 1 {
page = 1
}
var (
users []*models.User
count int64
err error
)
keyword := ctx.Query("q")
if len(keyword) == 0 {
users, err = ranger(page, pagingNum)
if err != nil {
ctx.Handle(500, "ranger", err)
return
}
count = counter()
} else {
users, count, err = models.SearchUserByName(&models.SearchUserOptions{
Keyword: keyword,
Type: userType,
OrderBy: orderBy,
Page: page,
PageSize: pagingNum,
})
if err != nil {
ctx.Handle(500, "SearchUserByName", err)
return
}
}
ctx.Data["Keyword"] = keyword
ctx.Data["Total"] = count
ctx.Data["Page"] = paginater.New(int(count), pagingNum, page, 5)
ctx.Data["Users"] = users
ctx.HTML(200, tplName)
}
示例13: SetLinkHeader
func (ctx *APIContext) SetLinkHeader(total, pageSize int) {
page := paginater.New(total, pageSize, ctx.QueryInt("page"), 0)
links := make([]string, 0, 4)
if page.HasNext() {
links = append(links, fmt.Sprintf("<%s%s?page=%d>; rel=\"next\"", setting.AppUrl, ctx.Req.URL.Path[1:], page.Next()))
}
if !page.IsLast() {
links = append(links, fmt.Sprintf("<%s%s?page=%d>; rel=\"last\"", setting.AppUrl, ctx.Req.URL.Path[1:], page.TotalPages()))
}
if !page.IsFirst() {
links = append(links, fmt.Sprintf("<%s%s?page=1>; rel=\"first\"", setting.AppUrl, ctx.Req.URL.Path[1:]))
}
if page.HasPrevious() {
links = append(links, fmt.Sprintf("<%s%s?page=%d>; rel=\"prev\"", setting.AppUrl, ctx.Req.URL.Path[1:], page.Previous()))
}
if len(links) > 0 {
ctx.Header().Set("Link", strings.Join(links, ","))
}
}
示例14: FileHistory
func FileHistory(ctx *middleware.Context) {
ctx.Data["IsRepoToolbarCommits"] = true
fileName := ctx.Repo.TreeName
if len(fileName) == 0 {
Commits(ctx)
return
}
branchName := ctx.Repo.BranchName
commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName)
if err != nil {
ctx.Handle(500, "FileCommitsCount", err)
return
} else if commitsCount == 0 {
ctx.Handle(404, "FileCommitsCount", nil)
return
}
page := ctx.QueryInt("page")
if page <= 1 {
page = 1
}
ctx.Data["Page"] = paginater.New(int(commitsCount), git.CommitsRangeSize, page, 5)
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page)
if err != nil {
ctx.Handle(500, "CommitsByFileAndRange", err)
return
}
commits = RenderIssueLinks(commits, ctx.Repo.RepoLink)
commits = models.ValidateCommitsWithEmails(commits)
ctx.Data["Commits"] = commits
ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
ctx.Data["FileName"] = fileName
ctx.Data["CommitCount"] = commitsCount
ctx.Data["Branch"] = branchName
ctx.HTML(200, COMMITS)
}
示例15: Feed
func Feed(c *middleware.Context) {
sid := c.ParamsInt64(":id")
p := c.ParamsInt(":p")
if p < 1 {
p = 1
}
feed, e := models.GetSiteFeed(sid, p)
if e != nil {
color.Red("%s", e)
}
cnt, e := models.SiteFeedCount(sid)
if e != nil {
color.Red("%s", e)
}
c.Data["feed"] = feed
c.Data["paginater"] = paginater.New(int(cnt), 10, p, 5)
c.Data["SiteId"] = sid
c.HTML(200, "catalog/feed")
}