diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6cb3ebdd4..8aa520365 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 00b8c9b58..c2a3b29c2 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -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 diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 9af1fc08b..a9315427c 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -1,7 +1,6 @@ # status 控制实训的状态,0:未开启;1: 已开启(TPM); 2:已认证 -# 实训云平台繁忙(繁忙等级:116) # 繁忙等级参数:80发布实训失败,返回code为-1;81:实训开启的时候fork失败;83:job创建失败;84:jenkins系统异常,post数据不成功 -# 85:challenge创建的时候Jenkins处理异常;86:实训评测失败,jenkins返回错误结果; 87:版本库删除异常;88:点击评测失败;89:重置失败 +# 85:challenge创建的时候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 diff --git a/app/views/shixuns/_shixun_list.html.erb b/app/views/shixuns/_shixun_list.html.erb index da7f27b9f..387acf83d 100644 --- a/app/views/shixuns/_shixun_list.html.erb +++ b/app/views/shixuns/_shixun_list.html.erb @@ -26,13 +26,9 @@ <% end %>
- - - - - - - - - \ No newline at end of file +