Merge branch 'szzh' into develop

This commit is contained in:
sw 2015-03-27 18:21:09 +08:00
commit 1315740e7b
16 changed files with 321 additions and 158 deletions

View File

@ -58,8 +58,6 @@ group :test do
#end #end
end end
# gem 'rspec-rails' , '2.13.1'
# gem 'guard-rspec','2.5.0'
# Gems used only for assets and not required # Gems used only for assets and not required
# in production environments by default. # in production environments by default.
group :assets do group :assets do

View File

@ -108,7 +108,7 @@ class AttachmentsController < ApplicationController
end end
rescue => e rescue => e
redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html" redirect_to "http: //" + (Setting.host_name.to_s) +"/file_not_found.html"
end end
#更新资源文件类型 #更新资源文件类型

View File

@ -1,140 +1,208 @@
# require 'zip' require 'zip'
# class ZipdownController < ApplicationController class ZipdownController < ApplicationController
# #查找项目(课程) #查找项目(课程)
# before_filter :find_project_by_bid_id, :only => [:assort] before_filter :find_project_by_bid_id, :only => [:assort]
# #检查权限 #检查权限
# #勿删 before_filter :authorize, :only => [:assort,:download_user_homework] #勿删 before_filter :authorize, :only => [:assort,:download_user_homework]
# SAVE_FOLDER = "#{Rails.root}/files" SAVE_FOLDER = "#{Rails.root}/files"
# OUTPUT_FOLDER = "#{Rails.root}/tmp/archiveZip" OUTPUT_FOLDER = "#{Rails.root}/tmp/archiveZip"
#
# #统一下载功能
# def assort def download
# if params[:obj_class] == "Bid" begin
# bid = Bid.find params[:obj_id] send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => params[:filename], :type => detect_content_type(params[:file])
# file_count = 0 rescue => e
# bid.homeworks.map { |homework| file_count += homework.attachments.count} render file: 'public/no_file_found.html'
# if file_count > 0 end
# zipfile = zip_bid bid end
# else
# render file: 'public/no_file_found.html' def assort
# end if params[:obj_class] == "Bid"
# else bid = Bid.find params[:obj_id]
# logger.error "[ZipDown#assort] ===> #{params[:obj_class]} unKown !!" file_count = 0
# end bid.homeworks.map { |homework| file_count += homework.attachments.count}
# send_file zipfile, :filename => bid.name + ".zip", :type => detect_content_type(zipfile) if zipfile if file_count > 0
# zipfile = zip_bid bid
# #rescue Exception => e else
# # render file: 'public/no_file_found.html' render file: 'public/no_file_found.html'
# end return
# end
# #下载某一学生的作业的所有文件 else
# def download_user_homework logger.error "[ZipDown#assort] ===> #{params[:obj_class]} unKown !!"
# homework = HomeworkAttach.find params[:homework] end
# if User.current.admin? || User.current.member_of_course?(homework.bid.courses.first)
# if homework != nil # if zipfile
# unless homework.attachments.empty? # if zipfile.length > 1
# zipfile = zip_homework_by_user homework # @mut_down_files = zipfile #zipfile.each{|x| File.basename(x)}
# send_file zipfile, :filename => ((homework.user.user_extensions.nil? || homework.user.user_extensions.student_id.nil?) ? "" : homework.user.user_extensions.student_id) + # else
# "_" + (homework.user.lastname.nil? ? "" : homework.user.lastname) + (homework.user.firstname.nil? ? "" : homework.user.firstname) + # send_file zipfile.first[:real_file], :filename => bid.name + ".zip", :type => detect_content_type(zipfile.first[:real_file])
# "_" + homework.name + ".zip", :type => detect_content_type(zipfile) if(zipfile) # return
# else # end
# render file: 'public/no_file_found.html' # end
# end
# else respond_to do |format|
# render file: 'public/file_not_found.html' format.json {
# end render json: zipfile.to_json
# else }
# render_403 end
# end #rescue Exception => e
# #rescue => e # render file: 'public/no_file_found.html'
# # render file: 'public/file_not_found.html' end
# end
# #下载某一学生的作业的所有文件
# private def download_user_homework
# homework = HomeworkAttach.find params[:homework]
# #通过作业Id找到项目课程 if User.current.admin? || User.current.member_of_course?(homework.bid.courses.first)
# def find_project_by_bid_id if homework != nil
# obj_class = params[:obj_class] unless homework.attachments.empty?
# obj_id = params[:obj_id] zipfile = zip_homework_by_user homework
# obj = obj_class.constantize.find(obj_id) send_file zipfile, :filename => ((homework.user.user_extensions.nil? || homework.user.user_extensions.student_id.nil?) ? "" : homework.user.user_extensions.student_id) +
# case obj.class.to_s.to_sym "_" + (homework.user.lastname.nil? ? "" : homework.user.lastname) + (homework.user.firstname.nil? ? "" : homework.user.firstname) +
# when :Bid "_" + homework.name + ".zip", :type => detect_content_type(zipfile) if(zipfile)
# @project = obj.courses[0] else
# end render file: 'public/no_file_found.html'
# end end
# else
# def zip_bid(bid) render file: 'public/file_not_found.html'
# # Todo: User Access Controll end
# bid_homework_path = [] else
# bid.homeworks.each do |homeattach| render_403
# unless homeattach.attachments.empty? end
# bid_homework_path << zip_homework_by_user(homeattach) #rescue => e
# end # render file: 'public/file_not_found.html'
# end end
# zipping "#{Time.now.to_i}_#{bid.name}.zip", bid_homework_path, OUTPUT_FOLDER
# end private
#
# def zip_homework_by_user(homeattach) #通过作业Id找到项目课程
# homeworks_attach_path = [] def find_project_by_bid_id
# not_exist_file = [] obj_class = params[:obj_class]
# # 需要将所有homework.attachments遍历加入zip obj_id = params[:obj_id]
# # 并且返回zip路径 obj = obj_class.constantize.find(obj_id)
# homeattach.attachments.each do |attach| case obj.class.to_s.to_sym
# if File.exist?(attach.diskfile) when :Bid
# homeworks_attach_path << attach.diskfile @project = obj.courses[0]
# else end
# not_exist_file << attach.filename end
# end
# end def zip_bid(bid)
# zipping("#{homeattach.user.lastname}#{homeattach.user.firstname}_#{((homeattach.user.user_extensions.nil? || homeattach.user.user_extensions.student_id.nil?) ? "" : homeattach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file) # Todo: User Access Controll
# end bid_homework_path = []
# bid.homeworks.each do |homeattach|
# unless homeattach.attachments.empty?
# def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[]) bid_homework_path << zip_homework_by_user(homeattach)
# # 输入待打包的文件列表已经打包文件定位到ouput_path end
# ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE') end
# input_filename = files_paths
# zips = split_pack_files(bid_homework_path, Setting.pack_attachment_max_size.to_i*1024)
# rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip" x = 0
# zipfile_name = "#{output_path}/#{rename_zipfile}"
#
# Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name)) zips.each { |o|
# x += 1
# Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| file = zipping "#{Time.now.to_i}_#{bid.name}_#{x}.zip", o[:files], OUTPUT_FOLDER
# input_filename.each do |filename| o[:real_file] = file
# flag = true o[:file] = File.basename(file)
# index = 1 o[:size] = (File.size(file) / 1024.0 / 1024.0).round(2)
# rename_file = ic.iconv( (File.basename(filename)) ).to_s }
# rename_file = ic.iconv( filename_to_real( File.basename(filename))).to_s if is_attachment
# end
# begin
# zipfile.add(rename_file, filename) def zip_homework_by_user(homeattach)
# flag = false homeworks_attach_path = []
# rescue Exception => e not_exist_file = []
# zipfile.get_output_stream('FILE_NOTICE.txt') do |os| # 需要将所有homework.attachments遍历加入zip
# os.write l(:label_file_exist) # 并且返回zip路径
# end homeattach.attachments.each do |attach|
# next if File.exist?(attach.diskfile)
# end homeworks_attach_path << attach.diskfile
# end else
# unless not_exist_file.empty? not_exist_file << attach.filename
# zipfile.get_output_stream('FILE_LOST.txt') do |os| end
# os.write l(:label_file_lost) + not_exist_file.join(',').to_s end
# end zipping("#{homeattach.user.lastname}#{homeattach.user.firstname}_#{((homeattach.user.user_extensions.nil? || homeattach.user.user_extensions.student_id.nil?) ? "" : homeattach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
# end end
# end
# zipfile_name
# #rescue Errno => e def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[])
# # logger.error "[zipdown#zipping] ===> #{e}" # 输入待打包的文件列表已经打包文件定位到ouput_path
# # @error = e ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE')
# end
# def detect_content_type(name) rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip"
# content_type = Redmine::MimeType.of(name) zipfile_name = "#{output_path}/#{rename_zipfile}"
# content_type.to_s
# end Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
#
# def filename_to_real(name) unless is_attachment
# attach = Attachment.find_by_disk_filename(name) #都是zip合并没必要再费力压缩了
# attach.filename Zip.default_compression = Zlib::NO_COMPRESSION
# end else
# end Zip.default_compression = Zlib::DEFAULT_COMPRESSION
end
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
files_paths.each do |filename|
flag = true
index = 1
rename_file = ic.iconv( (File.basename(filename)) ).to_s
rename_file = ic.iconv( filename_to_real( File.basename(filename))).to_s if is_attachment
begin
zipfile.add(rename_file, filename)
flag = false
rescue Exception => e
zipfile.get_output_stream('FILE_NOTICE.txt') do |os|
os.write l(:label_file_exist)
end
next
end
end
unless not_exist_file.empty?
zipfile.get_output_stream('FILE_LOST.txt') do |os|
os.write l(:label_file_lost) + not_exist_file.join(',').to_s
end
end
end
zipfile_name
#rescue Errno => e
# logger.error "[zipdown#zipping] ===> #{e}"
# @error = e
end
# 合理分配文件打包
# 如果小于 pack_attachment_max_size, 则返回单个文件
# 反之则切分为多个文件组返回
def split_pack_files(files, pack_attachment_max_size)
max_size = 0
last_files = []
ret_files = []
files.each_with_index do |f,i|
if (max_size += File.size(f)) > pack_attachment_max_size
max_size = 0
if last_files.empty? #如果单个文件超过大小,也将此文件作为一组
ret_files << {files: [f], count: 1, index: ret_files.count+1}
last_files.clear
else
ret_files << {files:last_files, count: last_files.count, index: ret_files.count+1}
last_files.clear
redo
end
else
last_files << f
end
end
ret_files << {files:last_files, count: last_files.count, index: ret_files.count+1} unless last_files.empty?
ret_files
end
def detect_content_type(name)
content_type = Redmine::MimeType.of(name)
content_type.to_s
end
def filename_to_real(name)
attach = Attachment.find_by_disk_filename(name)
attach.filename
end
end

