Standard attachments upload form used for large files

This commit is contained in:
Karel Pičman 2014-08-22 14:53:24 +02:00
parent 2e8b51bb37
commit 951ccadf26
4 changed files with 43 additions and 50 deletions

View File

@ -1,7 +1,7 @@
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2014 Karel Pičman <karel.picman@kontron.com>
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2011-14 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -30,12 +30,12 @@ class DmsfUploadController < ApplicationController
helper :dmsf_workflows
def upload_files
uploaded_files = params[:uploaded_files]
uploaded_files = params[:attachments]
@uploads = []
if uploaded_files && uploaded_files.is_a?(Hash)
# standard file input uploads
uploaded_files.each_value do |uploaded_file|
@uploads.push(DmsfUpload.create_from_uploaded_file(@project, @folder, uploaded_file))
uploaded_files.each_value do |uploaded_file|
@uploads.push(DmsfUpload.create_from_uploaded_attachment(@project, @folder, uploaded_file))
end
else
# plupload multi upload completed

View File

@ -30,25 +30,31 @@ class DmsfUpload
attr_accessor :minor_version
attr_accessor :locked
attr_accessor :workflow
attr_accessor :custom_values
attr_accessor :custom_values
def disk_file
"#{DmsfHelper.temp_dir}/#{self.disk_filename}"
end
end
def self.create_from_uploaded_file(project, folder, uploaded_file)
uploaded = {
:disk_filename => DmsfHelper.temp_filename(uploaded_file.original_filename),
:content_type => uploaded_file.content_type.to_s,
:original_filename => uploaded_file.original_filename,
}
File.open("#{DmsfHelper.temp_dir}/#{uploaded[:disk_filename]}", 'wb') do |f|
while (buffer = uploaded_file.read(8192))
f.write(buffer)
def self.create_from_uploaded_attachment(project, folder, uploaded_file)
a = Attachment.find_by_token(uploaded_file[:token])
if a
uploaded = {
:disk_filename => DmsfHelper.temp_filename(a.filename),
:content_type => a.content_type,
:original_filename => a.filename,
:comment => uploaded_file[:description]
}
File.open(a.diskfile, 'rb') do |fr|
File.open("#{DmsfHelper.temp_dir}/#{uploaded[:disk_filename]}", 'wb') do |fw|
while (buffer = fr.read(8192))
fw.write(buffer)
end
end
end
a.destroy
DmsfUpload.new(project, folder, uploaded)
end
DmsfUpload.new(project, folder, uploaded)
end
def initialize(project, folder, uploaded)
@ -62,19 +68,24 @@ class DmsfUpload
@disk_filename = uploaded[:disk_filename]
@mime_type = uploaded[:content_type]
@size = File.size(disk_file)
@size = File.size(disk_file)
if file.nil? || file.last_revision.nil?
@title = DmsfFileRevision.filename_to_title(@name)
@description = nil
@description = uploaded[:comment]
@major_version = 0
@minor_version = 0
@workflow = nil
@custom_values = DmsfFileRevision.new(:file => DmsfFile.new(:project => @project)).custom_field_values
@custom_values = DmsfFileRevision.new(:file => DmsfFile.new(:project => @project)).custom_field_values
else
last_revision = file.last_revision
@title = last_revision.title
@description = last_revision.description
if last_revision.description.present?
@description = last_revision.description
@comment = uploaded[:comment] if uploaded[:comment].present?
elsif uploaded[:comment].present?
@comment = uploaded[:comment]
end
@major_version = last_revision.major_version
@minor_version = last_revision.minor_version
@workflow = last_revision.workflow

View File

@ -274,4 +274,4 @@
</script>
<% end %>
<%= render(:partial => 'multi_upload') if (@file_manipulation_allowed && !@locked_for_user) %>
<%= render(:partial => 'dmsf_upload/multi_upload') if (@file_manipulation_allowed && !@locked_for_user) %>

View File

@ -1,7 +1,8 @@
<%# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011-14 Karel Picman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -41,18 +42,13 @@
<%= l(:note_upload_files_greater_than_two_gb) if Setting.attachment_max_size.to_i >= 2097151 %>
</span>
</div>
<div id="uploader">
<div id="uploader">
<p>
<span id="uploaded_files_fields">
<%= file_field_tag('uploaded_files[1]', :size => 30, :id => nil) %>
</span>
<br />
<small><%= link_to(l(:label_add_another_file), '#', :onclick => 'dmsfAddFileField(); return false;' ) %>
(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
</small>
</p>
<label><%=l(:label_attachment_plural)%></label>
<%= render :partial => 'attachments/form' %>
</p>
<%= submit_tag(l(:submit_upload_files)) %>
</div>
</div>
<% end %>
</div>
@ -72,21 +68,7 @@
initPlUploader(uploader);
var dmsfFileFieldCount = 1;
function dmsfAddFileField() {
if (dmsfFileFieldCount >= 10) return false;
dmsfFileFieldCount++;
var f = document.createElement('input');
f.type = 'file';
f.name = 'uploaded_files[' + dmsfFileFieldCount + ']';
f.size = 30;
var p = document.getElementById('uploaded_files_fields');
p.appendChild(document.createElement('br'));
p.appendChild(f);
}
var dmsfFileFieldCount = 1;
</script>
<% content_for :header_tags do %>