题库支持按引用数和发布时间排序

This commit is contained in:
cxt 2016-03-11 18:06:43 +08:00
parent 1d93c6c56b
commit 12c60547ad
7 changed files with 68 additions and 47 deletions

View File

@ -376,13 +376,15 @@ class UsersController < ApplicationController
#用户作业列表
def user_homeworks
@order,@b_sort = params[:order] || "created_at",params[:sort] || "desc"
@user = User.current
@r_sort = @b_sort == "desc" ? "asc" : "desc"
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}'").order("created_at desc")
@homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
elsif params[:type] == "2" #我的题库
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("created_at desc")
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
end
@type = params[:type]
@limit = 15
@ -525,20 +527,22 @@ class UsersController < ApplicationController
end
def user_homework_type
@order,@b_sort = params[:order] || "created_at",params[:sort] || "desc"
@r_sort = @b_sort == "desc" ? "asc" : "desc"
@user = User.current
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}'").order("created_at desc")
@homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
elsif params[:type] == "2" #我的题库
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("created_at desc")
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}")
end
if params[:property] && params[:property] == "1"
@homeworks = @homeworks.where("homework_type = 1").reorder("created_at desc")
@homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}")
elsif params[:property] && params[:property] == "2"
@homeworks = @homeworks.where("homework_type = 2").reorder("created_at desc")
@homeworks = @homeworks.where("homework_type = 2").reorder("#{@order} #{@b_sort}")
elsif params[:property] && params[:property] == "3"
@homeworks = @homeworks.where("homework_type = 3").reorder("created_at desc")
@homeworks = @homeworks.where("homework_type = 3").reorder("#{@order} #{@b_sort}")
end
@type = params[:type]
@property = params[:property]
@ -564,6 +568,8 @@ class UsersController < ApplicationController
#用户主页过滤作业
def user_search_homeworks
@order,@b_sort = params[:order] || "created_at",params[:sort] || "desc"
@r_sort = @b_sort == "desc" ? "asc" : "desc"
@user = User.current
search = params[:name].to_s.strip.downcase
if(params[:type].blank? || params[:type] == "1") #全部
@ -573,16 +579,16 @@ class UsersController < ApplicationController
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")
@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("#{@order} #{@b_sort}")
elsif params[:type] == "2" #课程资源
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("created_at desc")
@homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("#{@order} #{@b_sort}")
end
if params[:property] && params[:property] == "1"
@homeworks = @homeworks.where("homework_type = 1").reorder("created_at desc")
@homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}")
elsif params[:property] && params[:property] == "2"
@homeworks = @homeworks.where("homework_type = 2").reorder("created_at desc")
@homeworks = @homeworks.where("homework_type = 2").reorder("#{@order} #{@b_sort}")
elsif params[:property] && params[:property] == "3"
@homeworks = @homeworks.where("homework_type = 3").reorder("created_at desc")
@homeworks = @homeworks.where("homework_type = 3").reorder("#{@order} #{@b_sort}")
end
@type = params[:type]
@limit = 15
@ -592,6 +598,8 @@ class UsersController < ApplicationController
@offset ||= @hw_pages.offset
@homeworks = paginateHelper @homeworks,15
@is_import = params[:is_import]
@property = params[:property]
@search = search
respond_to do |format|
format.js
end

View File

@ -0,0 +1,21 @@
<ul class="subject-list-banner">
<li class="subject-list-name fl hidden"><span style="padding-left:15px;">作业名称</span></li>
<li class="subject-list-from fl">来源</li>
<li class="subject-list-type fl">类别</li>
<li class="subject-list-publisher fl">贡献者</li>
<li class="subject-list-count fl">
<%= link_to "引用数",user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "quotes", :sort => @r_sort),:class => "fl",:remote => true%>
<% if @order == "quotes"%>
<%= link_to "", user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "quotes", :sort => @r_sort),:class => "#{@r_sort == 'desc' ? 'st_up' : 'st_down'} mt12" ,:remote => true%>
<% end%>
</li>
<li class="fl subject-list-date">
<%= link_to "发布时间",user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "created_at", :sort => @r_sort),:class => "fl",:remote => true%>
<% if @order == "created_at"%>
<%= link_to "", user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "created_at", :sort => @r_sort),:class => "#{@r_sort == 'desc' ? 'st_up' : 'st_down'} mt12" ,:remote => true%>
<% end%>
</li>
</ul>
<div id="homework_repository">
<%=render :partial => 'homework_repository', :locals => {:homeworks => homeworks} %>
</div>

View File

