竞赛的成员配置页,增加“单位名称”的显示,同时增加excel导出功能

This commit is contained in:
cxt 2017-01-10 11:00:18 +08:00
parent d4d8a82e8b
commit fe24382157
5 changed files with 56 additions and 5 deletions

View File

@ -9,7 +9,7 @@ class ContestsController < ApplicationController
include AvatarHelper
before_filter :find_contest, :only => [:show, :settings, :update, :destroy, :contest_activities, :search_member, :private_or_public, :switch_role, :set_invite_code_halt, :renew,
:member]
:member, :export_all_members]
before_filter :is_logged, :only => [:index, :new, :create]
before_filter :is_admin?, :only => [:settings, :set_invite_code_halt, :destroy]
before_filter :is_member?, :only => [:show, :contest_activities]
@ -284,8 +284,52 @@ class ContestsController < ApplicationController
end
end
def export_all_members
sql = "SELECT DISTINCT(cmr.id) AS cmr_id, cmr.role_id, users.`login`, users.id AS user_id, users.`mail`, cmr.created_at FROM users, contest_members cm, contest_member_roles cmr, user_extensions ue, schools " +
"WHERE users.id = cm.`user_id` AND users.id=ue.`user_id` AND cmr.`contest_member_id` = cm.`id` AND cm.`contest_id` = #{@contest.id} AND (ue.`school_id` IS NULL OR ue.`school_id` = schools.`id`) " +
"ORDER BY role_id ASC, CONVERT(schools.`name` USING gbk) COLLATE gbk_chinese_ci DESC, CONVERT(users.`lastname` USING gbk) COLLATE gbk_chinese_ci DESC"
@members = ContestMemberRole.find_by_sql sql
respond_to do |format|
format.xls {
filename = "#{@contest.name.to_s}-成员列表-#{DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s}.xls"
send_data(member_to_xls(@members), :type => "text/excel;charset=utf-8; header=present",
:filename => filename_for_content_disposition("#{filename}.xls"))
}
end
end
private
def member_to_xls members
xls_report = StringIO.new
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet :name => "成员列表"
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
#sheet1.row(0).default_format = blue
#sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)])
sheet1[0,0] = "id"
sheet1[0,1] = "姓名"
sheet1[0,2] = "登录名"
sheet1[0,3] = "电子邮箱"
sheet1[0,4] = "单位"
sheet1[0,5] = "角色"
sheet1[0,6] = "加入时间"
count_row = 1
members.each_with_index do |member, i|
user = User.find(member.user_id)
sheet1[count_row,0]= user.id
sheet1[count_row,1] = user.show_name
sheet1[count_row,2] = user.login
sheet1[count_row,3] = user.mail
sheet1[count_row,4] = user.user_extensions.school_id.blank? ? "" : (user.user_extensions.school.blank? ? "" : user.user_extensions.school.name)
sheet1[count_row,5] = member.role_id == 13 ? "管理员" : (member.role_id == 14 ? "评委" : "参赛者")
sheet1[count_row,6] = format_time member.created_at
count_row += 1
end
book.write xls_report
xls_report.string
end
def find_contest
if params[:id].to_i < 780
render_403

View File

@ -2,7 +2,8 @@
<thead>
<tr>
<th style="width: 35px;">序号</th>
<th style="width:320px;">姓名</th>
<th style="width:180px;">姓名</th>
<th style="width:140px;">单位</th>
<th>角色</th>
<th class="sy_new_namebox">操作</th>
</tr>
@ -12,7 +13,10 @@
<tr>
<td><%= index + 1 %></td>
<td>
<%= link_to member.user.show_name, user_path(member.user), :class => "pro_new_idname ml10", :title => "#{member.user.show_name}" %>
<%= link_to member.user.show_name, user_path(member.user), :class => "pro_new_idname ml10 mr10", :title => "#{member.user.show_name}" %>
</td>
<td>
<span class="pro_new_school_name ml5 mr5"><%=member.user.user_extensions.school ? member.user.user_extensions.school.name : '--' %></span>
</td>
<td style="width: 200px">
<span id="member_role_<%=member.id %>"><%= zh_contest_role(h member.roles.sort.collect(&:to_s).join(', ')) %></span>

View File

@ -1,5 +1,6 @@
<div class="pro_new_setting_conbox fl " style="width:100%; border:none;">
<a href="javascript:void(0);" class="fl sy_btn_green mb10 ml15" onclick="add_contest_member();">添加成员</a>
<a href="javascript:void(0);" class="fl sy_btn_green mb10 ml15" onclick="add_contest_member();">添加成员</a>
<%= link_to "Excel导出", export_all_members_contest_path(@contest, :format => 'xls'), :class => 'fl sy_btn_green mb10 ml15' %>
<div class="cl"></div>
<div class=" sy_new_tchbox clear undis" style="margin-left:10px; margin-right:10px" id="add_contest_member">
<%= form_tag url_for(:controller => 'contest_members', :action => 'create', :contest => @contest.id),:id => 'contest_member_add_form', :remote => true do |f|%>

View File

@ -637,6 +637,7 @@ RedmineApp::Application.routes.draw do
get 'set_invite_code_halt'
get 'renew'
get 'member'
get 'export_all_members'
end
resources :boards

View File

@ -12,7 +12,8 @@
.mt12{ margin-top:12px;}
.pro_new_idbox{ width: 40%; padding-left: 30px;}
.pro_new_idlist{ width: 50%; border-right: 1px solid #e5e5e5; padding-right: 30px; min-height: 100px;}
.pro_new_idname{display:block;width:300px; overflow:hidden;white-space: nowrap; text-overflow:ellipsis;}
.pro_new_idname{display:block;width:160px; overflow:hidden;white-space: nowrap; text-overflow:ellipsis;}
.pro_new_school_name{display:block;width:130px; overflow:hidden;white-space: nowrap; text-overflow:ellipsis;}
.sy_new_tchbox p{ line-height: 30px;}
.pro_newsetting_con p,.pro_newsetting_con { line-height: 30px;}
.w650{ width: 650px;}