View File

@ -23,7 +23,7 @@
(<span id="jours_count" class="c_red f_12"><%= @jours_count %></span>) (<span id="jours_count" class="c_red f_12"><%= @jours_count %></span>)
</li> </li>
<li> <li>
<%#= link_to "作品打包下载", zipdown_assort_path(obj_class: @bid.class, obj_id: @bid), class: "tb_all" unless @bid.homeworks.empty? %> <%#= link_to "作品打包下载", zipdown_assort_path(obj_class: @bid.class, obj_id: @bid), class: "tb_all" unless @bid.homeworks.empty? %>
</li> </li>
</ul> </ul>
<% else %> <% else %>
@ -63,6 +63,19 @@
</div> </div>
</div> </div>
</div> </div>
<div id="light" class="upload_box">
<a href="javascript:void(0)" onClick="document.getElementById('light').style.display='none';" class="close">
</a>
<div class="upload_box_" >
<h2 class="upload_box_tit">下载文件包太大,分成多个下载包</h2>
<ul class="upload_box_ul" >
<li><span class="upload_box_span" >1.</span> <a href="#">前20名学生的作业</a><span class="c_grey">&nbsp;&nbsp;共200M</span> </li>
</ul>
<div class="cl"></div>
</div>
</div><!---upload_box en--->
<div id="show_homework_attach_model"></div> <div id="show_homework_attach_model"></div>
</body> </body>
</html> </html>

