Browse Source

Fix dashboard issues/pull request counting

pull/3536/merge
Unknwon 8 years ago
parent
commit
8059175a5c
No known key found for this signature in database
GPG Key ID: 7A02C406FAC875A2
  1. 2
      .gopmfile
  2. 2
      glide.lock
  3. 8
      models/issue.go
  4. 49
      models/repo.go
  5. 7
      models/user.go
  6. 7
      routers/api/v1/repo/repo.go
  7. 27
      routers/user/home.go
  8. 7
      routers/user/profile.go
  9. 8
      templates/user/dashboard/issues.tmpl

2
.gopmfile

@ -16,7 +16,7 @@ github.com/go-macaron/toolbox = commit:82b5115
github.com/go-sql-driver/mysql = commit:a0583e0 github.com/go-sql-driver/mysql = commit:a0583e0
github.com/go-xorm/builder = commit:db75972 github.com/go-xorm/builder = commit:db75972
github.com/go-xorm/core = commit:87aca22 github.com/go-xorm/core = commit:87aca22
github.com/go-xorm/xorm = commit:3ad0b42 github.com/go-xorm/xorm = commit:d75356f
github.com/gogits/chardet = commit:2404f77 github.com/gogits/chardet = commit:2404f77
github.com/gogits/cron = commit:2fc07a4 github.com/gogits/cron = commit:2fc07a4
github.com/gogits/git-module = commit:df1013f github.com/gogits/git-module = commit:df1013f

2
glide.lock generated

@ -37,7 +37,7 @@ imports:
- name: github.com/go-xorm/core - name: github.com/go-xorm/core
version: 87aca223378aab7a4bf31ef53f20fde4997ad793 version: 87aca223378aab7a4bf31ef53f20fde4997ad793
- name: github.com/go-xorm/xorm - name: github.com/go-xorm/xorm
version: 3ad0b428ae702d7d3f880c90a7f6d89805fcd2f7 version: d75356fc733fce7683c6d961fc2aeb16ededc8ef
- name: github.com/gogits/chardet - name: github.com/gogits/chardet
version: 2404f777256163ea3eadb273dada5dcb037993c0 version: 2404f777256163ea3eadb273dada5dcb037993c0
- name: github.com/gogits/cron - name: github.com/gogits/cron

8
models/issue.go

