#1801 打包上传分个数下载完成
This commit is contained in:
parent
15accd7d9f
commit
4b636d8be6
|
@ -182,8 +182,6 @@ class AttachmentsController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
|
||||
logger.debug "upload ..... "
|
||||
@attachment = Attachment.new(:file => request.raw_post)
|
||||
@attachment.author = User.current
|
||||
if !params[:project].nil?
|
||||
|
@ -192,8 +190,6 @@ class AttachmentsController < ApplicationController
|
|||
end
|
||||
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
|
||||
saved = @attachment.save
|
||||
logger.debug "upload save ..... "
|
||||
logger.debug @attchement
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
|
|
@ -25,17 +25,25 @@ class ZipdownController < ApplicationController
|
|||
zipfile = zip_bid bid
|
||||
else
|
||||
render file: 'public/no_file_found.html'
|
||||
return
|
||||
end
|
||||
else
|
||||
logger.error "[ZipDown#assort] ===> #{params[:obj_class]} unKown !!"
|
||||
end
|
||||
|
||||
if zipfile
|
||||
if zipfile.length > 1
|
||||
@mut_down_files = zipfile.map{|x| File.basename(x)}
|
||||
else
|
||||
send_file zipfile, :filename => bid.name + ".zip", :type => detect_content_type(zipfile)
|
||||
end
|
||||
# if zipfile
|
||||
# if zipfile.length > 1
|
||||
# @mut_down_files = zipfile #zipfile.each{|x| File.basename(x)}
|
||||
# else
|
||||
# send_file zipfile.first[:real_file], :filename => bid.name + ".zip", :type => detect_content_type(zipfile.first[:real_file])
|
||||
# return
|
||||
# end
|
||||
# end
|
||||
|
||||
respond_to do |format|
|
||||
format.json {
|
||||
render json: zipfile.to_json
|
||||
}
|
||||
end
|
||||
#rescue Exception => e
|
||||
# render file: 'public/no_file_found.html'
|
||||
|
@ -86,13 +94,18 @@ class ZipdownController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
zips = split_pack_files(bid_homework_path, Setting.pack_attachment_max_size.to_i)
|
||||
zips = split_pack_files(bid_homework_path, Setting.pack_attachment_max_size.to_i*1024)
|
||||
x = 0
|
||||
|
||||
zips.map { |o|
|
||||
|
||||
zips.each { |o|
|
||||
x += 1
|
||||
zipping "#{Time.now.to_i}_#{bid.name}_#{x}.zip", o, OUTPUT_FOLDER
|
||||
file = zipping "#{Time.now.to_i}_#{bid.name}_#{x}.zip", o[:files], OUTPUT_FOLDER
|
||||
o[:real_file] = file
|
||||
o[:file] = File.basename(file)
|
||||
o[:size] = (File.size(file) / 1024.0 / 1024.0).round(2)
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
def zip_homework_by_user(homeattach)
|
||||
|
@ -163,14 +176,14 @@ class ZipdownController < ApplicationController
|
|||
max_size = 0
|
||||
last_files = []
|
||||
ret_files = []
|
||||
files.each do |f|
|
||||
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 << [f]
|
||||
ret_files << {files: [f], count: 1, index: ret_files.count+1}
|
||||
last_files.clear
|
||||
else
|
||||
ret_files << last_files
|
||||
ret_files << {files:last_files, count: last_files.count, index: ret_files.count+1}
|
||||
last_files.clear
|
||||
redo
|
||||
end
|
||||
|
@ -179,7 +192,7 @@ class ZipdownController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
ret_files << last_files unless last_files.empty?
|
||||
ret_files << {files:last_files, count: last_files.count, index: ret_files.count+1} unless last_files.empty?
|
||||
ret_files
|
||||
end
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
(<span id="jours_count" class="c_red f_12"><%= @jours_count %></span>)
|
||||
</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, format: :json), remote: true, class: "tb_all" unless @bid.homeworks.empty? %>
|
||||
</li>
|
||||
</ul>
|
||||
<% else %>
|
||||
|
@ -63,6 +63,19 @@
|
|||
</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"> (共200M)</span> </li>
|
||||
</ul>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
</div><!---upload_box en--->
|
||||
|
||||
<div id="show_homework_attach_model"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -864,4 +864,32 @@ $(function(){
|
|||
$(this).parent('p').remove();
|
||||
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"> (共'+res[i].size+'M)</span> </li>').appendTo($container);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
});
|
||||
|
|
|
@ -149,8 +149,18 @@ a:hover.tijiao{ background:#0f99a9 !important;}
|
|||
.ni_con p{ color:#808181;}
|
||||
.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 |
Loading…
Reference in New Issue