From c082d3d5dba4b3493c008a07882f2f65e5eaab50 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 31 Aug 2019 10:59:11 +0800 Subject: [PATCH] =?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/exercise_banks_controller.rb | 38 +++++++++++-------- app/controllers/student_works_controller.rb | 10 ++--- .../choose_shixun.json.jbuilder | 25 +++++++----- 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/app/controllers/exercise_banks_controller.rb b/app/controllers/exercise_banks_controller.rb index 8602bb018..dafaf131e 100644 --- a/app/controllers/exercise_banks_controller.rb +++ b/app/controllers/exercise_banks_controller.rb @@ -24,28 +24,34 @@ class ExerciseBanksController < ApplicationController def choose_shixun search = params[:search] - if !current_user.admin? #当不为管理员的时候 - user_school_id = current_user.school_id #当前用户的学校id - if user_school_id.present? - none_shixun_ids = ShixunSchool.where("school_id != #{user_school_id}").pluck(:shixun_id) - @publish_shixuns = Shixun.where.not(id: none_shixun_ids).unhidden - end + type = params[:type] + # 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭) + if current_user.admin? + @shixuns = Shixun.unhidden else - @publish_shixuns = Shixun.unhidden + none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) + + @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden end - if search.present? - @publish_shixuns = @publish_shixuns.search_by_name(search) + + # 实训的所有标签 + @tags = TagRepertoire.select([:id, :name]).joins(:shixuns).where(shixuns: {id: @shixuns}).distinct + + if params[:search] && params[:search].strip != "" + @shixuns = @shixuns.joins(:user).where("shixuns.name like ? or concat(users.lastname, users.firstname) like ?", + "%#{search}%", "%#{search}%").distinct end - @shixuns = @publish_shixuns.joins(:challenges).where("challenges.st != 0").distinct - # 全部页面,需返回 - @shixuns_count = @shixuns.count + unless type.blank? || type == "all" + @shixuns = @shixuns.joins(:shixun_tag_repertoires).where(shixun_tag_repertoires: {tag_repertoire_id: type}).distinct + end - # 分页 - @page = params[:page] || 1 - @limit = params[:limit] || 8 + @shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier, :user_id, :trainee]) + @total_count = @shixuns.size - @shixuns = @shixuns.page(@page).per(@limit) + ## 分页参数 + page = params[:page] || 1 + @shixuns = @shixuns.reorder("shixuns.created_at desc").includes(:challenges, user: [user_extension: :school]).page(page).per(10) end #确认实训的选择 diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index f6872e533..519bb7e7d 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -655,15 +655,15 @@ class StudentWorksController < ApplicationController # 查重作品调分 def adjust_review_score tip_exception("缺少type参数") if params[:type].blank? || !["review", "report"].include?(params[:type]) - if params[:type] == "review" && (params[:score].nil? || params[:challenge_id].nil? || params[:code_rate].nil? || params[:copy_user_id].nil?) + if params[:type] == "review" && (params[:score].blank? || params[:challenge_id].blank? || params[:code_rate].blank? || params[:copy_user_id].blank?) tip_exception("参数错误,score和challenge_id和code_rate和copy_user_id不能为空") - elsif params[:type] == "report" && (params[:score].nil? || params[:challenge_id].nil?) - tip_exception("参数错误,score和challenge_id") + elsif params[:type] == "report" && (params[:score].blank? || params[:challenge_id].blank?) + tip_exception("参数错误,score和challenge_id不能为空") end challenge_setting = @homework.homework_challenge_settings.find_by(challenge_id: params[:challenge_id]) challenge = challenge_setting&.challenge - tip_exception("不能小于零") if params[:score] < 0 - tip_exception("不能大于关卡分值:#{challenge_setting.score}分") if challenge_setting.score < params[:score] + tip_exception("不能小于零") if params[:score].to_i < 0 + tip_exception("不能大于关卡分值:#{challenge_setting.score}分") if challenge_setting.score < params[:score].to_i ActiveRecord::Base.transaction do begin diff --git a/app/views/exercise_banks/choose_shixun.json.jbuilder b/app/views/exercise_banks/choose_shixun.json.jbuilder index 96a9a2b61..f0a0733d2 100644 --- a/app/views/exercise_banks/choose_shixun.json.jbuilder +++ b/app/views/exercise_banks/choose_shixun.json.jbuilder @@ -1,10 +1,17 @@ -json.shixun_counts @shixuns_count +json.shixun_list @shixuns do |shixun| + json.shixun_id shixun.id + json.identifier shixun.identifier + json.shixun_name shixun.name + json.myshixuns_count shixun.myshixuns_count + json.school shixun.user&.school_name + json.creator shixun.user&.full_name + json.level level_to_s(shixun.trainee) +end -json.shixuns do - json.array! @shixuns do |s| - json.shixun_id s.id - json.shixun_name s.name - json.shixun_user s.user.real_name - json.shixun_user_count s.myshixuns_count - end -end \ No newline at end of file +json.tags @tags do |tag| + json.tag_id tag.id + json.tag_name tag.name +end + +json.shixuns_count @total_count +json.search_tags @search_tags \ No newline at end of file