From dbe37b1df698dc9ef66f93e962cd47b49308753a Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 1 Jun 2017 14:35:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=B8=AD=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E6=9D=A1=E4=BB=B6=E5=92=8C=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 4 +- app/controllers/shixuns_controller.rb | 59 +++++++++++++++++++++-- app/models/shixun.rb | 3 +- app/views/shixuns/_shixun_list.html.erb | 16 +++--- app/views/shixuns/index.html.erb | 20 ++++---- app/views/shixuns/index.js.erb | 1 + app/views/shixuns/search.js.erb | 2 +- config/routes.rb | 2 +- 8 files changed, 77 insertions(+), 30 deletions(-) create mode 100644 app/views/shixuns/index.js.erb 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 +
+ +
+
\ No newline at end of file diff --git a/app/views/shixuns/index.html.erb b/app/views/shixuns/index.html.erb index 79c497735..b54841cdd 100644 --- a/app/views/shixuns/index.html.erb +++ b/app/views/shixuns/index.html.erb @@ -15,7 +15,6 @@
  • 所有状态 @@ -23,22 +22,25 @@
  • 所有进展
  • -
    + <%= 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| %> + +
    - +
    -
    + + <% end %>

    热度排序 diff --git a/app/views/shixuns/index.js.erb b/app/views/shixuns/index.js.erb new file mode 100644 index 000000000..e82692b2f --- /dev/null +++ b/app/views/shixuns/index.js.erb @@ -0,0 +1 @@ +$("#shixun_list_content").html('<%= escape_javascript( render :partial => 'shixuns/shixun_list') %>'); \ No newline at end of file diff --git a/app/views/shixuns/search.js.erb b/app/views/shixuns/search.js.erb index e82692b2f..e95a097ab 100644 --- a/app/views/shixuns/search.js.erb +++ b/app/views/shixuns/search.js.erb @@ -1 +1 @@ -$("#shixun_list_content").html('<%= escape_javascript( render :partial => 'shixuns/shixun_list') %>'); \ No newline at end of file +$("#shixun_list_content").html('<%= escape_javascript( render :partial => 'shixuns/shixun_list', :type => @type, :status => @status, :search => @search) %>'); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 6fa0b0066..7cbddfcfa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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