aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-08-25 22:58:34 +0800
committerUnknwon <u@gogs.io>2015-08-25 22:58:34 +0800
commitf808df5a7b36d134ec92d62e9041a6320f416054 (patch)
tree9aa7c7758a02e1d8fa87a9af8ada4f3296eca0ae /models
parentbe90ea583a3d65566be8bfbf3440cf0c20557972 (diff)
downloadgitea-f808df5a7b36d134ec92d62e9041a6320f416054.tar.gz
gitea-f808df5a7b36d134ec92d62e9041a6320f416054.zip
new user dahsboard issues
Diffstat (limited to 'models')
-rw-r--r--models/issue.go66
-rw-r--r--models/repo.go5
2 files changed, 56 insertions, 15 deletions
diff --git a/models/issue.go b/models/issue.go
index f1ae400a05..f5070d1ec4 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -641,9 +641,8 @@ func parseCountResult(results []map[string][]byte) int64 {
}
// GetIssueStats returns issue statistic information by given conditions.
-func GetIssueStats(repoID, uid, labelID, milestoneID, assigneeID int64, isShowClosed bool, filterMode int) *IssueStats {
+func GetIssueStats(repoID, uid, labelID, milestoneID, assigneeID int64, filterMode int) *IssueStats {
stats := &IssueStats{}
- // issue := new(Issue)
queryStr := "SELECT COUNT(*) FROM `issue` "
if labelID > 0 {
@@ -659,38 +658,75 @@ func GetIssueStats(repoID, uid, labelID, milestoneID, assigneeID int64, isShowCl
}
switch filterMode {
case FM_ALL, FM_ASSIGN:
- resutls, _ := x.Query(queryStr+baseCond, repoID, false)
- stats.OpenCount = parseCountResult(resutls)
- resutls, _ = x.Query(queryStr+baseCond, repoID, true)
- stats.ClosedCount = parseCountResult(resutls)
+ results, _ := x.Query(queryStr+baseCond, repoID, false)
+ stats.OpenCount = parseCountResult(results)
+ results, _ = x.Query(queryStr+baseCond, repoID, true)
+ stats.ClosedCount = parseCountResult(results)
case FM_CREATE:
baseCond += " AND poster_id=?"
- resutls, _ := x.Query(queryStr+baseCond, repoID, false, uid)
- stats.OpenCount = parseCountResult(resutls)
- resutls, _ = x.Query(queryStr+baseCond, repoID, true, uid)
- stats.ClosedCount = parseCountResult(resutls)
+ results, _ := x.Query(queryStr+baseCond, repoID, false, uid)
+ stats.OpenCount = parseCountResult(results)
+ results, _ = x.Query(queryStr+baseCond, repoID, true, uid)
+ stats.ClosedCount = parseCountResult(results)
case FM_MENTION:
queryStr += " INNER JOIN `issue_user` ON `issue`.id=`issue_user`.issue_id"
baseCond += " AND `issue_user`.uid=? AND `issue_user`.is_mentioned=?"
- resutls, _ := x.Query(queryStr+baseCond, repoID, false, uid, true)
- stats.OpenCount = parseCountResult(resutls)
- resutls, _ = x.Query(queryStr+baseCond, repoID, true, uid, true)
- stats.ClosedCount = parseCountResult(resutls)
+ results, _ := x.Query(queryStr+baseCond, repoID, false, uid, true)
+ stats.OpenCount = parseCountResult(results)
+ results, _ = x.Query(queryStr+baseCond, repoID, true, uid, true)
+ stats.ClosedCount = parseCountResult(results)
}
return stats
}
// GetUserIssueStats returns issue statistic information for dashboard by given conditions.
-func GetUserIssueStats(uid int64, filterMode int) *IssueStats {
+func GetUserIssueStats(repoID, uid int64, filterMode int) *IssueStats {
stats := &IssueStats{}
issue := new(Issue)
stats.AssignCount, _ = x.Where("assignee_id=?", uid).And("is_closed=?", false).Count(issue)
stats.CreateCount, _ = x.Where("poster_id=?", uid).And("is_closed=?", false).Count(issue)
+
+ queryStr := "SELECT COUNT(*) FROM `issue` "
+ baseCond := " WHERE issue.is_closed=?"
+ if repoID > 0 {
+ baseCond += " AND issue.repo_id=" + com.ToStr(repoID)
+ }
+ switch filterMode {
+ case FM_ASSIGN:
+ baseCond += " AND assignee_id=" + com.ToStr(uid)
+
+ case FM_CREATE:
+ baseCond += " AND poster_id=" + com.ToStr(uid)
+ }
+
+ results, _ := x.Query(queryStr+baseCond, false)
+ stats.OpenCount = parseCountResult(results)
+ results, _ = x.Query(queryStr+baseCond, true)
+ stats.ClosedCount = parseCountResult(results)
return stats
}
+// GetRepoIssueStats returns number of open and closed repository issues by given filter mode.
+func GetRepoIssueStats(repoID, uid int64, filterMode int) (numOpen int64, numClosed int64) {
+ queryStr := "SELECT COUNT(*) FROM `issue` "
+ baseCond := " WHERE issue.repo_id=? AND issue.is_closed=?"
+ switch filterMode {
+ case FM_ASSIGN:
+ baseCond += " AND assignee_id=" + com.ToStr(uid)
+
+ case FM_CREATE:
+ baseCond += " AND poster_id=" + com.ToStr(uid)
+ }
+
+ results, _ := x.Query(queryStr+baseCond, repoID, false)
+ numOpen = parseCountResult(results)
+ results, _ = x.Query(queryStr+baseCond, repoID, true)
+ numClosed = parseCountResult(results)
+ return numOpen, numClosed
+}
+
func updateIssue(e Engine, issue *Issue) error {
_, err := e.Id(issue.ID).AllCols().Update(issue)
return err
diff --git a/models/repo.go b/models/repo.go
index f99d28ccc6..9da8ad36ed 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -221,6 +221,11 @@ func (repo *Repository) GetMilestoneByID(milestoneID int64) (*Milestone, error)
return GetRepoMilestoneByID(repo.ID, milestoneID)
}
+// IssueStats returns number of open and closed repository issues by given filter mode.
+func (repo *Repository) IssueStats(uid int64, filterMode int) (int64, int64) {
+ return GetRepoIssueStats(repo.ID, uid, filterMode)
+}
+
func (repo *Repository) GetMirror() (err error) {
repo.Mirror, err = GetMirror(repo.ID)
return err