From fe9ebbb6d63eac286d8b7bec5cce624f5cdb02a2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 26 Apr 2017 11:10:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E9=A6=96=E9=A1=B5=E7=9A=84?= =?UTF-8?q?=E7=83=AD=E5=BA=A6=E6=8E=92=E5=BA=8F=E4=B8=8E=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 21 ++- app/models/shixun.rb | 2 +- app/views/shixuns/index.html.erb | 162 ++++++++++-------- app/views/shixuns/shixun_search.js.erb | 2 +- ...70426020613_add_shixun_count_to_shixuns.rb | 5 + 5 files changed, 111 insertions(+), 81 deletions(-) create mode 100644 db/migrate/20170426020613_add_shixun_count_to_shixuns.rb diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index ec52390e6..4fd84d586 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -21,7 +21,7 @@ class ShixunsController < ApplicationController end def index - @shixuns = Shixun.where(:status => 2) + @shixuns = Shixun.where(:authentication => 1).order('updated_at desc') @shixun_my_score = Game.sum(:final_score) @current_user_had_passed = Myshixun.where(:status => 1).count @shixuns_count = @shixuns.count @@ -30,7 +30,16 @@ class ShixunsController < ApplicationController def shixun_search # 确定 sort 1升序 2 降序 - @order, @sort, @type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 + if params[:time_reorder] + order = "#{Shixun.table_name}.updated_at #{params[:time_reorder]}" + elsif params[:hot_reorder] + order = "shixun_count #{params[:hot_reorder]}, #{Shixun.table_name}.updated_at #{params[:hot_reorder]}" + else + order = "#{Shixun.table_name}.updated_at desc" + end + + # @order, @sort, @type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 +=begin if @order.to_i == @type.to_i @sort = (@sort.to_i == 1 ? 2 : 1) else @@ -38,9 +47,15 @@ class ShixunsController < ApplicationController end sort_name = "updated_on" sort_type = @sort == 1 ? "asc" : "desc" - @shixuns = Shixun.where(:status => 2).reorder() +=end + @shixuns = Shixun.where(:authentication => 1).reorder(order) +=begin order = params[:sort] @shixuns = Shixun.where(:status => 2).order("#{order.nil? ? 'created_at' : order} desc") +=end + respond_to do |format| + format.js + end end # jenkins回调脚本 diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 9cd7c320a..001a922db 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -1,6 +1,6 @@ # status 控制实训的状态,0:未开启;1: 已开启(TPM); 2:已认证 class Shixun < ActiveRecord::Base - attr_accessible :description, :is_public, :name, :changeset_num, :status, :user_id, :gpid, :language, :identifier + attr_accessible :description, :is_public, :name, :changeset_num, :status, :user_id, :gpid, :language, :identifier, :authentication, :hixun_count has_many :users, :through => :shixun_members has_many :shixun_members diff --git a/app/views/shixuns/index.html.erb b/app/views/shixuns/index.html.erb index 99161ff15..6975a3e1f 100644 --- a/app/views/shixuns/index.html.erb +++ b/app/views/shixuns/index.html.erb @@ -1,4 +1,4 @@ -