测验结果列表增加检索条件

This commit is contained in:
cxt 2017-03-07 15:39:37 +08:00
parent 69e3c8e893
commit b8856f845a
4 changed files with 67 additions and 15 deletions

View File

@ -483,6 +483,7 @@ class ExerciseController < ApplicationController
end
end
=end
@name,@select_group = params[:name].to_s.strip || "",params[:group]
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
if @is_teacher
@all_exercises = @course.exercises.order("created_at desc")
@ -490,17 +491,53 @@ class ExerciseController < ApplicationController
@all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc")
end
student_id = @course.student.blank? ? "(-1)" : "(" + @course.student.map{|student| student.student_id}.join(",") + ")"
@exercise_count = @exercise.exercise_users.where("commit_status = 1 and user_id in #{student_id}").count
if @is_teacher || (!@exercise.exercise_users.where("user_id = #{User.current.id} and user_id in #{student_id}").empty? && @exercise.end_time <= Time.now)
@exercise_users_list = @exercise.exercise_users.where("user_id in #{student_id}")
if @select_group
if @select_group == "0"
none_group_students = @course.members.select{ |member| member.course_group_id == 0 }
if none_group_students.empty?
student_in_group = '(0)'
else
student_in_group = '(' + none_group_students.map{ |member| member.user_id }.join(',') + ')'
end
elsif @select_group == "-1"
all_group_students = @course.members.select{ |member| member.course_group_id }
if all_group_students.empty?
student_in_group = '(0)'
else
student_in_group = '(' + all_group_students.map{ |member| member.user_id }.join(',') + ')'
end
else
course_group = CourseGroup.find_by_id(@select_group)
group_students = course_group.users
if group_students.empty?
student_in_group = '(0)'
else
student_in_group = '(' + group_students.map{ |user| user.id }.join(',') + ')'
end
end
if @is_teacher || (!@exercise.exercise_users.where("user_id = #{User.current.id}").empty? && @exercise.end_time <= Time.now)
@exercise_users_list = search_exercise_member @exercise.exercise_users.where("user_id in #{student_id} and user_id in #{student_in_group}"), @name
@show_all = true;
elsif !@exercise.exercise_users.where("user_id = #{User.current.id} and user_id in #{student_id}").empty? && @exercise.end_time > Time.now
@exercise_users_list = @exercise.exercise_users.where("user_id = ? and user_id in #{student_id}",User.current.id)
elsif !@exercise.exercise_users.where("user_id = #{User.current.id}").empty? && @exercise.end_time > Time.now
@exercise_users_list = search_exercise_member @exercise.exercise_users.where("user_id = ? and user_id in #{student_id} and user_id in #{student_in_group}",User.current.id), @name
else
@exercise_users_list = []
end
else
if @is_teacher || (!@exercise.exercise_users.where("user_id = #{User.current.id}").empty? && @exercise.end_time <= Time.now)
@exercise_users_list = search_exercise_member @exercise.exercise_users.where("user_id in #{student_id}"), @name
@show_all = true;
elsif !@exercise.exercise_users.where("user_id = #{User.current.id}").empty? && @exercise.end_time > Time.now
@exercise_users_list = search_exercise_member @exercise.exercise_users.where("user_id = ? and user_id in #{student_id}",User.current.id), @name
else
@exercise_users_list = []
end
end
@exercise_count = @exercise.exercise_users.where("commit_status = 1 and user_id in #{student_id}").count
@left_nav_type = 8
respond_to do |format|
format.js
format.html
format.xls {
filename = "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@exercise.exercise_name}#{l(:excel_exercise_list)}.xls"
@ -893,6 +930,19 @@ class ExerciseController < ApplicationController
xls_report.string
end
#根据条件过滤作业结果
def search_exercise_member exercises,name
if name == ""
select_exercises = exercises
else
name = name.downcase
select_exercises = exercises.select{ |exercise|
exercise.user[:login].to_s.downcase.include?(name) || exercise.user.user_extensions[:student_id].to_s.downcase.include?(name) || (exercise.user[:lastname].to_s.downcase + exercise.user[:firstname].to_s.downcase).include?(name)
}
end
select_exercises
end
# ExerciseUser记录用户是否已提交问卷有对应的记录则已提交没有则新建一个
def get_exercise_user exercise_id,user_id
eu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id,user_id)

View File

@ -5,13 +5,13 @@
(<%= @exercise_count%>人已答)
</font>
</span>
<%#if @is_teacher || @exercise.exercise_status == 3%>
<!--<div class="hworkSearchBox">
<input type="text" id="course_student_name" value="<%#= @name%>" placeholder="姓名、学号、邮箱" class="hworkSearchInput" onkeypress="SearchByName('<%#= student_work_index_path(:homework => @homework.id)%>',event);"/>
<a class="hworkSearchIcon" id="search_in_student_work" onclick="SearchByName_1('<%#= student_work_index_path(:homework => @homework.id)%>');" href="javascript:void(0)"></a>
</div>-->
<%#= select_tag(:student_work_in_group,options_for_select(course_group_list(@course),@group), {:class => "classSplit"}) unless course_group_list(@course).empty? %>
<%# end%>
<%if @is_teacher || @exercise.exercise_status == 3%>
<div class="hworkSearchBox">
<input type="text" id="course_student_name" value="<%= @name%>" placeholder="姓名、学号、邮箱" class="hworkSearchInput" onkeypress="SearchByName('<%= student_exercise_list_exercise_path(@exercise)%>',event);"/>
<a class="hworkSearchIcon" id="search_in_student_work" onclick="SearchByName_1('<%= student_exercise_list_exercise_path(@exercise)%>');" href="javascript:void(0)"></a>
</div>
<%= select_tag(:student_work_in_group,options_for_select(course_group_list(@course),@select_group), {:class => "classSplit"}) unless course_group_list(@course).empty? %>
<% end %>
<span class="fr c_grey"> <a href="javascript:void(0);" class="linkGrey2" id="homework_info_show" onclick="show_or_hide_info();" style="display: none">[ 显示测验信息 ]</a> </span>
<div class="group_work_tip_box fontGrey2">

View File

@ -114,7 +114,7 @@
<div class="hworkListContainer">
<div class="ctt2">
<div class="dis" id="homework_student_work_list">
<div class="dis" id="exercise_student_work_list">
<%= render :partial => "exercise/student_exercise"%>
</div>
</div>

View File

@ -0,0 +1,2 @@
$("#exercise_student_work_list").html("<%= escape_javascript(render :partial => 'exercise/student_exercise') %>");
$("#export_student_work").replaceWith("<%= escape_javascript( link_to "导出成绩", student_exercise_list_exercise_path(@exercise.id,:course_id => @course.id, :group => @select_group, :name => @name, :format => 'xls'),:class=>'linkBlue', :id => 'export_student_work') %>");