@ -4,7 +4,7 @@ $("#homewrok_ref_pages").html('<%= pagination_links_full @hw_pages, @hw_count, :
$("#homework_detail_information").html("<%=escape_javascript(render :partial => 'users/homework_detail_information', :locals => {:homework=>nil}) %>");
$("#homework_search_input").html("<%=escape_javascript(render :partial=>'homework_search_input', :locals=>{:type=>@type,:is_import=>@is_import}) %>");
<% else %>
$("#homework_repository").html('<%= escape_javascript(render :partial => 'users/homework_repository', :locals => {:homeworks => @homeworks})%>');
$("#homework_repository_list").html('<%= escape_javascript(render :partial => 'users/homework_repository_list', :locals => {:homeworks => @homeworks,:sort => @order,:b_sort => @b_sort,:type=>@type,:is_import => @is_import,:property => @property,:search=>''})%>');
$("#homework_pository_ref_pages").html('<%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true %>');
$("#homework_repository_detail").html("<%=escape_javascript(render :partial => 'users/homework_repository_detail', :locals => {:homework=>nil}) %>");
$("#homework_search_input").html("<%=escape_javascript(render :partial=>'homework_repository_search', :locals=>{:type=>@type,:is_import=>@is_import,:property=>@property}) %>");

View File

@ -58,40 +58,26 @@
</ul>
<div class="cl"></div>
<div id="homework_search_input" class="mt10 fl">
<%=render :partial=>'homework_repository_search', :locals=>{:type => @type,:is_import => 0,:property => @property} %>
<%=render :partial=>'homework_repository_search', :locals=>{:type => @type,:is_import => 0,:property => @property} %>
</div>
<!--<form class="resourcesSearchloadBox mt10">
<input type="text" name="serach" placeholder="输入题库关键词进行搜索" class="searchResource" />
<a href="javascript:void(0);" class="homepageSearchIcon"></a>
</form>-->
<div class="cl"></div>
<div class="w583 fl mr10 mt10">
<ul class="subject-list-banner">
<li class="subject-list-name fl hidden"><span style="padding-left:15px;">作业名称</span></li>
<li class="subject-list-from fl">来源</li>
<li class="subject-list-type fl">类别</li>
<li class="subject-list-publisher fl">贡献者</li>
<li class="subject-list-count fl">引用数</li>
<li class="fl subject-list-date">发布时间</li>
</ul>
<div id="homework_repository">
<%=render :partial => 'homework_repository', :locals => {:homeworks => @homeworks} %>
<div class="w583 fl mr10 mt10" id="homework_repository_list">
<%=render :partial => 'homework_repository_list', :locals => {:homeworks => @homeworks,:type=>@type,:is_import => 0,:property => @property,:search=>''} %>
</div>
<div id="homework_repository_detail">
<%=render :partial => 'homework_repository_detail', :locals => {:homework => nil} %>
</div>
<div class="cl"></div>
<div>
<ul class="wlist mt10" id="homework_pository_ref_pages" style="margin-top: 5px;margin-right: 395px">
<%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true%>
</ul>
</div>
<div class="fl resourcesSelectSendButton mr15 inactive-border mt10">
<a href="javascript:void(0)" onclick="choose_course('<%=User.current.id %>');" class="sendButtonBlue db inactive-text" data-remote="true">发送至</a>
</div>
<span class="c_red fl mt15" id="choose_homework_notice"></span>
</div>
</div>
</div>
<div id="homework_repository_detail">
<%=render :partial => 'homework_repository_detail', :locals => {:homework => nil} %>
</div>
<div class="cl"></div>
<div>
<ul class="wlist mt10" id="homework_pository_ref_pages" style="margin-top: 5px;margin-right: 395px">
<%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true%>
</ul>
</div>
<div class="fl resourcesSelectSendButton mr15 inactive-border mt10">
<a href="javascript:void(0)" onclick="choose_course('<%=User.current.id %>');" class="sendButtonBlue db inactive-text" data-remote="true">发送至</a>
</div>
<span class="c_red fl mt15" id="choose_homework_notice"></span>
</div>
</div>
</div>
</div>

View File

@ -1,3 +1,4 @@
$("#homework_repository").html('<%= escape_javascript(render :partial => 'users/homework_repository', :locals => {:homeworks => @homeworks})%>');
/*$("#homework_repository").html('<%#= escape_javascript(render :partial => 'users/homework_repository', :locals => {:homeworks => @homeworks})%>');*/
$("#homework_repository_list").html('<%= escape_javascript(render :partial => 'users/homework_repository_list', :locals => {:homeworks => @homeworks,:sort => @order,:b_sort => @b_sort,:type=>@type,:is_import => 0,:property => @property,:search=>''})%>');
$("#homework_pository_ref_pages").html('<%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true %>');
$("#homework_repository_detail").html("<%=escape_javascript(render :partial => 'users/homework_repository_detail', :locals => {:homework=>nil}) %>");

View File

@ -3,7 +3,7 @@ $("#homework_list_form_show").html('<%= escape_javascript(render :partial => 'us
$("#homewrok_ref_pages").html('<%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true %>');
$("#homework_detail_information").html("<%=escape_javascript(render :partial => 'users/homework_detail_information', :locals => {:homework=>nil}) %>");
<% else %>
$("#homework_repository").html('<%= escape_javascript(render :partial => 'users/homework_repository', :locals => {:homeworks => @homeworks})%>');
$("#homework_repository_list").html('<%= escape_javascript(render :partial => 'users/homework_repository_list', :locals => {:homeworks => @homeworks,:sort => @order,:b_sort => @b_sort,:type=>@type,:is_import => @is_import,:property => @property,:search=>@search})%>');
$("#homework_pository_ref_pages").html('<%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true %>');
$("#homework_repository_detail").html("<%=escape_javascript(render :partial => 'users/homework_repository_detail', :locals => {:homework=>nil}) %>");
<% end %>

View File

@ -1480,3 +1480,8 @@ a.choose-active {background-color:#269ac9; color:#ffffff;}
.subject-list-type {width:50px; text-align:center;}
.subject-list-count {width:60px; text-align:center;}
.subject-list-from {width:105px; text-align:center;}
a.st_up{ display: block; width:8px; float:left; height:13px; background:url(../images/pic_up.png) 0 0 no-repeat; margin-top:5px; margin-left:3px;}
a.st_down{ display: block; width:8px; float:left; height:13px; background:url(../images/pic_up.png) 0 -22px no-repeat; margin-top:5px; margin-left:3px;}
a.st_img { display:block;width:32px; height:32px; border:1px solid #CCC; padding:1px;}
a:hover.st_img { border:1px solid #1c9ec7; }