From 35dce16924364b8c7c35a8d1db26c382fe54643f Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 30 Dec 2014 17:49:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=88=90=E5=91=98=E5=88=97?= =?UTF-8?q?=E8=A1=A8excel=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 54 ++++++++++++++++++++--- app/views/courses/_searchmembers.html.erb | 1 + config/locales/zh.yml | 3 ++ config/routes.rb | 1 + public/stylesheets/course_group.css | 9 ++++ public/stylesheets/nyan.css | 3 +- 6 files changed, 65 insertions(+), 6 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 49cc40f10..f595a0c7d 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -340,14 +340,14 @@ class CoursesController < ApplicationController case @role when '1' @subPage_title = l :label_teacher_list - @members = searchTeacherAndAssistant(@course) - @members = paginateHelper @members, 10 + @all_members = searchTeacherAndAssistant(@course) + @members = paginateHelper @all_members, 10 when '2' @subPage_title = l :label_student_list page = params[:page].nil? ? 0 : (params['page'].to_i - 1) - @members = student_homework_score(0,page, 10,"desc") + @all_members = student_homework_score(0,page, 10,"desc") - @members = paginateHelper_for_members @members, 10 + @members = paginateHelper_for_members @all_members, 10 end @@ -357,7 +357,6 @@ class CoursesController < ApplicationController else format.html {render :layout => 'base_courses'} end - end # render :layout => 'base_courses' @@ -367,6 +366,16 @@ class CoursesController < ApplicationController end + def export_course_member_excel + @all_members = student_homework_score(0,0,0,"desc") + respond_to do |format| + format.xls { + send_data(member_to_xls(@all_members,@course.course_groups), :type => "text/excel;charset=utf-8; header=present", + :filename => "student_list_#{Time.now.strftime("%Y%m%d")}.xls") + } + end + end + def member_score_sort # @teachers= searchTeacherAndAssistant(@course) @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @@ -924,4 +933,39 @@ class CoursesController < ApplicationController @results = paginateHelper @results, 10 end + + def member_to_xls members,groups + xls_report = StringIO.new + book = Spreadsheet::Workbook.new + sheet1 = book.create_worksheet :name => "student" + + 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_homework_score)]) + count_row = 1 + group0 = CourseGroup.new(); + group0.id = 0; + group0.name = l(:excel_member_with_out_class) + groups_dup = groups.dup + groups_dup << group0 + groups_dup.each do |group| + sheet1[count_row,0] = l(:excel_class) + sheet1[count_row,1] = group.name + count_row += 1 + members.each do |member| + if member.course_group_id == group.id + sheet1[count_row,0]= member.user.id + sheet1[count_row,1] = member.user.lastname.to_s + member.user.firstname.to_s + sheet1[count_row,2] = member.user.login + sheet1[count_row,3] = member.user.user_extensions.student_id + sheet1[count_row,4] = member.user.mail + sheet1[count_row,5] = format("%0.2f",member.score.to_s) + count_row += 1 + end + end + end + book.write xls_report + xls_report.string + end end diff --git a/app/views/courses/_searchmembers.html.erb b/app/views/courses/_searchmembers.html.erb index 426c52ca5..71bacd02e 100644 --- a/app/views/courses/_searchmembers.html.erb +++ b/app/views/courses/_searchmembers.html.erb @@ -8,4 +8,5 @@ <%= submit_tag l(:label_search_member),:style => "float: left", :name => 'incourse',:onclick => "checkclass('group_name_0')",:class => "f_2"%> <% end %> <% end %> + <%= link_to l(:label_export_excel), export_course_member_excel_course_path(@course,:format => 'xls'),:class=>'xls'%> <% end %> \ No newline at end of file diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 0620a8355..46fdc417a 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2099,6 +2099,9 @@ zh: excel_t_score: 教师评分 excel_n_score: 匿名评分 excel_commit_time: 提交时间 + excel_homework_score: 作业积分 + excel_class: "班级:" + excel_member_with_out_class: "未加入班级的学生" label_export_excel: 导出Excel label_softapplication: 应用软件 diff --git a/config/routes.rb b/config/routes.rb index e2f207870..a350f5de3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -641,6 +641,7 @@ RedmineApp::Application.routes.draw do get 'file', :action => 'file', :as => 'file' get 'feedback', :action => 'feedback', :as => 'course_feedback' get 'member', :controller => 'courses', :action => 'member', :as => 'member' + get 'export_course_member_excel',:controller => 'courses',:action => 'export_course_member_excel' get 'member_score', :to => 'courses#member_score' post 'finishcourse' post 'restartcourse' diff --git a/public/stylesheets/course_group.css b/public/stylesheets/course_group.css index cf1806819..71f870a9a 100644 --- a/public/stylesheets/course_group.css +++ b/public/stylesheets/course_group.css @@ -41,7 +41,16 @@ input.f_2 { .st_search{ margin:10px 0;} .st_search span{ font-size:14px; font-weight:bold; color:#606060; margin-right:35px;} .st_search input{ border:1px solid #1c9ec7; height:20px; width:200px;} + a:hover.xls{ background: url('../images/icon_excel.gif') no-repeat scroll 1px 50% transparent !important; + padding: 2px 0px 3px 16px; + font-family:微软雅黑 !important; + font-size: 12px !important; + color: #136b3b !important; + text-decoration: underline !important; + font-weight:normal !important; + } .st_search a:hover{ background:#048fbb; text-decoration:none;} + /*.st_search input.f_2{ background:#1c9ec7; padding: 3px; margin-left: 3px; color:#fff;border:1px solid #1c9ec7; text-align:center; display:block; width:45px; height:28px; font-size:12px; }*/ .classbox{ border:1px solid #f8df8c; background:#fffce6; color:#0d90c3; padding:0 3px; float:left; margin-left:15px;} diff --git a/public/stylesheets/nyan.css b/public/stylesheets/nyan.css index e00c5c63f..c532e7112 100644 --- a/public/stylesheets/nyan.css +++ b/public/stylesheets/nyan.css @@ -1432,10 +1432,11 @@ ul.contest-notification-list li span{ word-break: break-all; } -a.xls { +.xls { background: url('../images/icon_excel.gif') no-repeat scroll 1px 50% transparent; padding: 2px 0px 3px 16px; font-family:微软雅黑 !important; font-size: 12px !important; color: #136b3b !important; + font-weight:normal !important; }