finish create issue with milestone and assignee

This commit is contained in:
Unknwon 2015-08-10 21:47:23 +08:00
parent 09a1b2a1f5
commit 75aff60c90
13 changed files with 275 additions and 206 deletions

View file

@ -376,6 +376,8 @@ issues.new.clear_milestone = Clear milestone
issues.new.open_milestone = Open Milestones issues.new.open_milestone = Open Milestones
issues.new.closed_milestone = Closed Milestones issues.new.closed_milestone = Closed Milestones
issues.new.assignee = Assignee issues.new.assignee = Assignee
issues.new.clear_assignee = Clear assignee
issues.new.no_assignee = No assignee
issues.create = Create Issue issues.create = Create Issue
issues.new_label = New Label issues.new_label = New Label
issues.new_label_placeholder = Label name... issues.new_label_placeholder = Label name...

View file

@ -17,6 +17,7 @@ import (
"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -59,10 +60,23 @@ func (i *Issue) AfterSet(colName string, _ xorm.Cell) {
var err error var err error
switch colName { switch colName {
case "milestone_id": case "milestone_id":
if i.MilestoneID == 0 {
return
}
i.Milestone, err = GetMilestoneByID(i.MilestoneID) i.Milestone, err = GetMilestoneByID(i.MilestoneID)
if err != nil { if err != nil {
log.Error(3, "GetMilestoneById: %v", err) log.Error(3, "GetMilestoneById: %v", err)
} }
case "assignee_id":
if i.AssigneeID == 0 {
return
}
i.Assignee, err = GetUserByID(i.AssigneeID)
if err != nil {
log.Error(3, "GetUserByID: %v", err)
}
} }
} }
@ -120,7 +134,7 @@ func (i *Issue) RemoveLabel(labelID int64) error {
} }
func (i *Issue) GetAssignee() (err error) { func (i *Issue) GetAssignee() (err error) {
if i.AssigneeID == 0 { if i.AssigneeID == 0 || i.Assignee != nil {
return nil return nil
} }
@ -145,7 +159,7 @@ func (i *Issue) AfterDelete() {
} }
// CreateIssue creates new issue with labels for repository. // CreateIssue creates new issue with labels for repository.
func NewIssue(issue *Issue, labelIDs []int64) (err error) { func NewIssue(repo *Repository, issue *Issue, labelIDs []int64) (err error) {
sess := x.NewSession() sess := x.NewSession()
defer sessionRelease(sess) defer sessionRelease(sess)
if err = sess.Begin(); err != nil { if err = sess.Begin(); err != nil {
@ -170,6 +184,10 @@ func NewIssue(issue *Issue, labelIDs []int64) (err error) {
} }
} }
if err = newIssueUsers(sess, repo, issue); err != nil {
return err
}
return sess.Commit() return sess.Commit()
} }
@ -221,7 +239,7 @@ func GetIssueById(id int64) (*Issue, error) {
} }
// Issues returns a list of issues by given conditions. // Issues returns a list of issues by given conditions.
func Issues(uid, assigneeID, repoID, posterID, milestoneID int64, page int, isClosed, isMention bool, labelIds, sortType string) ([]*Issue, error) { func Issues(uid, assigneeID, repoID, posterID, milestoneID int64, page int, isClosed, isMention bool, labels, sortType string) ([]*Issue, error) {
sess := x.Limit(setting.IssuePagingNum, (page-1)*setting.IssuePagingNum) sess := x.Limit(setting.IssuePagingNum, (page-1)*setting.IssuePagingNum)
if repoID > 0 { if repoID > 0 {
@ -240,14 +258,6 @@ func Issues(uid, assigneeID, repoID, posterID, milestoneID int64, page int, isCl
sess.And("issue.milestone_id=?", milestoneID) sess.And("issue.milestone_id=?", milestoneID)
} }
if len(labelIds) > 0 {
for _, label := range strings.Split(labelIds, ",") {
if com.StrTo(label).MustInt() > 0 {
sess.And("label_ids like ?", "%$"+label+"|%")
}
}
}
switch sortType { switch sortType {
case "oldest": case "oldest":
sess.Asc("created") sess.Asc("created")
@ -265,6 +275,22 @@ func Issues(uid, assigneeID, repoID, posterID, milestoneID int64, page int, isCl
sess.Desc("created") sess.Desc("created")
} }
labelIDs := base.StringsToInt64s(strings.Split(labels, ","))
if len(labelIDs) > 0 {
validJoin := false
queryStr := "issue.id=issue_label.issue_id"
for _, id := range labelIDs {
if id == 0 {
continue
}
validJoin = true
queryStr += " AND issue_label.label_id=" + com.ToStr(id)
}
if validJoin {
sess.Join("INNER", "issue_label", queryStr)
}
}
if isMention { if isMention {
queryStr := "issue.id=issue_user.issue_id AND issue_user.is_mentioned=1" queryStr := "issue.id=issue_user.issue_id AND issue_user.is_mentioned=1"
if uid > 0 { if uid > 0 {
@ -299,11 +325,11 @@ func GetIssueCountByPoster(uid, rid int64, isClosed bool) int64 {
// IssueUser represents an issue-user relation. // IssueUser represents an issue-user relation.
type IssueUser struct { type IssueUser struct {
Id int64 ID int64 `xorm:"pk autoincr"`
Uid int64 `xorm:"INDEX"` // User ID. UID int64 `xorm:"uid INDEX"` // User ID.
IssueId int64 IssueID int64
RepoId int64 `xorm:"INDEX"` RepoID int64 `xorm:"INDEX"`
MilestoneId int64 MilestoneID int64
IsRead bool IsRead bool
IsAssigned bool IsAssigned bool
IsMentioned bool IsMentioned bool
@ -312,59 +338,62 @@ type IssueUser struct {
} }
// FIXME: organization // FIXME: organization
// NewIssueUserPairs adds new issue-user pairs for new issue of repository. func newIssueUsers(e *xorm.Session, repo *Repository, issue *Issue) error {
func NewIssueUserPairs(repo *Repository, issue *Issue) error { users, err := repo.GetAssignees()
users, err := repo.GetCollaborators()
if err != nil { if err != nil {
return err return err
} }
iu := &IssueUser{ iu := &IssueUser{
IssueId: issue.ID, IssueID: issue.ID,
RepoId: repo.ID, RepoID: repo.ID,
} }
// Poster can be anyone.
isNeedAddPoster := true isNeedAddPoster := true
for _, u := range users { for _, u := range users {
iu.Id = 0 iu.ID = 0
iu.Uid = u.Id iu.UID = u.Id
iu.IsPoster = iu.Uid == issue.PosterID iu.IsPoster = iu.UID == issue.PosterID
if isNeedAddPoster && iu.IsPoster { if isNeedAddPoster && iu.IsPoster {
isNeedAddPoster = false isNeedAddPoster = false
} }
iu.IsAssigned = iu.Uid == issue.AssigneeID iu.IsAssigned = iu.UID == issue.AssigneeID
if _, err = x.Insert(iu); err != nil { if _, err = e.Insert(iu); err != nil {
return err return err
} }
} }
if isNeedAddPoster { if isNeedAddPoster {
iu.Id = 0 iu.ID = 0
iu.Uid = issue.PosterID iu.UID = issue.PosterID
iu.IsPoster = true iu.IsPoster = true
iu.IsAssigned = iu.Uid == issue.AssigneeID if _, err = e.Insert(iu); err != nil {
if _, err = x.Insert(iu); err != nil {
return err return err
} }
} }
// Add owner's as well.
if repo.OwnerID != issue.PosterID {
iu.Id = 0
iu.Uid = repo.OwnerID
iu.IsAssigned = iu.Uid == issue.AssigneeID
if _, err = x.Insert(iu); err != nil {
return err
}
}
return nil return nil
} }
// NewIssueUsers adds new issue-user relations for new issue of repository.
func NewIssueUsers(repo *Repository, issue *Issue) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err
}
if err = newIssueUsers(sess, repo, issue); err != nil {
return err
}
return sess.Commit()
}
// PairsContains returns true when pairs list contains given issue. // PairsContains returns true when pairs list contains given issue.
func PairsContains(ius []*IssueUser, issueId, uid int64) int { func PairsContains(ius []*IssueUser, issueId, uid int64) int {
for i := range ius { for i := range ius {
if ius[i].IssueId == issueId && if ius[i].IssueID == issueId &&
ius[i].Uid == uid { ius[i].UID == uid {
return i return i
} }
} }
@ -374,7 +403,7 @@ func PairsContains(ius []*IssueUser, issueId, uid int64) int {
// GetIssueUserPairs returns issue-user pairs by given repository and user. // GetIssueUserPairs returns issue-user pairs by given repository and user.
func GetIssueUserPairs(rid, uid int64, isClosed bool) ([]*IssueUser, error) { func GetIssueUserPairs(rid, uid int64, isClosed bool) ([]*IssueUser, error) {
ius := make([]*IssueUser, 0, 10) ius := make([]*IssueUser, 0, 10)
err := x.Where("is_closed=?", isClosed).Find(&ius, &IssueUser{RepoId: rid, Uid: uid}) err := x.Where("is_closed=?", isClosed).Find(&ius, &IssueUser{RepoID: rid, UID: uid})
return ius, err return ius, err
} }
@ -437,50 +466,58 @@ const (
FM_MENTION FM_MENTION
) )
func parseCountResult(results []map[string][]byte) int64 {
if len(results) == 0 {
return 0
}
for _, result := range results[0] {
return com.StrTo(string(result)).MustInt64()
}
return 0
}
// GetIssueStats returns issue statistic information by given conditions. // GetIssueStats returns issue statistic information by given conditions.
func GetIssueStats(repoID, uid, labelID, milestoneID int64, isShowClosed bool, filterMode int) *IssueStats { func GetIssueStats(repoID, uid, labelID, milestoneID int64, isShowClosed bool, filterMode int) *IssueStats {
stats := &IssueStats{} stats := &IssueStats{}
issue := new(Issue) // issue := new(Issue)
queryStr := "issue.repo_id=? AND issue.is_closed=?" queryStr := "SELECT COUNT(*) FROM `issue` "
if labelID > 0 { if labelID > 0 {
queryStr += " AND issue.label_ids like '%$" + com.ToStr(labelID) + "|%'" queryStr += "INNER JOIN `issue_label` ON `issue`.id=`issue_label`.issue_id AND `issue_label`.label_id=" + com.ToStr(labelID)
} }
baseCond := " WHERE issue.repo_id=? AND issue.is_closed=?"
if milestoneID > 0 { if milestoneID > 0 {
queryStr += " AND milestone_id=" + com.ToStr(milestoneID) baseCond += " AND issue.milestone_id=" + com.ToStr(milestoneID)
} }
switch filterMode { switch filterMode {
case FM_ALL: case FM_ALL:
stats.OpenCount, _ = x.Where(queryStr, repoID, false).Count(issue) resutls, _ := x.Query(queryStr+baseCond, repoID, false)
stats.ClosedCount, _ = x.Where(queryStr, repoID, true).Count(issue) stats.OpenCount = parseCountResult(resutls)
return stats resutls, _ = x.Query(queryStr+baseCond, repoID, true)
stats.ClosedCount = parseCountResult(resutls)
case FM_ASSIGN: case FM_ASSIGN:
queryStr += " AND assignee_id=?" baseCond += " AND assignee_id=?"
stats.OpenCount, _ = x.Where(queryStr, repoID, false, uid).Count(issue) resutls, _ := x.Query(queryStr+baseCond, repoID, false, uid)
stats.ClosedCount, _ = x.Where(queryStr, repoID, true, uid).Count(issue) stats.OpenCount = parseCountResult(resutls)
return stats resutls, _ = x.Query(queryStr+baseCond, repoID, true, uid)
stats.ClosedCount = parseCountResult(resutls)
case FM_CREATE: case FM_CREATE:
queryStr += " AND poster_id=?" baseCond += " AND poster_id=?"
stats.OpenCount, _ = x.Where(queryStr, repoID, false, uid).Count(issue) resutls, _ := x.Query(queryStr+baseCond, repoID, false, uid)
stats.ClosedCount, _ = x.Where(queryStr, repoID, true, uid).Count(issue) stats.OpenCount = parseCountResult(resutls)
return stats resutls, _ = x.Query(queryStr+baseCond, repoID, true, uid)
stats.ClosedCount = parseCountResult(resutls)
case FM_MENTION: case FM_MENTION:
queryStr += " AND uid=? AND is_mentioned=?" queryStr += " INNER JOIN `issue_user` ON `issue`.id=`issue_user`.issue_id"
if labelID > 0 { baseCond += " AND `issue_user`.uid=? AND `issue_user`.is_mentioned=?"
stats.OpenCount, _ = x.Where(queryStr, repoID, false, uid, true). resutls, _ := x.Query(queryStr+baseCond, repoID, false, uid, true)
Join("INNER", "issue", "issue.id = issue_id").Count(new(IssueUser)) stats.OpenCount = parseCountResult(resutls)
stats.ClosedCount, _ = x.Where(queryStr, repoID, true, uid, true). resutls, _ = x.Query(queryStr+baseCond, repoID, true, uid, true)
Join("INNER", "issue", "issue.id = issue_id").Count(new(IssueUser)) stats.ClosedCount = parseCountResult(resutls)
return stats
}
queryStr = strings.Replace(queryStr, "issue.", "", 2)
stats.OpenCount, _ = x.Where(queryStr, repoID, false, uid, true).Count(new(IssueUser))
stats.ClosedCount, _ = x.Where(queryStr, repoID, true, uid, true).Count(new(IssueUser))
return stats
} }
return stats return stats
} }
@ -511,22 +548,34 @@ func UpdateIssueUserPairsByStatus(iid int64, isClosed bool) error {
return err return err
} }
// UpdateIssueUserPairByAssignee updates issue-user pair for assigning. func updateIssueUserByAssignee(e *xorm.Session, issueID, assigneeID int64) (err error) {
func UpdateIssueUserPairByAssignee(aid, iid int64) error { if _, err = e.Exec("UPDATE `issue_user` SET is_assigned=? WHERE issue_id=?", false, issueID); err != nil {
rawSql := "UPDATE `issue_user` SET is_assigned = ? WHERE issue_id = ?"
if _, err := x.Exec(rawSql, false, iid); err != nil {
return err return err
} }
// Assignee ID equals to 0 means clear assignee. // Assignee ID equals to 0 means clear assignee.
if aid == 0 { if assigneeID == 0 {
return nil return nil
} }
rawSql = "UPDATE `issue_user` SET is_assigned = ? WHERE uid = ? AND issue_id = ?" _, err = e.Exec("UPDATE `issue_user` SET is_assigned=? WHERE uid=? AND issue_id=?", true, assigneeID, issueID)
_, err := x.Exec(rawSql, true, aid, iid)
return err return err
} }
// UpdateIssueUserByAssignee updates issue-user relation for assignee.
func UpdateIssueUserByAssignee(issueID, assigneeID int64) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err
}
if err = updateIssueUserByAssignee(sess, issueID, assigneeID); err != nil {
return err
}
return sess.Commit()
}
// UpdateIssueUserPairByRead updates issue-user pair for reading. // UpdateIssueUserPairByRead updates issue-user pair for reading.
func UpdateIssueUserPairByRead(uid, iid int64) error { func UpdateIssueUserPairByRead(uid, iid int64) error {
rawSql := "UPDATE `issue_user` SET is_read = ? WHERE uid = ? AND issue_id = ?" rawSql := "UPDATE `issue_user` SET is_read = ? WHERE uid = ? AND issue_id = ?"
@ -537,7 +586,7 @@ func UpdateIssueUserPairByRead(uid, iid int64) error {
// UpdateIssueUserPairsByMentions updates issue-user pairs by mentioning. // UpdateIssueUserPairsByMentions updates issue-user pairs by mentioning.
func UpdateIssueUserPairsByMentions(uids []int64, iid int64) error { func UpdateIssueUserPairsByMentions(uids []int64, iid int64) error {
for _, uid := range uids { for _, uid := range uids {
iu := &IssueUser{Uid: uid, IssueId: iid} iu := &IssueUser{UID: uid, IssueID: iid}
has, err := x.Get(iu) has, err := x.Get(iu)
if err != nil { if err != nil {
return err return err
@ -545,7 +594,7 @@ func UpdateIssueUserPairsByMentions(uids []int64, iid int64) error {
iu.IsMentioned = true iu.IsMentioned = true
if has { if has {
_, err = x.Id(iu.Id).AllCols().Update(iu) _, err = x.Id(iu.ID).AllCols().Update(iu)
} else { } else {
_, err = x.Insert(iu) _, err = x.Insert(iu)
} }

View file

@ -177,6 +177,43 @@ func (repo *Repository) GetOwner() (err error) {
return repo.getOwner(x) return repo.getOwner(x)
} }
// GetAssignees returns all users that have write access of repository.
func (repo *Repository) GetAssignees() (_ []*User, err error) {
if err = repo.GetOwner(); err != nil {
return nil, err
}
accesses := make([]*Access, 0, 10)
if err = x.Where("repo_id=? AND mode>=?", repo.ID, ACCESS_MODE_WRITE).Find(&accesses); err != nil {
return nil, err
}
users := make([]*User, 0, len(accesses)+1) // Just waste 1 unit does not matter.
if !repo.Owner.IsOrganization() {
users = append(users, repo.Owner)
}
var u *User
for i := range accesses {
u, err = GetUserByID(accesses[i].UserID)
if err != nil {
return nil, err
}
users = append(users, u)
}
return users, nil
}
// GetAssigneeByID returns the user that has write access of repository by given ID.
func (repo *Repository) GetAssigneeByID(userID int64) (*User, error) {
return GetAssigneeByID(repo, userID)
}
// GetMilestoneByID returns the milestone belongs to repository by given ID.
func (repo *Repository) GetMilestoneByID(milestoneID int64) (*Milestone, error) {
return GetRepoMilestoneByID(repo.ID, milestoneID)
}
func (repo *Repository) GetMirror() (err error) { func (repo *Repository) GetMirror() (err error) {
repo.Mirror, err = GetMirror(repo.ID) repo.Mirror, err = GetMirror(repo.ID)
return err return err
@ -876,7 +913,7 @@ func DeleteRepository(uid, repoID int64, userName string) error {
return err return err
} else if _, err = sess.Delete(&Mirror{RepoID: repoID}); err != nil { } else if _, err = sess.Delete(&Mirror{RepoID: repoID}); err != nil {
return err return err
} else if _, err = sess.Delete(&IssueUser{RepoId: repoID}); err != nil { } else if _, err = sess.Delete(&IssueUser{RepoID: repoID}); err != nil {
return err return err
} else if _, err = sess.Delete(&Milestone{RepoID: repoID}); err != nil { } else if _, err = sess.Delete(&Milestone{RepoID: repoID}); err != nil {
return err return err

View file

@ -602,6 +602,17 @@ func GetUserByID(id int64) (*User, error) {
return getUserByID(x, id) return getUserByID(x, id)
} }
// GetAssigneeByID returns the user with write access of repository by given ID.
func GetAssigneeByID(repo *Repository, userID int64) (*User, error) {
has, err := HasAccess(&User{Id: userID}, repo, ACCESS_MODE_WRITE)
if err != nil {
return nil, err
} else if !has {
return nil, ErrUserNotExist{userID, ""}
}
return GetUserByID(userID)
}
// GetUserByName returns user by given name. // GetUserByName returns user by given name.
func GetUserByName(name string) (*User, error) { func GetUserByName(name string) (*User, error) {
if len(name) == 0 { if len(name) == 0 {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -65,31 +65,44 @@ function initCommentForm() {
$($(this).parent().data('id')).val(''); $($(this).parent().data('id')).val('');
}); });
var $milestone_menu = $('.select-milestone .menu'); function selectItem(select_id, input_id) {
var $milestone_list = $('.ui.select-milestone.list') var $menu = $(select_id + ' .menu');
// Milestones var $list = $('.ui' + select_id + '.list')
$milestone_menu.find('.item:not(.no-select)').click(function () { $menu.find('.item:not(.no-select)').click(function () {
$(this).parent().find('.item').each(function () { $(this).parent().find('.item').each(function () {
$(this).removeClass('selected active') $(this).removeClass('selected active')
}); });
$(this).addClass('selected active'); $(this).addClass('selected active');
$milestone_list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' + switch (input_id) {
case '#milestone_id':
$list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' +
$(this).text() + '</a>'); $(this).text() + '</a>');
$('.ui.select-milestone.list .no-select').addClass('hide'); break;
$('#milestone_id').val($(this).data('id')); case '#assignee_id':
$list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' +
'<img class="ui avatar image" src=' + $(this).data('avatar') + '>' +
$(this).text() + '</a>');
}
$('.ui' + select_id + '.list .no-select').addClass('hide');
$(input_id).val($(this).data('id'));
}); });
$milestone_menu.find('.no-select.item').click(function () { $menu.find('.no-select.item').click(function () {
$(this).parent().find('.item:not(.no-select)').each(function () { $(this).parent().find('.item:not(.no-select)').each(function () {
$(this).removeClass('selected active') $(this).removeClass('selected active')
}); });
$milestone_list.find('.selected').html(''); $list.find('.selected').html('');
$milestone_list.find('.no-select').removeClass('hide'); $list.find('.no-select').removeClass('hide');
$('#milestone_id').val(''); $(input_id).val('');
}); });
} }
// Milestone and assignee
selectItem('.select-milestone', '#milestone_id');
selectItem('.select-assignee', '#assignee_id');
}
function initInstall() { function initInstall() {
if ($('.install').length == 0) { if ($('.install').length == 0) {
return; return;

View file

@ -35,6 +35,9 @@
overflow-x: auto; overflow-x: auto;
} }
.ui.list { .ui.list {
.ui.avatar.image {
border-radius: 0;
}
.hide { .hide {
display: none!important; display: none!important;
} }
@ -109,6 +112,9 @@
color: #000!important; color: #000!important;
} }
} }
.assignee {
margin-top: -5px;
}
} }
} }
} }

View file

@ -202,17 +202,12 @@ func NewIssue(ctx *middleware.Context) {
return return
} }
// ctx.Data["AssigneeID"] = 0 ctx.Data["Assignees"], err = repo.GetAssignees()
// ctx.Data["Assignees"], err = repo.GetCollaborators() if err != nil {
ctx.Handle(500, "GetAssignees: %v", err)
return
}
} }
// us, err := repo.GetCollaborators()
// if err != nil {
// ctx.Handle(500, "GetCollaborators", err)
// return
// }
// ctx.Data["Collaborators"] = us
ctx.HTML(200, ISSUE_NEW) ctx.HTML(200, ISSUE_NEW)
} }
@ -227,6 +222,7 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
repo = ctx.Repo.Repository repo = ctx.Repo.Repository
labelIDs []int64 labelIDs []int64
milestoneID int64 milestoneID int64
assigneeID int64
) )
if ctx.User.IsAdmin { if ctx.User.IsAdmin {
// Check labels. // Check labels.
@ -260,12 +256,26 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
ctx.Handle(500, "GetMilestones: %v", err) ctx.Handle(500, "GetMilestones: %v", err)
return return
} }
ctx.Data["Milestone"], err = models.GetRepoMilestoneByID(repo.ID, milestoneID) ctx.Data["Milestone"], err = repo.GetMilestoneByID(milestoneID)
if err != nil { if err != nil {
ctx.Handle(500, "GetRepoMilestoneByID: %v", err) ctx.Handle(500, "GetMilestoneByID: %v", err)
return return
} }
ctx.Data["milestone_id"] = milestoneID ctx.Data["milestone_id"] = milestoneID
// Check assignee.
assigneeID = form.AssigneeID
ctx.Data["Assignees"], err = repo.GetAssignees()
if err != nil {
ctx.Handle(500, "GetAssignees: %v", err)
return
}
ctx.Data["Assignee"], err = repo.GetAssigneeByID(assigneeID)
if err != nil {
ctx.Handle(500, "GetAssigneeByID: %v", err)
return
}
ctx.Data["assignee_id"] = assigneeID
} }
if ctx.HasError() { if ctx.HasError() {
@ -279,13 +289,10 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
Name: form.Title, Name: form.Title,
PosterID: ctx.User.Id, PosterID: ctx.User.Id,
MilestoneID: milestoneID, MilestoneID: milestoneID,
// AssigneeID: form.AssigneeID, AssigneeID: assigneeID,
Content: form.Content, Content: form.Content,
} }
if err := models.NewIssue(issue, labelIDs); err != nil { if err := models.NewIssue(repo, issue, labelIDs); err != nil {
ctx.Handle(500, "NewIssue", err)
return
} else if err := models.NewIssueUserPairs(repo, issue); err != nil {
ctx.Handle(500, "NewIssue", err) ctx.Handle(500, "NewIssue", err)
return return
} }
@ -294,71 +301,6 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
} }
func CreateIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) { func CreateIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
// send := func(status int, data interface{}, err error) {
// if err != nil {
// log.Error(4, "issue.CreateIssuePost(?): %s", err)
// ctx.JSON(status, map[string]interface{}{
// "ok": false,
// "status": status,
// "error": err.Error(),
// })
// } else {
// ctx.JSON(status, map[string]interface{}{
// "ok": true,
// "status": status,
// "data": data,
// })
// }
// }
// var err error
// // Get all milestones.
// _, err = models.GetMilestones(ctx.Repo.Repository.ID, -1, false)
// if err != nil {
// send(500, nil, err)
// return
// }
// _, err = models.GetMilestones(ctx.Repo.Repository.ID, -1, true)
// if err != nil {
// send(500, nil, err)
// return
// }
// _, err = ctx.Repo.Repository.GetCollaborators()
// if err != nil {
// send(500, nil, err)
// return
// }
// if ctx.HasError() {
// send(400, nil, errors.New(ctx.Flash.ErrorMsg))
// return
// }
// // Only collaborators can assign.
// if !ctx.Repo.IsOwner() {
// form.AssigneeId = 0
// }
// issue := &models.Issue{
// RepoID: ctx.Repo.Repository.ID,
// Index: int64(ctx.Repo.Repository.NumIssues) + 1,
// Name: form.IssueName,
// PosterID: ctx.User.Id,
// MilestoneID: form.MilestoneId,
// AssigneeID: form.AssigneeId,
// LabelIds: form.Labels,
// Content: form.Content,
// }
// if err := models.NewIssue(issue); err != nil {
// send(500, nil, err)
// return
// } else if err := models.NewIssueUserPairs(ctx.Repo.Repository, issue.ID, ctx.Repo.Owner.Id,
// ctx.User.Id, form.AssigneeId); err != nil {
// send(500, nil, err)
// return
// }
// if setting.AttachmentEnabled { // if setting.AttachmentEnabled {
// uploadFiles(ctx, issue.ID, 0) // uploadFiles(ctx, issue.ID, 0)
// } // }
@ -743,7 +685,7 @@ func UpdateAssignee(ctx *middleware.Context) {
aid := com.StrTo(ctx.Query("assigneeid")).MustInt64() aid := com.StrTo(ctx.Query("assigneeid")).MustInt64()
// Not check for invalid assignee id and give responsibility to owners. // Not check for invalid assignee id and give responsibility to owners.
issue.AssigneeID = aid issue.AssigneeID = aid
if err = models.UpdateIssueUserPairByAssignee(aid, issue.ID); err != nil { if err = models.UpdateIssueUserByAssignee(issue.ID, aid); err != nil {
ctx.Handle(500, "UpdateIssueUserPairByAssignee: %v", err) ctx.Handle(500, "UpdateIssueUserPairByAssignee: %v", err)
return return
} else if err = models.UpdateIssue(issue); err != nil { } else if err = models.UpdateIssue(issue); err != nil {

View file

@ -339,13 +339,13 @@ func Issues(ctx *middleware.Context) {
issues := make([]*models.Issue, len(ius)) issues := make([]*models.Issue, len(ius))
for i := range ius { for i := range ius {
issues[i], err = models.GetIssueById(ius[i].IssueId) issues[i], err = models.GetIssueById(ius[i].IssueID)
if err != nil { if err != nil {
if err == models.ErrIssueNotExist { if err == models.ErrIssueNotExist {
log.Warn("user.Issues(GetIssueById #%d): issue not exist", ius[i].IssueId) log.Warn("user.Issues(GetIssueById #%d): issue not exist", ius[i].IssueID)
continue continue
} else { } else {
ctx.Handle(500, fmt.Sprintf("user.Issues(GetIssueById #%d)", ius[i].IssueId), err) ctx.Handle(500, fmt.Sprintf("user.Issues(GetIssueById #%d)", ius[i].IssueID), err)
return return
} }
} }

View file

@ -87,11 +87,14 @@
<p class="desc"> <p class="desc">
{{$.i18n.Tr "repo.issues.opened_by" $timeStr .Poster.Name|Str2html}} {{$.i18n.Tr "repo.issues.opened_by" $timeStr .Poster.Name|Str2html}}
{{if .Milestone}} {{if .Milestone}}
{{with .Milestone}} <a class="milestone" href="{{$.RepoLink}}/issues?type={{$.ViewType}}&state={{$.State}}&labels={{$.SelectLabels}}&milestone={{.Milestone.ID}}">
<a class="milestone" href="{{$.RepoLink}}/issues?type={{$.ViewType}}&state={{$.State}}&labels={{$.SelectLabels}}&milestone={{.ID}}"> <span class="octicon octicon-milestone"></span> {{.Milestone.Name}}
<span class="octicon octicon-milestone"></span> {{.Name}}
</a> </a>
{{end}} {{end}}
{{if .Assignee}}
<a class="ui right assignee poping up" href="{{.Assignee.HomeLink}}" data-content="{{.Assignee.Name}}" data-variation="inverted" data-position="left center">
<img class="ui avatar image" src="{{.Assignee.AvatarLink}}">
</a>
{{end}} {{end}}
</p> </p>
</li> </li>

View file

@ -101,23 +101,29 @@
</div> </div>
</div> </div>
<!-- <div class="ui divider"></div> <div class="ui divider"></div>
<div class="ui {{if not .Assignees}}disabled{{end}} dropdown jump item"> <input id="assignee_id" name="assignee_id" type="hidden" value="{{.assignee_id}}">
<div class="ui {{if not .Assignees}}disabled{{end}} jump select-assignee dropdown">
<span class="text"> <span class="text">
<strong>{{.i18n.Tr "repo.issues.new.assignee"}}</strong> <strong>{{.i18n.Tr "repo.issues.new.assignee"}}</strong>
<span class="octicon octicon-gear"></span> <span class="octicon octicon-gear"></span>
</span> </span>
<div class="menu"> <div class="menu">
<div class="item">{{.i18n.Tr "repo.issues.new.clear_assignee"}}</a> <div class="no-select item">{{.i18n.Tr "repo.issues.new.clear_assignee"}}</div>
{{range .Assignees}} {{range .Assignees}}
<a class="item" href="#"><span class="octicon {{if eq .ID $.AssigneeID}}octicon-check{{end}}"></span> {{.Name}}</a> <div class="item" data-id="{{.Id}}" data-href="{{.HomeLink}}" data-avatar="{{.AvatarLink}}"><img src="{{.AvatarLink}}"> {{.Name}}</div>
{{end}}
</div>
</div>
<div class="ui select-assignee list">
<span class="no-select item {{if .Assignee}}hide{{end}}">{{.i18n.Tr "repo.issues.new.no_assignee"}}</span>
<div class="selected">
{{if .Assignee}}
<a class="item" href="{{.Assignee.HomeLink}}"><img class="ui avatar image" src="{{.Assignee.AvatarLink}}"> {{.Assignee.Name}}</a>
{{end}} {{end}}
</div> </div>
</div> </div>
<div class="ui list">
<span class="item">filter_label_no_select</span>
</div> -->
</div> </div>
</div> </div>
{{end}} {{end}}

View file

@ -12,7 +12,7 @@
<li><a href="{{AppSubUrl}}/issues?type=created_by&repoid={{.RepoId}}&state={{.State}}" class="radius{{if eq .ViewType "created_by"}} active{{end}}">Created by you <strong class="pull-right">{{.IssueStats.CreateCount}}</strong></a></li> <li><a href="{{AppSubUrl}}/issues?type=created_by&repoid={{.RepoId}}&state={{.State}}" class="radius{{if eq .ViewType "created_by"}} active{{end}}">Created by you <strong class="pull-right">{{.IssueStats.CreateCount}}</strong></a></li>
<li><hr/></li> <li><hr/></li>
{{range .Repos}} {{range .Repos}}
<li><a href="{{AppSubUrl}}/issues?type={{$.ViewType}}{{if eq $.RepoId .Id}}{{else}}&repoid={{.Id}}{{end}}&state={{$.State}}" class="radius{{if eq $.RepoId .Id}} active{{end}}">{{$.SignedUser.Name}}/{{.Name}} <strong class="pull-right">{{if $.IsShowClosed}}{{.NumClosedIssues}}{{else}}{{.NumOpenIssues}}{{end}}</strong></a></li> <li><a href="{{AppSubUrl}}/issues?type={{$.ViewType}}{{if eq $.RepoId .ID}}{{else}}&repoid={{.ID}}{{end}}&state={{$.State}}" class="radius{{if eq $.RepoId .ID}} active{{end}}">{{$.SignedUser.Name}}/{{.Name}} <strong class="pull-right">{{if $.IsShowClosed}}{{.NumClosedIssues}}{{else}}{{.NumOpenIssues}}{{end}}</strong></a></li>
{{end}} {{end}}
</ul> </ul>
</div> </div>