View File

@ -7,6 +7,7 @@
<%= wikitoolbar_for 'settings_welcome_text' %> <%= wikitoolbar_for 'settings_welcome_text' %>
<p style="padding-left: 180px;"><%= setting_text_field :attachment_max_size, :size => 6 %> <%= l(:"number.human.storage_units.units.kb") %></p> <p style="padding-left: 180px;"><%= setting_text_field :attachment_max_size, :size => 6 %> <%= l(:"number.human.storage_units.units.kb") %></p>
<p style="padding-left: 180px;"><%= setting_text_field :pack_attachment_max_size, :size => 6 %> <%= l(:"number.human.storage_units.units.kb") %></p>
<p style="padding-left: 180px;"><%= setting_text_field :per_page_options, :size => 20 %> <p style="padding-left: 180px;"><%= setting_text_field :per_page_options, :size => 20 %>
<em class="info"><%= l(:text_comma_separated) %></em></p> <em class="info"><%= l(:text_comma_separated) %></em></p>

View File

@ -1,2 +1,11 @@
<h1>Download Status:</h1> <% unless @mut_down_files %>
<%= @error.class %> <h1>Download Status:</h1>
<%= @error.class %>
<% else %>
<h1>下载文件包太大,分成<%= @mut_down_files.count %>个下载包</h1>
<ul>
<% @mut_down_files.each_with_index do |file,i| %>
<li><%= link_to "第#{i+1}个文件包", zipdown_download_path(file: File.basename(file)) %></li>
<% end %>
</ul>
<% end %>

