导出作品列表功能

This commit is contained in:
z9hang 2014-12-29 17:44:39 +08:00
parent cd6508efa2
commit 61e1f0fa52
3 changed files with 28 additions and 5 deletions

View File

@ -55,9 +55,31 @@ class HomeworkAttachController < ApplicationController
@direction = direction == 'asc'? 'desc' : 'asc'
respond_to do |format|
format.js
format.csv {
send_data(homework_to_csv(all_homework_list), :type => 'text/csv; header=present', :filename => 'issues.csv')
}
end
end
def homework_to_csv items
encoding = l(:general_csv_encoding)
columns = ["student_id","user_name","login","student_num","mail","work_name","teacher_score","ni_score","commit_time"]
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
# csv header fields
csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c, encoding) }
# csv lines
items.each do |homework|
csv << [homework.user.id,Redmine::CodesetUtil.from_utf8(homework.user.lastname.to_s + homework.user.firstname.to_s, encoding),Redmine::CodesetUtil.from_utf8(homework.user.login, encoding),
Redmine::CodesetUtil.from_utf8(homework.user.user_extensions.student_id, encoding),Redmine::CodesetUtil.from_utf8(homework.user.mail, encoding),Redmine::CodesetUtil.from_utf8(homework.name, encoding),
Redmine::CodesetUtil.from_utf8((homework.t_score.nil? || (homework.t_score && homework.t_score.to_i == 0)) ? l(:label_without_score) : format("%.2f",homework.t_score), encoding),
Redmine::CodesetUtil.from_utf8( homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score), encoding),Redmine::CodesetUtil.from_utf8(format_time(homework.created_at), encoding)]
end
end
export
end
#获取所有作业列表
def get_homeworks
sort, direction = params[:sort] || "s_socre", params[:direction] || "desc"

View File

@ -62,11 +62,6 @@
:is_student_batch_homework => @is_student_batch_homework}%>
</div>
</div>
<% if @is_teacher %>
<!--<div>
导出 <a>csv</a>
</div>-->
<% end %>
</div>
<div id="show_homework_attach_model"></div>
</body>

View File

@ -63,4 +63,10 @@
<span style="color: red;">
<%= anonymous_comment_notice(@bid, @bid.courses.first) %>
</span>
<% other_formats_links do |f| %>
<%= f.link_to 'CSV', :url => params %>
<% end %>
<!--<div>
导出 <a>csv</a>
</div> -->
<% end %>