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 @@
<%= form_tag(admins_shixuns_path, method: :get, class: 'form-inline search-form',id:"shixuns-search-form",remote:true) do %> -
- - <% status_options = [['全部', ''], ["编辑中(#{@editing_shixuns})", "editing"], ["待审核(#{@pending_shixuns})", 'pending'], ["已发布(#{@processed_shixuns})", 'processed'],["已关闭(#{@closed_shixuns})",'closed']] %> - <%= select_tag(:status, options_for_select(status_options), class: 'form-control') %> -
+
+
+
+ + <% status_options = [['全部', ''], ["编辑中(#{@editing_shixuns})", "editing"], ["待审核(#{@pending_shixuns})", 'pending'], ["已发布(#{@processed_shixuns})", 'processed'],["已关闭(#{@closed_shixuns})",'closed']] %> + <%= select_tag(:status, options_for_select(status_options), class: 'form-control') %> +
-
- - <% public_options = [['全部', ''], ["未公开(#{@none_public_shixuns})", "editing"], ["待审核(#{@pending_public_shixuns})", 'pending'], ["已公开(#{@processed_pubic_shixuns})", 'processed']] %> - <%= select_tag(:public, options_for_select(public_options), class: 'form-control') %> -
+
+ + <% public_options = [['全部', ''], ["未公开(#{@none_public_shixuns})", "editing"], ["待审核(#{@pending_public_shixuns})", 'pending'], ["已公开(#{@processed_pubic_shixuns})", 'processed']] %> + <%= select_tag(:public, options_for_select(public_options), class: 'form-control') %> +
-
- - <%= select_tag(:tag, options_for_select(@shixuns_type_check.unshift(["",nil])), class: 'form-control',id:"tag-choosed") %> -
+
+ + <%= select_tag(:tag, options_for_select(@shixuns_type_check.unshift(["",nil])), class: 'form-control',id:"tag-choosed") %> +
+ +
+ + <% auto_trial_options = [['创建者姓名', 0], ['实训名称', 1], ['学校名称', 2]] %> + <%= select_tag(:search_type, options_for_select(auto_trial_options), class: 'form-control') %> +
+ <%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: '输入关键字搜索') %> +
+ 导出 +
+
+ +
+
+ + <% fork_status_options = [['全部', ''], ["全部fork实训", "Fork"], ["实训内容升级", 'Shixun'], ["课堂教学使用", 'Course'],["实践课程使用",'Subject'],["其他原因",'Other']] %> + <%= select_tag(:fork_status, options_for_select(fork_status_options), class: 'form-control') %> +
-
- - <% auto_trial_options = [['创建者姓名', 0], ['实训名称', 1], ['学校名称', 2]] %> - <%= select_tag(:search_type, options_for_select(auto_trial_options), class: 'form-control') %> + <%= submit_tag('搜索', class: 'btn btn-primary ml-3','data-disable-with': '搜索中...') %> + <%= link_to "清除", admins_shixuns_path,class: "btn btn-default",id:"shixuns-clear-search",'data-disable-with': '清除中...' %> +
- <%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2', placeholder: '输入关键字搜索') %> - <%= submit_tag('搜索', class: 'btn btn-primary','data-disable-with': '搜索中...') %> - <%= link_to "清除", admins_shixuns_path,class: "btn btn-default",id:"shixuns-clear-search",'data-disable-with': '清除中...' %> <% end %> - 导出
diff --git a/app/views/admins/shixuns/shared/_list.html.erb b/app/views/admins/shixuns/shared/_list.html.erb index 9ee44ece3..b0a0c715d 100644 --- a/app/views/admins/shixuns/shared/_list.html.erb +++ b/app/views/admins/shixuns/shared/_list.html.erb @@ -2,17 +2,18 @@ 序号 ID - 实训名称 + 实训名称 技术平台 Fork源 + Fork原因 实践 - 选择 + 选择 状态 公开 - 创建者 - <%= sort_tag('创建于', name: 'created_at', path: admins_shixuns_path) %> - 单测 - 操作 + 创建者 + <%= sort_tag('创建于', name: 'created_at', path: admins_shixuns_path) %> + 单测 + 操作 <% if shixuns.present? %> @@ -31,6 +32,7 @@ <%= link_to shixun.try(:identifier), shixun_path(shixun.try(:identifier)), target: '_blank'%> <% end%> + <%= overflow_hidden_span(shixun&.fork_reason) %> <%= shixun.challenges.where(:st => 0).size %> <%= shixun.challenges.where(:st => 1).size %> <%= shixun_authentication_status shixun %> diff --git a/db/migrate/20191219060435_add_fork_reason_to_shixun_info.rb b/db/migrate/20191219060435_add_fork_reason_to_shixun_info.rb new file mode 100644 index 000000000..8a1446d54 --- /dev/null +++ b/db/migrate/20191219060435_add_fork_reason_to_shixun_info.rb @@ -0,0 +1,5 @@ +class AddForkReasonToShixunInfo < ActiveRecord::Migration[5.2] + def change + add_column :shixun_infos, :fork_reason, :string + end +end