View File

@ -177,6 +177,7 @@ en:
setting_login_required: Authentication required setting_login_required: Authentication required
setting_self_registration: Self-registration setting_self_registration: Self-registration
setting_attachment_max_size: Maximum attachment size setting_attachment_max_size: Maximum attachment size
setting_pack_attachment_max_size: Maximum pack attachment size
setting_issues_export_limit: Issues export limit setting_issues_export_limit: Issues export limit
setting_mail_from: Emission email address setting_mail_from: Emission email address
setting_bcc_recipients: Blind carbon copy recipients (bcc) setting_bcc_recipients: Blind carbon copy recipients (bcc)

View File

@ -188,6 +188,7 @@ zh:
setting_login_required: 要求认证 setting_login_required: 要求认证
setting_self_registration: 允许自注册 setting_self_registration: 允许自注册
setting_attachment_max_size: 附件大小限制 setting_attachment_max_size: 附件大小限制
setting_pack_attachment_max_size: 附件打包最大限制
setting_issues_export_limit: 问题导出条目的限制 setting_issues_export_limit: 问题导出条目的限制
setting_mail_from: 邮件发件人地址 setting_mail_from: 邮件发件人地址
setting_bcc_recipients: 使用密件抄送 (bcc) setting_bcc_recipients: 使用密件抄送 (bcc)

View File

