diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 3afb32982..29d530ebb 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -827,7 +827,7 @@ class HomeworkCommonsController < ApplicationController ## 我的实训 @shixuns = if params[:order_by] == 'mine' - current_user.my_shixuns + current_user.my_shixuns.unhidden else Shixun.unhidden end @@ -855,12 +855,6 @@ class HomeworkCommonsController < ApplicationController or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct end - ## 筛选 状态 - if params[:status].present? && params[:status].to_i != 0 - params[:status] = [0, 1] if params[:status].to_i == 1 - @shixuns = @shixuns.where(status: params[:status]) - end - ## 筛选 难度 if params[:diff].present? && params[:diff].to_i != 0 @shixuns = @shixuns.where(trainee: params[:diff]) @@ -868,25 +862,22 @@ class HomeworkCommonsController < ApplicationController ## 排序参数 bsort = params[:sort] || 'desc' - case params[:order_by] || 'myshixuns_count' - when 'new' - @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}") + case params[:order_by] || 'hot' when 'hot' - @shixuns = @shixuns.order("shixuns.status = 2 desc, myshixuns_count #{bsort}") + @shixuns = @shixuns.order("myshixuns_count #{bsort}") when 'mine' @shixuns = @shixuns.order("shixuns.created_at #{bsort}") else - @shixuns = @shixuns.order("shixuns.status = 2 desc, myshixuns_count #{bsort}") + @shixuns = @shixuns.order("myshixuns_count #{bsort}") end - @total_count = @shixuns.count ## 分页参数 page = params[:page] || 1 limit = params[:limit] || 15 - @shixuns = @shixuns.includes(:tag_repertoires, :challenges).page(page).per(limit) + @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit) end def create_shixun_homework diff --git a/app/views/homework_commons/shixuns.json.jbuilder b/app/views/homework_commons/shixuns.json.jbuilder index 129a0b6d3..8bfeea562 100644 --- a/app/views/homework_commons/shixuns.json.jbuilder +++ b/app/views/homework_commons/shixuns.json.jbuilder @@ -1,12 +1,15 @@ -json.tags @tags do |tag| - json.tag_id tag.id - json.tag_name tag.name +json.shixun_list @shixuns do |shixun| + json.shixun_identifier shixun.identifier + json.name shixun.name + json.creator shixun.user&.full_name + json.creator_login shixun.user&.login + json.school shixun.user&.school_name + json.myshixuns_count shixun.myshixuns_count + json.level level_to_s(shixun.trainee) + json.challenge_tags shixun.challenge_tags_name end -json.shixun_list do - json.partial! 'shixuns/choose_shixun', locals: {shixuns: @shixuns} -end - -json.shixuns_count @shixuns_count +json.shixuns_count @total_count +json.search_tags @search_tags json.partial! 'homework_commons/second_category', locals: {main_catrgory: @main_catrgory, homework_category: @homework_category} \ No newline at end of file