Browse Source

WIP: Allow attachments for issues, not only comments

for-closed-social
Justin Nuß 10 years ago
parent
commit
34304e6a0c
5 changed files with 34 additions and 3 deletions
  1. +15
    -3
      models/issue.go
  2. +1
    -0
      public/js/app.js
  3. +7
    -0
      routers/repo/issue.go
  4. +6
    -0
      templates/repo/issue/create.tmpl
  5. +5
    -0
      templates/repo/issue/view.tmpl

+ 15
- 3
models/issue.go View File

@ -96,6 +96,11 @@ func (i *Issue) GetAssignee() (err error) {
return err return err
} }
func (i *Issue) Attachments() []*Attachment {
a, _ := GetAttachmentsForIssue(i.Id)
return a
}
func (i *Issue) AfterDelete() { func (i *Issue) AfterDelete() {
_, err := DeleteAttachmentsByIssue(i.Id, true) _, err := DeleteAttachmentsByIssue(i.Id, true)
@ -871,8 +876,9 @@ func GetIssueComments(issueId int64) ([]Comment, error) {
} }
// Attachments returns the attachments for this comment. // 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() { func (c *Comment) AfterDelete() {
@ -928,10 +934,16 @@ func GetAttachmentById(id int64) (*Attachment, error) {
return m, nil 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 // GetAttachmentsByIssue returns a list of attachments for the given issue
func GetAttachmentsByIssue(issueId int64) ([]*Attachment, error) { func GetAttachmentsByIssue(issueId int64) ([]*Attachment, error) {
attachments := make([]*Attachment, 0, 10) 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 return attachments, err
} }

+ 1
- 0
public/js/app.js View File

@ -525,6 +525,7 @@ function initIssue() {
var $attachments = $("input[name=attachments]"); var $attachments = $("input[name=attachments]");
var $addButton = $("#attachments-button"); var $addButton = $("#attachments-button");
var commentId = $addButton.attr("data-comment-id"); // "0" == for issue, "" == for comment
var accepted = $addButton.attr("data-accept"); var accepted = $addButton.attr("data-accept");
$addButton.on("click", function() { $addButton.on("click", function() {

+ 7
- 0
routers/repo/issue.go View File

@ -173,7 +173,10 @@ func CreateIssue(ctx *middleware.Context, params martini.Params) {
ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err) ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err)
return return
} }
ctx.Data["AllowedTypes"] = setting.AttachmentAllowedTypes
ctx.Data["Collaborators"] = us ctx.Data["Collaborators"] = us
ctx.HTML(200, ISSUE_CREATE) ctx.HTML(200, ISSUE_CREATE)
} }
@ -1030,6 +1033,10 @@ func IssuePostAttachment(ctx *middleware.Context, params martini.Params) {
return return
} }
if commentId == 0 {
commentId = -1
}
file, header, err := ctx.Req.FormFile("attachment") file, header, err := ctx.Req.FormFile("attachment")
if err != nil { if err != nil {

+ 6
- 0
templates/repo/issue/create.tmpl View File

@ -101,8 +101,14 @@
<div class="tab-pane issue-preview-content" id="issue-preview">loading...</div> <div class="tab-pane issue-preview-content" id="issue-preview">loading...</div>
</div> </div>
</div> </div>
<div>
<div id="attached"></div>
</div>
<div class="text-right panel-body"> <div class="text-right panel-body">
<div class="form-group"> <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"/> <input type="hidden" value="id" name="repo-id"/>
<button class="btn-success btn">Create new issue</button> <button class="btn-success btn">Create new issue</button>
</div> </div>

+ 5
- 0
templates/repo/issue/view.tmpl View File

@ -46,6 +46,11 @@
</div> </div>
</div> </div>
</div> </div>
<div class="attachments">
{{range .Attachments}}
<a class="attachment" href="{{.IssueId}}/attachment/{{.Id}}">{{.Name}}</a>
{{end}}
</div>
</div> </div>
</div> </div>
{{range .Comments}} {{range .Comments}}

Loading…
Cancel
Save