diff --git a/app/controllers/admins/shixun_settings_controller.rb b/app/controllers/admins/shixun_settings_controller.rb index fd06fddb3..37ca45674 100644 --- a/app/controllers/admins/shixun_settings_controller.rb +++ b/app/controllers/admins/shixun_settings_controller.rb @@ -5,9 +5,10 @@ class Admins::ShixunSettingsController < Admins::BaseController shixun_settings = Admins::ShixunSettingsQuery.call(params) @editing_shixuns = shixun_settings.where(status:0).size - @pending_shixuns = shixun_settings.where(status:1).size - @processed_shixuns = shixun_settings.where(status:2).size + @processed_shixuns = shixun_settings.where(status:2, public: 0).size @closed_shixuns = shixun_settings.where(status:3).size + @pending_public_shixuns = shixun_settings.where(public:1).size + @processed_pubic_shixuns = shixun_settings.where(public:2).size @sort_json = { can_copy: params[:can_copy].present? ? params[:can_copy] : false, diff --git a/app/controllers/admins/shixuns_controller.rb b/app/controllers/admins/shixuns_controller.rb index 6593f27c2..86cb9b45f 100644 --- a/app/controllers/admins/shixuns_controller.rb +++ b/app/controllers/admins/shixuns_controller.rb @@ -5,10 +5,8 @@ class Admins::ShixunsController < Admins::BaseController params[:sort_direction] = params[:sort_direction].presence || 'desc' shixuns = Admins::ShixunQuery.call(params) @editing_shixuns = shixuns.where(status:0).size - @pending_shixuns = shixuns.where(status:1).size - @processed_shixuns = shixuns.where(status:2).size + @processed_shixuns = shixuns.where(status:2, public: 0).size @closed_shixuns = shixuns.where(status:3).size - @none_public_shixuns = shixuns.where(public:0).size @pending_public_shixuns = shixuns.where(public:1).size @processed_pubic_shixuns = shixuns.where(public:2).size @shixuns_type_check = MirrorRepository.pluck(:type_name,:id) diff --git a/app/controllers/hack_user_lastest_codes_controller.rb b/app/controllers/hack_user_lastest_codes_controller.rb index 655fea471..ff0af5958 100644 --- a/app/controllers/hack_user_lastest_codes_controller.rb +++ b/app/controllers/hack_user_lastest_codes_controller.rb @@ -1,9 +1,9 @@ class HackUserLastestCodesController < ApplicationController before_action :require_login, except: [:listen_result] - before_action :find_my_hack, only: [:show, :code_debug, :code_submit, :update_code, :sync_code, + before_action :find_my_hack, only: [:show, :code_debug, :code_submit, :update_code, :sync_code, :add_notes, :listen_result, :result, :submit_records, :restore_initial_code] before_action :update_user_hack_status, only: [:code_debug, :code_submit] - #before_action :require_auth_identity, only: [:restore_initial_code, :sync_code] + before_action :require_auth_identity, only: [:add_notes] before_action :require_manager_identity, only: [:show, :update_code, :restore_initial_code, :sync_code] def show @@ -67,7 +67,6 @@ class HackUserLastestCodesController < ApplicationController end - # 提交记录详情 def record_detail @hack_user = HackUserCode.find params[:id] @@ -109,6 +108,11 @@ class HackUserLastestCodesController < ApplicationController end + def add_notes + @my_hack.update_attribute(:notes, params[:notes]) + render_ok + end + private def find_my_hack @my_hack = HackUserLastestCode.find_by(identifier: params[:identifier]) diff --git a/app/models/hack_set.rb b/app/models/hack_set.rb index 6afe05663..9e2186fb5 100644 --- a/app/models/hack_set.rb +++ b/app/models/hack_set.rb @@ -1,5 +1,5 @@ class HackSet < ApplicationRecord - #validates :input, presence: { message: "测试集输入不能为空" } + validates :input, presence: { message: "测试集输入不能为空" } validates :output, presence: { message: "测试集输出不能为空" } validates_uniqueness_of :input, scope: [:hack_id, :input], message: "多个测试集的输入不能相同" # 编程题测试集 diff --git a/app/models/hack_user_lastest_code.rb b/app/models/hack_user_lastest_code.rb index 830f16dde..99582af41 100644 --- a/app/models/hack_user_lastest_code.rb +++ b/app/models/hack_user_lastest_code.rb @@ -12,4 +12,6 @@ class HackUserLastestCode < ApplicationRecord scope :mine_hack, ->(author_id){ where(user_id: author_id) } scope :passed, -> {where(status: 1)} + validates_length_of :notes, maximum: 5000, message: "笔记不能超过5000个字" + end diff --git a/app/queries/admins/shixun_query.rb b/app/queries/admins/shixun_query.rb index 4f9f4676e..29e087332 100644 --- a/app/queries/admins/shixun_query.rb +++ b/app/queries/admins/shixun_query.rb @@ -13,25 +13,14 @@ class Admins::ShixunQuery < ApplicationQuery all_shixuns = Shixun.all status = case params[:status] - when "editing" then [0] - when "pending" then [1] - when "processed" then [2] - when "closed" then [3] - else - [0,1,2,3] + when "editing" then {status: 0} + when "processed" then {status: 2, public: 0} + when "pending" then {public: 1} + when "publiced" then {public: 2} + when "closed" then {status: 3} end - public = - case params[:public] - when "editing" then [0] - when "pending" then [1] - when "processed" then [2] - else - [0,1,2] - end - - all_shixuns = all_shixuns.where(status: status) if status.present? - all_shixuns = all_shixuns.where(public: public) if public.present? + all_shixuns = all_shixuns.where(status) if status.present? if params[:fork_status].present? all_shixuns = all_shixuns.where.not(fork_from: nil) diff --git a/app/queries/admins/shixun_settings_query.rb b/app/queries/admins/shixun_settings_query.rb index 377e7bf60..1e45952bf 100644 --- a/app/queries/admins/shixun_settings_query.rb +++ b/app/queries/admins/shixun_settings_query.rb @@ -15,16 +15,15 @@ class Admins::ShixunSettingsQuery < ApplicationQuery all_shixuns = all_shixuns.where(id: params[:id]) if params[:id].present? status = - case params[:status] - when "editing" then [0] - when "pending" then [1] - when "processed" then [2] - when "closed" then [3] - else - [0,1,2,3] - end - - all_shixuns = all_shixuns.where(status: status) if status.present? + case params[:status] + when "editing" then {status: 0} + when "processed" then {status: 2, public: 0} + when "pending" then {public: 1} + when "publiced" then {public: 2} + when "closed" then {status: 3} + end + + all_shixuns = all_shixuns.where(status) if status.present? if params[:tag].present? all_shixuns = all_shixuns.joins(:mirror_repositories).where("mirror_repositories.id = ?",params[:tag].to_i) diff --git a/app/services/shixun_search_service.rb b/app/services/shixun_search_service.rb index 248d7d176..32488a7c3 100644 --- a/app/services/shixun_search_service.rb +++ b/app/services/shixun_search_service.rb @@ -33,6 +33,10 @@ class ShixunSearchService < ApplicationService @shixuns = status == "published" ? @shixuns.where(status: 2) : @shixuns.where(status: [0, 1]) end + if params[:no_jupyter] + @shixuns = @shixuns.where(is_jupyter: 0) + end + ## 筛选 难度 if params[:diff].present? && params[:diff].to_i != 0 @shixuns = @shixuns.where(trainee: params[:diff]) diff --git a/app/views/admins/shixun_settings/index.html.erb b/app/views/admins/shixun_settings/index.html.erb index 66286926a..16a02ab96 100644 --- a/app/views/admins/shixun_settings/index.html.erb +++ b/app/views/admins/shixun_settings/index.html.erb @@ -8,7 +8,7 @@