Browse Source

repo/release: add pagination (#2164)

pull/4150/head
Unknwon 8 years ago
parent
commit
07801cbf09
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 2
      cmd/web.go
  2. 2
      gogs.go
  3. 47
      routers/repo/release.go
  4. 2
      templates/.VERSION
  5. 8
      templates/repo/release/list.tmpl
  6. 2
      vendor/github.com/gogits/git-module/git.go
  7. 80
      vendor/github.com/gogits/git-module/repo_tag.go
  8. 6
      vendor/vendor.json

2
cmd/web.go

@ -95,7 +95,7 @@ func checkVersion() {
{"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"}, {"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"},
{"gopkg.in/ini.v1", ini.Version, "1.8.4"}, {"gopkg.in/ini.v1", ini.Version, "1.8.4"},
{"gopkg.in/macaron.v1", macaron.Version, "1.1.7"}, {"gopkg.in/macaron.v1", macaron.Version, "1.1.7"},
{"github.com/gogits/git-module", git.Version, "0.4.9"}, {"github.com/gogits/git-module", git.Version, "0.4.10"},
{"github.com/gogits/go-gogs-client", gogs.Version, "0.12.1"}, {"github.com/gogits/go-gogs-client", gogs.Version, "0.12.1"},
} }
for _, c := range checkers { for _, c := range checkers {

2
gogs.go

@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.9.154.0217" const APP_VER = "0.9.155.0217"
func init() { func init() {
setting.AppVer = APP_VER setting.AppVer = APP_VER

47
routers/repo/release.go

@ -53,7 +53,7 @@ func Releases(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.release.releases") ctx.Data["Title"] = ctx.Tr("repo.release.releases")
ctx.Data["PageIsReleaseList"] = true ctx.Data["PageIsReleaseList"] = true
rawTags, err := ctx.Repo.GitRepo.GetTags() tagsResult, err := ctx.Repo.GitRepo.GetTagsAfter(ctx.Query("after"), 10)
if err != nil { if err != nil {
ctx.Handle(500, fmt.Sprintf("GetTags '%s'", ctx.Repo.Repository.RepoPath()), err) ctx.Handle(500, fmt.Sprintf("GetTags '%s'", ctx.Repo.Repository.RepoPath()), err)
return return
@ -68,13 +68,15 @@ func Releases(ctx *context.Context) {
// Temproray cache commits count of used branches to speed up. // Temproray cache commits count of used branches to speed up.
countCache := make(map[string]int64) countCache := make(map[string]int64)
tags := make([]*models.Release, len(rawTags)) drafts := make([]*models.Release, 0, 1)
for i, rawTag := range rawTags { tags := make([]*models.Release, len(tagsResult.Tags))
for i, rawTag := range tagsResult.Tags {
for j, r := range releases { for j, r := range releases {
if r == nil || (r.IsDraft && !ctx.Repo.IsOwner()) { if r == nil || (r.IsDraft && !ctx.Repo.IsOwner()) {
continue continue
} }
if r.TagName == rawTag { releases[j] = nil // Mark as used.
r.Publisher, err = models.GetUserByID(r.PublisherID) r.Publisher, err = models.GetUserByID(r.PublisherID)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
@ -91,10 +93,14 @@ func Releases(ctx *context.Context) {
} }
r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()) r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())
if r.TagName == rawTag {
tags[i] = r tags[i] = r
releases[j] = nil // Mark as used.
break break
} }
if r.IsDraft {
drafts = append(drafts, r)
}
} }
if tags[i] == nil { if tags[i] == nil {
@ -119,31 +125,18 @@ func Releases(ctx *context.Context) {
} }
} }
for _, r := range releases { models.SortReleases(tags)
if r == nil { if len(drafts) > 0 && tagsResult.HasLatest {
continue tags = append(drafts, tags...)
}
r.Publisher, err = models.GetUserByID(r.PublisherID)
if err != nil {
if models.IsErrUserNotExist(err) {
r.Publisher = models.NewGhostUser()
} else {
ctx.Handle(500, "GetUserByID", err)
return
}
}
if err := calReleaseNumCommitsBehind(ctx.Repo, r, countCache); err != nil {
ctx.Handle(500, "calReleaseNumCommitsBehind", err)
return
} }
r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())
tags = append(tags, r)
}
models.SortReleases(tags)
ctx.Data["Releases"] = tags ctx.Data["Releases"] = tags
ctx.Data["HasPrevious"] = !tagsResult.HasLatest
ctx.Data["ReachEnd"] = tagsResult.ReachEnd
ctx.Data["PreviousAfter"] = tagsResult.PreviousAfter
if len(tags) > 0 {
ctx.Data["NextAfter"] = tags[len(tags)-1].TagName
}
ctx.HTML(200, RELEASES) ctx.HTML(200, RELEASES)
} }

2
templates/.VERSION

@ -1 +1 @@
0.9.154.0217 0.9.155.0217

8
templates/repo/release/list.tmpl

@ -75,6 +75,14 @@
</li> </li>
{{end}} {{end}}
</ul> </ul>
<div class="center">
<a class="ui small button {{if not .HasPrevious}}disabled{{end}}" {{if .HasPrevious}}href="{{$.Link}}?after={{.PreviousAfter}}"{{end}}>
{{$.i18n.Tr "repo.issues.previous"}}
</a>
<a class="ui small button {{if .ReachEnd}}disabled{{end}}" {{if not .ReachEnd}}href="{{$.Link}}?after={{.NextAfter}}"{{end}}>
{{$.i18n.Tr "repo.issues.next"}}
</a>
</div>
</div> </div>
</div> </div>
{{template "base/footer" .}} {{template "base/footer" .}}

2
vendor/github.com/gogits/git-module/git.go generated vendored

@ -10,7 +10,7 @@ import (
"time" "time"
) )
const _VERSION = "0.4.9" const _VERSION = "0.4.10"
func Version() string { func Version() string {
return _VERSION return _VERSION

80
vendor/github.com/gogits/git-module/repo_tag.go generated vendored

@ -5,6 +5,7 @@
package git package git
import ( import (
"fmt"
"strings" "strings"
"github.com/mcuadros/go-version" "github.com/mcuadros/go-version"
@ -119,6 +120,84 @@ func (repo *Repository) GetTags() ([]string, error) {
return tags, nil return tags, nil
} }
type TagsResult struct {
// Indicates whether results include the latest tag.
HasLatest bool
// If results do not include the latest tag, a indicator 'after' to go back.
PreviousAfter string
// Indicates whether results include the oldest tag.
ReachEnd bool
// List of returned tags.
Tags []string
}
// GetTagsAfter returns list of tags 'after' (exlusive) given tag.
func (repo *Repository) GetTagsAfter(after string, limit int) (*TagsResult, error) {
allTags, err := repo.GetTags()
if err != nil {
return nil, fmt.Errorf("GetTags: %v", err)
}
if limit < 0 {
limit = 0
}
numAllTags := len(allTags)
if len(after) == 0 && limit == 0 {
return &TagsResult{
HasLatest: true,
ReachEnd: true,
Tags: allTags,
}, nil
} else if len(after) == 0 && limit > 0 {
endIdx := limit
if limit >= numAllTags {
endIdx = numAllTags
}
return &TagsResult{
HasLatest: true,
ReachEnd: limit >= numAllTags,
Tags: allTags[:endIdx],
}, nil
}
previousAfter := ""
hasMatch := false
tags := make([]string, 0, len(allTags))
for i := range allTags {
if hasMatch {
tags = allTags[i:]
break
}
if allTags[i] == after {
hasMatch = true
if limit > 0 && i-limit > 0 {
previousAfter = allTags[i-limit]
}
continue
}
}
if !hasMatch {
tags = allTags
}
// If all tags after match is equal to the limit, it reaches the oldest tag as well.
if limit == 0 || len(tags) <= limit {
return &TagsResult{
HasLatest: !hasMatch,
PreviousAfter: previousAfter,
ReachEnd: true,
Tags: tags,
}, nil
}
return &TagsResult{
HasLatest: !hasMatch,
PreviousAfter: previousAfter,
Tags: tags[:limit],
}, nil
}
// DeleteTag deletes a tag from the repository // DeleteTag deletes a tag from the repository
func (repo *Repository) DeleteTag(name string) error { func (repo *Repository) DeleteTag(name string) error {
cmd := NewCommand("tag", "-d") cmd := NewCommand("tag", "-d")
@ -128,4 +207,3 @@ func (repo *Repository) DeleteTag(name string) error {
return err return err
} }

6
vendor/vendor.json vendored

@ -159,10 +159,10 @@
"revisionTime": "2016-08-10T03:50:02Z" "revisionTime": "2016-08-10T03:50:02Z"
}, },
{ {
"checksumSHA1": "RSr3IvGo5PFxAP3ybtDcEojTWPI=", "checksumSHA1": "5SLknh130FbmnSNWkf6LtVFqdMI=",
"path": "github.com/gogits/git-module", "path": "github.com/gogits/git-module",
"revision": "41f3ca26f6b202c82d022a1062f7b7ea6339924b", "revision": "7c2ab580a5b25e8b045139a44635258ceef64ace",
"revisionTime": "2017-02-16T16:46:07Z" "revisionTime": "2017-02-17T22:39:06Z"
}, },
{ {
"checksumSHA1": "xvG+RgJODQqlmdAkHUQK2TyLR88=", "checksumSHA1": "xvG+RgJODQqlmdAkHUQK2TyLR88=",

Loading…
Cancel
Save