@ -1169,7 +1169,7 @@ func GetIssueStats(opts *IssueStatsOptions) *IssueStats {
// GetUserIssueStats returns issue statistic information for dashboard by given conditions. // GetUserIssueStats returns issue statistic information for dashboard by given conditions.
func GetUserIssueStats(repoID, userID int64, repoIDs []int64, filterMode FilterMode, isPull bool) *IssueStats { func GetUserIssueStats(repoID, userID int64, repoIDs []int64, filterMode FilterMode, isPull bool) *IssueStats {
stats := &IssueStats{} stats := &IssueStats{}
hasAnyRepo := repoID > 0 || repoIDs != nil
countSession := func(isClosed, isPull bool, repoID int64, repoIDs []int64) *xorm.Session { countSession := func(isClosed, isPull bool, repoID int64, repoIDs []int64) *xorm.Session {
sess := x.Where("issue.is_closed = ?", isClosed).And("issue.is_pull = ?", isPull) sess := x.Where("issue.is_closed = ?", isClosed).And("issue.is_pull = ?", isPull)
@ -1190,11 +1190,17 @@ func GetUserIssueStats(repoID, userID int64, repoIDs []int64, filterMode FilterM
And("poster_id = ?", userID). And("poster_id = ?", userID).
Count(new(Issue)) Count(new(Issue))
if hasAnyRepo {
stats.YourReposCount, _ = countSession(false, isPull, repoID, repoIDs). stats.YourReposCount, _ = countSession(false, isPull, repoID, repoIDs).
Count(new(Issue)) Count(new(Issue))
}
switch filterMode { switch filterMode {
case FILTER_MODE_YOUR_REPOS: case FILTER_MODE_YOUR_REPOS:
if !hasAnyRepo {
break
}
stats.OpenCount, _ = countSession(false, isPull, repoID, repoIDs). stats.OpenCount, _ = countSession(false, isPull, repoID, repoIDs).
Count(new(Issue)) Count(new(Issue))
stats.ClosedCount, _ = countSession(true, isPull, repoID, repoIDs). stats.ClosedCount, _ = countSession(true, isPull, repoID, repoIDs).

49
models/repo.go

@ -1055,6 +1055,34 @@ func RepositoriesWithUsers(page, pageSize int) (_ []*Repository, err error) {
return repos, nil return repos, nil
} }
// FilterRepositoryWithIssues selects repositories that are using interal issue tracker
// and has disabled external tracker from given set.
// It returns nil if result set is empty.
func FilterRepositoryWithIssues(repoIDs []int64) ([]int64, error) {
if len(repoIDs) == 0 {
return nil, nil
}
repos := make([]*Repository, 0, len(repoIDs))
if err := x.Where("enable_issues=?", true).
And("enable_external_tracker=?", false).
In("id", repoIDs).
Cols("id").
Find(&repos); err != nil {
return nil, fmt.Errorf("filter valid repositories %v: %v", repoIDs, err)
}
if len(repos) == 0 {
return nil, nil
}
repoIDs = make([]int64, len(repos))
for i := range repos {
repoIDs[i] = repos[i].ID
}
return repoIDs, nil
}
// RepoPath returns repository path by given user and repository name. // RepoPath returns repository path by given user and repository name.
func RepoPath(userName, repoName string) string { func RepoPath(userName, repoName string) string {
return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git") return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git")
@ -1454,19 +1482,26 @@ func GetRepositoryByID(id int64) (*Repository, error) {
return getRepositoryByID(x, id) return getRepositoryByID(x, id)
} }
type UserRepoOptions struct {
UserID int64
Private bool
Page int
PageSize int
}
// GetUserRepositories returns a list of repositories of given user. // GetUserRepositories returns a list of repositories of given user.
func GetUserRepositories(userID int64, private bool, page, pageSize int) ([]*Repository, error) { func GetUserRepositories(opts *UserRepoOptions) ([]*Repository, error) {
sess := x.Where("owner_id = ?", userID).Desc("updated_unix") sess := x.Where("owner_id=?", opts.UserID).Desc("updated_unix")
if !private { if !opts.Private {
sess.And("is_private=?", false) sess.And("is_private=?", false)
} }
if page <= 0 { if opts.Page <= 0 {
page = 1 opts.Page = 1
} }
sess.Limit(pageSize, (page-1)*pageSize) sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
repos := make([]*Repository, 0, pageSize) repos := make([]*Repository, 0, opts.PageSize)
return repos, sess.Find(&repos) return repos, sess.Find(&repos)
} }

7
models/user.go

@ -418,7 +418,12 @@ func (u *User) GetOrganizationCount() (int64, error) {
// GetRepositories returns repositories that user owns, including private repositories. // GetRepositories returns repositories that user owns, including private repositories.
func (u *User) GetRepositories(page, pageSize int) (err error) { func (u *User) GetRepositories(page, pageSize int) (err error) {
u.Repos, err = GetUserRepositories(u.ID, true, page, pageSize) u.Repos, err = GetUserRepositories(&UserRepoOptions{
UserID: u.ID,
Private: true,
Page: page,
PageSize: pageSize,
})
return err return err
} }

7
routers/api/v1/repo/repo.go

@ -78,7 +78,12 @@ func Search(ctx *context.APIContext) {
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories // https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories
func ListMyRepos(ctx *context.APIContext) { func ListMyRepos(ctx *context.APIContext) {
ownRepos, err := models.GetUserRepositories(ctx.User.ID, true, 1, ctx.User.NumRepos) ownRepos, err := models.GetUserRepositories(&models.UserRepoOptions{
UserID: ctx.User.ID,
Private: true,
Page: 1,
PageSize: ctx.User.NumRepos,
})
if err != nil { if err != nil {
ctx.Error(500, "GetRepositories", err) ctx.Error(500, "GetRepositories", err)
return return

27
routers/user/home.go

@ -218,6 +218,12 @@ func Issues(ctx *context.Context) {
userRepoIDs = make([]int64, 0, len(repos)) userRepoIDs = make([]int64, 0, len(repos))
for _, repo := range repos { for _, repo := range repos {
userRepoIDs = append(userRepoIDs, repo.ID)
if filterMode != models.FILTER_MODE_YOUR_REPOS {
continue
}
if isPullList { if isPullList {
if isShowClosed && repo.NumClosedPulls == 0 || if isShowClosed && repo.NumClosedPulls == 0 ||
!isShowClosed && repo.NumOpenPulls == 0 { !isShowClosed && repo.NumOpenPulls == 0 {
@ -231,10 +237,16 @@ func Issues(ctx *context.Context) {
} }
} }
userRepoIDs = append(userRepoIDs, repo.ID)
if filterMode == models.FILTER_MODE_YOUR_REPOS {
showRepos = append(showRepos, repo) showRepos = append(showRepos, repo)
} }
// Filter repositories if the page shows issues.
if !isPullList {
userRepoIDs, err = models.FilterRepositoryWithIssues(userRepoIDs)
if err != nil {
ctx.Handle(500, "FilterRepositoryWithIssues", err)
return
}
} }
issueOptions := &models.IssuesOptions{ issueOptions := &models.IssuesOptions{
@ -247,7 +259,11 @@ func Issues(ctx *context.Context) {
switch filterMode { switch filterMode {
case models.FILTER_MODE_YOUR_REPOS: case models.FILTER_MODE_YOUR_REPOS:
// Get all issues from repositories from this user. // Get all issues from repositories from this user.
if userRepoIDs == nil {
issueOptions.RepoIDs = []int64{-1}
} else {
issueOptions.RepoIDs = userRepoIDs issueOptions.RepoIDs = userRepoIDs
}
case models.FILTER_MODE_ASSIGN: case models.FILTER_MODE_ASSIGN:
// Get all issues assigned to this user. // Get all issues assigned to this user.
@ -361,7 +377,12 @@ func showOrgProfile(ctx *context.Context) {
ctx.Data["Repos"] = repos ctx.Data["Repos"] = repos
} else { } else {
showPrivate := ctx.IsSigned && ctx.User.IsAdmin showPrivate := ctx.IsSigned && ctx.User.IsAdmin
repos, err = models.GetUserRepositories(org.ID, showPrivate, page, setting.UI.User.RepoPagingNum) repos, err = models.GetUserRepositories(&models.UserRepoOptions{
UserID: org.ID,
Private: showPrivate,
Page: page,
PageSize: setting.UI.User.RepoPagingNum,
})
if err != nil { if err != nil {
ctx.Handle(500, "GetRepositories", err) ctx.Handle(500, "GetRepositories", err)
return return

7
routers/user/profile.go

@ -99,7 +99,12 @@ func Profile(ctx *context.Context) {
page = 1 page = 1
} }
ctx.Data["Repos"], err = models.GetUserRepositories(ctxUser.ID, ctx.IsSigned && ctx.User.ID == ctxUser.ID, page, setting.UI.User.RepoPagingNum) ctx.Data["Repos"], err = models.GetUserRepositories(&models.UserRepoOptions{
UserID: ctxUser.ID,
Private: ctx.IsSigned && ctx.User.ID == ctxUser.ID,
Page: page,
PageSize: setting.UI.User.RepoPagingNum,
})
if err != nil { if err != nil {
ctx.Handle(500, "GetRepositories", err) ctx.Handle(500, "GetRepositories", err)
return return

8
templates/user/dashboard/issues.tmpl

@ -23,7 +23,13 @@
{{range .Repos}} {{range .Repos}}
<a class="{{if eq $.RepoID .ID}}ui basic blue button{{end}} repo name item" href="{{$.Link}}?type={{$.ViewType}}{{if not (eq $.RepoID .ID)}}&repo={{.ID}}{{end}}&sort={{$.SortType}}&state={{$.State}}"> <a class="{{if eq $.RepoID .ID}}ui basic blue button{{end}} repo name item" href="{{$.Link}}?type={{$.ViewType}}{{if not (eq $.RepoID .ID)}}&repo={{.ID}}{{end}}&sort={{$.SortType}}&state={{$.State}}">
<span class="text truncate">{{.FullName}}</span> <span class="text truncate">{{.FullName}}</span>
<div class="floating ui {{if $.IsShowClosed}}red{{else}}green{{end}} label">{{if $.IsShowClosed}}{{.NumClosedIssues}}{{else}}{{.NumOpenIssues}}{{end}}</div> <div class="floating ui {{if $.IsShowClosed}}red{{else}}green{{end}} label">
{{if $.PageIsIssues}}
{{if $.IsShowClosed}}{{.NumClosedIssues}}{{else}}{{.NumOpenIssues}}{{end}}
{{else}}
{{if $.IsShowClosed}}{{.NumClosedPulls}}{{else}}{{.NumOpenPulls}}{{end}}
{{end}}
</div>
</a> </a>
{{end}} {{end}}
</div> </div>

Loading…
Cancel
Save