finish create issue with labels
This commit is contained in:
parent
17de3ab0a3
commit
922f3f3062
9 changed files with 160 additions and 41 deletions
|
@ -144,8 +144,8 @@ func (i *Issue) AfterDelete() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateIssue creates new issue for repository.
|
// CreateIssue creates new issue with labels for repository.
|
||||||
func NewIssue(issue *Issue) (err error) {
|
func NewIssue(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 {
|
||||||
|
@ -158,6 +158,12 @@ func NewIssue(issue *Issue) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, id := range labelIDs {
|
||||||
|
if err = issue.addLabel(sess, id); err != nil {
|
||||||
|
return fmt.Errorf("addLabel: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err = sess.Commit(); err != nil {
|
if err = sess.Commit(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -688,6 +694,10 @@ func HasIssueLabel(issueID, labelID int64) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newIssueLabel(e Engine, issueID, labelID int64) error {
|
func newIssueLabel(e Engine, issueID, labelID int64) error {
|
||||||
|
if issueID == 0 || labelID == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
_, err := e.Insert(&IssueLabel{
|
_, err := e.Insert(&IssueLabel{
|
||||||
IssueID: issueID,
|
IssueID: issueID,
|
||||||
LabelID: labelID,
|
LabelID: labelID,
|
||||||
|
|
|
@ -99,7 +99,7 @@ func (f *NewSlackHookForm) Validate(ctx *macaron.Context, errs binding.Errors) b
|
||||||
|
|
||||||
type CreateIssueForm struct {
|
type CreateIssueForm struct {
|
||||||
Title string `binding:"Required;MaxSize(255)"`
|
Title string `binding:"Required;MaxSize(255)"`
|
||||||
LabelIDs []int64 `form:"label_id"`
|
LabelIDs string `form:"label_ids"`
|
||||||
MilestoneID int64
|
MilestoneID int64
|
||||||
AssigneeID int64
|
AssigneeID int64
|
||||||
Content string
|
Content string
|
||||||
|
|
|
@ -420,3 +420,21 @@ func Subtract(left interface{}, right interface{}) interface{} {
|
||||||
return fleft + float64(rleft) - (fright + float64(rright))
|
return fleft + float64(rleft) - (fright + float64(rright))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StringsToInt64s converts a slice of string to a slice of int64.
|
||||||
|
func StringsToInt64s(strs []string) []int64 {
|
||||||
|
ints := make([]int64, len(strs))
|
||||||
|
for i := range strs {
|
||||||
|
ints[i] = com.StrTo(strs[i]).MustInt64()
|
||||||
|
}
|
||||||
|
return ints
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int64sToMap converts a slice of int64 to a int64 map.
|
||||||
|
func Int64sToMap(ints []int64) map[int64]bool {
|
||||||
|
m := make(map[int64]bool)
|
||||||
|
for _, i := range ints {
|
||||||
|
m[i] = true
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
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
|
@ -134,24 +134,65 @@ $(document).ready(function () {
|
||||||
$('.poping.up').popup();
|
$('.poping.up').popup();
|
||||||
|
|
||||||
// Comment form
|
// Comment form
|
||||||
$('.comment.form .tabular.menu .item').tab();
|
if ($('.comment.form').length > 0) {
|
||||||
$('.comment.form .tabular.menu .item[data-tab="preview"]').click(function () {
|
var $form = $(this);
|
||||||
|
$form.find('.tabular.menu .item').tab();
|
||||||
|
$form.find('.tabular.menu .item[data-tab="preview"]').click(function () {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
console.log($('.comment.form .tab.segment[data-tab="write"] textarea').val())
|
|
||||||
console.log($('.comment.form .tab.segment[data-tab="preview"]').html())
|
|
||||||
$.post($this.data('url'), {
|
$.post($this.data('url'), {
|
||||||
"_csrf": csrf,
|
"_csrf": csrf,
|
||||||
"mode": "gfm",
|
"mode": "gfm",
|
||||||
"context": $this.data('context'),
|
"context": $this.data('context'),
|
||||||
"text": $('.comment.form .tab.segment[data-tab="write"] textarea').val()
|
"text": $form.find('.tab.segment[data-tab="write"] textarea').val()
|
||||||
},
|
},
|
||||||
function (data) {
|
function (data) {
|
||||||
console.log(data)
|
$form.find('.tab.segment[data-tab="preview"]').html(data);
|
||||||
$('.comment.form .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.
|
// Helpers.
|
||||||
$('.delete-button').click(function () {
|
$('.delete-button').click(function () {
|
||||||
|
|
|
@ -102,7 +102,7 @@ footer {
|
||||||
}
|
}
|
||||||
|
|
||||||
.hide {
|
.hide {
|
||||||
display: none;
|
display: none!important;
|
||||||
}
|
}
|
||||||
.center {
|
.center {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
|
@ -29,6 +29,22 @@
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.metas .ui.list {
|
||||||
|
.label.color {
|
||||||
|
padding: 0 8px;
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
padding-top: 5px;
|
||||||
|
padding-right: 10px;
|
||||||
|
.text {
|
||||||
|
color: #444;
|
||||||
|
&:hover {
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
.filter.menu {
|
.filter.menu {
|
||||||
.label.color {
|
.label.color {
|
||||||
margin-left: 15px;
|
margin-left: 15px;
|
||||||
|
@ -91,6 +107,10 @@
|
||||||
.comment.form {
|
.comment.form {
|
||||||
.metas {
|
.metas {
|
||||||
min-width: 220px;
|
min-width: 220px;
|
||||||
|
.filter.menu {
|
||||||
|
max-height: 300px;
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,6 +180,7 @@ func NewIssue(ctx *middleware.Context) {
|
||||||
ctx.Data["IsAttachmentEnabled"] = setting.AttachmentEnabled
|
ctx.Data["IsAttachmentEnabled"] = setting.AttachmentEnabled
|
||||||
ctx.Data["AttachmentAllowedTypes"] = setting.AttachmentAllowedTypes
|
ctx.Data["AttachmentAllowedTypes"] = setting.AttachmentAllowedTypes
|
||||||
|
|
||||||
|
if ctx.User.IsAdmin {
|
||||||
var (
|
var (
|
||||||
repo = ctx.Repo.Repository
|
repo = ctx.Repo.Repository
|
||||||
err error
|
err error
|
||||||
|
@ -189,6 +190,7 @@ func NewIssue(ctx *middleware.Context) {
|
||||||
ctx.Handle(500, "GetLabelsByRepoID: %v", err)
|
ctx.Handle(500, "GetLabelsByRepoID: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// // Get all milestones.
|
// // Get all milestones.
|
||||||
// ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false)
|
// ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false)
|
||||||
|
@ -219,6 +221,31 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
|
||||||
ctx.Data["IsAttachmentEnabled"] = setting.AttachmentEnabled
|
ctx.Data["IsAttachmentEnabled"] = setting.AttachmentEnabled
|
||||||
ctx.Data["AttachmentAllowedTypes"] = setting.AttachmentAllowedTypes
|
ctx.Data["AttachmentAllowedTypes"] = setting.AttachmentAllowedTypes
|
||||||
|
|
||||||
|
var (
|
||||||
|
repo = ctx.Repo.Repository
|
||||||
|
labelIDs []int64
|
||||||
|
)
|
||||||
|
if ctx.User.IsAdmin {
|
||||||
|
// Check labels.
|
||||||
|
labelIDs = base.StringsToInt64s(strings.Split(form.LabelIDs, ","))
|
||||||
|
labelIDMark := base.Int64sToMap(labelIDs)
|
||||||
|
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["label_ids"] = form.LabelIDs
|
||||||
|
ctx.Data["Labels"] = labels
|
||||||
|
}
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
ctx.HTML(200, ISSUE_NEW)
|
ctx.HTML(200, ISSUE_NEW)
|
||||||
return
|
return
|
||||||
|
@ -226,18 +253,17 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
|
||||||
|
|
||||||
issue := &models.Issue{
|
issue := &models.Issue{
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
Index: int64(ctx.Repo.Repository.NumIssues) + 1,
|
Index: int64(repo.NumIssues) + 1,
|
||||||
Name: form.Title,
|
Name: form.Title,
|
||||||
PosterID: ctx.User.Id,
|
PosterID: ctx.User.Id,
|
||||||
// MilestoneID: form.MilestoneID,
|
// MilestoneID: form.MilestoneID,
|
||||||
// AssigneeID: form.AssigneeID,
|
// AssigneeID: form.AssigneeID,
|
||||||
// LabelIDs: "$" + strings.Join(form.LabelIDs, "|$") + "|",
|
|
||||||
Content: form.Content,
|
Content: form.Content,
|
||||||
}
|
}
|
||||||
if err := models.NewIssue(issue); err != nil {
|
if err := models.NewIssue(issue, labelIDs); err != nil {
|
||||||
ctx.Handle(500, "NewIssue", err)
|
ctx.Handle(500, "NewIssue", err)
|
||||||
return
|
return
|
||||||
} else if err := models.NewIssueUserPairs(ctx.Repo.Repository, issue); err != nil {
|
} else if err := models.NewIssueUserPairs(repo, issue); err != nil {
|
||||||
ctx.Handle(500, "NewIssue", err)
|
ctx.Handle(500, "NewIssue", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,22 +38,26 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{if .IsRepositoryAdmin}}
|
{{if .IsRepositoryAdmin}}
|
||||||
|
<input id="label_ids" name="label_ids" type="hidden" value="{{.label_ids}}">
|
||||||
<div class="four wide column">
|
<div class="four wide column">
|
||||||
<div class="ui segment metas">
|
<div class="ui segment metas">
|
||||||
<div class="ui {{if not .Labels}}disabled{{end}} dropdown jump item">
|
<div class="ui {{if not .Labels}}disabled{{end}} jump select-label dropdown">
|
||||||
<span class="text">
|
<span class="text">
|
||||||
<strong>{{.i18n.Tr "repo.issues.new.labels"}}</strong>
|
<strong>{{.i18n.Tr "repo.issues.new.labels"}}</strong>
|
||||||
<span class="octicon octicon-gear"></span>
|
<span class="octicon octicon-gear"></span>
|
||||||
</span>
|
</span>
|
||||||
<div class="filter menu">
|
<div class="filter menu" data-id="#label_ids">
|
||||||
<a class="item" href="#">{{.i18n.Tr "repo.issues.new.clear_labels"}}</a>
|
<a class="no-select item" href="#">{{.i18n.Tr "repo.issues.new.clear_labels"}}</a>
|
||||||
{{range .Labels}}
|
{{range .Labels}}
|
||||||
<a class="item" href="#"><span class="octicon {{if .IsChecked}}octicon-check{{end}}"></span><span class="label color" style="background-color: {{.Color}}"></span> {{.Name}}</a>
|
<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}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ui list">
|
<div class="ui labels list">
|
||||||
<span class="item {{if .SelectedLabels}}hide{{end}}">{{.i18n.Tr "repo.issues.new.no_label"}}</span>
|
<span class="no-select item {{if .HasSelectedLabel}}hide{{end}}">{{.i18n.Tr "repo.issues.new.no_label"}}</span>
|
||||||
|
{{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>
|
||||||
<!-- <div class="ui divider"></div>
|
<!-- <div class="ui divider"></div>
|
||||||
<div class="ui {{if .Labels}}disabled{{end}} dropdown jump item">
|
<div class="ui {{if .Labels}}disabled{{end}} dropdown jump item">
|
||||||
|
|
Loading…
Reference in a new issue