@ -103,8 +103,9 @@ RedmineApp::Application.routes.draw do
mount SeemsRateable::Engine => '/rateable', :as => :rateable mount SeemsRateable::Engine => '/rateable', :as => :rateable
# namespace :zipdown do # namespace :zipdown do
# match 'assort' # match 'assort'
# match 'download_user_homework', :as => :download_user_homework # match 'download_user_homework', :as => :download_user_homework
# match 'download'
# end # end
namespace :test do namespace :test do
match 'courselist' match 'courselist'

View File

@ -46,7 +46,10 @@ session_timeout:
default: 2880 default: 2880
attachment_max_size: attachment_max_size:
format: int format: int
default: 5120 default: 51200
pack_attachment_max_size:
format: int
default: 51200
issues_export_limit: issues_export_limit:
format: int format: int
default: 500 default: 500

View File

@ -0,0 +1,11 @@
class AddPackAttachmentMaxSizeToSettings < ActiveRecord::Migration
def up
Setting.where(name: 'attachment_max_size').update_all(value: 51200)
Setting.create(name: 'pack_attachment_max_size', value: 51200 )
end
def down
Setting.delete(name: 'pack_attachment_max_size')
Setting.where(name: 'attachment_max_size').update_all(value: 204800)
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20150324021043) do ActiveRecord::Schema.define(:version => 20150309090143) do
create_table "activities", :force => true do |t| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false

View File

@ -864,4 +864,32 @@ $(function(){
$(this).parent('p').remove(); $(this).parent('p').remove();
console.log("delete complete."); console.log("delete complete.");
}); });
$('a.tb_all').bind('ajax:complete', function (event, data, status, xhr) {
if(status == 'success'){
var res = JSON.parse(data.responseText);
if(res.length<1){
return;
}
if(res.length==1){
location.href = '/zipdown/download?file='+res[0].file;return;
}
document.getElementById('light').style.display='block';
$container = $('#light .upload_box_ul');
$container.empty();
for(var i = 0; i <res.length; ++i){
var des = '';
if(res.count > 1){
des = '第'+res[i].index+'-'+(res[i].count+res[i].index-1)+'个学生的作品下载';
} else {
des = '第'+res[i].index+'个学生的作品下载';
}
$('<li><span class="upload_box_span" >'+(i+1)+'.</span> <a href="/zipdown/download?file='+res[i].file+'">'+des+'</a><span class="c_grey">&nbsp;&nbsp;(共'+res[i].size+'M</span> </li>').appendTo($container);
}
}
})
}); });

View File

