From 4b636d8be6a0287d8ad0650b93f067f0ac87aef6 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 25 Mar 2015 13:13:09 +0800 Subject: [PATCH] =?UTF-8?q?#1801=20=E6=89=93=E5=8C=85=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=88=86=E4=B8=AA=E6=95=B0=E4=B8=8B=E8=BD=BD=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 4 --- app/controllers/zipdown_controller.rb | 39 ++++++++++++++------- app/views/bids/_homework_list.html.erb | 15 +++++++- public/javascripts/application.js | 28 +++++++++++++++ public/stylesheets/css.css | 14 ++++++-- public/stylesheets/images/img_floatbox.png | Bin 0 -> 1012 bytes 6 files changed, 80 insertions(+), 20 deletions(-) create mode 100644 public/stylesheets/images/img_floatbox.png diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 23d4c3a16..d458b73e4 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -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 diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 75ffe75bd..9880a6382 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -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 diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 6572ee2c9..7ac686e09 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -23,7 +23,7 @@ (<%= @jours_count %>)
  • - <%= 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? %>
  • <% else %> @@ -63,6 +63,19 @@ + +
    + + +
    +

    下载文件包太大,分成多个下载包

    + +
    +
    +
    +
    diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 5d2423238..a18a282e4 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -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 1){ + des = '第'+res[i].index+'-'+(res[i].count+res[i].index-1)+'个学生的作品下载'; + } else { + des = '第'+res[i].index+'个学生的作品下载'; + } + $('
  • '+(i+1)+'. '+des+'  (共'+res[i].size+'M)
  • ').appendTo($container); + + } + } + + }) }); diff --git a/public/stylesheets/css.css b/public/stylesheets/css.css index 2319d1f59..0f51322df 100644 --- a/public/stylesheets/css.css +++ b/public/stylesheets/css.css @@ -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;} diff --git a/public/stylesheets/images/img_floatbox.png b/public/stylesheets/images/img_floatbox.png new file mode 100644 index 0000000000000000000000000000000000000000..b2167f5ffffb44e15fa2aa86f6e816dadab940f7 GIT binary patch literal 1012 zcmV(_`g8%^e{{R4h=>PzAFaQARU;qF*m;eA5Z<1fd zMgRZfy+RDBcRZ>YIIFMFfw3b-O#rB zqfK+bbKooRO98b6JOFxuzGnRp+E$Hj8p`y8SU0q-K2jIY0?!msOTeUzOz(M38roKk zZUiM^CS_z|-E<@>zzcc!C-6odx&)M3t(?%dYIIFMh;>8Ts?k;DbryIE90ODGv%YrA zSw^ZxH%e0@Ab=|}Z6^}O_)Bf3MptEY)kQCXhq48{0)Au|{anlR1Ep>ns;GdOk_L`) zdjdR?P(8qDi!f8tz$N)vtZVu~PiR}G=?E<L)Ds8gnaG>`_;KpIE`X`pTaavW#N zahxFcCunuPyL}N6Dt1a(Mz=^*w0>?rKtJ5AT@#i_@ro31MvnltK@-X!T zum_B$p%O5oa?ibnfASs2sR9Tg3T>oqP!6Hd#p6IV1yfF@v{0#3wpuXoR+RG=pvZ!0 zCuL1XO$c!)BNL@B69%9tgc$2o$`Y&E;C+6bT4CTl;0Cavsy-uUm~o(-fI8C>j2vOg zLWo1@n{rl5=wyV}vka_&T5ksEgM78Rz60A?)s%qRmV5Qn4-KS&G>`_;KpN=304nb9 z?<>FXJZ}rAx~{97E{2DP^=#kPnwgo2XM5Lmk210l&-U~4^ZCv8@?sUt#m)9fs07TJ z*}h{yuIr{J)=kgz1{E;nWJ(Lu)6*@@_EFBWR#d&7=hdCTxG87 zj%8FpRSN!Fv%SJI@ocZEJ|kzCGqZgf%E%F>?7Hru^i4UdCFC~SCk?EC%6GO`RZ{{= i&-NNf1O4AXzXt%Mbf5S7A4@j?0000