summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Nuß <nuss.justin@gmail.com>2014-07-23 21:24:24 +0200
committerJustin Nuß <nuss.justin@gmail.com>2014-07-23 21:24:24 +0200
commit34304e6a0c9a3904b999e3ae1fcc9e6518d3f026 (patch)
treeb5b225396138e7fd68bff0f4e8f5123e4e148883
parent4617bef8954deeef5bd2ba36d84aba3b05a4dd83 (diff)
downloadgitea-34304e6a0c9a3904b999e3ae1fcc9e6518d3f026.tar.gz
gitea-34304e6a0c9a3904b999e3ae1fcc9e6518d3f026.zip
WIP: Allow attachments for issues, not only comments
-rw-r--r--models/issue.go18
-rw-r--r--public/js/app.js1
-rw-r--r--routers/repo/issue.go7
-rw-r--r--templates/repo/issue/create.tmpl6
-rw-r--r--templates/repo/issue/view.tmpl5
5 files changed, 34 insertions, 3 deletions
diff --git a/models/issue.go b/models/issue.go
index 90ef287cec..c0f2da2f2b 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -96,6 +96,11 @@ func (i *Issue) GetAssignee() (err error) {
return err
}
+func (i *Issue) Attachments() []*Attachment {
+ a, _ := GetAttachmentsForIssue(i.Id)
+ return a
+}
+
func (i *Issue) AfterDelete() {
_, err := DeleteAttachmentsByIssue(i.Id, true)
@@ -871,8 +876,9 @@ func GetIssueComments(issueId int64) ([]Comment, error) {
}
// Attachments returns the attachments for this comment.
-func (c *Comment) Attachments() ([]*Attachment, error) {
- return GetAttachmentsByComment(c.Id)
+func (c *Comment) Attachments() []*Attachment {
+ a, _ := GetAttachmentsByComment(c.Id)
+ return a
}
func (c *Comment) AfterDelete() {
@@ -928,10 +934,16 @@ func GetAttachmentById(id int64) (*Attachment, error) {
return m, nil
}
+func GetAttachmentsForIssue(issueId int64) ([]*Attachment, error) {
+ attachments := make([]*Attachment, 0, 10)
+ err := x.Where("issue_id = ?", issueId).Where("comment_id = 0").Find(&attachments)
+ return attachments, err
+}
+
// GetAttachmentsByIssue returns a list of attachments for the given issue
func GetAttachmentsByIssue(issueId int64) ([]*Attachment, error) {
attachments := make([]*Attachment, 0, 10)
- err := x.Where("issue_id = ?", issueId).Find(&attachments)
+ err := x.Where("issue_id = ?", issueId).Where("comment_id > 0").Find(&attachments)
return attachments, err
}
diff --git a/public/js/app.js b/public/js/app.js
index 77719efe09..16d1d5dab1 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -525,6 +525,7 @@ function initIssue() {
var $attachments = $("input[name=attachments]");
var $addButton = $("#attachments-button");
+ var commentId = $addButton.attr("data-comment-id"); // "0" == for issue, "" == for comment
var accepted = $addButton.attr("data-accept");
$addButton.on("click", function() {
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 9a265e0959..abcf43a945 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -173,7 +173,10 @@ func CreateIssue(ctx *middleware.Context, params martini.Params) {
ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err)
return
}
+
+ ctx.Data["AllowedTypes"] = setting.AttachmentAllowedTypes
ctx.Data["Collaborators"] = us
+
ctx.HTML(200, ISSUE_CREATE)
}
@@ -1030,6 +1033,10 @@ func IssuePostAttachment(ctx *middleware.Context, params martini.Params) {
return
}
+ if commentId == 0 {
+ commentId = -1
+ }
+
file, header, err := ctx.Req.FormFile("attachment")
if err != nil {
diff --git a/templates/repo/issue/create.tmpl b/templates/repo/issue/create.tmpl
index b548b1e749..b7f281c51d 100644
--- a/templates/repo/issue/create.tmpl
+++ b/templates/repo/issue/create.tmpl
@@ -101,8 +101,14 @@
<div class="tab-pane issue-preview-content" id="issue-preview">loading...</div>
</div>
</div>
+ <div>
+ <div id="attached"></div>
+ </div>
<div class="text-right panel-body">
<div class="form-group">
+ <input type="hidden" name="attachments" value="" />
+ <button data-accept="{{AllowedTypes}}" data-comment-id="0" class="btn-default btn attachment-add" id="attachments-button">Add Attachments...</button>
+
<input type="hidden" value="id" name="repo-id"/>
<button class="btn-success btn">Create new issue</button>
</div>
diff --git a/templates/repo/issue/view.tmpl b/templates/repo/issue/view.tmpl
index 246055e183..500d3ce3f6 100644
--- a/templates/repo/issue/view.tmpl
+++ b/templates/repo/issue/view.tmpl
@@ -46,6 +46,11 @@
</div>
</div>
</div>
+ <div class="attachments">
+ {{range .Attachments}}
+ <a class="attachment" href="{{.IssueId}}/attachment/{{.Id}}">{{.Name}}</a>
+ {{end}}
+ </div>
</div>
</div>
{{range .Comments}}