题库增加发布者姓名搜索
This commit is contained in:
parent
8e5abe997a
commit
0cd536fcc9
|
@ -559,7 +559,11 @@ class UsersController < ApplicationController
|
|||
if(params[:type].blank? || params[:type] == "1") #全部
|
||||
visible_course = Course.where("is_public = 1 && is_delete = 0")
|
||||
visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")"
|
||||
@homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("created_at desc")
|
||||
all_homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'")
|
||||
all_user_ids = all_homeworks.map{|hw| hw.user_id}
|
||||
user_str_ids = search_user_by_name all_user_ids, search
|
||||
user_ids = user_str_ids.empty? ? "(-1)" : "(" + user_str_ids.join(",") + ")"
|
||||
@homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%' or user_id in #{user_ids})").order("created_at desc")
|
||||
elsif params[:type] == "2" #课程资源
|
||||
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("created_at desc")
|
||||
end
|
||||
|
|
|
@ -606,4 +606,16 @@ module UsersHelper
|
|||
type
|
||||
end
|
||||
|
||||
#根据姓名搜索用户
|
||||
def search_user_by_name user_ids, name
|
||||
result_ids = []
|
||||
user_ids.each do |user_id|
|
||||
user = User.find user_id
|
||||
username = user.lastname.to_s.downcase + user.firstname.to_s.downcase
|
||||
if username.include?(name)
|
||||
result_ids << user_id
|
||||
end
|
||||
end
|
||||
result_ids
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<input type="text" name="search" placeholder="输入关键词进行搜索" class="subject-pop-search fr" />
|
||||
<input type="text" name="search" placeholder="输入作业、老师姓名的关键词进行搜索" class="subject-pop-search fr" />
|
||||
<script type="text/javascript">
|
||||
var lastSearchCondition = '';
|
||||
var count = 0;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<span title="<%= homework.name%>"><%= homework.name%></span>
|
||||
</label>
|
||||
</li>
|
||||
<li class="subject-pop-from fl hidden">攻城狮</li>
|
||||
<li class="subject-pop-from fl hidden"><span title="<%=homework.course.name %>(<%=current_time_and_term(homework.course) %>)"><%=homework.course.name %>(<%=current_time_and_term_short(homework.course) %>)</span></li>
|
||||
<li class="subject-pop-type fl">
|
||||
<% case homework.homework_type %>
|
||||
<% when 1 %>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<div class="w985"> <a href="javascript:void(0);" class="popup-close" onclick="hideModal()"></a>
|
||||
<div class="f16 fb fontBlue mb10">选用题库中的题目</div>
|
||||
<div class="subject-list fl mr10">
|
||||
<a href="<%= user_homework_type_user_path(@user,:is_import => 1) %>" id="public_homeworks_choose" class="subjectChoose chooseActive fl" data-remote="true">公共题库</a>
|
||||
<a href="<%= user_homework_type_user_path(@user,:type=>'2',:is_import => 1) %>" id="user_homeworks_choose" class="subjectChoose fl" data-remote="true">我的题库</a>
|
||||
<a href="<%= user_homework_type_user_path(@user,:is_import => 1) %>" id="public_homeworks_choose" class="resource-tab resource-tab-active fl" data-remote="true">公共题库</a>
|
||||
<a href="<%= user_homework_type_user_path(@user,:type=>'2',:is_import => 1) %>" id="user_homeworks_choose" class="resource-tab fl" data-remote="true">我的题库</a>
|
||||
<div id="homework_search_input">
|
||||
<%=render :partial=>'homework_search_input', :locals=>{:type => @type,:is_import => 1} %>
|
||||
</div>
|
||||
|
@ -43,11 +43,11 @@
|
|||
</div>
|
||||
<script type="text/javascript">
|
||||
$("#public_homeworks_choose").click(function(){
|
||||
$(this).toggleClass("choose-active");
|
||||
$("#user_homeworks_choose").toggleClass("choose-active");
|
||||
$(this).toggleClass("resource-tab-active");
|
||||
$("#user_homeworks_choose").toggleClass("resource-tab-active");
|
||||
});
|
||||
$("#user_homeworks_choose").click(function(){
|
||||
$(this).toggleClass("choose-active");
|
||||
$("#public_homeworks_choose").toggleClass("choose-active");
|
||||
$(this).toggleClass("resource-tab-active");
|
||||
$("#public_homeworks_choose").toggleClass("resource-tab-active");
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue