From 2b56634c7b3f54cbf2be56c19cda0af530875c8f Mon Sep 17 00:00:00 2001 From: "karel.picman@lbcfree.net" Date: Mon, 20 Jul 2020 08:08:51 +0200 Subject: [PATCH] #1150 Uploading big files --- app/controllers/dmsf_upload_controller.rb | 2 +- app/views/dmsf_upload/_upload_file.html.erb | 2 +- .../dmsf_upload/_upload_file_locked.html.erb | 2 +- .../dmsf_upload/delete_dmsf_attachment.js.erb | 22 +++++++++++++++++++ app/views/dmsf_upload/multi_upload.html.erb | 2 +- assets/javascripts/attachments_dmsf.js | 19 +++++----------- assets/stylesheets/redmine_dmsf.css | 4 ++++ lib/redmine_dmsf/webdav/dmsf_resource.rb | 8 +++---- 8 files changed, 40 insertions(+), 21 deletions(-) diff --git a/app/controllers/dmsf_upload_controller.rb b/app/controllers/dmsf_upload_controller.rb index 50bac58b..5ca043d7 100644 --- a/app/controllers/dmsf_upload_controller.rb +++ b/app/controllers/dmsf_upload_controller.rb @@ -62,7 +62,7 @@ class DmsfUploadController < ApplicationController return end - @attachment = Attachment.new(file: request.raw_post) + @attachment = Attachment.new(file: request.body) @attachment.author = User.current @attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16) @attachment.content_type = params[:content_type].presence diff --git a/app/views/dmsf_upload/_upload_file.html.erb b/app/views/dmsf_upload/_upload_file.html.erb index 306113c7..6763818a 100644 --- a/app/views/dmsf_upload/_upload_file.html.erb +++ b/app/views/dmsf_upload/_upload_file.html.erb @@ -22,7 +22,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. %> -
+
<%= hidden_field_tag "commited_files[#{i}][disk_filename]", upload.disk_filename %> <%= hidden_field_tag "commited_files[#{i}][tempfile_path]", upload.tempfile_path %> <%= hidden_field_tag "commited_files[#{i}][size]", upload.size %> diff --git a/app/views/dmsf_upload/_upload_file_locked.html.erb b/app/views/dmsf_upload/_upload_file_locked.html.erb index 2c7fd992..d97b069d 100644 --- a/app/views/dmsf_upload/_upload_file_locked.html.erb +++ b/app/views/dmsf_upload/_upload_file_locked.html.erb @@ -22,7 +22,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. %> -
+
<%= hidden_field_tag "commited_files[#{i}][disk_filename]", upload.disk_filename %> <%= hidden_field_tag "commited_files[#{i}][tempfile_path]", upload.tempfile_path %> <%= hidden_field_tag "commited_files[#{i}][size]", upload.size %> diff --git a/app/views/dmsf_upload/delete_dmsf_attachment.js.erb b/app/views/dmsf_upload/delete_dmsf_attachment.js.erb index 790ae591..6c297d74 100644 --- a/app/views/dmsf_upload/delete_dmsf_attachment.js.erb +++ b/app/views/dmsf_upload/delete_dmsf_attachment.js.erb @@ -1 +1,23 @@ +<% +# encoding: utf-8 +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-20 Karel Pičman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +%> + $('#dmsf_attachments_<%= j params[:attachment_id] %>').remove(); diff --git a/app/views/dmsf_upload/multi_upload.html.erb b/app/views/dmsf_upload/multi_upload.html.erb index d46f1355..e4fc1bca 100644 --- a/app/views/dmsf_upload/multi_upload.html.erb +++ b/app/views/dmsf_upload/multi_upload.html.erb @@ -23,7 +23,7 @@ <%= render partial: '/dmsf/path', locals: { folder: @folder, filename: nil, title: l(:label_attachment_new) } %> <%= form_tag({ controller: 'dmsf_upload', action: 'upload_files', id: @project, folder_id: @folder }, - id: 'uploadform', method: :post, multipart: true) do %> + { id: 'uploadform', multipart: true }) do %>
<%= render partial: 'dmsf_upload/form', diff --git a/assets/javascripts/attachments_dmsf.js b/assets/javascripts/attachments_dmsf.js index 4981e07e..87aaeca4 100644 --- a/assets/javascripts/attachments_dmsf.js +++ b/assets/javascripts/attachments_dmsf.js @@ -113,7 +113,7 @@ function dmsfAjaxUpload(file, attachmentId, fileSpan, inputEl) { function onProgress(e) { if(e.lengthComputable) { - this.progressbar( 'value', e.loaded * 100 / e.total ); + this.progressbar('value', e.loaded * 100 / e.total); } } @@ -132,11 +132,11 @@ function dmsfAjaxUpload(file, attachmentId, fileSpan, inputEl) { .fail(function(result) { progressSpan.text(result.statusText); }).always(function() { - dmsfAjaxUpload.uploading--; - fileSpan.removeClass('ajax-loading'); - let form = fileSpan.parents('form'); - if ((form.queue('upload').length == 0) && (dmsfAjaxUpload.uploading == 0)) { - $('input:submit', form).removeAttr('disabled'); + dmsfAjaxUpload.uploading--; + fileSpan.removeClass('ajax-loading'); + let form = fileSpan.parents('form'); + if ((form.queue('upload').length == 0) && (dmsfAjaxUpload.uploading == 0)) { + $('input:submit', form).removeAttr('disabled'); } form.dequeue('upload'); }); @@ -163,13 +163,6 @@ function dmsfRemoveFileLbl() { return false; } -/*function dmsfRemoveFile() { - - $(this).parent('span').parent('span').remove(); - - return false; -}*/ - function dmsfUploadBlob(blob, uploadUrl, attachmentId, options) { let actualOptions = $.extend({ diff --git a/assets/stylesheets/redmine_dmsf.css b/assets/stylesheets/redmine_dmsf.css index 3bcc7a5b..177cbb0f 100644 --- a/assets/stylesheets/redmine_dmsf.css +++ b/assets/stylesheets/redmine_dmsf.css @@ -319,6 +319,10 @@ div[id*="revision_access_"] { padding-left: 18px; } +.dmfs-box-tabular { + padding-top: 10px +} + /* New link form */ #dmsf_link_target_file_id, #dmsf_link_target_folder_id, #dmsf_link_target_project_id, #dmsf_link_name{ min-width: 40%; diff --git a/lib/redmine_dmsf/webdav/dmsf_resource.rb b/lib/redmine_dmsf/webdav/dmsf_resource.rb index 27673594..8b835425 100644 --- a/lib/redmine_dmsf/webdav/dmsf_resource.rb +++ b/lib/redmine_dmsf/webdav/dmsf_resource.rb @@ -564,9 +564,9 @@ module RedmineDmsf # Phusion passenger does not have a method "length" in its model # however, includes a size method - so we instead use reflection # to determine best approach to problem - if request.body.respond_to? 'length' + if request.body.respond_to?(:length) new_revision.size = request.body.length - elsif request.body.respond_to? 'size' + elsif request.body.respond_to?(:size) new_revision.size = request.body.size else new_revision.size = request.content_length # Bad Guess @@ -577,10 +577,10 @@ module RedmineDmsf new_revision.disk_filename = new_revision.new_storage_filename unless reuse_revision if new_revision.save - new_revision.copy_file_content(request.body) + new_revision.copy_file_content request.body new_revision.save # Notifications - DmsfMailer.deliver_files_updated(project, [f]) + DmsfMailer.deliver_files_updated project, [f] else raise InternalServerError end