From ed73af6fa1d4ab8ae880be5381849cab2b6f7640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Justin=20Nu=C3=9F?= Date: Tue, 22 Jul 2014 15:46:15 +0200 Subject: [PATCH 1/2] Fix #216. Change milestones, labels and assigne without reloading the page --- public/js/app.js | 59 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 4c376ea08..3d154e1f7 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -575,15 +575,28 @@ function initIssue() { if (is_issue_bar) { var assignee = $a.data("assigned"); if (uid != assignee) { + var text = $(this).text(); + var img = $("img", this).attr("src"); + $.post($a.data("ajax"), { issue: $('#issue').data("id"), assigneeid: uid }, function (json) { if (json.ok) { - window.location.reload(); + //window.location.reload(); + $a.data("assigned", uid); + + if (uid > 0) { + $('.clear-assignee').toggleShow(); + $(".assignee > p").html('' + text + ''); + } else { + $('.clear-assignee').toggleHide(); + $(".assignee > p").text("No one assigned"); + } } }) } + return; } $('#assignee').val(uid); @@ -609,24 +622,31 @@ function initIssue() { $('.clear-milestone').toggleShow(); } $('.milestone', '#issue').on('click', 'li.milestone-item', function () { - var id = $(this).data("id"); + var id = $(this).data("id"); if (is_issue_bar) { var m = $m.data("milestone"); if (id != m) { + var text = $(this).text(); + $.post($m.data("ajax"), { issue: $('#issue').data("id"), milestone: id }, function (json) { if (json.ok) { - window.location.reload(); - if (id > 0) { + //window.location.reload(); + $m.data("milestone", id); + + if (id > 0) { $('.clear-milestone').toggleShow(); + $(".milestone > .name").html('' + text + ''); } else { $('.clear-milestone').toggleHide(); + $(".milestone > .name").text("No milestone"); } } - }) + }); } + return; } $('#milestone-id').val(id); @@ -706,13 +726,38 @@ function initIssue() { var color = $item.find('.color').data('color'); $item.css('background-color', color); }); + $('.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 check = $(this).hasClass("checked"); + var item = this; $.post(url, {id: id, action: check ? 'detach' : "attach", issue: $('#issue').data('id')}, function (json) { 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(''); + + $(item).removeClass("no-checked"); + $(item).addClass("checked"); + + var $l = $("

"); + 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("" + $(item).text() + ""); + $labels.append($l); + } } }); e.stopPropagation(); From 0d06c7e5f2f8239383a3727c69ef938d12c037e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Justin=20Nu=C3=9F?= Date: Tue, 22 Jul 2014 20:57:48 +0200 Subject: [PATCH 2/2] Prevent panic when dividing through zero --- models/issue.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/models/issue.go b/models/issue.go index baf710a5e..8b2d57cd2 100644 --- a/models/issue.go +++ b/models/issue.go @@ -19,6 +19,7 @@ var ( ErrIssueNotExist = errors.New("Issue does not exist") ErrLabelNotExist = errors.New("Label 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. @@ -703,6 +704,11 @@ func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) { if issue.IsClosed { m.NumClosedIssues++ } + + if m.NumIssues == 0 { + return ErrWrongIssueCounter + } + m.Completeness = m.NumClosedIssues * 100 / m.NumIssues if _, err = sess.Id(m.Id).Update(m); err != nil { sess.Rollback()