@ -12,6 +12,17 @@ function postUpMsg(attachmentId)
}) })
} }
function reload(fileSpan) {
fileSpan.remove();
$('#upload_file_count').html("未上传文件");
$old_file = $("#_file");
$new_file = $old_file.clone(true);
$old_file.replaceWith($new_file);
$new_file.show();
}
function addFile(inputEl, file, eagerUpload) { function addFile(inputEl, file, eagerUpload) {
if ($('#attachments_fields').children().length < 10) { if ($('#attachments_fields').children().length < 10) {
@ -22,10 +33,20 @@ function addFile(inputEl, file, eagerUpload) {
fileSpan.append( fileSpan.append(
$('<input>', { 'type': 'text', 'class': 'filename readonly', 'name': 'attachments[' + attachmentId + '][filename]', 'readonly': 'readonly'} ).val(file.name), $('<input>', { 'type': 'text', 'class': 'filename readonly', 'name': 'attachments[' + attachmentId + '][filename]', 'readonly': 'readonly'} ).val(file.name),
$('<input>', { 'type': 'text', 'class': 'description','style':'margin-left: 9px;', 'name': 'attachments[' + attachmentId + '][description]', 'maxlength': 254, 'placeholder': $(inputEl).data('descriptionPlaceholder') } ).toggle(!eagerUpload), $('<input>', { 'type': 'text', 'class': 'description', 'name': 'attachments[' + attachmentId + '][description]', 'maxlength': 254, 'placeholder': $(inputEl).data('descriptionPlaceholder') } ).toggle(!eagerUpload),
$('<span >'+$(inputEl).data('fieldIsPublic')+':</span>').attr({ 'class': 'ispublic-label','style':'margin-left: 15px;' }) , $('<span >'+$(inputEl).data('fieldIsPublic')+':</span>').attr({ 'class': 'ispublic-label' }) ,
$('<input>', { 'type': 'checkbox','style':'margin-left: 5px;', 'class': 'is_public_checkbox','value':1, 'name': 'attachments[' + attachmentId + '][is_public_checkbox]', checked:'checked' } ).toggle(!eagerUpload), $('<input>', { 'type': 'checkbox', 'class': 'is_public_checkbox','value':1, 'name': 'attachments[' + attachmentId + '][is_public_checkbox]', checked:'checked' } ).toggle(!eagerUpload),
$('<a>&nbsp;&nbsp;&nbsp;</a>').attr({ 'href': "#", 'class': 'remove-upload','style':'margin-left: 3px;', 'data-confirm' : $(inputEl).data('areYouSure') }).click(removeFile).toggle(!eagerUpload), $('<a>&nbsp</a>').attr({ 'href': "#", 'class': 'remove-upload' }).click(function(){
if(confirm('您确定要删除吗?')){
removeFile();
if(!eagerUpload){
(function(e){
reload(e);
})(fileSpan);
}
}
}).toggle(!eagerUpload),
$('<div>', { 'class': 'div_attachments', 'name': 'div_'+'attachments_' + attachmentId} ) $('<div>', { 'class': 'div_attachments', 'name': 'div_'+'attachments_' + attachmentId} )
).appendTo('#attachments_fields'); ).appendTo('#attachments_fields');
@ -166,11 +187,9 @@ function addInputFiles(inputEl) {
if (inputEl.files) { if (inputEl.files) {
// upload files using ajax // upload files using ajax
//alert("11");
uploadAndAttachFiles(inputEl.files, inputEl); uploadAndAttachFiles(inputEl.files, inputEl);
// $(inputEl).remove(); // $(inputEl).remove();
} else { } else {
//alert("11");
// browser not supporting the file API, upload on form submission // browser not supporting the file API, upload on form submission
var attachmentId; var attachmentId;
var aFilename = inputEl.value.split(/\/|\\/); var aFilename = inputEl.value.split(/\/|\\/);

View File

@ -151,8 +151,18 @@ a:hover.tijiao{ background:#0f99a9 !important;}
.ni_con p{ color:#808181;} .ni_con p{ color:#808181;}
.ni_con a:hover{ text-decoration:none;} .ni_con a:hover{ text-decoration:none;}
/*弹框*/
.black_overlay{display:none;position:absolute;top:0%;left:0%;width:100%;height:100%;background-color:black;z-index:1001;-moz-opacity:0.3;opacity:.30;filter:alpha(opacity=30);}
.upload_box{display:none;position:absolute;top:25%;left:35%;width:30%;height: auto;padding:5px;border:3px solid #15bccf; background:#fff;z-index:1002;overflow:auto;}
.close{background:url(images/img_floatbox.png) 0 0 no-repeat; width:16px; height:16px; display:block; float:right;}
.close:hover{background:url(images/img_floatbox.png) -22px 0 no-repeat; width:16px; height:16px; display:block; float:right;}
.upload_box_tit{ font-size:16px; color:#15bccf; text-align:center; }
.upload_box_{ margin-left:10%; margin-bottom:5px; margin-right:10%;}
.upload_box_ul{ margin-bottom:10px;}
.upload_box_ul a{ color:#09658c;}
.upload_box_ul a:hover{ color:#15bccf;}
.upload_box_span{ color: #333; font-weight: bold;}
.c_grey{ color:#A7A7A7;}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1012 B