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( a.icon-delete(
href="" href=""
title="{{'COMMON.DELETE' | translate}}" title="{{'COMMON.DELETE' | translate}}"
ng-if="!vm.attachment.get('editable')"
tg-check-permission="modify_{{vm.type}}"
ng-click="vm.delete()" ng-click="vm.delete()"
) )
tg-svg(svg-icon="icon-trash") tg-svg(svg-icon="icon-trash")

View File

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

View File

@ -25,13 +25,14 @@
CommentEditWysiwyg = (attachmentsFullService) -> CommentEditWysiwyg = (attachmentsFullService) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
types = { types = {
epics: "epic",
userstories: "us", userstories: "us",
issues: "issue", issues: "issue",
tasks: "task" tasks: "task"
} }
uploadFile = (file, cb) -> 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'])) cb(result.getIn(['file', 'name']), result.getIn(['file', 'url']))
$scope.uploadFiles = (files, cb) -> $scope.uploadFiles = (files, cb) ->

View File

@ -32,13 +32,14 @@ CommentWysiwyg = (attachmentsFullService) ->
$scope.vm.onAddComment({callback: cb}) $scope.vm.onAddComment({callback: cb})
types = { types = {
epics: "epic",
userstories: "us", userstories: "us",
issues: "issue", issues: "issue",
tasks: "task" tasks: "task"
} }
uploadFile = (file, cb) -> 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'])) cb(result.getIn(['file', 'name']), result.getIn(['file', 'url']))
$scope.onChange = (markdown) -> $scope.onChange = (markdown) ->

View File

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

View File

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