增加《学生列表按作业评分排序功能》

Signed-off-by: alan <547533434@qq.com>
This commit is contained in:
alan 2014-12-29 20:46:27 +08:00
parent 9ba0c75ddb
commit e39e801c61
3 changed files with 36 additions and 20 deletions

View File

@ -210,14 +210,15 @@ class CoursesController < ApplicationController
@render_file = 'member_list' @render_file = 'member_list'
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@is_remote = true @is_remote = true
@score_sort_by = "desc"
q = "#{params[:name].strip}" q = "#{params[:name].strip}"
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
if params[:incourse] if params[:incourse]
@results = searchmember_by_name(student_homework_score(0,0,0), q) @results = searchmember_by_name(student_homework_score(0,0,0,"desc"), q)
elsif params[:ingroup] elsif params[:ingroup]
@group = CourseGroup.find(params[:search_group_id]) @group = CourseGroup.find(params[:search_group_id])
@results = searchmember_by_name(student_homework_score(@group.id,0,0), q) @results = searchmember_by_name(student_homework_score(@group.id,0,0,"desc"), q)
end end
@is_remote = true @is_remote = true
@result_count = @results.count @result_count = @results.count
@ -307,16 +308,17 @@ class CoursesController < ApplicationController
@render_file = 'member_list' @render_file = 'member_list'
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@is_remote = true @is_remote = true
@score_sort_by = "desc"
if params[:group_id] && params[:group_id] != "0" if params[:group_id] && params[:group_id] != "0"
@group = CourseGroup.find(params[:group_id]) @group = CourseGroup.find(params[:group_id])
@results = student_homework_score(@group.id,0, 0) @results = student_homework_score(@group.id,0, 0,"desc")
@results = paginateHelper @results, 10 @results = paginateHelper @results, 10
else else
page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1) page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1)
@results = student_homework_score(0,page_from, 10) @results = student_homework_score(0,page_from, 10,"")
@results = paginateHelper_for_members @results, 10 @results = paginateHelper_for_members @results, 10
end end
@ -329,7 +331,7 @@ class CoursesController < ApplicationController
## 有角色参数的才是课程,没有的就是项目 ## 有角色参数的才是课程,没有的就是项目
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
@render_file = 'member_list' @render_file = 'member_list'
@score_sort_by = "desc"
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@role = params[:role].nil? ? '2':params[:role] @role = params[:role].nil? ? '2':params[:role]
@is_remote = true @is_remote = true
@ -343,7 +345,7 @@ class CoursesController < ApplicationController
when '2' when '2'
@subPage_title = l :label_student_list @subPage_title = l :label_student_list
page = params[:page].nil? ? 0 : (params['page'].to_i - 1) page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
@members = student_homework_score(0,page, 10) @members = student_homework_score(0,page, 10,"desc")
@members = paginateHelper_for_members @members, 10 @members = paginateHelper_for_members @members, 10
@ -367,18 +369,31 @@ class CoursesController < ApplicationController
def member_score_sort def member_score_sort
# @teachers= searchTeacherAndAssistant(@course) # @teachers= searchTeacherAndAssistant(@course)
# @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
# @role = params[:role] # @role = params[:role]
# @course_groups = @course.course_groups if @course.course_groups # @course_groups = @course.course_groups if @course.course_groups
# @show_serch = params[:role] == '2' # @show_serch = params[:role] == '2'
# @subPage_title = l :label_student_list @subPage_title = l :label_student_list
# @render_file = 'member_list' @render_file = 'member_list'
# @results = params[:result] if params[:result] # @results = params[:result] if params[:result]
# unless @result.nil? # unless @result.nil?
# @results = @result.reverse # @results = @result.reverse
# #
# end # end
# @results = paginateHelper @results # @results = paginateHelper @results@score_sort_by = "desc"
@is_remote = true
@score_sort_by = params[:sort_by] if params[:sort_by]
group_id = params[:group_id]
if group_id == '0'
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
@results = student_homework_score(0,page, 10,@score_sort_by)
@results = paginateHelper_for_members @results, 10
else
@group = Group.find(group_id)
@results = student_homework_score(group_id, 0, 0,@score_sort_by)
@results = paginateHelper @results, 10
end
end end
# 显示每个学生的作业评分详情 # 显示每个学生的作业评分详情
def show_member_score def show_member_score
@ -882,12 +897,12 @@ class CoursesController < ApplicationController
end end
end end
def student_homework_score(groupid,start_from, nums) def student_homework_score(groupid,start_from, nums, score_sort_by)
#teachers = find_course_teachers(@course) #teachers = find_course_teachers(@course)
start_from = start_from * nums start_from = start_from * nums
sql = ActiveRecord::Base.connection() sql = ActiveRecord::Base.connection()
homework_scores = Member.find_by_sql("call member_score(#{@course.id},#{groupid},#{start_from},#{nums})") homework_scores = Member.find_by_sql("call member_score(#{@course.id},#{groupid},#{start_from},#{nums}, '#{score_sort_by}')")
sql.close() sql.close()
homework_scores homework_scores
@ -903,10 +918,9 @@ class CoursesController < ApplicationController
@render_file = 'member_list' @render_file = 'member_list'
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1' @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@is_remote = true @is_remote = true
@score_sort_by = "desc"
page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1) page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1)
@results = student_homework_score(group.id,0,0) @results = student_homework_score(group.id,0,0, "desc")
@results = paginateHelper @results, 10 @results = paginateHelper @results, 10
end end

View File

@ -1,13 +1,15 @@
<script type=" text/javascript" charset="utf-8"> <script type=" text/javascript" charset="utf-8">
function change_pic(id){ function change_pic(id){
var classname = document.getElementById(id).className var classname = document.getElementById(id).className
if(classname == 'st_up') { if(classname == 'st_up') {
document.getElementById(id).className = 'st_down' document.getElementById(id).className = 'st_down';
} }
else else {
document.getElementById(id).className = 'st_up' document.getElementById(id).className = 'st_up';
}
} }
</script> </script>
<div style="margin-left: 15px" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html"> <div style="margin-left: 15px" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
@ -36,7 +38,7 @@
<div class="st_box"> <div class="st_box">
<ul class="st_box_top" style="margin-left: 17px;"> <ul class="st_box_top" style="margin-left: 17px;">
<% if @subPage_title == l(:label_student_list) %> <% if @subPage_title == l(:label_student_list) %>
<li class="ml358"><%= link_to '作业积分', member_score_sort_course_path ,:result => members,method: 'get', remote: true, :onclick => "change_pic('pic')"%> <li class="ml358"><%= link_to '作业积分', member_score_sort_course_path(:sort_by => (@score_sort_by == "desc" ? "asc" : "desc"), :group_id => (@group ? @group.id : 0)) ,:result => members,method: 'get', remote: true, :onclick => "change_pic('pic')"%>
<a id="pic" href="#" class="st_down"></a> <a id="pic" href="#" class="st_down"></a>
</li> </li>
<li class="ml50"> <li class="ml50">

View File

@ -1,4 +1,4 @@
/** /**
* Created by Administrator on 2014/12/3. * Created by Administrator on 2014/12/3.
*/ */
$("#list_detail").html("<%= escape_javascript( render :partial => 'member_list_detail', :locals => {:members => @results})%>"); $("#member_content").html("<%= escape_javascript( render :partial => @render_file, :locals => {:members => @results})%>");