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 @@ -
+

游戏实训

@@ -27,16 +27,7 @@ - - - -
-
-
- - -
- + –> + --> + +

+

+ 热度排序 + +
+ - -

-

- 时间排序 - -
-
- 热度排序 - -
- 排序方式: 102 个搜索结果 -

-
- - -

- 热度排序 - | - <%#= link_to "时间排序", shixun_search_shixuns_path(:type => @type, :sort => @b_sort, :order => 1), :class => "sortTxt", :remote => true %> - - 时间排序 - 排序方式: -

@@ -92,34 +67,69 @@ <%= render "shixun_list" %>
-
\ No newline at end of file diff --git a/app/views/shixuns/shixun_search.js.erb b/app/views/shixuns/shixun_search.js.erb index d2684b6b8..e82692b2f 100644 --- a/app/views/shixuns/shixun_search.js.erb +++ b/app/views/shixuns/shixun_search.js.erb @@ -1 +1 @@ -$("#shixun_list_content").replaceWith('<%= escape_javascript( render :partial => 'shixuns/shixun_list') %>'); \ No newline at end of file +$("#shixun_list_content").html('<%= escape_javascript( render :partial => 'shixuns/shixun_list') %>'); \ No newline at end of file diff --git a/db/migrate/20170426020613_add_shixun_count_to_shixuns.rb b/db/migrate/20170426020613_add_shixun_count_to_shixuns.rb new file mode 100644 index 000000000..e33f4a15c --- /dev/null +++ b/db/migrate/20170426020613_add_shixun_count_to_shixuns.rb @@ -0,0 +1,5 @@ +class AddShixunCountToShixuns < ActiveRecord::Migration + def change + add_column :shixuns, :shixun_count, :integer, default: 0 + end +end