增加点击作业名下载改作业下所有附件的功能

This commit is contained in:
sw 2014-06-04 12:01:08 +08:00
parent 2bbcff54d3
commit 94542e935a
3 changed files with 35 additions and 3 deletions

View File

@ -20,8 +20,36 @@ class ZipdownController < ApplicationController
#@error = e #@error = e
end end
#下载某一学生的作业的所有文件
def download_user_homework
obj_class = params[:obj_class]
obj_id = params[:obj_id]
user_id = params[:user_id]
obj = obj_class.constantize.find(obj_id)
zipfile = nil
case obj.class.to_s.to_sym
when :Bid
zipfile = zip_user_bid obj,user_id
else
logger.error "[ZipDown#assort] ===> #{obj.class.to_s.to_sym} unKown !!"
end
send_file zipfile, :filename => obj.name, :type => detect_content_type(zipfile) if zipfile
end
private private
def zip_user_bid(bid,user_id)
# Todo: User Access Controll
homeattaches = bid.homeworks.where("user_id = ?",user_id)
# 得到每一个人所有文件打包的zip文件
# 并将每一个人的zip打包为一个并返回路径
user_zip_paths = homeattaches.map do |homeattach|
zip_homework_by_user homeattach
end
zipping "#{Time.now.to_i}_#{bid.name}.zip", user_zip_paths, OUTPUT_FOLDER
end
def zip_bid(bid) def zip_bid(bid)
# Todo: User Access Controll # Todo: User Access Controll

View File

@ -50,10 +50,10 @@
<% end %> <% end %>
--> -->
<% end %> <% end %>
<strong><%= homework_filename %></strong>
<% else %> <% else %>
<strong><%= homework.name %></strong> <% homework_filename = homework.name %>
<% end %> <% end %>
<strong><%= link_to homework_filename, :controller => "zipdown", :action => "download_user_homework",:obj_class => @bid.class,:obj_id => @bid, :user_id =>homework.user%></strong>
</td> </td>
<td style="vertical-align: top"> <td style="vertical-align: top">
<% if is_student %> <% if is_student %>
@ -92,7 +92,8 @@
<% end %> <% end %>
</td> </td>
<td> <td>
<% if (User.current == homework.user) || (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',3,7, 9)).size >0) %> <% if (User.current == homework.user) || (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? &&
(Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',3,7, 9)).size >0) %>
<%= link_to l(:button_edit), edit_homework_attach_path(homework) %> <%= link_to l(:button_edit), edit_homework_attach_path(homework) %>
<%= link_to(l(:label_bid_respond_delete), homework, <%= link_to(l(:label_bid_respond_delete), homework,
method: :delete, :confirm => l(:text_are_you_sure)) %> method: :delete, :confirm => l(:text_are_you_sure)) %>

View File

@ -46,10 +46,13 @@ RedmineApp::Application.routes.draw do
match 'showbug', via: [:get, :post] match 'showbug', via: [:get, :post]
end end
end end
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
end end
namespace :test do namespace :test do
match 'courselist' match 'courselist'