From f90d58f5b391e38b229ed84784de07bce7ec04d0 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 19 Dec 2019 15:03:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E5=8F=91=E5=B8=83=E4=BC=98?= =?UTF-8?q?=E5=8C=962.0=E3=80=81=E8=B6=85=E7=AE=A1=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 3 +- app/helpers/application_helper.rb | 2 +- app/models/shixun.rb | 13 ++++ app/queries/admins/shixun_query.rb | 10 ++++ app/services/shixun_search_service.rb | 8 ++- app/services/users/shixun_service.rb | 19 +++--- app/views/admins/shixuns/index.html.erb | 59 ++++++++++++------- .../admins/shixuns/shared/_list.html.erb | 14 +++-- ...19060435_add_fork_reason_to_shixun_info.rb | 5 ++ 9 files changed, 94 insertions(+), 39 deletions(-) create mode 100644 db/migrate/20191219060435_add_fork_reason_to_shixun_info.rb diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index aa25d0875..960d56a40 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -215,7 +215,8 @@ class ShixunsController < ApplicationController if @shixun.shixun_info.present? ShixunInfo.create!(shixun_id: @new_shixun.id, description: @shixun.description, - evaluate_script: @shixun.evaluate_script) + evaluate_script: @shixun.evaluate_script, + shixun_reason: params[:reason].to_s.strip) end # 同步私密版本库 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cabf8d244..40e6cb365 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -64,7 +64,7 @@ module ApplicationHelper shixun_id = shixun_id.blank? ? -1 : shixun_id.join(",") Shixun.select([:id, :name, :user_id, :challenges_count, :myshixuns_count, :trainee, :identifier]).where("id - in(#{shixun_id})").unhidden.order("homepage_show asc, myshixuns_count desc").limit(3) + in(#{shixun_id})").unhidden.publiced.order("homepage_show asc, myshixuns_count desc").limit(3) end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index de014f87b..9522c54da 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -103,6 +103,19 @@ class Shixun < ApplicationRecord shixun_info.try(:evaluate_script) end + def fork_reason + case shixun_info.try(:fork_reason) + when 'Shixun' + '实训内容升级' + when 'Course' + '课堂教学使用' + when 'Subject' + '实践课程使用' + else + shixun_info.try(:fork_reason) + end + end + def fork_identifier self.fork_from.nil? ? "--" : fork_shixuns.first&.identifier end diff --git a/app/queries/admins/shixun_query.rb b/app/queries/admins/shixun_query.rb index 0f8523599..4f9f4676e 100644 --- a/app/queries/admins/shixun_query.rb +++ b/app/queries/admins/shixun_query.rb @@ -33,6 +33,16 @@ class Admins::ShixunQuery < ApplicationQuery all_shixuns = all_shixuns.where(status: status) if status.present? all_shixuns = all_shixuns.where(public: public) if public.present? + if params[:fork_status].present? + all_shixuns = all_shixuns.where.not(fork_from: nil) + case params[:fork_status] + when 'Shixun', 'Course', 'Subject' + all_shixuns = all_shixuns.joins(:shixun_info).where(shixun_infos: {fork_reason: params[:fork_status]}) + when 'Other' + all_shixuns = all_shixuns.joins(:shixun_info).where("fork_reason is null or fork_reason not in ('Shixun', 'Course', 'Subject')") + end + end + if params[:tag].present? all_shixuns = all_shixuns.joins(:mirror_repositories).where("mirror_repositories.id = ?",params[:tag].to_i) end diff --git a/app/services/shixun_search_service.rb b/app/services/shixun_search_service.rb index f5af69179..248d7d176 100644 --- a/app/services/shixun_search_service.rb +++ b/app/services/shixun_search_service.rb @@ -49,12 +49,16 @@ class ShixunSearchService < ApplicationService includes: [ :shixun_info, :challenges, :subjects, user: { user_extension: :school } ] } model_options.merge!(where: { id: @shixuns.pluck(:id) }) - model_options.merge!(order: {"myshixuns_count" => sort_str}) + model_options.merge!(order: {sort_str => order_str}) model_options.merge!(default_options) model_options end - def sort_str + def order_str params[:order] || "desc" end + + def sort_str + params[:sort] || "myshixuns_count" + end end \ No newline at end of file diff --git a/app/services/users/shixun_service.rb b/app/services/users/shixun_service.rb index 279d147f4..b13b0ab1f 100644 --- a/app/services/users/shixun_service.rb +++ b/app/services/users/shixun_service.rb @@ -65,13 +65,18 @@ class Users::ShixunService end def manage_shixun_status_filter(relations) - status = case params[:status] - when 'editing' then 0 - when 'applying' then 1 - when 'published' then 2 - when 'closed' then 3 - end - relations = relations.where(status: status) if status + if params[:status] == "publiced" + relations = relations.where(public: 2) + elsif params[:status] == "applying" + relations = relations.where(public: 1) + else + status = case params[:status] + when 'editing' then 0 + when 'published' then 2 + when 'closed' then 3 + end + relations = relations.where(status: status) if status + end relations end diff --git a/app/views/admins/shixuns/index.html.erb b/app/views/admins/shixuns/index.html.erb index d04257927..9bb09f86f 100644 --- a/app/views/admins/shixuns/index.html.erb +++ b/app/views/admins/shixuns/index.html.erb @@ -4,33 +4,48 @@