Merge pull request #299 from nuss-justin/issue/216

Fix #216. Change milestones, labels and assigne without reloading the page
tokarchuk/v1.17
无闻 10 years ago
commit 94b100ce43
  1. 6
      models/issue.go
  2. 55
      public/js/app.js

@ -19,6 +19,7 @@ var (
ErrIssueNotExist = errors.New("Issue does not exist") ErrIssueNotExist = errors.New("Issue does not exist")
ErrLabelNotExist = errors.New("Label does not exist") ErrLabelNotExist = errors.New("Label does not exist")
ErrMilestoneNotExist = errors.New("Milestone does not exist") ErrMilestoneNotExist = errors.New("Milestone does not exist")
ErrWrongIssueCounter = errors.New("Invalid number of issues for this milestone")
) )
// Issue represents an issue or pull request of repository. // Issue represents an issue or pull request of repository.
@ -713,6 +714,11 @@ func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) {
if issue.IsClosed { if issue.IsClosed {
m.NumClosedIssues++ m.NumClosedIssues++
} }
if m.NumIssues == 0 {
return ErrWrongIssueCounter
}
m.Completeness = m.NumClosedIssues * 100 / m.NumIssues m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
if _, err = sess.Id(m.Id).Update(m); err != nil { if _, err = sess.Id(m.Id).Update(m); err != nil {
sess.Rollback() sess.Rollback()

@ -577,15 +577,28 @@ function initIssue() {
if (is_issue_bar) { if (is_issue_bar) {
var assignee = $a.data("assigned"); var assignee = $a.data("assigned");
if (uid != assignee) { if (uid != assignee) {
var text = $(this).text();
var img = $("img", this).attr("src");
$.post($a.data("ajax"), { $.post($a.data("ajax"), {
issue: $('#issue').data("id"), issue: $('#issue').data("id"),
assigneeid: uid assigneeid: uid
}, function (json) { }, function (json) {
if (json.ok) { if (json.ok) {
window.location.reload(); //window.location.reload();
$a.data("assigned", uid);
if (uid > 0) {
$('.clear-assignee').toggleShow();
$(".assignee > p").html('<img src="' + img + '"><strong>' + text + '</strong>');
} else {
$('.clear-assignee').toggleHide();
$(".assignee > p").text("No one assigned");
}
} }
}) })
} }
return; return;
} }
$('#assignee').val(uid); $('#assignee').val(uid);
@ -615,20 +628,27 @@ function initIssue() {
if (is_issue_bar) { if (is_issue_bar) {
var m = $m.data("milestone"); var m = $m.data("milestone");
if (id != m) { if (id != m) {
var text = $(this).text();
$.post($m.data("ajax"), { $.post($m.data("ajax"), {
issue: $('#issue').data("id"), issue: $('#issue').data("id"),
milestone: id milestone: id
}, function (json) { }, function (json) {
if (json.ok) { if (json.ok) {
window.location.reload(); //window.location.reload();
$m.data("milestone", id);
if (id > 0) { if (id > 0) {
$('.clear-milestone').toggleShow(); $('.clear-milestone').toggleShow();
$(".milestone > .name").html('<a href="' + location.pathname + '?milestone=' + id + '"><strong>' + text + '</strong></a>');
} else { } else {
$('.clear-milestone').toggleHide(); $('.clear-milestone').toggleHide();
$(".milestone > .name").text("No milestone");
} }
} }
}) });
} }
return; return;
} }
$('#milestone-id').val(id); $('#milestone-id').val(id);
@ -708,13 +728,38 @@ function initIssue() {
var color = $item.find('.color').data('color'); var color = $item.find('.color').data('color');
$item.css('background-color', color); $item.css('background-color', color);
}); });
$('.issue-bar .labels .dropdown-menu').on('click', 'li', function (e) { $('.issue-bar .labels .dropdown-menu').on('click', 'li', function (e) {
var url = $('.issue-bar .labels').data("ajax"); var $labels = $('.issue-bar .labels');
var url = $labels.data("ajax");
var id = $(this).data('id'); var id = $(this).data('id');
var check = $(this).hasClass("checked"); var check = $(this).hasClass("checked");
var item = this;
$.post(url, {id: id, action: check ? 'detach' : "attach", issue: $('#issue').data('id')}, function (json) { $.post(url, {id: id, action: check ? 'detach' : "attach", issue: $('#issue').data('id')}, function (json) {
if (json.ok) { if (json.ok) {
window.location.reload(); if (check) {
$("span.check.pull-left", item).remove();
$(item).removeClass("checked");
$(item).addClass("no-checked");
$("#label-" + id, $labels).remove();
} else {
$(item).prepend('<span class="check pull-left"><i class="fa fa-check"></i></span>');
$(item).removeClass("no-checked");
$(item).addClass("checked");
var $l = $("<p></p>");
var c = $("span.color", item).css("background-color");
$l.attr("id", "label-" + id);
$l.attr("class", "label-item label-white");
$l.css("background-color", c);
$l.append("<strong>" + $(item).text() + "</strong>");
$labels.append($l);
}
} }
}); });
e.stopPropagation(); e.stopPropagation();

Loading…
Cancel
Save