实训中增加过滤条件和搜索结果

This commit is contained in:
huang 2017-06-01 14:35:31 +08:00
parent 891fb66699
commit dbe37b1df6
8 changed files with 77 additions and 30 deletions

View File

@ -45,8 +45,8 @@ class ApplicationController < ActionController::Base
before_filter :find_first_page
before_filter :find_web_footer
before_filter :check_authentication, :session_expiration, :user_setup, :check_if_login_required, :set_localization
before_filter :user_agent
before_filter :session_expiration, :user_setup, :check_if_login_required, :set_localization, :check_authentication
before_filter :user_agent
rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
rescue_from ::Unauthorized, :with => :deny_access

View File

@ -28,12 +28,36 @@ class ShixunsController < ApplicationController
end
def index
@shixuns = Shixun.where(:authentication => 1).order('updated_at desc')
# @type = params[:type]
# @status = params[:status]
# @search = params[:search]
# if @type == 1 || @type.nil?
# case @status
# when 1, nil # 所有进展
# @shixuns = Shixun.where(:authentication => 1).where("name like ?", "%#{@search}%")
# when 2 # 我已创建
# @shixuns = Shixun.where(:authentication => 1, :user_id => User.current).where("name like ?", "%#{@search}%")
# when 3 # 我未挑战
# @shixuns = Shixun.find_by_sql("select * from shixuns where id not in (SELECT shixun_id FROM `myshixuns` where shixun_id in (SELECT id FROM `shixuns` where authentication=1) and user_id=#{User.current.id})and name like %#{@search}%;")
# when 4 # 我未通关
# @shixuns = Shixun.find_by_sql("select * from shixuns where id in (SELECT shixun_id FROM `myshixuns` where shixun_id in (SELECT id FROM `shixuns` where authentication=1) and user_id=#{User.current.id} and status=0) and name like %#{@search}%;")
# when 5 # 我已通关
# @shixuns = Shixun.find_by_sql("select * from shixuns where id in (SELECT shixun_id FROM `myshixuns` where shixun_id in (SELECT id FROM `shixuns` where authentication=1) and user_id=#{User.current.id} and status=1) and name like %#{@search}%;")
# end
# else
# @shixuns = User.current.shixuns
# end
@shixuns = Shixun.where(:authentication => 1)
@shixun_my_score = Game.find_by_sql("select sum(final_score) as score from games where myshixun_id in (select id from myshixuns where status =1
and user_id=#{User.current.id} and shixun_id in (SELECT id FROM `shixuns` where authentication=1))").first.try(:score).to_i
@current_user_had_passed = Myshixun.find_by_sql("select count(*) as had_passed from myshixuns where status =1 and user_id=#{User.current.id}
and shixun_id in (SELECT id FROM `shixuns` where authentication=1)").first.try(:had_passed).to_i
@shixuns_count = @shixuns.count
@limit = 8
@is_remote = true
@shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1
@offset ||= @shixun_pages.offset
@shixuns = paginateHelper @shixuns, @limit
render :layout => "base_edu"
end
@ -86,13 +110,38 @@ class ShixunsController < ApplicationController
def search
# 确定 sort 1升序 2 降序
if params[:time_reorder]
order = "#{Shixun.table_name}.created_at #{params[:time_reorder]}"
@order = "#{Shixun.table_name}.created_at #{params[:time_reorder]}"
elsif params[:hot_reorder]
order = "myshixun_count #{params[:hot_reorder]}, #{Shixun.table_name}.updated_at #{params[:hot_reorder]}"
@order = "myshixun_count #{params[:hot_reorder]}, #{Shixun.table_name}.updated_at #{params[:hot_reorder]}"
else
order = "#{Shixun.table_name}.created_at desc"
@order = "#{Shixun.table_name}.created_at desc"
end
@shixuns = Shixun.where(:authentication => 1).reorder(order)
@type = params[:type]
@status = params[:status]
@search = params[:search]
if @type == 1 || @type.nil?
case @status
when 1, nil # 所有进展
@shixuns = Shixun.where(:authentication => 1).where("name like ?", "%#{@search}%").reorder(@order)
when 2 # 我已创建
@shixuns = Shixun.where(:authentication => 1, :user_id => User.current).where("name like ?", "%#{@search}%").reorder(@order)
when 3 # 我未挑战
@shixuns = Shixun.find_by_sql("select * from shixuns where id not in (SELECT shixun_id FROM `myshixuns` where shixun_id in (SELECT id FROM `shixuns` where authentication=1) and user_id=#{User.current.id})and name like %#{@search}% order by #{@order};")
when 4 # 我未通关
@shixuns = Shixun.find_by_sql("select * from shixuns where id in (SELECT shixun_id FROM `myshixuns` where shixun_id in (SELECT id FROM `shixuns` where authentication=1) and user_id=#{User.current.id} and status=0) and name like %#{@search}% order by #{@order};")
when 5 # 我已通关
@shixuns = Shixun.find_by_sql("select * from shixuns where id in (SELECT shixun_id FROM `myshixuns` where shixun_id in (SELECT id FROM `shixuns` where authentication=1) and user_id=#{User.current.id} and status=1) and name like %#{@search}% order by #{@order};")
end
else
@shixuns = User.current.shixuns
end
# @shixuns = Shixun.where(:authentication => 1).reorder(order)
@shixuns_count = @shixuns.count
@limit = 8
@is_remote = true
@shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1
@offset ||= @shixun_pages.offset
@shixuns = paginateHelper @shixuns, @limit
respond_to do |format|
format.js
end

View File

@ -1,7 +1,6 @@
# status 控制实训的状态0未开启1: 已开启TPM; 2已认证
# 实训云平台繁忙繁忙等级116
# 繁忙等级参数80发布实训失败返回code为-181实训开启的时候fork失败;83job创建失败84jenkins系统异常post数据不成功
# 85challenge创建的时候Jenkins处理异常;86实训评测失败jenkins返回错误结果; 87版本库删除异常88点击评测失败89重置失败
# 85challenge创建的时候Jenkins处理异常;86实训评测失败jenkins返回错误结果; 87版本库删除异常88点击评测失败,没返回数据89重置链接jenkins返回失败
class Shixun < ActiveRecord::Base
attr_accessible :description, :is_public, :name, :changeset_num, :status, :user_id, :gpid, :language, :identifier, :authentication, :myshixun_count, :propaedeutics

View File

@ -26,13 +26,9 @@
</div>
<% end %>
<div class="cl"></div>
<!--<div class="panel-pages mt20 ">-->
<!--<a href="javascript:void(0);" class="pages-big">上一页</a>-->
<!--<a href="javascript:void(0);" class="active ">1</a>-->
<!--<a href="javascript:void(0);">2</a>-->
<!--<a href="javascript:void(0);">3</a>-->
<!--<a href="javascript:void(0);">...</a>-->
<!--<a href="javascript:void(0);">31</a>-->
<!--<a href="javascript:void(0);" class="pages-big">下一页</a>-->
<!--<div class="cl"></div>
</div>-->
<div class="pages_right_min">
<ul>
<%= pagination_links_full @shixun_pages, @shixuns_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %>
</ul>
<div class="cl"></div>
</div>

View File

@ -15,7 +15,6 @@
<li class="fl ml15 mr5 edu-dropdown">
<a href="#" class="edu-dropdown-toggle">所有状态<i class="fa fa-caret-down ml5" ></i></a>
<ul class="edu-dropdown-menu" role="menu">
<li><a href="#">所有状态</a></li>
<li><a href="#">已 审 核</a></li>
<li><a href="#">审 核 中</a></li>
</ul>
@ -23,22 +22,25 @@
<li class="edu-dropdown fl ml15 mr5">
<a href="#" class="edu-dropdown-toggle" >所有进展<i class="fa fa-caret-down ml5" ></i></a>
<ul class="edu-dropdown-menu" >
<li><a href="#">所有进展</a></li>
<li><a href="#">我已创建</a></li>
<li><a href="#">我未挑战</a></li>
<li><a href="#">我未通关</a></li>
<li><a href="#">我已通关</a></li>
<li><a href="<%= shixuns_path(:status => 1, :search => @search, :type => @type, :order => @order) %>" data-remote="true">所有进展</a></li>
<li><a href="<%= shixuns_path(:status => 2, :search => @search, :type => @type, :order => @order) %>" data-remote="true">我已创建</a></li>
<li><a href="<%= shixuns_path(:status => 3, :search => @search, :type => @type, :order => @order) %>" data-remote="true">我未挑战</a></li>
<li><a href="<%= shixuns_path(:status => 4, :search => @search, :type => @type, :order => @order) %>" data-remote="true">我未通关</a></li>
<li><a href="<%= shixuns_path(:status => 5, :search => @search, :type => @type, :order => @order) %>" data-remote="true">我已通关</a></li>
</ul>
</li>
<form onsubmit="submitFn(this, event);" class="fl ml15">
<%= form_tag url_for(search_shixuns_path(:status => @status, :type => @type, :order => @order)), :remote => true, :method => :post, :id => 'add_collaborators_form', :onsubmit => "submitFn(this, event);", :class => "fl ml15" do |f| %>
<!--<form onsubmit="submitFn(this, event);" class="fl ml15" >-->
<div class="search-wrapper">
<div class="input-holder">
<input type="text" class="search-input" placeholder="搜索" />
<input type="text" class="search-input" name="search" placeholder="搜索" />
<button class="search-icon" onclick="searchToggle(this, event);"><i class="fa fa-search font-16 mt5"></i></button>
</div>
<span class="close" onclick="searchToggle(this, event);"><i class="fa fa-times font-16 mt5"></i></span>
</div>
</form>
<!--</form>-->
<% end %>
<p class="color-grey fr">
<div class="postSort fr" id="shixun_hot">
<a href="javascript:void(0);" class="linkGrey2 fl">热度排序</a>

View File

@ -0,0 +1 @@
$("#shixun_list_content").html('<%= escape_javascript( render :partial => 'shixuns/shixun_list') %>');

View File

@ -1 +1 @@
$("#shixun_list_content").html('<%= escape_javascript( render :partial => 'shixuns/shixun_list') %>');
$("#shixun_list_content").html('<%= escape_javascript( render :partial => 'shixuns/shixun_list', :type => @type, :status => @status, :search => @search) %>');

View File

@ -51,7 +51,7 @@ RedmineApp::Application.routes.draw do
match 'publish', :via => [:get, :post]
end
collection do
get 'search'
match 'search', :via => [:get, :post]
end
resources :challenges do