Merge pull request #1206 from taigaio/attachments-on-comment

Add from_comment field in attachments from comment
stable
David Barragán Merino 2017-01-18 14:12:05 +01:00 committed by GitHub
commit 312395bd9e
6 changed files with 14 additions and 8 deletions

View File

@ -32,6 +32,8 @@
a.icon-delete(
href=""
title="{{'COMMON.DELETE' | translate}}"
ng-if="!vm.attachment.get('editable')"
tg-check-permission="modify_{{vm.type}}"
ng-click="vm.delete()"
)
tg-svg(svg-icon="icon-trash")

View File

@ -47,12 +47,12 @@ class AttachmentsFullService extends taiga.Service
else
@._attachmentsVisible = @._attachments.filter (it) -> !it.getIn(['file', 'is_deprecated'])
addAttachment: (projectId, objId, type, file, editable = true) ->
addAttachment: (projectId, objId, type, file, editable = true, comment = false) ->
return new Promise (resolve, reject) =>
if @attachmentsService.validate(file)
@.uploadingAttachments.push(file)
promise = @attachmentsService.upload(file, objId, projectId, type)
promise = @attachmentsService.upload(file, objId, projectId, type, comment)
promise.then (file) =>
@.uploadingAttachments = @.uploadingAttachments.filter (uploading) ->
return uploading.name != file.get('name')
@ -62,7 +62,8 @@ class AttachmentsFullService extends taiga.Service
attachment = attachment.merge({
file: file,
editable: editable,
loading: false
loading: false,
from_comment: comment
})
@._attachments = @._attachments.push(attachment)

View File

@ -25,13 +25,14 @@
CommentEditWysiwyg = (attachmentsFullService) ->
link = ($scope, $el, $attrs) ->
types = {
epics: "epic",
userstories: "us",
issues: "issue",
tasks: "task"
}
uploadFile = (file, cb) ->
return attachmentsFullService.addAttachment($scope.vm.projectId, $scope.vm.comment.comment.id, types[$scope.vm.comment.comment._name], file).then (result) ->
return attachmentsFullService.addAttachment($scope.vm.projectId, $scope.vm.comment.comment.id, types[$scope.vm.comment.comment._name], file, true, true).then (result) ->
cb(result.getIn(['file', 'name']), result.getIn(['file', 'url']))
$scope.uploadFiles = (files, cb) ->

View File

@ -32,13 +32,14 @@ CommentWysiwyg = (attachmentsFullService) ->
$scope.vm.onAddComment({callback: cb})
types = {
epics: "epic",
userstories: "us",
issues: "issue",
tasks: "task"
}
uploadFile = (file, cb) ->
return attachmentsFullService.addAttachment($scope.vm.projectId, $scope.vm.type.id, types[$scope.vm.type._name], file).then (result) ->
return attachmentsFullService.addAttachment($scope.vm.projectId, $scope.vm.type.id, types[$scope.vm.type._name], file, true, true).then (result) ->
cb(result.getIn(['file', 'name']), result.getIn(['file', 'url']))
$scope.onChange = (markdown) ->

View File

@ -58,7 +58,7 @@ Resource = (urlsService, http, config, $rootScope, $q, storage) ->
return http.patch(url, patch)
service.create = (type, projectId, objectId, file) ->
service.create = (type, projectId, objectId, file, from_comment) ->
urlname = "attachments/#{type}"
url = urlsService.resolve(urlname)
@ -116,6 +116,7 @@ Resource = (urlsService, http, config, $rootScope, $q, storage) ->
data.append("project", projectId)
data.append("object_id", objectId)
data.append("attached_file", file)
data.append("from_comment", from_comment)
xhr = new XMLHttpRequest()
xhr.upload.addEventListener("progress", uploadProgress, false)

View File

@ -70,8 +70,8 @@ class AttachmentsService
@confirm.notify("error", message)
upload: (file, objId, projectId, type) ->
promise = @rs.attachments.create(type, projectId, objId, file)
upload: (file, objId, projectId, type, from_comment = false) ->
promise = @rs.attachments.create(type, projectId, objId, file, from_comment)
promise.then null, @.saveError.bind(this, file)