finish create issue with milestone

pull/197/head
Unknwon 9 years ago
parent 922f3f3062
commit 09a1b2a1f5
  1. 6
      conf/locale/locale_en-US.ini
  2. 5
      models/error.go
  3. 94
      models/issue.go
  4. 4
      modules/bindata/bindata.go
  5. 2
      public/css/gogs.min.css
  6. 149
      public/js/gogs.js
  7. 2
      public/less/_base.less
  8. 31
      public/less/_repository.less
  9. 62
      routers/repo/issue.go
  10. 55
      templates/repo/issue/new_form.tmpl

@ -368,10 +368,14 @@ commits.newer = Newer
issues.new = New Issue
issues.new.labels = Labels
issues.new.no_label = No Label
issues.new.clear_labels = Clear labels
issues.new.milestone = Milestone
issues.new.no_milestone = No Milestone
issues.new.clear_milestone = Clear milestone
issues.new.open_milestone = Open Milestones
issues.new.closed_milestone = Closed Milestones
issues.new.assignee = Assignee
issues.new.no_label = No Label
issues.create = Create Issue
issues.new_label = New Label
issues.new_label_placeholder = Label name...

@ -267,7 +267,8 @@ func (err ErrLabelNotExist) Error() string {
// \/ \/ \/ \/ \/
type ErrMilestoneNotExist struct {
ID int64
ID int64
RepoID int64
}
func IsErrMilestoneNotExist(err error) bool {
@ -276,5 +277,5 @@ func IsErrMilestoneNotExist(err error) bool {
}
func (err ErrMilestoneNotExist) Error() string {
return fmt.Sprintf("milestone does not exist [id: %d]", err.ID)
return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
}

@ -164,16 +164,13 @@ func NewIssue(issue *Issue, labelIDs []int64) (err error) {
}
}
if err = sess.Commit(); err != nil {
return err
}
if issue.MilestoneID > 0 {
// FIXES(280): Update milestone counter.
return ChangeMilestoneAssign(0, issue.MilestoneID, issue)
if err = changeMilestoneAssign(sess, 0, issue); err != nil {
return err
}
}
return
return sess.Commit()
}
// GetIssueByRef returns an Issue specified by a GFM reference.
@ -497,15 +494,14 @@ func GetUserIssueStats(uid int64, filterMode int) *IssueStats {
return stats
}
func updateIssue(e Engine, issue *Issue) error {
_, err := e.Id(issue.ID).AllCols().Update(issue)
return err
}
// UpdateIssue updates information of issue.
func UpdateIssue(issue *Issue) error {
_, err := x.Id(issue.ID).AllCols().Update(issue)
if err != nil {
return err
}
return err
return updateIssue(x, issue)
}
// UpdateIssueUserByStatus updates issue-user pairs by issue status.
@ -712,7 +708,7 @@ func NewIssueLabel(issueID, labelID int64) error {
func getIssueLabels(e Engine, issueID int64) ([]*IssueLabel, error) {
issueLabels := make([]*IssueLabel, 0, 10)
return issueLabels, e.Where("issue_id=?", issueID).Find(&issueLabels)
return issueLabels, e.Where("issue_id=?", issueID).Asc("label_id").Find(&issueLabels)
}
// GetIssueLabels returns all issue-label relations of given issue by ID.
@ -802,14 +798,30 @@ func NewMilestone(m *Milestone) (err error) {
return sess.Commit()
}
func getMilestoneByID(e Engine, id int64) (*Milestone, error) {
m := &Milestone{ID: id}
has, err := x.Get(m)
if err != nil {
return nil, err
} else if !has {
return nil, ErrMilestoneNotExist{id, 0}
}
return m, nil
}
// GetMilestoneByID returns the milestone of given ID.
func GetMilestoneByID(id int64) (*Milestone, error) {
m := &Milestone{ID: id}
return getMilestoneByID(x, id)
}
// GetRepoMilestoneByID returns the milestone of given ID and repository.
func GetRepoMilestoneByID(repoID, milestoneID int64) (*Milestone, error) {
m := &Milestone{ID: milestoneID, RepoID: repoID}
has, err := x.Get(m)
if err != nil {
return nil, err
} else if !has {
return nil, ErrMilestoneNotExist{id}
return nil, ErrMilestoneNotExist{milestoneID, repoID}
}
return m, nil
}
@ -915,16 +927,9 @@ func ChangeMilestoneIssueStats(issue *Issue) error {
return UpdateMilestone(m)
}
// ChangeMilestoneAssign changes assignment of milestone for issue.
func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) {
sess := x.NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
func changeMilestoneAssign(e *xorm.Session, oldMid int64, issue *Issue) error {
if oldMid > 0 {
m, err := GetMilestoneByID(oldMid)
m, err := getMilestoneByID(e, oldMid)
if err != nil {
return err
}
@ -934,20 +939,15 @@ func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) {
m.NumClosedIssues--
}
if _, err = sess.Id(m.ID).AllCols().Update(m); err != nil {
sess.Rollback()
if err = updateMilestone(e, m); err != nil {
return err
}
rawSql := "UPDATE `issue_user` SET milestone_id = 0 WHERE issue_id = ?"
if _, err = sess.Exec(rawSql, issue.ID); err != nil {
sess.Rollback()
} else if _, err = e.Exec("UPDATE `issue_user` SET milestone_id=0 WHERE issue_id=?", issue.ID); err != nil {
return err
}
}
if mid > 0 {
m, err := GetMilestoneByID(mid)
if issue.MilestoneID > 0 {
m, err := GetMilestoneByID(issue.MilestoneID)
if err != nil {
return err
}
@ -961,18 +961,28 @@ func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) {
return ErrWrongIssueCounter
}
if _, err = sess.Id(m.ID).AllCols().Update(m); err != nil {
sess.Rollback()
if err = updateMilestone(e, m); err != nil {
return err
}
rawSql := "UPDATE `issue_user` SET milestone_id = ? WHERE issue_id = ?"
if _, err = sess.Exec(rawSql, m.ID, issue.ID); err != nil {
sess.Rollback()
} else if _, err = e.Exec("UPDATE `issue_user` SET milestone_id=? WHERE issue_id=?", m.ID, issue.ID); err != nil {
return err
}
}
return nil
}
// ChangeMilestoneAssign changes assignment of milestone for issue.
func ChangeMilestoneAssign(oldMid int64, issue *Issue) (err error) {
sess := x.NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
if err = changeMilestoneAssign(sess, oldMid, issue); err != nil {
return err
}
return sess.Commit()
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -2,6 +2,94 @@
var csrf;
function initCommentForm() {
if ($('.comment.form').length == 0) {
return
}
var $form = $('.comment.form');
$form.find('.tabular.menu .item').tab();
$form.find('.tabular.menu .item[data-tab="preview"]').click(function () {
var $this = $(this);
$.post($this.data('url'), {
"_csrf": csrf,
"mode": "gfm",
"context": $this.data('context'),
"text": $form.find('.tab.segment[data-tab="write"] textarea').val()
},
function (data) {
$form.find('.tab.segment[data-tab="preview"]').html(data);
}
);
});
// Labels
var $list = $('.ui.labels.list');
var $no_select = $list.find('.no-select');
$('.select-label .menu .item:not(.no-select)').click(function () {
if ($(this).hasClass('checked')) {
$(this).removeClass('checked')
$(this).find('.octicon').removeClass('octicon-check')
} else {
$(this).addClass('checked')
$(this).find('.octicon').addClass('octicon-check')
}
var label_ids = "";
$(this).parent().find('.item').each(function () {
if ($(this).hasClass('checked')) {
label_ids += $(this).data('id') + ",";
$($(this).data('id-selector')).removeClass('hide');
} else {
$($(this).data('id-selector')).addClass('hide');
}
});
if (label_ids.length == 0) {
$no_select.removeClass('hide');
} else {
$no_select.addClass('hide');
}
$($(this).parent().data('id')).val(label_ids);
return false;
});
$('.select-label .menu .no-select.item').click(function () {
$(this).parent().find('.item').each(function () {
$(this).removeClass('checked');
$(this).find('.octicon').removeClass('octicon-check');
});
$list.find('.item').each(function () {
$(this).addClass('hide');
});
$no_select.removeClass('hide');
$($(this).parent().data('id')).val('');
});
var $milestone_menu = $('.select-milestone .menu');
var $milestone_list = $('.ui.select-milestone.list')
// Milestones
$milestone_menu.find('.item:not(.no-select)').click(function () {
$(this).parent().find('.item').each(function () {
$(this).removeClass('selected active')
});
$(this).addClass('selected active');
$milestone_list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' +
$(this).text() + '</a>');
$('.ui.select-milestone.list .no-select').addClass('hide');
$('#milestone_id').val($(this).data('id'));
});
$milestone_menu.find('.no-select.item').click(function () {
$(this).parent().find('.item:not(.no-select)').each(function () {
$(this).removeClass('selected active')
});
$milestone_list.find('.selected').html('');
$milestone_list.find('.no-select').removeClass('hide');
$('#milestone_id').val('');
});
}
function initInstall() {
if ($('.install').length == 0) {
return;
@ -133,66 +221,6 @@ $(document).ready(function () {
});
$('.poping.up').popup();
// Comment form
if ($('.comment.form').length > 0) {
var $form = $(this);
$form.find('.tabular.menu .item').tab();
$form.find('.tabular.menu .item[data-tab="preview"]').click(function () {
var $this = $(this);
$.post($this.data('url'), {
"_csrf": csrf,
"mode": "gfm",
"context": $this.data('context'),
"text": $form.find('.tab.segment[data-tab="write"] textarea').val()
},
function (data) {
$form.find('.tab.segment[data-tab="preview"]').html(data);
}
);
});
// Labels
var $list = $('.ui.labels.list');
var $no_select = $list.find('.no-select');
$('.select-label .item:not(.no-select)').click(function () {
if ($(this).hasClass('checked')) {
$(this).removeClass('checked')
$(this).find('.octicon').removeClass('octicon-check')
} else {
$(this).addClass('checked')
$(this).find('.octicon').addClass('octicon-check')
}
var label_ids = "";
$(this).parent().find('.item').each(function () {
if ($(this).hasClass('checked')) {
label_ids += $(this).data('id') + ",";
$($(this).data('id-selector')).removeClass('hide');
} else {
$($(this).data('id-selector')).addClass('hide');
}
});
if (label_ids.length == 0) {
$no_select.removeClass('hide');
} else {
$no_select.addClass('hide');
}
$($(this).parent().data('id')).val(label_ids);
return false;
});
$('.select-label .no-select.item').click(function () {
$(this).parent().find('.item').each(function () {
$(this).removeClass('checked');
$(this).find('.octicon').removeClass('octicon-check');
});
$list.find('.item').each(function () {
$(this).addClass('hide');
});
$no_select.removeClass('hide');
$($(this).parent().data('id')).val('');
});
}
// Helpers.
$('.delete-button').click(function () {
@ -211,6 +239,7 @@ $(document).ready(function () {
return false;
});
initCommentForm();
initInstall();
initRepository();
});

@ -102,7 +102,7 @@ footer {
}
.hide {
display: none!important;
display: none;
}
.center {
text-align: center;

@ -29,18 +29,27 @@
font-weight: bold;
}
}
.metas .ui.list {
.label.color {
padding: 0 8px;
margin-right: 5px;
.metas {
.menu {
max-height: 300px;
overflow-x: auto;
}
a {
padding-top: 5px;
padding-right: 10px;
.text {
color: #444;
&:hover {
color: #000;
.ui.list {
.hide {
display: none!important;
}
.label.color {
padding: 0 8px;
margin-right: 5px;
}
a {
padding-top: 5px;
padding-right: 10px;
.text {
color: #444;
&:hover {
color: #000;
}
}
}
}

@ -190,19 +190,21 @@ func NewIssue(ctx *middleware.Context) {
ctx.Handle(500, "GetLabelsByRepoID: %v", err)
return
}
}
// // Get all milestones.
// ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false)
// if err != nil {
// ctx.Handle(500, "GetMilestones.1: %v", err)
// return
// }
// ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true)
// if err != nil {
// ctx.Handle(500, "GetMilestones.2: %v", err)
// return
// }
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["AssigneeID"] = 0
// ctx.Data["Assignees"], err = repo.GetCollaborators()
}
// us, err := repo.GetCollaborators()
// if err != nil {
@ -222,8 +224,9 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
ctx.Data["AttachmentAllowedTypes"] = setting.AttachmentAllowedTypes
var (
repo = ctx.Repo.Repository
labelIDs []int64
repo = ctx.Repo.Repository
labelIDs []int64
milestoneID int64
)
if ctx.User.IsAdmin {
// Check labels.
@ -244,6 +247,25 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
ctx.Data["HasSelectedLabel"] = hasSelected
ctx.Data["label_ids"] = form.LabelIDs
ctx.Data["Labels"] = labels
// Check milestone.
milestoneID = form.MilestoneID
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["Milestone"], err = models.GetRepoMilestoneByID(repo.ID, milestoneID)
if err != nil {
ctx.Handle(500, "GetRepoMilestoneByID: %v", err)
return
}
ctx.Data["milestone_id"] = milestoneID
}
if ctx.HasError() {
@ -252,11 +274,11 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
}
issue := &models.Issue{
RepoID: ctx.Repo.Repository.ID,
Index: int64(repo.NumIssues) + 1,
Name: form.Title,
PosterID: ctx.User.Id,
// MilestoneID: form.MilestoneID,
RepoID: ctx.Repo.Repository.ID,
Index: int64(repo.NumIssues) + 1,
Name: form.Title,
PosterID: ctx.User.Id,
MilestoneID: milestoneID,
// AssigneeID: form.AssigneeID,
Content: form.Content,
}
@ -683,7 +705,7 @@ func UpdateIssueMilestone(ctx *middleware.Context) {
// Not check for invalid milestone id and give responsibility to owners.
issue.MilestoneID = mid
if err = models.ChangeMilestoneAssign(oldMid, mid, issue); err != nil {
if err = models.ChangeMilestoneAssign(oldMid, issue); err != nil {
ctx.Handle(500, "issue.UpdateIssueMilestone(ChangeMilestoneAssign)", err)
return
} else if err = models.UpdateIssue(issue); err != nil {

@ -38,16 +38,16 @@
</div>
{{if .IsRepositoryAdmin}}
<input id="label_ids" name="label_ids" type="hidden" value="{{.label_ids}}">
<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">
<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">
<a class="no-select item" href="#">{{.i18n.Tr "repo.issues.new.clear_labels"}}</a>
<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>
{{end}}
@ -59,32 +59,59 @@
<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>
<div class="ui {{if .Labels}}disabled{{end}} dropdown jump item">
<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">
<span class="text">
<strong>{{.i18n.Tr "repo.issues.new.milestone"}}</strong>
<span class="octicon octicon-gear"></span>
</span>
<div class="menu">
<a class="item" href="{{$.RepoLink}}/issues?type={{$.ViewType}}&state={{$.State}}&milestone={{$.MilestoneID}}">{{.i18n.Tr "repo.issues.filter_label_no_select"}}</a>
{{range .Labels}}
<a class="item" href="{{$.RepoLink}}/issues?type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}&milestone={{$.MilestoneID}}"><span class="octicon {{if .IsChecked}}octicon-check{{end}}"></span><span class="label color" style="background-color: {{.Color}}"></span> {{.Name}}</a>
<div class="no-select item">{{.i18n.Tr "repo.issues.new.clear_milestone"}}</div>
{{if .OpenMilestones}}
<div class="divider"></div>
<div class="header">
<i class="octicon octicon-milestone"></i>
{{.i18n.Tr "repo.issues.new.open_milestone"}}
</div>
{{range .OpenMilestones}}
<div class="item" data-id="{{.ID}}" data-href="{{$.RepoLink}}/issues?milestone={{.ID}}"> {{.Name}}</div>
{{end}}
{{end}}
{{if .ClosedMilestones}}
<div class="divider"></div>
<div class="header">
<i class="octicon octicon-milestone"></i>
{{.i18n.Tr "repo.issues.new.closed_milestone"}}
</div>
{{range .ClosedMilestones}}
<a class="item" data-id="{{.ID}}" data-href="{{$.RepoLink}}/issues?milestone={{.ID}}"> {{.Name}}</a>
{{end}}
{{end}}
</div>
</div>
<div class="ui list">
<span class="item">filter_label_no_select</span>
<div class="ui select-milestone list">
<span class="no-select item {{if .Milestone}}hide{{end}}">{{.i18n.Tr "repo.issues.new.no_milestone"}}</span>
<div class="selected">
{{if .Milestone}}
<a class="item" href="{{.RepoLink}}/issues?milestone={{.Milestone.ID}}"> {{.Milestone.Name}}</a>
{{end}}
</div>
</div>
<div class="ui divider"></div>
<div class="ui {{if .Labels}}disabled{{end}} dropdown jump item">
<!-- <div class="ui divider"></div>
<div class="ui {{if not .Assignees}}disabled{{end}} dropdown jump item">
<span class="text">
<strong>{{.i18n.Tr "repo.issues.new.assignee"}}</strong>
<span class="octicon octicon-gear"></span>
</span>
<div class="menu">
<a class="item" href="{{$.RepoLink}}/issues?type={{$.ViewType}}&state={{$.State}}&milestone={{$.MilestoneID}}">{{.i18n.Tr "repo.issues.filter_label_no_select"}}</a>
{{range .Labels}}
<a class="item" href="{{$.RepoLink}}/issues?type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}&milestone={{$.MilestoneID}}"><span class="octicon {{if .IsChecked}}octicon-check{{end}}"></span><span class="label color" style="background-color: {{.Color}}"></span> {{.Name}}</a>
<div class="item">{{.i18n.Tr "repo.issues.new.clear_assignee"}}</a>
{{range .Assignees}}
<a class="item" href="#"><span class="octicon {{if eq .ID $.AssigneeID}}octicon-check{{end}}"></span> {{.Name}}</a>
{{end}}
</div>
</div>

Loading…
Cancel
Save