mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-25 09:20:36 +00:00
able edit issue labels/milestone/assignee
This commit is contained in:
parent
d07c081920
commit
cec38f2a8c
12 changed files with 279 additions and 217 deletions
|
@ -457,9 +457,9 @@ func runWeb(ctx *cli.Context) {
|
|||
m.Post("", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue)
|
||||
m.Post("/label", repo.UpdateIssueLabel)
|
||||
m.Post("/milestone", repo.UpdateIssueMilestone)
|
||||
m.Post("/assignee", repo.UpdateAssignee)
|
||||
m.Post("/assignee", repo.UpdateIssueAssignee)
|
||||
m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment)
|
||||
})
|
||||
}, reqRepoAdmin)
|
||||
})
|
||||
m.Group("/labels", func() {
|
||||
m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel)
|
||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const APP_VER = "0.6.4.0814 Beta"
|
||||
const APP_VER = "0.6.5.0815 Beta"
|
||||
|
||||
func init() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
|
159
models/issue.go
159
models/issue.go
|
@ -123,13 +123,23 @@ func (i *Issue) HasLabel(labelID int64) bool {
|
|||
return i.hasLabel(x, labelID)
|
||||
}
|
||||
|
||||
func (i *Issue) addLabel(e Engine, labelID int64) error {
|
||||
return newIssueLabel(e, i.ID, labelID)
|
||||
func (i *Issue) addLabel(e *xorm.Session, label *Label) error {
|
||||
return newIssueLabel(e, i, label)
|
||||
}
|
||||
|
||||
// AddLabel adds new label to issue by given ID.
|
||||
func (i *Issue) AddLabel(labelID int64) error {
|
||||
return i.addLabel(x, labelID)
|
||||
func (i *Issue) AddLabel(label *Label) (err error) {
|
||||
sess := x.NewSession()
|
||||
defer sessionRelease(sess)
|
||||
if err = sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = i.addLabel(sess, label); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
func (i *Issue) getLabels(e Engine) (err error) {
|
||||
|
@ -149,13 +159,43 @@ func (i *Issue) GetLabels() error {
|
|||
return i.getLabels(x)
|
||||
}
|
||||
|
||||
func (i *Issue) removeLabel(e Engine, labelID int64) error {
|
||||
return deleteIssueLabel(e, i.ID, labelID)
|
||||
func (i *Issue) removeLabel(e *xorm.Session, label *Label) error {
|
||||
return deleteIssueLabel(e, i, label)
|
||||
}
|
||||
|
||||
// RemoveLabel removes a label from issue by given ID.
|
||||
func (i *Issue) RemoveLabel(labelID int64) error {
|
||||
return i.removeLabel(x, labelID)
|
||||
func (i *Issue) RemoveLabel(label *Label) (err error) {
|
||||
sess := x.NewSession()
|
||||
defer sessionRelease(sess)
|
||||
if err = sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = i.removeLabel(sess, label); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
func (i *Issue) ClearLabels() (err error) {
|
||||
sess := x.NewSession()
|
||||
defer sessionRelease(sess)
|
||||
if err = sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = i.getLabels(sess); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for idx := range i.Labels {
|
||||
if err = i.removeLabel(sess, i.Labels[idx]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
func (i *Issue) GetAssignee() (err error) {
|
||||
|
@ -257,10 +297,20 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string)
|
|||
return err
|
||||
}
|
||||
|
||||
var label *Label
|
||||
for _, id := range labelIDs {
|
||||
if err = issue.addLabel(sess, id); err != nil {
|
||||
if id == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
label, err = getLabelByID(sess, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = issue.addLabel(sess, label); err != nil {
|
||||
return fmt.Errorf("addLabel: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if issue.MilestoneID > 0 {
|
||||
|
@ -662,28 +712,30 @@ func UpdateIssueUsersByStatus(issueID int64, isClosed bool) error {
|
|||
return updateIssueUsersByStatus(x, issueID, isClosed)
|
||||
}
|
||||
|
||||
func updateIssueUserByAssignee(e *xorm.Session, issueID, assigneeID int64) (err error) {
|
||||
if _, err = e.Exec("UPDATE `issue_user` SET is_assigned=? WHERE issue_id=?", false, issueID); err != nil {
|
||||
func updateIssueUserByAssignee(e *xorm.Session, issue *Issue) (err error) {
|
||||
if _, err = e.Exec("UPDATE `issue_user` SET is_assigned=? WHERE issue_id=?", false, issue.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Assignee ID equals to 0 means clear assignee.
|
||||
if assigneeID == 0 {
|
||||
return nil
|
||||
if issue.AssigneeID > 0 {
|
||||
if _, err = e.Exec("UPDATE `issue_user` SET is_assigned=? WHERE uid=? AND issue_id=?", true, issue.AssigneeID, issue.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err = e.Exec("UPDATE `issue_user` SET is_assigned=? WHERE uid=? AND issue_id=?", true, assigneeID, issueID)
|
||||
return err
|
||||
|
||||
return updateIssue(e, issue)
|
||||
}
|
||||
|
||||
// UpdateIssueUserByAssignee updates issue-user relation for assignee.
|
||||
func UpdateIssueUserByAssignee(issueID, assigneeID int64) (err error) {
|
||||
func UpdateIssueUserByAssignee(issue *Issue) (err error) {
|
||||
sess := x.NewSession()
|
||||
defer sessionRelease(sess)
|
||||
if err = sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = updateIssueUserByAssignee(sess, issueID, assigneeID); err != nil {
|
||||
if err = updateIssueUserByAssignee(sess, issue); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -855,21 +907,34 @@ func HasIssueLabel(issueID, labelID int64) bool {
|
|||
return hasIssueLabel(x, issueID, labelID)
|
||||
}
|
||||
|
||||
func newIssueLabel(e Engine, issueID, labelID int64) error {
|
||||
if issueID == 0 || labelID == 0 {
|
||||
return nil
|
||||
func newIssueLabel(e *xorm.Session, issue *Issue, label *Label) (err error) {
|
||||
if _, err = e.Insert(&IssueLabel{
|
||||
IssueID: issue.ID,
|
||||
LabelID: label.ID,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := e.Insert(&IssueLabel{
|
||||
IssueID: issueID,
|
||||
LabelID: labelID,
|
||||
})
|
||||
return err
|
||||
label.NumIssues++
|
||||
if issue.IsClosed {
|
||||
label.NumClosedIssues++
|
||||
}
|
||||
return updateLabel(e, label)
|
||||
}
|
||||
|
||||
// NewIssueLabel creates a new issue-label relation.
|
||||
func NewIssueLabel(issueID, labelID int64) error {
|
||||
return newIssueLabel(x, issueID, labelID)
|
||||
func NewIssueLabel(issue *Issue, label *Label) (err error) {
|
||||
sess := x.NewSession()
|
||||
defer sessionRelease(sess)
|
||||
if err = sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = newIssueLabel(sess, issue, label); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
func getIssueLabels(e Engine, issueID int64) ([]*IssueLabel, error) {
|
||||
|
@ -882,17 +947,34 @@ func GetIssueLabels(issueID int64) ([]*IssueLabel, error) {
|
|||
return getIssueLabels(x, issueID)
|
||||
}
|
||||
|
||||
func deleteIssueLabel(e Engine, issueID, labelID int64) error {
|
||||
_, err := e.Delete(&IssueLabel{
|
||||
IssueID: issueID,
|
||||
LabelID: labelID,
|
||||
})
|
||||
return err
|
||||
func deleteIssueLabel(e *xorm.Session, issue *Issue, label *Label) (err error) {
|
||||
if _, err = e.Delete(&IssueLabel{
|
||||
IssueID: issue.ID,
|
||||
LabelID: label.ID,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
label.NumIssues--
|
||||
if issue.IsClosed {
|
||||
label.NumClosedIssues--
|
||||
}
|
||||
return updateLabel(e, label)
|
||||
}
|
||||
|
||||
// DeleteIssueLabel deletes issue-label relation.
|
||||
func DeleteIssueLabel(issueID, labelID int64) error {
|
||||
return deleteIssueLabel(x, issueID, labelID)
|
||||
func DeleteIssueLabel(issue *Issue, label *Label) (err error) {
|
||||
sess := x.NewSession()
|
||||
defer sessionRelease(sess)
|
||||
if err = sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = deleteIssueLabel(sess, issue, label); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
// _____ .__.__ __
|
||||
|
@ -966,7 +1048,7 @@ func NewMilestone(m *Milestone) (err error) {
|
|||
|
||||
func getMilestoneByID(e Engine, id int64) (*Milestone, error) {
|
||||
m := &Milestone{ID: id}
|
||||
has, err := x.Get(m)
|
||||
has, err := e.Get(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
|
@ -1127,7 +1209,7 @@ func changeMilestoneAssign(e *xorm.Session, oldMid int64, issue *Issue) error {
|
|||
}
|
||||
|
||||
if issue.MilestoneID > 0 {
|
||||
m, err := GetMilestoneByID(issue.MilestoneID)
|
||||
m, err := getMilestoneByID(e, issue.MilestoneID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1148,7 +1230,7 @@ func changeMilestoneAssign(e *xorm.Session, oldMid int64, issue *Issue) error {
|
|||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return updateIssue(e, issue)
|
||||
}
|
||||
|
||||
// ChangeMilestoneAssign changes assignment of milestone for issue.
|
||||
|
@ -1162,7 +1244,6 @@ func ChangeMilestoneAssign(oldMid int64, issue *Issue) (err error) {
|
|||
if err = changeMilestoneAssign(sess, oldMid, issue); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
|
|
|
@ -72,9 +72,14 @@ type RepoContext struct {
|
|||
Mirror *models.Mirror
|
||||
}
|
||||
|
||||
// Return if the current user has write access for this repository
|
||||
// IsOwner returns true if current user is the owner of repository.
|
||||
func (r RepoContext) IsOwner() bool {
|
||||
return r.AccessMode >= models.ACCESS_MODE_WRITE
|
||||
return r.AccessMode >= models.ACCESS_MODE_OWNER
|
||||
}
|
||||
|
||||
// IsAdmin returns true if current user has admin or higher access of repository.
|
||||
func (r RepoContext) IsAdmin() bool {
|
||||
return r.AccessMode >= models.ACCESS_MODE_ADMIN
|
||||
}
|
||||
|
||||
// Return if the current user has read access for this repository
|
||||
|
|
|
@ -324,8 +324,8 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
|
|||
ctx.Data["Title"] = u.Name + "/" + repo.Name
|
||||
ctx.Data["Repository"] = repo
|
||||
ctx.Data["Owner"] = ctx.Repo.Repository.Owner
|
||||
ctx.Data["IsRepositoryOwner"] = ctx.Repo.AccessMode >= models.ACCESS_MODE_WRITE
|
||||
ctx.Data["IsRepositoryAdmin"] = ctx.Repo.AccessMode >= models.ACCESS_MODE_ADMIN
|
||||
ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner()
|
||||
ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin()
|
||||
|
||||
ctx.Data["DisableSSH"] = setting.DisableSSH
|
||||
ctx.Repo.CloneLink, err = repo.CloneLink()
|
||||
|
@ -388,7 +388,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
|
|||
|
||||
func RequireRepoAdmin() macaron.Handler {
|
||||
return func(ctx *Context) {
|
||||
if ctx.Repo.AccessMode < models.ACCESS_MODE_ADMIN {
|
||||
if !ctx.Repo.IsAdmin() {
|
||||
if !ctx.IsSigned {
|
||||
ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppSubUrl+ctx.Req.RequestURI), 0, setting.AppSubUrl)
|
||||
ctx.Redirect(setting.AppSubUrl + "/user/login")
|
||||
|
|
2
public/css/gogs.min.css
vendored
2
public/css/gogs.min.css
vendored
File diff suppressed because one or more lines are too long
|
@ -26,13 +26,30 @@ function initCommentForm() {
|
|||
// Labels
|
||||
var $list = $('.ui.labels.list');
|
||||
var $no_select = $list.find('.no-select');
|
||||
$('.select-label .menu .item:not(.no-select)').click(function () {
|
||||
var $label_menu = $('.select-label .menu');
|
||||
var has_label_update_action = $label_menu.data('action') == 'update';
|
||||
|
||||
function updateIssueMeta(url, action, id) {
|
||||
$.post(url, {
|
||||
"_csrf": csrf,
|
||||
"action": action,
|
||||
"id": id
|
||||
});
|
||||
}
|
||||
|
||||
$label_menu.find('.item:not(.no-select)').click(function () {
|
||||
if ($(this).hasClass('checked')) {
|
||||
$(this).removeClass('checked')
|
||||
$(this).find('.octicon').removeClass('octicon-check')
|
||||
if (has_label_update_action) {
|
||||
updateIssueMeta($label_menu.data('update-url'), "detach", $(this).data('id'));
|
||||
}
|
||||
} else {
|
||||
$(this).addClass('checked')
|
||||
$(this).find('.octicon').addClass('octicon-check')
|
||||
if (has_label_update_action) {
|
||||
updateIssueMeta($label_menu.data('update-url'), "attach", $(this).data('id'));
|
||||
}
|
||||
}
|
||||
|
||||
var label_ids = "";
|
||||
|
@ -52,7 +69,11 @@ function initCommentForm() {
|
|||
$($(this).parent().data('id')).val(label_ids);
|
||||
return false;
|
||||
});
|
||||
$('.select-label .menu .no-select.item').click(function () {
|
||||
$label_menu.find('.no-select.item').click(function () {
|
||||
if (has_label_update_action) {
|
||||
updateIssueMeta($label_menu.data('update-url'), "clear", '');
|
||||
}
|
||||
|
||||
$(this).parent().find('.item').each(function () {
|
||||
$(this).removeClass('checked');
|
||||
$(this).find('.octicon').removeClass('octicon-check');
|
||||
|
@ -68,12 +89,17 @@ function initCommentForm() {
|
|||
function selectItem(select_id, input_id) {
|
||||
var $menu = $(select_id + ' .menu');
|
||||
var $list = $('.ui' + select_id + '.list')
|
||||
var has_update_action = $menu.data('action') == 'update';
|
||||
|
||||
$menu.find('.item:not(.no-select)').click(function () {
|
||||
$(this).parent().find('.item').each(function () {
|
||||
$(this).removeClass('selected active')
|
||||
});
|
||||
|
||||
$(this).addClass('selected active');
|
||||
if (has_update_action) {
|
||||
updateIssueMeta($menu.data('update-url'), '', $(this).data('id'));
|
||||
}
|
||||
switch (input_id) {
|
||||
case '#milestone_id':
|
||||
$list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' +
|
||||
|
@ -92,6 +118,11 @@ function initCommentForm() {
|
|||
$(this).removeClass('selected active')
|
||||
});
|
||||
|
||||
|
||||
if (has_update_action) {
|
||||
updateIssueMeta($menu.data('update-url'), '', '');
|
||||
}
|
||||
|
||||
$list.find('.selected').html('');
|
||||
$list.find('.no-select').removeClass('hide');
|
||||
$(input_id).val('');
|
||||
|
@ -235,6 +266,14 @@ function initRepository() {
|
|||
$(document).ready(function () {
|
||||
csrf = $('meta[name=_csrf]').attr("content");
|
||||
|
||||
// Show exact time
|
||||
$('.time-since').each(function () {
|
||||
$(this).addClass('poping up').
|
||||
attr('data-content', $(this).attr('title')).
|
||||
attr('data-variation', 'inverted tiny').
|
||||
attr('title', '');
|
||||
});
|
||||
|
||||
// Semantic UI modules.
|
||||
$('.dropdown').dropdown();
|
||||
$('.jump.dropdown').dropdown({
|
||||
|
|
|
@ -99,6 +99,10 @@ img {
|
|||
padding-left: 0.75rem;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.avatar.image {
|
||||
border-radius: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
footer {
|
||||
|
|
|
@ -38,9 +38,6 @@
|
|||
overflow-x: auto;
|
||||
}
|
||||
.ui.list {
|
||||
.ui.avatar.image {
|
||||
border-radius: 0;
|
||||
}
|
||||
.hide {
|
||||
display: none!important;
|
||||
}
|
||||
|
@ -116,7 +113,7 @@
|
|||
}
|
||||
}
|
||||
.assignee {
|
||||
margin-top: -10px;
|
||||
margin-top: -5px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -184,7 +184,7 @@ func NewIssue(ctx *middleware.Context) {
|
|||
ctx.Data["RequireDropzone"] = true
|
||||
renderAttachmentSettings(ctx)
|
||||
|
||||
if ctx.User.IsAdmin {
|
||||
if ctx.Repo.IsAdmin() {
|
||||
var (
|
||||
repo = ctx.Repo.Repository
|
||||
err error
|
||||
|
@ -229,7 +229,7 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
|
|||
assigneeID int64
|
||||
attachments []string
|
||||
)
|
||||
if ctx.User.IsAdmin {
|
||||
if ctx.Repo.IsAdmin() {
|
||||
// Check labels.
|
||||
labelIDs = base.StringsToInt64s(strings.Split(form.LabelIDs, ","))
|
||||
labelIDMark := base.Int64sToMap(labelIDs)
|
||||
|
@ -399,17 +399,6 @@ func UploadIssueAttachment(ctx *middleware.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
func checkLabels(labels, allLabels []*models.Label) {
|
||||
for _, l := range labels {
|
||||
for _, l2 := range allLabels {
|
||||
if l.ID == l2.ID {
|
||||
l2.IsChecked = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ViewIssue(ctx *middleware.Context) {
|
||||
ctx.Data["PageIsIssueList"] = true
|
||||
ctx.Data["RequireDropzone"] = true
|
||||
|
@ -432,11 +421,52 @@ func ViewIssue(ctx *middleware.Context) {
|
|||
}
|
||||
issue.RenderedContent = string(base.RenderMarkdown([]byte(issue.Content), ctx.Repo.RepoLink))
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
// Metas.
|
||||
// Check labels.
|
||||
if err = issue.GetLabels(); err != nil {
|
||||
ctx.Handle(500, "GetLabels", err)
|
||||
return
|
||||
}
|
||||
labelIDMark := make(map[int64]bool)
|
||||
for i := range issue.Labels {
|
||||
labelIDMark[issue.Labels[i].ID] = true
|
||||
}
|
||||
labels, err := models.GetLabelsByRepoID(repo.ID)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetLabelsByRepoID: %v", err)
|
||||
return
|
||||
}
|
||||
hasSelected := false
|
||||
for i := range labels {
|
||||
if labelIDMark[labels[i].ID] {
|
||||
labels[i].IsChecked = true
|
||||
hasSelected = true
|
||||
}
|
||||
}
|
||||
ctx.Data["HasSelectedLabel"] = hasSelected
|
||||
ctx.Data["Labels"] = labels
|
||||
|
||||
// Check milestone and assignee.
|
||||
if ctx.Repo.IsAdmin() {
|
||||
ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetMilestones: %v", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetMilestones: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Assignees"], err = repo.GetAssignees()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetAssignees: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.IsSigned {
|
||||
// Update issue-user.
|
||||
|
@ -444,39 +474,9 @@ func ViewIssue(ctx *middleware.Context) {
|
|||
ctx.Handle(500, "ReadBy", err)
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.User.IsAdmin {
|
||||
// labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID)
|
||||
// if err != nil {
|
||||
// ctx.Handle(500, "GetLabels.2", err)
|
||||
// return
|
||||
// }
|
||||
// checkLabels(issue.Labels, labels)
|
||||
// ctx.Data["Labels"] = labels
|
||||
|
||||
// // Get all milestones.
|
||||
// ctx.Data["OpenMilestones"], err = models.GetMilestones(ctx.Repo.Repository.ID, -1, false)
|
||||
// if err != nil {
|
||||
// ctx.Handle(500, "GetMilestones.1: %v", err)
|
||||
// return
|
||||
// }
|
||||
// ctx.Data["ClosedMilestones"], err = models.GetMilestones(ctx.Repo.Repository.ID, -1, true)
|
||||
// if err != nil {
|
||||
// ctx.Handle(500, "GetMilestones.2: %v", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// // Get all collaborators.
|
||||
// ctx.Data["Collaborators"], err = ctx.Repo.Repository.GetCollaborators()
|
||||
// if err != nil {
|
||||
// ctx.Handle(500, "GetCollaborators", err)
|
||||
// return
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
repo = ctx.Repo.Repository
|
||||
tag models.CommentTag
|
||||
ok bool
|
||||
marked = make(map[int64]models.CommentTag)
|
||||
|
@ -555,112 +555,68 @@ func UpdateIssue(ctx *middleware.Context, form auth.CreateIssueForm) {
|
|||
})
|
||||
}
|
||||
|
||||
func UpdateIssueLabel(ctx *middleware.Context) {
|
||||
if !ctx.Repo.IsOwner() {
|
||||
ctx.Error(403)
|
||||
return
|
||||
}
|
||||
|
||||
idx := com.StrTo(ctx.Params(":index")).MustInt64()
|
||||
if idx <= 0 {
|
||||
ctx.Error(404)
|
||||
return
|
||||
}
|
||||
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, idx)
|
||||
func getActionIssue(ctx *middleware.Context) *models.Issue {
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrIssueNotExist(err) {
|
||||
ctx.Handle(404, "issue.UpdateIssueLabel(GetIssueByIndex)", err)
|
||||
ctx.Error(404, "GetIssueByIndex")
|
||||
} else {
|
||||
ctx.Handle(500, "issue.UpdateIssueLabel(GetIssueByIndex)", err)
|
||||
ctx.Handle(500, "GetIssueByIndex", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return issue
|
||||
}
|
||||
|
||||
func UpdateIssueLabel(ctx *middleware.Context) {
|
||||
issue := getActionIssue(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
isAttach := ctx.Query("action") == "attach"
|
||||
labelStrId := ctx.Query("id")
|
||||
labelID := com.StrTo(labelStrId).MustInt64()
|
||||
label, err := models.GetLabelByID(labelID)
|
||||
if err != nil {
|
||||
if models.IsErrLabelNotExist(err) {
|
||||
ctx.Handle(404, "issue.UpdateIssueLabel(GetLabelById)", err)
|
||||
} else {
|
||||
ctx.Handle(500, "issue.UpdateIssueLabel(GetLabelById)", err)
|
||||
if ctx.Query("action") == "clear" {
|
||||
if err := issue.ClearLabels(); err != nil {
|
||||
ctx.Handle(500, "ClearLabels", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
isAttach := ctx.Query("action") == "attach"
|
||||
label, err := models.GetLabelByID(ctx.QueryInt64("id"))
|
||||
if err != nil {
|
||||
if models.IsErrLabelNotExist(err) {
|
||||
ctx.Error(404, "GetLabelByID")
|
||||
} else {
|
||||
ctx.Handle(500, "GetLabelByID", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
isNeedUpdate := false
|
||||
if isAttach {
|
||||
if !issue.HasLabel(labelID) {
|
||||
if err = issue.AddLabel(labelID); err != nil {
|
||||
if isAttach && !issue.HasLabel(label.ID) {
|
||||
if err = issue.AddLabel(label); err != nil {
|
||||
ctx.Handle(500, "AddLabel", err)
|
||||
return
|
||||
}
|
||||
isNeedUpdate = true
|
||||
}
|
||||
} else {
|
||||
if issue.HasLabel(labelID) {
|
||||
if err = issue.RemoveLabel(labelID); err != nil {
|
||||
} else if !isAttach && issue.HasLabel(label.ID) {
|
||||
if err = issue.RemoveLabel(label); err != nil {
|
||||
ctx.Handle(500, "RemoveLabel", err)
|
||||
return
|
||||
}
|
||||
isNeedUpdate = true
|
||||
}
|
||||
}
|
||||
|
||||
if isNeedUpdate {
|
||||
if err = models.UpdateIssue(issue); err != nil {
|
||||
ctx.Handle(500, "issue.UpdateIssueLabel(UpdateIssue)", err)
|
||||
return
|
||||
}
|
||||
|
||||
if isAttach {
|
||||
label.NumIssues++
|
||||
if issue.IsClosed {
|
||||
label.NumClosedIssues++
|
||||
}
|
||||
} else {
|
||||
label.NumIssues--
|
||||
if issue.IsClosed {
|
||||
label.NumClosedIssues--
|
||||
}
|
||||
}
|
||||
|
||||
if err = models.UpdateLabel(label); err != nil {
|
||||
ctx.Handle(500, "issue.UpdateIssueLabel(UpdateLabel)", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
"ok": true,
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateIssueMilestone(ctx *middleware.Context) {
|
||||
if !ctx.Repo.IsOwner() {
|
||||
ctx.Error(403)
|
||||
return
|
||||
}
|
||||
|
||||
issueId := com.StrTo(ctx.Query("issue")).MustInt64()
|
||||
if issueId == 0 {
|
||||
ctx.Error(404)
|
||||
return
|
||||
}
|
||||
|
||||
issue, err := models.GetIssueByID(issueId)
|
||||
if err != nil {
|
||||
if models.IsErrIssueNotExist(err) {
|
||||
ctx.Handle(404, "issue.UpdateIssueMilestone(GetIssueByID)", err)
|
||||
} else {
|
||||
ctx.Handle(500, "issue.UpdateIssueMilestone(GetIssueByID)", err)
|
||||
}
|
||||
issue := getActionIssue(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
oldMid := issue.MilestoneID
|
||||
mid := com.StrTo(ctx.Query("milestoneid")).MustInt64()
|
||||
mid := ctx.QueryInt64("id")
|
||||
if oldMid == mid {
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
"ok": true,
|
||||
|
@ -670,11 +626,8 @@ func UpdateIssueMilestone(ctx *middleware.Context) {
|
|||
|
||||
// Not check for invalid milestone id and give responsibility to owners.
|
||||
issue.MilestoneID = mid
|
||||
if err = models.ChangeMilestoneAssign(oldMid, issue); err != nil {
|
||||
ctx.Handle(500, "issue.UpdateIssueMilestone(ChangeMilestoneAssign)", err)
|
||||
return
|
||||
} else if err = models.UpdateIssue(issue); err != nil {
|
||||
ctx.Handle(500, "issue.UpdateIssueMilestone(UpdateIssue)", err)
|
||||
if err := models.ChangeMilestoneAssign(oldMid, issue); err != nil {
|
||||
ctx.Handle(500, "ChangeMilestoneAssign", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -683,36 +636,24 @@ func UpdateIssueMilestone(ctx *middleware.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
func UpdateAssignee(ctx *middleware.Context) {
|
||||
if !ctx.Repo.IsOwner() {
|
||||
ctx.Error(403)
|
||||
func UpdateIssueAssignee(ctx *middleware.Context) {
|
||||
issue := getActionIssue(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
issueId := com.StrTo(ctx.Query("issue")).MustInt64()
|
||||
if issueId == 0 {
|
||||
ctx.Error(404)
|
||||
aid := ctx.QueryInt64("id")
|
||||
if issue.AssigneeID == aid {
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
"ok": true,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
issue, err := models.GetIssueByID(issueId)
|
||||
if err != nil {
|
||||
if models.IsErrIssueNotExist(err) {
|
||||
ctx.Handle(404, "GetIssueByID", err)
|
||||
} else {
|
||||
ctx.Handle(500, "GetIssueByID", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
aid := com.StrTo(ctx.Query("assigneeid")).MustInt64()
|
||||
// Not check for invalid assignee id and give responsibility to owners.
|
||||
issue.AssigneeID = aid
|
||||
if err = models.UpdateIssueUserByAssignee(issue.ID, aid); err != nil {
|
||||
ctx.Handle(500, "UpdateIssueUserPairByAssignee: %v", err)
|
||||
return
|
||||
} else if err = models.UpdateIssue(issue); err != nil {
|
||||
ctx.Handle(500, "UpdateIssue", err)
|
||||
if err := models.UpdateIssueUserByAssignee(issue); err != nil {
|
||||
ctx.Handle(500, "UpdateIssueUserByAssignee: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.6.4.0814 Beta
|
||||
0.6.5.0815 Beta
|
|
@ -13,7 +13,7 @@
|
|||
{{end}}
|
||||
{{ $createdStr:= TimeSince .Issue.Created $.Lang }}
|
||||
<span class="time-desc">
|
||||
{{$.i18n.Tr "repo.issues.opened_by" $createdStr .Issue.Poster.Name|Str2html}}
|
||||
{{$.i18n.Tr "repo.issues.opened_by" $createdStr .Issue.Poster.Name | Safe}}
|
||||
·
|
||||
{{$.i18n.Tr "repo.issues.num_comments" .Issue.NumComments}}
|
||||
</span>
|
||||
|
@ -152,13 +152,12 @@
|
|||
|
||||
<div class="four wide column">
|
||||
<div class="ui segment metas">
|
||||
<input id="label_ids" name="label_ids" type="hidden" value="{{.label_ids}}">
|
||||
<div class="ui {{if not .Labels}}disabled{{end}} jump select-label dropdown">
|
||||
<div class="ui {{if not .IsRepositoryAdmin}}disabled{{end}} jump select-label dropdown">
|
||||
<span class="text">
|
||||
<strong>{{.i18n.Tr "repo.issues.new.labels"}}</strong>
|
||||
<span class="octicon octicon-gear"></span>
|
||||
</span>
|
||||
<div class="filter menu" data-id="#label_ids">
|
||||
<div class="filter menu" data-action="update" data-update-url="{{$.RepoLink}}/issues/{{$.Issue.Index}}/label">
|
||||
<div class="no-select item">{{.i18n.Tr "repo.issues.new.clear_labels"}}</div>
|
||||
{{range .Labels}}
|
||||
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}"><span class="octicon {{if .IsChecked}}octicon-check{{end}}"></span><span class="label color" style="background-color: {{.Color}}"></span> {{.Name}}</a>
|
||||
|
@ -166,24 +165,20 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="ui labels list">
|
||||
{{if not .Issue.Labels}}
|
||||
<span class="no-select item {{if .HasSelectedLabel}}hide{{end}}">{{.i18n.Tr "repo.issues.new.no_label"}}</span>
|
||||
{{else}}
|
||||
{{range .Issue.Labels}}
|
||||
<a class="item" id="label_{{.ID}}" href="{{$.RepoLink}}/issues?labels={{.ID}}"><span class="label color" style="background-color: {{.Color}}"></span> <span class="text">{{.Name}}</span></a>
|
||||
{{end}}
|
||||
{{range .Labels}}
|
||||
<a class="{{if not .IsChecked}}hide{{end}} item" id="label_{{.ID}}" href="{{$.RepoLink}}/issues?labels={{.ID}}"><span class="label color" style="background-color: {{.Color}}"></span> <span class="text">{{.Name}}</span></a>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
<div class="ui divider"></div>
|
||||
|
||||
<input id="milestone_id" name="milestone_id" type="hidden" value="{{.milestone_id}}">
|
||||
<div class="ui {{if not (or .OpenMilestones .ClosedMilestones)}}disabled{{end}} jump select-milestone dropdown">
|
||||
<div class="ui {{if not .IsRepositoryAdmin}}disabled{{end}} jump select-milestone dropdown">
|
||||
<span class="text">
|
||||
<strong>{{.i18n.Tr "repo.issues.new.milestone"}}</strong>
|
||||
<span class="octicon octicon-gear"></span>
|
||||
</span>
|
||||
<div class="menu">
|
||||
<div class="menu" data-action="update" data-update-url="{{$.RepoLink}}/issues/{{$.Issue.Index}}/milestone">
|
||||
<div class="no-select item">{{.i18n.Tr "repo.issues.new.clear_milestone"}}</div>
|
||||
{{if .OpenMilestones}}
|
||||
<div class="divider"></div>
|
||||
|
@ -219,12 +214,12 @@
|
|||
<div class="ui divider"></div>
|
||||
|
||||
<input id="assignee_id" name="assignee_id" type="hidden" value="{{.assignee_id}}">
|
||||
<div class="ui {{if not .Assignees}}disabled{{end}} jump select-assignee dropdown">
|
||||
<div class="ui {{if not .IsRepositoryAdmin}}disabled{{end}} jump select-assignee dropdown">
|
||||
<span class="text">
|
||||
<strong>{{.i18n.Tr "repo.issues.new.assignee"}}</strong>
|
||||
<span class="octicon octicon-gear"></span>
|
||||
</span>
|
||||
<div class="menu">
|
||||
<div class="menu" data-action="update" data-update-url="{{$.RepoLink}}/issues/{{$.Issue.Index}}/assignee">
|
||||
<div class="no-select item">{{.i18n.Tr "repo.issues.new.clear_assignee"}}</div>
|
||||
{{range .Assignees}}
|
||||
<div class="item" data-id="{{.Id}}" data-href="{{.HomeLink}}" data-avatar="{{.AvatarLink}}"><img src="{{.AvatarLink}}"> {{.Name}}</div>
|
||||
|
|
Loading…
Reference in a new issue