aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-07 16:51:14 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-07 16:51:14 -0400
commit33d32585b1b7232c764e8cb8629a33076902c882 (patch)
tree4450575c9a0a71c8a7d51e9b4eafee321226d8c2
parent6fb7229beaadb53f59cb85d80976f99708a7434d (diff)
downloadgitea-33d32585b1b7232c764e8cb8629a33076902c882.tar.gz
gitea-33d32585b1b7232c764e8cb8629a33076902c882.zip
Add mention, read/unread support of issue tracker
-rw-r--r--models/issue.go252
-rw-r--r--models/models.go2
-rw-r--r--models/repo.go58
-rw-r--r--models/user.go15
-rw-r--r--modules/mailer/mail.go12
-rw-r--r--routers/admin/admin.go2
-rw-r--r--routers/repo/issue.go78
-rw-r--r--routers/user/home.go123
-rw-r--r--templates/admin/repos.tmpl4
-rw-r--r--templates/issue/list.tmpl2
-rw-r--r--templates/issue/user.tmpl10
11 files changed, 356 insertions, 202 deletions
diff --git a/models/issue.go b/models/issue.go
index eb88190cc8..b93989435a 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -5,9 +5,12 @@
package models
import (
+ "bytes"
"errors"
"strings"
"time"
+
+ "github.com/gogits/gogs/modules/base"
)
var (
@@ -25,6 +28,7 @@ type Issue struct {
Poster *User `xorm:"-"`
MilestoneId int64
AssigneeId int64
+ IsRead bool `xorm:"-"`
IsPull bool // Indicates whether is a pull request or not.
IsClosed bool
Labels string `xorm:"TEXT"`
@@ -42,18 +46,6 @@ func (i *Issue) GetPoster() (err error) {
return err
}
-// IssseUser represents an issue-user relation.
-type IssseUser struct {
- Id int64
- Iid int64 // Issue ID.
- Rid int64 // Repository ID.
- Uid int64 // User ID.
- IsRead bool
- IsAssigned bool
- IsMentioned bool
- IsClosed bool
-}
-
// CreateIssue creates new issue for repository.
func NewIssue(issue *Issue) (err error) {
sess := orm.NewSession()
@@ -87,6 +79,18 @@ func GetIssueByIndex(rid, index int64) (*Issue, error) {
return issue, nil
}
+// GetIssueById returns an issue by ID.
+func GetIssueById(id int64) (*Issue, error) {
+ issue := &Issue{Id: id}
+ has, err := orm.Get(issue)
+ if err != nil {
+ return nil, err
+ } else if !has {
+ return nil, ErrIssueNotExist
+ }
+ return issue, nil
+}
+
// GetIssues returns a list of issues by given conditions.
func GetIssues(uid, rid, pid, mid int64, page int, isClosed bool, labels, sortType string) ([]Issue, error) {
sess := orm.Limit(20, (page-1)*20)
@@ -133,27 +137,115 @@ func GetIssues(uid, rid, pid, mid int64, page int, isClosed bool, labels, sortTy
return issues, err
}
+// GetIssueCountByPoster returns number of issues of repository by poster.
+func GetIssueCountByPoster(uid, rid int64, isClosed bool) int64 {
+ count, _ := orm.Where("repo_id=?", rid).And("poster_id=?", uid).And("is_closed=?", isClosed).Count(new(Issue))
+ return count
+}
+
+// IssueUser represents an issue-user relation.
+type IssueUser struct {
+ Id int64
+ Uid int64 // User ID.
+ IssueId int64
+ RepoId int64
+ IsRead bool
+ IsAssigned bool
+ IsMentioned bool
+ IsPoster bool
+ IsClosed bool
+}
+
+// NewIssueUserPairs adds new issue-user pairs for new issue of repository.
+func NewIssueUserPairs(rid, iid, oid, uid, aid int64) (err error) {
+ iu := &IssueUser{IssueId: iid, RepoId: rid}
+
+ ws, err := GetWatchers(rid)
+ if err != nil {
+ return err
+ }
+
+ // TODO: check collaborators.
+ // Add owner.
+ ids := []int64{oid}
+ for _, id := range ids {
+ if IsWatching(id, rid) {
+ continue
+ }
+
+ // In case owner is not watching.
+ ws = append(ws, &Watch{Uid: id})
+ }
+
+ for _, w := range ws {
+ if w.Uid == 0 {
+ continue
+ }
+
+ iu.Uid = w.Uid
+ iu.IsPoster = iu.Uid == uid
+ iu.IsAssigned = iu.Uid == aid
+ if _, err = orm.Insert(iu); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
// PairsContains returns true when pairs list contains given issue.
-func PairsContains(ius []*IssseUser, issueId int64) bool {
+func PairsContains(ius []*IssueUser, issueId int64) int {
for i := range ius {
- if ius[i].Iid == issueId {
- return true
+ if ius[i].IssueId == issueId {
+ return i
}
}
- return false
+ return -1
}
-// GetIssueUserPairs returns all issue-user pairs by given repository and user.
-func GetIssueUserPairs(rid, uid int64, isClosed bool) ([]*IssseUser, error) {
- ius := make([]*IssseUser, 0, 10)
- err := orm.Find(&ius, &IssseUser{Rid: rid, Uid: uid, IsClosed: isClosed})
+// GetIssueUserPairs returns issue-user pairs by given repository and user.
+func GetIssueUserPairs(rid, uid int64, isClosed bool) ([]*IssueUser, error) {
+ ius := make([]*IssueUser, 0, 10)
+ err := orm.Where("is_closed=?", isClosed).Find(&ius, &IssueUser{RepoId: rid, Uid: uid})
return ius, err
}
-// GetUserIssueCount returns the number of issues that were created by given user in repository.
-func GetUserIssueCount(uid, rid int64) int64 {
- count, _ := orm.Where("poster_id=?", uid).And("repo_id=?", rid).Count(new(Issue))
- return count
+// GetIssueUserPairsByRepoIds returns issue-user pairs by given repository IDs.
+func GetIssueUserPairsByRepoIds(rids []int64, isClosed bool, page int) ([]*IssueUser, error) {
+ buf := bytes.NewBufferString("")
+ for _, rid := range rids {
+ buf.WriteString("repo_id=")
+ buf.WriteString(base.ToStr(rid))
+ buf.WriteString(" OR ")
+ }
+ cond := strings.TrimSuffix(buf.String(), " OR ")
+
+ ius := make([]*IssueUser, 0, 10)
+ sess := orm.Limit(20, (page-1)*20).Where("is_closed=?", isClosed)
+ if len(cond) > 0 {
+ sess.And(cond)
+ }
+ err := sess.Find(&ius)
+ return ius, err
+}
+
+// GetIssueUserPairsByMode returns issue-user pairs by given repository and user.
+func GetIssueUserPairsByMode(uid, rid int64, isClosed bool, page, filterMode int) ([]*IssueUser, error) {
+ ius := make([]*IssueUser, 0, 10)
+ sess := orm.Limit(20, (page-1)*20).Where("uid=?", uid).And("is_closed=?", isClosed)
+ if rid > 0 {
+ sess.And("repo_id=?", rid)
+ }
+
+ switch filterMode {
+ case FM_ASSIGN:
+ sess.And("is_assigned=?", true)
+ case FM_CREATE:
+ sess.And("is_poster=?", true)
+ default:
+ return ius, nil
+ }
+ err := sess.Find(&ius)
+ return ius, err
}
// IssueStats represents issue statistic information.
@@ -172,7 +264,7 @@ const (
FM_MENTION
)
-// GetIssueStats returns issue statistic information by given condition.
+// GetIssueStats returns issue statistic information by given conditions.
func GetIssueStats(rid, uid int64, isShowClosed bool, filterMode int) *IssueStats {
stats := &IssueStats{}
issue := new(Issue)
@@ -203,48 +295,23 @@ func GetIssueStats(rid, uid int64, isShowClosed bool, filterMode int) *IssueStat
*tmpSess = *sess
stats.ClosedCount, _ = tmpSess.And("is_closed=?", true).Count(issue)
} else {
- sess := orm.Where("rid=?", rid).And("uid=?", uid).And("is_mentioned=?", true)
- tmpSess := sess
- stats.OpenCount, _ = tmpSess.And("is_closed=?", false).Count(new(IssseUser))
+ sess := orm.Where("repo_id=?", rid).And("uid=?", uid).And("is_mentioned=?", true)
*tmpSess = *sess
- stats.ClosedCount, _ = tmpSess.And("is_closed=?", true).Count(new(IssseUser))
+ stats.OpenCount, _ = tmpSess.And("is_closed=?", false).Count(new(IssueUser))
+ *tmpSess = *sess
+ stats.ClosedCount, _ = tmpSess.And("is_closed=?", true).Count(new(IssueUser))
}
nofilter:
stats.AssignCount, _ = orm.Where("repo_id=?", rid).And("is_closed=?", isShowClosed).And("assignee_id=?", uid).Count(issue)
stats.CreateCount, _ = orm.Where("repo_id=?", rid).And("is_closed=?", isShowClosed).And("poster_id=?", uid).Count(issue)
- stats.MentionCount, _ = orm.Where("rid=?", rid).And("uid=?", uid).And("is_closed=?", isShowClosed).And("is_mentioned=?", true).Count(new(IssseUser))
+ stats.MentionCount, _ = orm.Where("repo_id=?", rid).And("uid=?", uid).And("is_closed=?", isShowClosed).And("is_mentioned=?", true).Count(new(IssueUser))
return stats
}
-// GetUserIssueStats returns issue statistic information for dashboard by given condition.
+// GetUserIssueStats returns issue statistic information for dashboard by given conditions.
func GetUserIssueStats(uid int64, filterMode int) *IssueStats {
stats := &IssueStats{}
issue := new(Issue)
- iu := new(IssseUser)
-
- sess := orm.Where("uid=?", uid)
- tmpSess := sess
- if filterMode == 0 {
- stats.OpenCount, _ = tmpSess.And("is_closed=?", false).Count(iu)
- *tmpSess = *sess
- stats.ClosedCount, _ = tmpSess.And("is_closed=?", true).Count(iu)
- }
-
- switch filterMode {
- case FM_ASSIGN:
- sess.And("is_assigned=?", true)
- *tmpSess = *sess
- stats.OpenCount, _ = tmpSess.And("is_closed=?", false).Count(iu)
- *tmpSess = *sess
- stats.ClosedCount, _ = tmpSess.And("is_closed=?", true).Count(iu)
- case FM_CREATE:
- sess.Where("poster_id=?", uid)
- *tmpSess = *sess
- stats.OpenCount, _ = tmpSess.And("is_closed=?", false).Count(issue)
- *tmpSess = *sess
- stats.ClosedCount, _ = tmpSess.And("is_closed=?", true).Count(issue)
- }
-
stats.AssignCount, _ = orm.Where("assignee_id=?", uid).And("is_closed=?", false).Count(issue)
stats.CreateCount, _ = orm.Where("poster_id=?", uid).And("is_closed=?", false).Count(issue)
return stats
@@ -252,28 +319,69 @@ func GetUserIssueStats(uid int64, filterMode int) *IssueStats {
// UpdateIssue updates information of issue.
func UpdateIssue(issue *Issue) error {
- _, err := orm.AllCols().Update(issue)
+ _, err := orm.Id(issue.Id).AllCols().Update(issue)
return err
}
-// Label represents a list of labels of repository for issues.
+// UpdateIssueUserByStatus updates issue-user pairs by issue status.
+func UpdateIssueUserPairsByStatus(iid int64, isClosed bool) error {
+ rawSql := "UPDATE `issue_user` SET is_closed = ? WHERE issue_id = ?"
+ _, err := orm.Exec(rawSql, isClosed, iid)
+ return err
+}
+
+// UpdateIssueUserPairByRead updates issue-user pair for reading.
+func UpdateIssueUserPairByRead(uid, iid int64) error {
+ rawSql := "UPDATE `issue_user` SET is_read = ? WHERE uid = ? AND issue_id = ?"
+ _, err := orm.Exec(rawSql, true, uid, iid)
+ return err
+}
+
+// UpdateIssueUserPairsByMentions updates issue-user pairs by mentioning.
+func UpdateIssueUserPairsByMentions(uids []int64, iid int64) error {
+ for _, uid := range uids {
+ iu := &IssueUser{Uid: uid, IssueId: iid}
+ has, err := orm.Get(iu)
+ if err != nil {
+ return err
+ }
+
+ iu.IsMentioned = true
+ if has {
+ _, err = orm.Id(iu.Id).AllCols().Update(iu)
+ } else {
+ _, err = orm.Insert(iu)
+ }
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+// Label represents a label of repository for issues.
type Label struct {
- Id int64
- RepoId int64 `xorm:"INDEX"`
- Names string
- Colors string
+ Id int64
+ Rid int64 `xorm:"INDEX"`
+ Name string
+ Color string
+ NumIssues int
+ NumClosedIssues int
+ NumOpenIssues int `xorm:"-"`
}
// Milestone represents a milestone of repository.
type Milestone struct {
- Id int64
- Name string
- RepoId int64 `xorm:"INDEX"`
- IsClosed bool
- Content string
- NumIssues int
- DueDate time.Time
- Created time.Time `xorm:"CREATED"`
+ Id int64
+ Rid int64 `xorm:"INDEX"`
+ Name string
+ Content string
+ IsClosed bool
+ NumIssues int
+ NumClosedIssues int
+ Completeness int // Percentage(1-100).
+ Deadline time.Time
+ ClosedDate time.Time
}
// Issue types.
@@ -300,7 +408,9 @@ type Comment struct {
func CreateComment(userId, repoId, issueId, commitId, line int64, cmtType int, content string) error {
sess := orm.NewSession()
defer sess.Close()
- sess.Begin()
+ if err := sess.Begin(); err != nil {
+ return err
+ }
if _, err := sess.Insert(&Comment{PosterId: userId, Type: cmtType, IssueId: issueId,
CommitId: commitId, Line: line, Content: content}); err != nil {
diff --git a/models/models.go b/models/models.go
index d7f3629927..02141b7a8f 100644
--- a/models/models.go
+++ b/models/models.go
@@ -34,7 +34,7 @@ var (
func init() {
tables = append(tables, new(User), new(PublicKey), new(Repository), new(Watch),
new(Action), new(Access), new(Issue), new(Comment), new(Oauth2), new(Follow),
- new(Mirror), new(Release), new(LoginSource), new(Webhook), new(IssseUser))
+ new(Mirror), new(Release), new(LoginSource), new(Webhook), new(IssueUser))
}
func LoadModelsConfig() {
diff --git a/models/repo.go b/models/repo.go
index 079e100a13..640b6e723d 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -466,33 +466,25 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep
return initRepoCommit(tmpDir, user.NewGitSig())
}
-// UserRepo reporesents a repository with user name.
-type UserRepo struct {
- *Repository
- UserName string
-}
-
-// GetRepos returns given number of repository objects with offset.
-func GetRepos(num, offset int) ([]UserRepo, error) {
- repos := make([]Repository, 0, num)
+// GetRepositoriesWithUsers returns given number of repository objects with offset.
+// It also auto-gets corresponding users.
+func GetRepositoriesWithUsers(num, offset int) ([]*Repository, error) {
+ repos := make([]*Repository, 0, num)
if err := orm.Limit(num, offset).Asc("id").Find(&repos); err != nil {
return nil, err
}
- urepos := make([]UserRepo, len(repos))
- for i := range repos {
- urepos[i].Repository = &repos[i]
- u := new(User)
- has, err := orm.Id(urepos[i].Repository.OwnerId).Get(u)
+ for _, repo := range repos {
+ repo.Owner = &User{Id: repo.OwnerId}
+ has, err := orm.Get(repo.Owner)
if err != nil {
return nil, err
} else if !has {
return nil, ErrUserNotExist
}
- urepos[i].UserName = u.Name
}
- return urepos, nil
+ return repos, nil
}
// RepoPath returns repository path by given user and repository name.
@@ -733,40 +725,40 @@ func GetCollaborators(repoName string) ([]string, error) {
// Watch is connection request for receiving repository notifycation.
type Watch struct {
Id int64
- RepoId int64 `xorm:"UNIQUE(watch)"`
- UserId int64 `xorm:"UNIQUE(watch)"`
+ Uid int64 `xorm:"UNIQUE(s)"`
+ RepoId int64 `xorm:"UNIQUE(s)"`
}
// Watch or unwatch repository.
-func WatchRepo(userId, repoId int64, watch bool) (err error) {
+func WatchRepo(uid, rid int64, watch bool) (err error) {
if watch {
- if _, err = orm.Insert(&Watch{RepoId: repoId, UserId: userId}); err != nil {
+ if _, err = orm.Insert(&Watch{RepoId: rid, Uid: uid}); err != nil {
return err
}
rawSql := "UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?"
- _, err = orm.Exec(rawSql, repoId)
+ _, err = orm.Exec(rawSql, rid)
} else {
- if _, err = orm.Delete(&Watch{0, repoId, userId}); err != nil {
+ if _, err = orm.Delete(&Watch{0, rid, uid}); err != nil {
return err
}
rawSql := "UPDATE `repository` SET num_watches = num_watches - 1 WHERE id = ?"
- _, err = orm.Exec(rawSql, repoId)
+ _, err = orm.Exec(rawSql, rid)
}
return err
}
-// GetWatches returns all watches of given repository.
-func GetWatches(repoId int64) ([]Watch, error) {
- watches := make([]Watch, 0, 10)
- err := orm.Find(&watches, &Watch{RepoId: repoId})
+// GetWatchers returns all watchers of given repository.
+func GetWatchers(rid int64) ([]*Watch, error) {
+ watches := make([]*Watch, 0, 10)
+ err := orm.Find(&watches, &Watch{RepoId: rid})
return watches, err
}
// NotifyWatchers creates batch of actions for every watcher.
func NotifyWatchers(act *Action) error {
// Add feeds for user self and all watchers.
- watches, err := GetWatches(act.RepoId)
+ watches, err := GetWatchers(act.RepoId)
if err != nil {
return errors.New("repo.NotifyWatchers(get watches): " + err.Error())
}
@@ -778,12 +770,12 @@ func NotifyWatchers(act *Action) error {
}
for i := range watches {
- if act.ActUserId == watches[i].UserId {
+ if act.ActUserId == watches[i].Uid {
continue
}
act.Id = 0
- act.UserId = watches[i].UserId
+ act.UserId = watches[i].Uid
if _, err = orm.InsertOne(act); err != nil {
return errors.New("repo.NotifyWatchers(create action): " + err.Error())
}
@@ -792,11 +784,11 @@ func NotifyWatchers(act *Action) error {
}
// IsWatching checks if user has watched given repository.
-func IsWatching(userId, repoId int64) bool {
- has, _ := orm.Get(&Watch{0, repoId, userId})
+func IsWatching(uid, rid int64) bool {
+ has, _ := orm.Get(&Watch{0, rid, uid})
return has
}
-func ForkRepository(reposName string, userId int64) {
+func ForkRepository(repoName string, uid int64) {
}
diff --git a/models/user.go b/models/user.go
index 720065c3f1..9ffdf8e6ae 100644
--- a/models/user.go
+++ b/models/user.go
@@ -304,7 +304,7 @@ func DeleteUser(user *User) error {
}
// Delete all watches.
- if _, err = orm.Delete(&Watch{UserId: user.Id}); err != nil {
+ if _, err = orm.Delete(&Watch{Uid: user.Id}); err != nil {
return err
}
@@ -392,6 +392,19 @@ func GetUserEmailsByNames(names []string) []string {
return mails
}
+// GetUserIdsByNames returns a slice of ids corresponds to names.
+func GetUserIdsByNames(names []string) []int64 {
+ ids := make([]int64, 0, len(names))
+ for _, name := range names {
+ u, err := GetUserByName(name)
+ if err != nil {
+ continue
+ }
+ ids = append(ids, u.Id)
+ }
+ return ids
+}
+
// GetUserByEmail returns the user object by given e-mail if exists.
func GetUserByEmail(email string) (*User, error) {
if len(email) == 0 {
diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go
index 2262b5455f..93ec1153f0 100644
--- a/modules/mailer/mail.go
+++ b/modules/mailer/mail.go
@@ -114,20 +114,20 @@ func SendResetPasswdMail(r *middleware.Render, user *models.User) {
// SendIssueNotifyMail sends mail notification of all watchers of repository.
func SendIssueNotifyMail(user, owner *models.User, repo *models.Repository, issue *models.Issue) ([]string, error) {
- watches, err := models.GetWatches(repo.Id)
+ ws, err := models.GetWatchers(repo.Id)
if err != nil {
- return nil, errors.New("mail.NotifyWatchers(get watches): " + err.Error())
+ return nil, errors.New("mail.NotifyWatchers(GetWatchers): " + err.Error())
}
- tos := make([]string, 0, len(watches))
- for i := range watches {
- uid := watches[i].UserId
+ tos := make([]string, 0, len(ws))
+ for i := range ws {
+ uid := ws[i].Uid
if user.Id == uid {
continue
}
u, err := models.GetUserById(uid)
if err != nil {
- return nil, errors.New("mail.NotifyWatchers(get user): " + err.Error())
+ return nil, errors.New("mail.NotifyWatchers(GetUserById): " + err.Error())
}
tos = append(tos, u.Email)
}
diff --git a/routers/admin/admin.go b/routers/admin/admin.go
index 910027881d..dbd5e94594 100644
--- a/routers/admin/admin.go
+++ b/routers/admin/admin.go
@@ -152,7 +152,7 @@ func Repositories(ctx *middleware.Context) {
ctx.Data["PageIsRepos"] = true
var err error
- ctx.Data["Repos"], err = models.GetRepos(200, 0)
+ ctx.Data["Repos"], err = models.GetRepositoriesWithUsers(200, 0)
if err != nil {
ctx.Handle(500, "admin.Repositories", err)
return
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 2a4c8e639f..31827f2d04 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -65,22 +65,27 @@ func Issues(ctx *middleware.Context) {
return
}
- var pairs []*models.IssseUser
- if filterMode == models.FM_MENTION {
- // Get issue-user pairs.
- pairs, err = models.GetIssueUserPairs(ctx.Repo.Repository.Id, ctx.User.Id, isShowClosed)
- if err != nil {
- ctx.Handle(500, "issue.Issues(GetIssueUserPairs): %v", err)
- return
- }
+ // Get issue-user pairs.
+ pairs, err := models.GetIssueUserPairs(ctx.Repo.Repository.Id, ctx.User.Id, isShowClosed)
+ if err != nil {
+ ctx.Handle(500, "issue.Issues(GetIssueUserPairs): %v", err)
+ return
}
// Get posters.
for i := range issues {
- if filterMode == models.FM_MENTION && !models.PairsContains(pairs, issues[i].Id) {
+ idx := models.PairsContains(pairs, issues[i].Id)
+
+ if filterMode == models.FM_MENTION && (idx == -1 || !pairs[idx].IsMentioned) {
continue
}
+ if idx > -1 {
+ issues[i].IsRead = pairs[idx].IsRead
+ } else {
+ issues[i].IsRead = true
+ }
+
if err = issues[i].GetPoster(); err != nil {
ctx.Handle(500, "issue.Issues(GetPoster): %v", err)
return
@@ -135,6 +140,24 @@ func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.C
if err := models.NewIssue(issue); err != nil {
ctx.Handle(500, "issue.CreateIssue(NewIssue)", err)
return
+ } else if err := models.NewIssueUserPairs(issue.RepoId, issue.Id,
+ ctx.Repo.Owner.Id, ctx.User.Id, form.AssigneeId); err != nil {
+ ctx.Handle(500, "issue.CreateIssue(NewIssueUserPairs)", err)
+ return
+ }
+
+ // Update mentions.
+ ms := base.MentionPattern.FindAllString(issue.Content, -1)
+ if len(ms) > 0 {
+ for i := range ms {
+ ms[i] = ms[i][1:]
+ }
+
+ ids := models.GetUserIdsByNames(ms)
+ if err := models.UpdateIssueUserPairsByMentions(ids, issue.Id); err != nil {
+ ctx.Handle(500, "issue.CreateIssue(UpdateIssueUserPairsByMentions)", err)
+ return
+ }
}
// Notify watchers.
@@ -154,14 +177,13 @@ func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.C
}
tos = append(tos, ctx.User.LowerName)
- ms := base.MentionPattern.FindAllString(issue.Content, -1)
newTos := make([]string, 0, len(ms))
for _, m := range ms {
- if com.IsSliceContainsStr(tos, m[1:]) {
+ if com.IsSliceContainsStr(tos, m) {
continue
}
- newTos = append(newTos, m[1:])
+ newTos = append(newTos, m)
}
if err = mailer.SendIssueMentionMail(ctx.Render, ctx.User, ctx.Repo.Owner,
ctx.Repo.Repository, issue, models.GetUserEmailsByNames(newTos)); err != nil {
@@ -191,6 +213,12 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) {
return
}
+ // Update issue-user.
+ if err = models.UpdateIssueUserPairByRead(ctx.User.Id, issue.Id); err != nil {
+ ctx.Handle(500, "issue.ViewIssue(UpdateIssueUserPairByRead): %v", err)
+ return
+ }
+
// Get poster.
u, err := models.GetUserById(issue.PosterId)
if err != nil {
@@ -294,7 +322,10 @@ func Comment(ctx *middleware.Context, params martini.Params) {
(strings.Contains(newStatus, "Close") && !issue.IsClosed) {
issue.IsClosed = !issue.IsClosed
if err = models.UpdateIssue(issue); err != nil {
- ctx.Handle(200, "issue.Comment(update issue status)", err)
+ ctx.Handle(500, "issue.Comment(UpdateIssue)", err)
+ return
+ } else if err = models.UpdateIssueUserPairsByStatus(issue.Id, issue.IsClosed); err != nil {
+ ctx.Handle(500, "issue.Comment(UpdateIssueUserPairsByStatus)", err)
return
}
@@ -311,6 +342,7 @@ func Comment(ctx *middleware.Context, params martini.Params) {
}
}
+ var ms []string
content := ctx.Query("content")
if len(content) > 0 {
switch params["action"] {
@@ -319,6 +351,21 @@ func Comment(ctx *middleware.Context, params martini.Params) {
ctx.Handle(500, "issue.Comment(create comment)", err)
return
}
+
+ // Update mentions.
+ ms = base.MentionPattern.FindAllString(issue.Content, -1)
+ if len(ms) > 0 {
+ for i := range ms {
+ ms[i] = ms[i][1:]
+ }
+
+ ids := models.GetUserIdsByNames(ms)
+ if err := models.UpdateIssueUserPairsByMentions(ids, issue.Id); err != nil {
+ ctx.Handle(500, "issue.CreateIssue(UpdateIssueUserPairsByMentions)", err)
+ return
+ }
+ }
+
log.Trace("%s Comment created: %d", ctx.Req.RequestURI, issue.Id)
default:
ctx.Handle(404, "issue.Comment", err)
@@ -344,14 +391,13 @@ func Comment(ctx *middleware.Context, params martini.Params) {
}
tos = append(tos, ctx.User.LowerName)
- ms := base.MentionPattern.FindAllString(issue.Content, -1)
newTos := make([]string, 0, len(ms))
for _, m := range ms {
- if com.IsSliceContainsStr(tos, m[1:]) {
+ if com.IsSliceContainsStr(tos, m) {
continue
}
- newTos = append(newTos, m[1:])
+ newTos = append(newTos, m)
}
if err = mailer.SendIssueMentionMail(ctx.Render, ctx.User, ctx.Repo.Owner,
ctx.Repo.Repository, issue, models.GetUserEmailsByNames(newTos)); err != nil {
diff --git a/routers/user/home.go b/routers/user/home.go
index 588cb8e3b0..11ac1a8126 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -13,6 +13,7 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
)
@@ -127,102 +128,94 @@ func Issues(ctx *middleware.Context) {
}
_, _ = assigneeId, posterId
- // page, _ := base.StrTo(ctx.Query("page")).Int()
- // repoId, _ := base.StrTo(ctx.Query("repoid")).Int64()
-
- // ctx.Data["RepoId"] = repoId
-
- // var posterId int64 = 0
- // if ctx.Query("type") == "created_by" {
- // posterId = ctx.User.Id
- // ctx.Data["ViewType"] = "created_by"
- // }
-
rid, _ := base.StrTo(ctx.Query("repoid")).Int64()
issueStats := models.GetUserIssueStats(ctx.User.Id, filterMode)
// Get all repositories.
repos, err := models.GetRepositories(ctx.User, true)
if err != nil {
- ctx.Handle(500, "user.Issues(get repositories)", err)
+ ctx.Handle(500, "user.Issues(GetRepositories)", err)
return
}
+ rids := make([]int64, 0, len(repos))
showRepos := make([]*models.Repository, 0, len(repos))
-
- // Get all issues.
- // allIssues := make([]models.Issue, 0, 5*len(repos))
for _, repo := range repos {
if repo.NumIssues == 0 {
continue
}
+ rids = append(rids, repo.Id)
repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
issueStats.AllCount += int64(repo.NumOpenIssues)
- // switch filterMode{
- // case models.FM_ASSIGN:
-
- // }
-
if isShowClosed {
if repo.NumClosedIssues > 0 {
+ if filterMode == models.FM_CREATE {
+ repo.NumClosedIssues = int(models.GetIssueCountByPoster(ctx.User.Id, repo.Id, isShowClosed))
+ }
showRepos = append(showRepos, repo)
}
} else {
if repo.NumOpenIssues > 0 {
+ if filterMode == models.FM_CREATE {
+ repo.NumOpenIssues = int(models.GetIssueCountByPoster(ctx.User.Id, repo.Id, isShowClosed))
+ }
showRepos = append(showRepos, repo)
}
}
+ }
- // issues, err := models.GetIssues(0, repo.Id, posterId, 0, page, isShowClosed, "", "")
- // if err != nil {
- // ctx.Handle(200, "user.Issues(get issues)", err)
- // return
- // }
- }
-
- // allIssueCount += repo.NumIssues
- // closedIssueCount += repo.NumClosedIssues
-
- // // Set repository information to issues.
- // for j := range issues {
- // issues[j].Repo = &repos[i]
- // }
- // allIssues = append(allIssues, issues...)
-
- // repos[i].NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
- // if repos[i].NumOpenIssues > 0 {
- // showRepos = append(showRepos, repos[i])
- // }
- // }
-
- // showIssues := make([]models.Issue, 0, len(allIssues))
- // ctx.Data["IsShowClosed"] = isShowClosed
-
- // // Get posters and filter issues.
- // for i := range allIssues {
- // u, err := models.GetUserById(allIssues[i].PosterId)
- // if err != nil {
- // ctx.Handle(200, "user.Issues(get poster): %v", err)
- // return
- // }
- // allIssues[i].Poster = u
- // if u.Id == ctx.User.Id {
- // createdByCount++
- // }
-
- // if repoId > 0 && repoId != allIssues[i].Repo.Id {
- // continue
- // }
-
- // if isShowClosed == allIssues[i].IsClosed {
- // showIssues = append(showIssues, allIssues[i])
- // }
- // }
+ if rid > 0 {
+ rids = []int64{rid}
+ }
+
+ page, _ := base.StrTo(ctx.Query("page")).Int()
+
+ // Get all issues.
+ var ius []*models.IssueUser
+ switch viewType {
+ case "assigned":
+ fallthrough
+ case "created_by":
+ ius, err = models.GetIssueUserPairsByMode(ctx.User.Id, rid, isShowClosed, page, filterMode)
+ default:
+ ius, err = models.GetIssueUserPairsByRepoIds(rids, isShowClosed, page)
+ }
+ if err != nil {
+ ctx.Handle(500, "user.Issues(GetAllIssueUserPairs)", err)
+ return
+ }
+
+ issues := make([]*models.Issue, len(ius))
+ for i := range ius {
+ issues[i], err = models.GetIssueById(ius[i].IssueId)
+ if err != nil {
+ if err == models.ErrIssueNotExist {
+ log.Error("user.Issues(#%d): issue not exist", ius[i].IssueId)
+ continue
+ } else {
+ ctx.Handle(500, "user.Issues(GetIssue)", err)
+ return
+ }
+ }
+
+ issues[i].Repo, err = models.GetRepositoryById(issues[i].RepoId)
+ if err != nil {
+ ctx.Handle(500, "user.Issues(GetRepositoryById)", err)
+ return
+ }
+
+ issues[i].Poster, err = models.GetUserById(issues[i].PosterId)
+ if err != nil {
+ ctx.Handle(500, "user.Issues(GetUserById)", err)
+ return
+ }
+ }
ctx.Data["RepoId"] = rid
ctx.Data["Repos"] = showRepos
+ ctx.Data["Issues"] = issues
ctx.Data["ViewType"] = viewType
ctx.Data["IssueStats"] = issueStats
ctx.Data["IsShowClosed"] = isShowClosed
diff --git a/templates/admin/repos.tmpl b/templates/admin/repos.tmpl
index 2c5e3d3b7d..f6f3a7be98 100644
--- a/templates/admin/repos.tmpl
+++ b/templates/admin/repos.tmpl
@@ -26,8 +26,8 @@
{{range .Repos}}
<tr>
<td>{{.Id}}</td>
- <th>{{.UserName}}</th>
- <td><a href="/{{.UserName}}/{{.Name}}">{{.Name}}</a></td>
+ <th>{{.Owner.Name}}</th>
+ <td><a href="/{{.Owner.Name}}/{{.Name}}">{{.Name}}</a></td>
<td><i class="fa fa{{if .IsPrivate}}-check{{end}}-square-o"></i></td>
<td>{{.NumWatches}}</td>
<td>{{.NumIssues}}</td>
diff --git a/templates/issue/list.tmpl b/templates/issue/list.tmpl
index 0b995f810c..e66015af87 100644
--- a/templates/issue/list.tmpl
+++ b/templates/issue/list.tmpl
@@ -21,7 +21,7 @@
</div>
<div class="issues list-group">
{{range .Issues}}{{if .Poster}}
- <div class="list-group-item issue-item" id="issue-{{.Id}}">
+ <div class="list-group-item issue-item{{if not .IsRead}} unread{{end}}" id="issue-{{.Id}}">
<span class="number pull-right">#{{.Index}}</span>
<h5 class="title"><a href="{{$.RepoLink}}/issues/{{.Index}}">{{.Name}}</a></h5>
<p class="info">
diff --git a/templates/issue/user.tmpl b/templates/issue/user.tmpl
index e1711d4476..f480c63a8f 100644
--- a/templates/issue/user.tmpl
+++ b/templates/issue/user.tmpl
@@ -21,19 +21,19 @@
<li><a href="/issues?type=created_by&repoid={{.RepoId}}&state={{.State}}"{{if eq .ViewType "created_by"}} class="active"{{end}}>Created by you <strong class="pull-right">{{.IssueStats.CreateCount}}</strong></a></li>
<li><hr/></li>
{{range .Repos}}
- <li><a href="/issues?type={{$.ViewType}}{{if eq $.RepoId .Id}}{{else}}&repoid={{.Id}}{{end}}" class="sm{{if eq $.RepoId .Id}} active{{end}}">{{$.SignedUser.Name}}/{{.Name}} <strong class="pull-right">{{.NumOpenIssues}}</strong></a></li>
+ <li><a href="/issues?type={{$.ViewType}}{{if eq $.RepoId .Id}}{{else}}&repoid={{.Id}}{{end}}&state={{$.State}}" class="sm{{if eq $.RepoId .Id}} active{{end}}">{{$.SignedUser.Name}}/{{.Name}} <strong class="pull-right">{{if $.IsShowClosed}}{{.NumClosedIssues}}{{else}}{{.NumOpenIssues}}{{end}}</strong></a></li>
{{end}}
</ul>
</div>
<div class="col-md-9">
<div class="filter-option">
<div class="btn-group">
- <a class="btn btn-default issue-open{{if not .IsShowClosed}} active{{end}}" href="/issues?type={{.ViewType}}">{{..IssueStats.OpenCount}} Open</a>
- <a class="btn btn-default issue-close{{if .IsShowClosed}} active{{end}}" href="/issues?type={{.ViewType}}&state=closed">{{.IssueStats.ClosedCount}} Closed</a>
+ <a class="btn btn-default issue-open{{if not .IsShowClosed}} active{{end}}" href="/issues?type={{.ViewType}}&repoid={{.RepoId}}">Open</a>
+ <a class="btn btn-default issue-close{{if .IsShowClosed}} active{{end}}" href="/issues?type={{.ViewType}}&repoid={{.RepoId}}&state=closed">Closed</a>
</div>
</div>
<div class="issues list-group">
- {{range .Issues}}
+ {{range .Issues}}{{if .}}
<div class="list-group-item issue-item" id="issue-{{.Id}}">
<span class="number pull-right">#{{.Index}}</span>
<h5 class="title"><a href="/{{$.SignedUser.Name}}/{{.Repo.Name}}/issues/{{.Index}}">{{.Name}}</a></h5>
@@ -44,7 +44,7 @@
<span class="comment"><i class="fa fa-comments"></i> {{.NumComments}}</span>
</p>
</div>
- {{end}}
+ {{end}}{{end}}
</div>
</div>
</div>