From 48bf9693d87b9f21a819bc210cb752a010c40376 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 09:19:35 +0800 Subject: [PATCH 01/44] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E9=A2=98=E6=9C=AA=E9=80=9A=E5=85=B3=E6=98=BE=E7=A4=BA=E5=85=B3?= =?UTF-8?q?=E5=8D=A1=E5=86=85=E5=AE=B9=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_questions_controller.rb | 2 +- .../exercise_questions/_exercise_questions.json.jbuilder | 2 +- app/views/exercises/_shixun_details.json.jbuilder | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index dd0247f70..79d671605 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -640,7 +640,7 @@ class ExerciseQuestionsController < ApplicationController if @exercise.exercise_status != 1 question_score = @exercise_question.question_score #原来的分数 update_question_score = params[:question_score].to_f.round(1) #传入的分数 - choices_count = @exercise_question.exercise_choices.count #原来的选项个数 + choices_count = @exercise_question.exercise_choices.size #原来的选项个数 exercise_choice_ids = @exercise_question.exercise_standard_answers.pluck(:exercise_choice_id).uniq standard_answers_text = @exercise_question.exercise_standard_answers.pluck(:answer_text).uniq update_choices_count = params[:question_choices].present? ? params[:question_choices].count : choices_count #传入的选项个数 diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 9445862ba..4e05ffb7a 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -86,7 +86,7 @@ elsif question.question_type == 5 user_get_score = games_score[:s_score].present? ? games_score[:s_score] : 0.0 json.shixun_challenge_id s.id if games_score[:games].count > 0 - json.partial! "exercises/shixun_details",games: games_score[:games], user_score: user_get_score,game_score: games_score[:game_score] + json.partial! "exercises/shixun_details",games: games_score[:games], user_score: user_get_score,game_score: games_score[:game_score],shixun_challenge:s else json.partial! "exercises/shixun_undo",games: [s], user_score: user_get_score ,game_score: s.question_score end diff --git a/app/views/exercises/_shixun_details.json.jbuilder b/app/views/exercises/_shixun_details.json.jbuilder index c788b8c1c..a28bf4145 100644 --- a/app/views/exercises/_shixun_details.json.jbuilder +++ b/app/views/exercises/_shixun_details.json.jbuilder @@ -26,6 +26,13 @@ json.shixun_detail do json.position output.query_index json.output_detail output_detail game, output end - json.passed_code game.try(:lastest_code) + + if game.try(:lastest_code).blank? + cha_path = challenge_path(shixun_challenge.challenge&.path) + latest_code = git_fle_content(shixun_challenge.shixun&.repo_path,cha_path) + else + latest_code = game.try(:lastest_code) + end + json.passed_code latest_code end end \ No newline at end of file From f2fed6a237d740b3f1c3825bdb6dfe4013a4464b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 09:32:59 +0800 Subject: [PATCH 02/44] fix bug --- app/controllers/concerns/git_helper.rb | 5 ----- app/helpers/application_helper.rb | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index 445d67087..f40e18e1c 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -53,9 +53,4 @@ module GitHelper container.update_attributes!(:repo_name => new_repo_name) end - #实训题的关卡url初始化 - def challenge_path(path) - cha_path = path.present? ? path.split(";") : [] - cha_path.reject(&:blank?)[0].try(:strip) - end end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 32c4438a6..0cdfeba06 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -332,6 +332,12 @@ module ApplicationHelper raw arr.join('') end + + #实训题的关卡url初始化 + def challenge_path(path) + cha_path = path.present? ? path.split(";") : [] + cha_path.reject(&:blank?)[0].try(:strip) + end end From 71ea32797d5193d8c891575dbc443fd5b5b27c65 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 09:39:05 +0800 Subject: [PATCH 03/44] fix bug --- app/controllers/concerns/git_helper.rb | 5 +++++ app/helpers/application_helper.rb | 6 +----- app/helpers/exercises_helper.rb | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index f40e18e1c..445d67087 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -53,4 +53,9 @@ module GitHelper container.update_attributes!(:repo_name => new_repo_name) end + #实训题的关卡url初始化 + def challenge_path(path) + cha_path = path.present? ? path.split(";") : [] + cha_path.reject(&:blank?)[0].try(:strip) + end end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0cdfeba06..d8ea8cd60 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,7 @@ # 所有的方法请按首字母的顺序依次列出 module ApplicationHelper include Educoder::I18n + include GitHelper ONE_MINUTE = 60 * 1000 ONE_HOUR = 60 * ONE_MINUTE @@ -333,11 +334,6 @@ module ApplicationHelper raw arr.join('') end - #实训题的关卡url初始化 - def challenge_path(path) - cha_path = path.present? ? path.split(";") : [] - cha_path.reject(&:blank?)[0].try(:strip) - end end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index a2a80c311..45666d296 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -1,5 +1,6 @@ module ExercisesHelper + # include GitHelper #获取每个学生对每个题的答案状态 def get_each_student_exercise(exercise_id,exercise_questions,user_id) From 226afa2d96beb9aea284303b1589220b9f377955 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 09:42:54 +0800 Subject: [PATCH 04/44] fix bug --- app/views/exercises/_shixun_details.json.jbuilder | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/views/exercises/_shixun_details.json.jbuilder b/app/views/exercises/_shixun_details.json.jbuilder index a28bf4145..de847ebed 100644 --- a/app/views/exercises/_shixun_details.json.jbuilder +++ b/app/views/exercises/_shixun_details.json.jbuilder @@ -27,12 +27,17 @@ json.shixun_detail do json.output_detail output_detail game, output end - if game.try(:lastest_code).blank? - cha_path = challenge_path(shixun_challenge.challenge&.path) - latest_code = git_fle_content(shixun_challenge.shixun&.repo_path,cha_path) + if game.evaluate_count > 0 + if game.try(:lastest_code).blank? + cha_path = challenge_path(shixun_challenge.challenge&.path) + latest_code = git_fle_content(shixun_challenge.shixun&.repo_path,cha_path) + else + latest_code = game.try(:lastest_code) + end else - latest_code = game.try(:lastest_code) + latest_code = nil end + json.passed_code latest_code end end \ No newline at end of file From a8b0f950c71eacef61154a822821c96978db7194 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 09:52:17 +0800 Subject: [PATCH 05/44] fix bug --- app/views/exercises/_shixun_details.json.jbuilder | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/views/exercises/_shixun_details.json.jbuilder b/app/views/exercises/_shixun_details.json.jbuilder index de847ebed..ac3884336 100644 --- a/app/views/exercises/_shixun_details.json.jbuilder +++ b/app/views/exercises/_shixun_details.json.jbuilder @@ -27,15 +27,11 @@ json.shixun_detail do json.output_detail output_detail game, output end - if game.evaluate_count > 0 - if game.try(:lastest_code).blank? - cha_path = challenge_path(shixun_challenge.challenge&.path) - latest_code = git_fle_content(shixun_challenge.shixun&.repo_path,cha_path) - else - latest_code = game.try(:lastest_code) - end + if game.try(:lastest_code).blank? + cha_path = challenge_path(shixun_challenge.challenge&.path) + latest_code = git_fle_content(shixun_challenge.shixun&.repo_path,cha_path) else - latest_code = nil + latest_code = game.try(:lastest_code) end json.passed_code latest_code From 4b71fc157677ad9ca15eeb9f856cd4dc30370c3f Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 09:59:06 +0800 Subject: [PATCH 06/44] fix bug --- app/controllers/concerns/git_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index 445d67087..8e7288df2 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -31,7 +31,8 @@ module GitHelper decode_content rescue Exception => e - uid_logger_error(e.message) + Rails.logger.error(e.message) + # uid_logger_error(e.message) raise Educoder::TipException.new("文档内容获取异常") end end From 5c74d71c947720f37b94e7e2dec7d6f630daf021 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 10:14:46 +0800 Subject: [PATCH 07/44] fix bug --- app/helpers/exercises_helper.rb | 2 +- app/views/exercises/_shixun_details.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 45666d296..5f8683fd0 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -436,7 +436,7 @@ module ExercisesHelper game_code = game_challenge code = game_code.try(:new_code) else - code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path) + code = git_fle_content(game.myshixun.repo_path,cha_path) end sx_option = { :exercise_question_id => q.id, diff --git a/app/views/exercises/_shixun_details.json.jbuilder b/app/views/exercises/_shixun_details.json.jbuilder index ac3884336..96e5c6281 100644 --- a/app/views/exercises/_shixun_details.json.jbuilder +++ b/app/views/exercises/_shixun_details.json.jbuilder @@ -29,7 +29,7 @@ json.shixun_detail do if game.try(:lastest_code).blank? cha_path = challenge_path(shixun_challenge.challenge&.path) - latest_code = git_fle_content(shixun_challenge.shixun&.repo_path,cha_path) + latest_code = git_fle_content(game&.myshixun.repo_path,cha_path) else latest_code = game.try(:lastest_code) end From a78759f8af49cc8c20d2d2b523256fe7875b7e6e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 10:19:10 +0800 Subject: [PATCH 08/44] =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=8A=A5500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 9e645c35a..8c364308f 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -52,7 +52,7 @@ class GamesController < ApplicationController record_onsume_time = EvaluateRecord.where(game_id: @game.id).first.try(:consume_time) # myshixun_manager判断用户是否有权限查看隐藏测试集(TPM管理员;平台认证的老师;花费金币查看者) - myshixun_manager = @identity < USER::EDU_GAME_MANAGER + myshixun_manager = @identity < User::EDU_GAME_MANAGER # 选择题和编程题公共部分 @base_date = {st: @st, discusses_count: discusses_count, game_count: game_count, myshixun: @myshixun, From 8cfb86d76c9857493bc5f926408fe80ad49cd91d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 10:28:30 +0800 Subject: [PATCH 09/44] fix bug --- app/views/exercises/_shixun_details.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/exercises/_shixun_details.json.jbuilder b/app/views/exercises/_shixun_details.json.jbuilder index 96e5c6281..85bf532e1 100644 --- a/app/views/exercises/_shixun_details.json.jbuilder +++ b/app/views/exercises/_shixun_details.json.jbuilder @@ -29,7 +29,7 @@ json.shixun_detail do if game.try(:lastest_code).blank? cha_path = challenge_path(shixun_challenge.challenge&.path) - latest_code = git_fle_content(game&.myshixun.repo_path,cha_path) + latest_code = git_fle_content(game.myshixun.repo_path,cha_path) else latest_code = game.try(:lastest_code) end From 067c516561d1fc70ae7152cf2893d0d16673fec8 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 10:43:50 +0800 Subject: [PATCH 10/44] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/concerns/git_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index 8e7288df2..78eae769c 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -9,6 +9,8 @@ module GitHelper # 版本库文件内容,带转码 def git_fle_content(repo_path, path) begin + logger.info("##########repo_path: #{repo_path}") + logger.info("##########path: #{path}") content = GitService.file_content(repo_path: repo_path, path: path) logger.info("@@@@@@@@@@@@@@@@@@#{content}") From 76d16698a1d83e3ac5753d6f8c3c56b3fd0bb72c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 10:49:05 +0800 Subject: [PATCH 11/44] fix bug --- app/helpers/exercises_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 5f8683fd0..6ec6cd601 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -430,7 +430,10 @@ module ExercisesHelper end ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 + logger.info("############_________exercise_cha.challenge&.path___________###############{exercise_cha.challenge&.path}") cha_path = challenge_path(exercise_cha.challenge&.path) + logger.info("############_________cha_path___________###############{cha_path}") + game_challenge = game.game_codes.search_challenge_path(cha_path)&.first if game_challenge.present? game_code = game_challenge From 831b1937f98eeb529283db11bae76f7cc8dff4c7 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 29 Jun 2019 10:57:24 +0800 Subject: [PATCH 12/44] =?UTF-8?q?challenge=E6=98=BE=E7=A4=BA=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 4 ++-- app/controllers/shixuns_controller.rb | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 2ba76c60a..afe0e14b6 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -151,8 +151,8 @@ class ChallengesController < ApplicationController def index uid_logger("identifier: #{params}") # 通过调试发现 这里includes(:games)性能会慢10倍 - - @challenges = @shixun.challenges.fields_for_list.includes(:games).where("games.user_id" => current_user.id) + current_myshixun = @shixun.current_myshixun(current_user.id) + @challenges = @shixun.challenges.includes(:games).where("games.user_id" => (current_myshixun ? current_user.id : nil)) @editable = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 @user = current_user diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 73029706f..b3069bc5d 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -553,11 +553,6 @@ class ShixunsController < ApplicationController end end - # REDO:开启实训时更新关联作品的状态 - # TODO:这个可以异步。或者放到课程里面取,不要在开启实训这边做 - # HomeworksService.new.update_myshixun_work_status myshixun - UpdateMyshixunWorkStatusJob.perform_later(myshixun.id) - @current_task = myshixun.current_task(myshixun.games) uid_logger("## shixun exec: myshixun id is #{myshixun.id}") rescue Exception => e From 538efef33aa40d3483da58d57bd933c569e1a48d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 11:18:59 +0800 Subject: [PATCH 13/44] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9F=A5=E9=87=8D?= =?UTF-8?q?=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2a1dfb14a..c3bd777ae 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1326,7 +1326,7 @@ class HomeworkCommonsController < ApplicationController # 代码查重届结果 def code_review_results # 如果有未获取结果的查重操作 则先读取结果 - #get_new_code_reviews_result @homework + get_new_code_reviews_result @homework @current_user = current_user # 列表数据 From 9d7d609bb5ebfa4d573dc6be55582653f445a0d3 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 11:28:36 +0800 Subject: [PATCH 14/44] fix bug --- app/helpers/exercises_helper.rb | 11 ++++++----- .../_exercise_questions.json.jbuilder | 6 +++++- app/views/exercises/_shixun_details.json.jbuilder | 13 ++++++++----- .../exercises/_user_exercise_info.json.jbuilder | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 6ec6cd601..68f6574ee 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -429,11 +429,9 @@ module ExercisesHelper answer_status = 1 end ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) - if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 - logger.info("############_________exercise_cha.challenge&.path___________###############{exercise_cha.challenge&.path}") + code = nil + if exercise_cha.challenge&.path.present? cha_path = challenge_path(exercise_cha.challenge&.path) - logger.info("############_________cha_path___________###############{cha_path}") - game_challenge = game.game_codes.search_challenge_path(cha_path)&.first if game_challenge.present? game_code = game_challenge @@ -441,6 +439,9 @@ module ExercisesHelper else code = git_fle_content(game.myshixun.repo_path,cha_path) end + end + if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 + ### Todo 实训题的_shixun_details里的代码是不是直接从这里取出就可以了?涉及到code的多个版本库的修改 sx_option = { :exercise_question_id => q.id, :exercise_shixun_challenge_id => exercise_cha.id, @@ -451,7 +452,7 @@ module ExercisesHelper } ExerciseShixunAnswer.create(sx_option) else - ex_shixun_answer_content.first.update_column('score',exercise_cha_score) + ex_shixun_answer_content.first.update_attributes(score:exercise_cha_score.round(1),answer_text:code) end score5 += exercise_cha_score else diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 4e05ffb7a..4cdd97f3c 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -1,6 +1,10 @@ json.question_id question.id # json.question_number question.question_number -json.q_position ques_position.present? ? ques_position : question.question_number +q_positon = question.question_number +if ques_position.present? + q_positon = ques_position +end +json.q_position q_positon json.question_title question.question_title json.question_type question.question_type json.question_score question.question_score.round(1).to_s diff --git a/app/views/exercises/_shixun_details.json.jbuilder b/app/views/exercises/_shixun_details.json.jbuilder index 85bf532e1..4a73a9bbb 100644 --- a/app/views/exercises/_shixun_details.json.jbuilder +++ b/app/views/exercises/_shixun_details.json.jbuilder @@ -27,11 +27,14 @@ json.shixun_detail do json.output_detail output_detail game, output end - if game.try(:lastest_code).blank? - cha_path = challenge_path(shixun_challenge.challenge&.path) - latest_code = git_fle_content(game.myshixun.repo_path,cha_path) - else - latest_code = game.try(:lastest_code) + latest_code = nil + if shixun_challenge.challenge&.path.present? + if game.try(:lastest_code).blank? + cha_path = challenge_path(shixun_challenge.challenge&.path) + latest_code = git_fle_content(game.myshixun.repo_path,cha_path) + else + latest_code = game.try(:lastest_code) + end end json.passed_code latest_code diff --git a/app/views/exercises/_user_exercise_info.json.jbuilder b/app/views/exercises/_user_exercise_info.json.jbuilder index 1ff929897..cba07fb3f 100644 --- a/app/views/exercises/_user_exercise_info.json.jbuilder +++ b/app/views/exercises/_user_exercise_info.json.jbuilder @@ -62,7 +62,7 @@ json.exercise_questions do exercise_type: ex_type, user_answer: user_ques_answers[:answered_content], shixun_type: user_ques_answers[:shixun_type], - ques_position:nil + ques_position: nil if user_ques_comments.count > 0 json.question_comments do json.partial! "exercises/exercise_comments", question_comment:user_ques_answers[:question_comment].first From 16dba624008e84859976f2223f4b094faea942a9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 11:31:54 +0800 Subject: [PATCH 15/44] fix bug --- app/views/exercise_questions/_exercise_questions.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 4cdd97f3c..ce8d0f1f2 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -4,7 +4,7 @@ q_positon = question.question_number if ques_position.present? q_positon = ques_position end -json.q_position q_positon +json.q_position question.question_number json.question_title question.question_title json.question_type question.question_type json.question_score question.question_score.round(1).to_s From 0ec0e612fa4d568db685c4c5b4df884ddff5d6dd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 11:41:10 +0800 Subject: [PATCH 16/44] fix bug --- app/views/exercise_questions/_exercise_questions.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index ce8d0f1f2..4cdd97f3c 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -4,7 +4,7 @@ q_positon = question.question_number if ques_position.present? q_positon = ques_position end -json.q_position question.question_number +json.q_position q_positon json.question_title question.question_title json.question_type question.question_type json.question_score question.question_score.round(1).to_s From da2c9c97c263743af8c3a6238ff63f9cede3a36b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 12:29:14 +0800 Subject: [PATCH 17/44] fix bug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 68f6574ee..72fbc9486 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -642,7 +642,7 @@ module ExercisesHelper end if student_status == 2 #当前为老师,或为学生且已提交 user_score_pre = exercise_answers.score_reviewed - user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : nil + user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : "0.0" end if user_score.present? && (user_score > q.question_score) From 8dd42b59a7237468f4c0c72487032e9293f82b2c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 12:30:32 +0800 Subject: [PATCH 18/44] fix bug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 72fbc9486..04890954b 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -642,7 +642,7 @@ module ExercisesHelper end if student_status == 2 #当前为老师,或为学生且已提交 user_score_pre = exercise_answers.score_reviewed - user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : "0.0" + user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0 end if user_score.present? && (user_score > q.question_score) From 079d757021b4678302f9e34832117f6222baf709 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 14:17:43 +0800 Subject: [PATCH 19/44] =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 035b43955..8629083dd 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -260,12 +260,12 @@ class MyshixunsController < ApplicationController unless @hide_code # 远程版本库文件内容 last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"] - - content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && params[:content].present? - params[:content].gsub(/\t/, ' ') - else - params[:content] - end + content = params[:content] + # content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && params[:content].present? + # params[:content].gsub(/\t/, ' ') + # else + # params[:content] + # end if content != last_content @content_modified = 1 From 0d5361b59cd9c45c10c585610ba1df83ef22a0dd Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 29 Jun 2019 14:38:12 +0800 Subject: [PATCH 20/44] shixun file update --- app/controllers/myshixuns_controller.rb | 85 ++++++++++--------- app/views/myshixuns/update_file.json.jbuilder | 1 + 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 035b43955..24c5066e5 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -243,55 +243,56 @@ class MyshixunsController < ApplicationController # -----Repository # TODO: 之类需要一个resubmit参数,但是是关于games. def update_file - @hide_code = Shixun.where(id: @myshixun.shixun_id).pluck(:hide_code).first - tip_exception("技术平台为空!") if @myshixun.mirror_name.blank? - path = params[:path].strip unless params[:path].blank? - game_id = params[:game_id] - game = Game.find(game_id) - @content_modified = 0 - # params[:evaluate] 实训评测时更新必须给的参数,需要依据该参数做性能统计,其它类型的更新可以跳过 - # 自动保存的时候evaluate为0;点评测的时候为1 - if params[:evaluate] == 1 - record = EvaluateRecord.create!(:user_id => current_user.id, :shixun_id => @myshixun.shixun_id, :game_id => game_id) - uid_logger("-- game is #{game_id}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") - student_work_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f - record.update_attributes!(:student_work => student_work_time) - end - unless @hide_code - # 远程版本库文件内容 - last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"] + begin + @hide_code = Shixun.where(id: @myshixun.shixun_id).pluck(:hide_code).first + tip_exception("技术平台为空!") if @myshixun.mirror_name.blank? + path = params[:path].strip unless params[:path].blank? + game_id = params[:game_id] + game = Game.find(game_id) + @content_modified = 0 + + # params[:evaluate] 实训评测时更新必须给的参数,需要依据该参数做性能统计,其它类型的更新可以跳过 + # 自动保存的时候evaluate为0;点评测的时候为1 + if params[:evaluate] == 1 + @sec_key = generate_identifier(EvaluateRecord, 12) + record = EvaluateRecord.create!(:user_id => current_user.id, :shixun_id => @myshixun.shixun_id, :game_id => game_id, + :identifier => @sec_key) + uid_logger("-- game build: file update #{@sec_key}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") + end + unless @hide_code + # 远程版本库文件内容 + last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"] - content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && params[:content].present? - params[:content].gsub(/\t/, ' ') - else - params[:content] - end - if content != last_content - @content_modified = 1 + content = params[:content] - author_name = current_user.full_name - author_email = current_user.mail - message = params[:evaluate] == 0 ? "auto commit" : "task commit" - @content = GitService.update_file(repo_path: @repo_path, - file_path: path, - message: message, - content: content, - author_name: author_name, - author_email: author_email) + if content != last_content + @content_modified = 1 - uid_logger("-- file update #{@content}") + author_name = current_user.full_name + author_email = current_user.mail + message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted" + @content = GitService.update_file(repo_path: @repo_path, + file_path: path, + message: message, + content: content, + author_name: author_name, + author_email: author_email) + end end - end - if game.status == 2 - @resubmit = Time.now.to_i - end + if game.status == 2 + @resubmit = Time.now.to_i + end - # 评测时间记录 - if record.present? - consume_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f - record.update_attributes!(:file_update => consume_time) + # 评测时间记录 + if record.present? + consume_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f + record.update_attributes!(:file_update => consume_time) + end + rescue Exception => e + uid_logger_error(e.message) + tip_exception("文件内容更新异常,请稍后重试") end end diff --git a/app/views/myshixuns/update_file.json.jbuilder b/app/views/myshixuns/update_file.json.jbuilder index c647927c4..ce8426715 100644 --- a/app/views/myshixuns/update_file.json.jbuilder +++ b/app/views/myshixuns/update_file.json.jbuilder @@ -1,3 +1,4 @@ json.content @content json.resubmit "#{@resubmit}" +json.sec_key "#{@sec_key}" json.content_modified @hide_code ? false : @content_modified From 84b6110c56e58c409628273315ad252bb82b9172 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 14:44:18 +0800 Subject: [PATCH 21/44] fix bug --- .../exercise_questions_controller.rb | 2 +- app/helpers/exercises_helper.rb | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 79d671605..b231d6af7 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -616,7 +616,7 @@ class ExerciseQuestionsController < ApplicationController elsif params[:question_type].to_i == 2 && (params[:standard_answers].count > 1 || params[:question_choices].blank? || params[:question_choices].include?("")) #判断题的标准答案不能大于1个,选项不能为空 normal_status(-1,"判断题选项不能为空/标准答案不能大于1个!") elsif params[:question_type].to_i <= 1 && (params[:question_choices].blank? || params[:question_choices].include?("") || params[:question_choices].count < 2) #选择题选项不能为空,且不能小于2 - normal_status(-1,"选择题选项内容不能为空,且不能少于3个!") + normal_status(-1,"选择题选项内容不能为空,且不能少于2个!") elsif params[:question_type].to_i == 3 && (params[:standard_answers].blank? || params[:standard_answers].count > 5 ) #填空题选项最多为5个,且如果为1个的话,不允许修改is_ordered normal_status(-1,"填空题标准答案不能为空/不能超过5个!") elsif params[:question_type].to_i == 4 && params[:standard_answers].count > 2 #简单题参考答案最多为1个 diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 04890954b..1442e1da3 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -167,10 +167,13 @@ module ExercisesHelper ex_score = ex&.question_score full_scores = effictive_users.search_exercise_answer("score",ex_score).count #满分人数 no_full_scores = effictive_users.exercise_no_full_scores(ex_score).count #部分分数人数 - all_zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的,及未评阅的 - review_scores = ex.exercise_answer_comments.count #主观题的评阅数量 - un_review_scores = effictive_users_count - review_scores #未评阅数 - zero_scores = all_zero_scores - un_review_scores #已评阅,且答案未0分的人数 + zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的,及未评阅的 + # review_scores = ex.exercise_answer_comments.count #主观题的评阅数量 + un_review_scores = effictive_users_count - full_scores - no_full_scores - zero_scores #未评阅数 + if un_review_scores < 0 + un_review_scores = 0 + end + # zero_scores = all_zero_scores - un_review_scores #已评阅,且答案未0分的人数 main_scores_array = [full_scores,no_full_scores,zero_scores,un_review_scores] main_scores_array.each_with_index do |s,index| if index == 0 @@ -642,7 +645,11 @@ module ExercisesHelper end if student_status == 2 #当前为老师,或为学生且已提交 user_score_pre = exercise_answers.score_reviewed - user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0 + if ques_type == 4 && user_score_pre.blank? #主观题时,且没有大于0的分数时,为空 + user_score = nil + else + user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0 + end end if user_score.present? && (user_score > q.question_score) From ab098a3e24d305b9069ee2c7419d0d3331b7f28a Mon Sep 17 00:00:00 2001 From: jasder Date: Sat, 29 Jun 2019 15:04:25 +0800 Subject: [PATCH 22/44] =?UTF-8?q?FIX=20=E8=B5=84=E6=BA=90=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E9=A1=B6=E9=83=A8=E6=95=B0=E9=87=8F=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 7e150c44c..c303c7e78 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -17,25 +17,27 @@ class FilesController < ApplicationController sort_type = params[:sort_type] || 'created_on' # created_on:时间排序, downloads:下载次数排序; quotes: 引用次数排序 course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id @user = current_user || nil - @attachments = @course.attachments.by_keywords(params[:search]) + @attachments = @course.attachments.by_course_second_category_id(course_second_category_id) .includes(attachment_group_settings: :course_group, author: [:user_extension, :course_members]) - .by_course_second_category_id(course_second_category_id) .ordered(sort: sort.to_i, sort_type: sort_type.strip) get_category(@course, course_second_category_id) - case @user.course_identity(@course) - when 5 - # 课程学生 - @attachments = @attachments.published - when 6 || 7 - # 非课堂成员 - @attachments = @attachments.publiced.published - end + @attachments = + case @user.course_identity(@course) + when 5 + @attachments.published + when 6, 7 + @attachments.publiced.published + else + @attachments + end @total_count = @attachments.size @public_count = @attachments.publiced.size @private_count = @total_count - @public_count + @attachments = @attachments.by_keywords(params[:search]) + @attachments = @attachments.page(@page).per(@page_size) end From d8ecd6e7728977f463a0975eaaef51640c5e7c9e Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 29 Jun 2019 15:09:44 +0800 Subject: [PATCH 23/44] =?UTF-8?q?tpi=20=E7=89=88=E6=9C=AC=E5=BA=93?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=9B=B4=E6=96=B0=E5=92=8C=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/concerns/git_common.rb | 1 - app/controllers/concerns/git_helper.rb | 6 ++---- app/controllers/games_controller.rb | 1 + 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/concerns/git_common.rb b/app/controllers/concerns/git_common.rb index 2f977245c..452204419 100644 --- a/app/controllers/concerns/git_common.rb +++ b/app/controllers/concerns/git_common.rb @@ -28,7 +28,6 @@ module GitCommon end def file_content - logger.info("#################{@repo_path}, #{@path}") @content = git_fle_content @repo_path, @path end diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index 78eae769c..8d769a244 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -9,11 +9,10 @@ module GitHelper # 版本库文件内容,带转码 def git_fle_content(repo_path, path) begin - logger.info("##########repo_path: #{repo_path}") - logger.info("##########path: #{path}") + logger.info("git file content: repo_path is #{repo_path}, path is #{path}") content = GitService.file_content(repo_path: repo_path, path: path) - logger.info("@@@@@@@@@@@@@@@@@@#{content}") + logger.info("git file content: content is #{content}") decode_content = nil if content.present? content = content["content"] #6.24 -hs 这个为新增,因为当实训题里含有选择题时,这里会报错,undefined method `[]' for nil:NilClass @@ -34,7 +33,6 @@ module GitHelper rescue Exception => e Rails.logger.error(e.message) - # uid_logger_error(e.message) raise Educoder::TipException.new("文档内容获取异常") end end diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 8c364308f..2a2439226 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -461,6 +461,7 @@ class GamesController < ApplicationController git_fle_content(@myshixun.shixun.repo_path, path) rescue Exception => e uid_logger_error("#{e.message}") + # 如果已发布的TPM实训也不能获取到内容,那么肯定是版本库异常了 if @myshixun.shixun.try(:status) < 2 tip_exception("代码获取异常,请检查实训模板的评测设置是否正确") else From cd3147dc970a41c91ef569fffe241a8da8dc69bc Mon Sep 17 00:00:00 2001 From: jasder Date: Sat, 29 Jun 2019 15:17:03 +0800 Subject: [PATCH 24/44] FIX bug --- app/controllers/files_controller.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index c303c7e78..c8fd042ea 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -16,12 +16,17 @@ class FilesController < ApplicationController sort = params[:sort] || 0 # 0: 降序;1: 升序 sort_type = params[:sort_type] || 'created_on' # created_on:时间排序, downloads:下载次数排序; quotes: 引用次数排序 course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id - @user = current_user || nil + @user = current_user @attachments = @course.attachments.by_course_second_category_id(course_second_category_id) .includes(attachment_group_settings: :course_group, author: [:user_extension, :course_members]) .ordered(sort: sort.to_i, sort_type: sort_type.strip) + get_category(@course, course_second_category_id) + @total_count = @attachments.size + @public_count = @attachments.publiced.size + @private_count = @total_count - @public_count + @attachments = @attachments.by_keywords(params[:search]) @attachments = case @user.course_identity(@course) when 5 @@ -32,12 +37,6 @@ class FilesController < ApplicationController @attachments end - @total_count = @attachments.size - @public_count = @attachments.publiced.size - @private_count = @total_count - @public_count - - @attachments = @attachments.by_keywords(params[:search]) - @attachments = @attachments.page(@page).per(@page_size) end From 069571bec2ad5de05dca27ac29a7a8c539007582 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 15:17:46 +0800 Subject: [PATCH 25/44] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index afe0e14b6..41ba59be8 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -160,8 +160,8 @@ class ChallengesController < ApplicationController def show @tab = params[:tab].nil? ? 1 : params[:tab].to_i - challenge_num = Challenge.where(shixun_id: @shixun).count - @power = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 + challenge_num = @shixun.challenges_count + @power = @shixun.status == 0 # 之前验证走过了是不是管理员,因此这里只用判断是否发布 @position = @challenge.position if @position < challenge_num @next_challenge = Challenge.where(:shixun_id => @shixun, :position => @position + 1).first From 6cf53047c35635351ec2f495cc3262b1858d044e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 15:25:24 +0800 Subject: [PATCH 26/44] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 41ba59be8..d56c3ecbd 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -138,7 +138,7 @@ class ChallengesController < ApplicationController # tab 0,nil 过关任务, 1 评测设置, 2 参考答案 def edit @tab = params[:tab].to_i - @power = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 + @power = @shixun.status == 0 challenge_num = Challenge.where(:shixun_id => @shixun).count @position = @challenge.position @chooses = @challenge.challenge_chooses @@ -279,9 +279,6 @@ class ChallengesController < ApplicationController def find_shixun @shixun = Shixun.find_by_identifier(params[:shixun_identifier]) - if !current_user.shixun_permission(@shixun) - tip_exception(403, "..") - end end # 通用接口 From 3c1710eefc7218f1ad82d4c2e3f75c4b8eb15a06 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 15:36:03 +0800 Subject: [PATCH 27/44] fix bug --- app/controllers/exercises_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 421c5177a..2fcd7275b 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1418,7 +1418,7 @@ class ExercisesController < ApplicationController :best_counts => best_counts, } - @exercise_questions = @exercise.exercise_questions + @exercise_questions = @exercise.exercise_questions&.includes(:exercise_choices,:exercise_answers,:exercise_standard_answers,:exercise_shixun_challenges,:exercise_shixun_answers) @paging_type = "percent" # 按题型排序 From 133eaf42cb390f68070119668b92e3719d9fe20f Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 15:53:04 +0800 Subject: [PATCH 28/44] =?UTF-8?q?=E9=97=AE=E5=8D=B7/=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E7=9A=84=E5=88=97=E8=A1=A8=E9=A1=B5=EF=BC=8C=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=8F=8A=E7=BB=9F=E8=AE=A1=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 4 ++-- app/controllers/polls_controller.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2fcd7275b..8b65d7c70 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -101,7 +101,7 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 15 @exercises = @exercises.page(@page).per(@limit) - @exercises = @exercises.includes(:exercise_users,:exercise_questions,:exercise_group_settings) + @exercises = @exercises&.includes(:exercise_users,:exercise_questions,:exercise_group_settings) else @exercises = [] end @@ -188,7 +188,7 @@ class ExercisesController < ApplicationController else @is_teacher_or = 0 #为学生 end - @exercise_questions = @exercise.exercise_questions.order("question_number ASC") + @exercise_questions = @exercise.exercise_questions&.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_standard_answers).order("question_number ASC") rescue Exception => e uid_logger_error(e.message) tip_exception("试卷创建失败!") diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 6fbba1c3d..cd9679972 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -90,7 +90,7 @@ class PollsController < ApplicationController @limit = params[:limit] || 15 @polls = @polls.page(@page).per(@limit) - @polls = @polls.includes(:poll_users,:poll_questions,:poll_group_settings) + @polls = @polls&.includes(:poll_users,:poll_questions,:poll_group_settings) else @polls = [] @@ -183,7 +183,7 @@ class PollsController < ApplicationController else @is_teacher_or = 0 end - @poll_questions = @poll.poll_questions.order("question_number ASC") + @poll_questions = @poll.poll_questions&.includes(:poll_answers).order("question_number ASC") rescue Exception => e uid_logger_error(e.message) tip_exception("没有权限") @@ -1148,7 +1148,7 @@ class PollsController < ApplicationController end def get_questions_count - @poll_questions = @poll.poll_questions.order("question_number ASC") + @poll_questions = @poll.poll_questions&.includes(:poll_answers,:poll_votes).order("question_number ASC") @poll_questions_count = @poll_questions.count # 全部的题目数 @poll_question_singles = @poll_questions.ques_count(1).all.count # 单选题 @poll_question_doubles = @poll_questions.ques_count(2).all.count # 多选题 From 783e2e1727cd0e29dc529c9eaf78df33dfe3602d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 16:23:37 +0800 Subject: [PATCH 29/44] fix bug --- app/helpers/polls_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index b5ba79dcc..d9b6ccee7 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -110,7 +110,7 @@ module PollsHelper poll_user_name = user.nickname end course_member = course_members.find_by(user_id:user.id) - course_group_id = course_members.present? ? course_member.course_group_id : nil + course_group_id = course_member.present? ? course_member.course_group_id : nil if course_group_id == 0 course_group_name = "未分班" else From ad9e7a58f70e584f7254f5049643e546779969e4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 17:21:38 +0800 Subject: [PATCH 30/44] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 2a2439226..76e15f9e2 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -426,12 +426,12 @@ class GamesController < ApplicationController game_code = GameCode.where(:game_id => @game.try(:id), :path => path).first if game_code.present? content = game_code.try(:new_code) - @content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && content.present? - content.gsub(/\t/, ' ') - else - content - end - update_file_content(@content, @myshixun.repo_path, path, current_user.mail, current_user.full_name, "game passed reset") + # @content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && content.present? + # content.gsub(/\t/, ' ') + # else + # content + # end + update_file_content(content, @myshixun.repo_path, path, current_user.mail, current_user.full_name, "game passed reset") else tip_exception("代码重置失败,代码为空") end From 07e7f0d206b7058438b06bb6f94c80a41c483961 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 17:23:40 +0800 Subject: [PATCH 31/44] fix bug --- app/controllers/zips_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index a8750fc3d..710846f64 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -52,15 +52,16 @@ class ZipsController < ApplicationController @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 if group_id.present? - exercise_students = @course.students.course_find_by_ids("course_group_id",group_id) # 试卷所分班的全部人数 - user_ids = exercise_students.pluck(:user_id).reject(&:blank?) - @ex_users = @ex_users.exercise_commit_users(user_ids) + exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 + user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq + logger.info("+++++++##################_________________user_ids_____________#########{user_ids}") + @ex_users = @ex_users.where(user_id: user_ids) end # @ex_users = @ex_users.first(200) if default_ex_users_size == 0 normal_status(-1,"导出失败,暂时没有已提交的学生") - elsif default_ex_users_size > 200 - normal_status(-1,"导出数量超过200,请分班导出或联系网站管理员导出") + elsif default_ex_users_size > 100 + normal_status(-1,"导出数量超过100,请分班导出或联系网站管理员导出") end end rescue Exception => e From c6e1fd3f8d0cb2ffd2078582e1eb00a19f1af684 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 17:26:36 +0800 Subject: [PATCH 32/44] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E7=9A=84=E7=AD=94=E9=A2=98=E8=AF=95=E5=8D=B7=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/zips_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 710846f64..4de85ec64 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -48,16 +48,16 @@ class ZipsController < ApplicationController @course = @exercise.course default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed - default_ex_users_size = default_ex_users.size @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 if group_id.present? exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq - logger.info("+++++++##################_________________user_ids_____________#########{user_ids}") @ex_users = @ex_users.where(user_id: user_ids) end - # @ex_users = @ex_users.first(200) + + default_ex_users_size = @ex_users.size + if default_ex_users_size == 0 normal_status(-1,"导出失败,暂时没有已提交的学生") elsif default_ex_users_size > 100 From 15668d41986e7851c9d29ac2719ad4cb986995aa Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 17:49:18 +0800 Subject: [PATCH 33/44] fix bug --- app/templates/exercise_export/exercise_user.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index c81f45d68..0c1c1bbab 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -9,6 +9,7 @@
+
<%= request.url %>

<%= @exercise.try(:exercise_name) %>

From 9ce0af33704eb849e2f5006f7aef686e7d3f973a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 18:06:25 +0800 Subject: [PATCH 34/44] fix bug --- app/controllers/zips_controller.rb | 4 +++- app/services/exercise_user_pdf_service.rb | 3 ++- app/services/export_exercises_service.rb | 5 +++-- app/templates/exercise_export/exercise_user.html.erb | 11 ++++++----- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 4de85ec64..c1ff95abd 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -17,7 +17,7 @@ class ZipsController < ApplicationController end def export_exercises - exercises = ExportExercisesService.new(@exercise,@ex_users) + exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) file_name = filename_for_content_disposition(exercises.filename) send_file exercises.ex_zip, filename: file_name, type: 'application/zip' @@ -41,6 +41,8 @@ class ZipsController < ApplicationController ActiveRecord::Base.transaction do begin @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) + @request_url = request.base_url + logger.info("######################____________@request_url____________##########################{@request_url}") group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 22804092e..913d0cfbc 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -5,9 +5,10 @@ class ExerciseUserPdfService attr_reader :exercise, :ex_user - def initialize(exercise, ex_user) + def initialize(exercise, ex_user,request_url) @exercise = exercise @ex_user = ex_user + @request_url = request_url @ex_user_user = @ex_user.user @course = @exercise.course end diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index 12b5501f9..48bfc9519 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -3,9 +3,10 @@ class ExportExercisesService include StudentWorksHelper attr_reader :exercise, :ex_users - def initialize(exercise, ex_users) + def initialize(exercise, ex_users,request_url) @exercise = exercise @ex_users = ex_users + @request_url = request_url end def filename @@ -18,7 +19,7 @@ class ExportExercisesService pdfs = [] Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| ex_users.each do |ex_user| - export = ExerciseUserPdfService.new(exercise, ex_user) + export = ExerciseUserPdfService.new(exercise, ex_user,@request_url) pdf = export.ex_pdf pdfs << pdf begin diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 0c1c1bbab..269237520 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -168,15 +168,16 @@ <% end %>
+ <% q_title = q.question_title&.gsub("src='","src='/#{@request_url}") %> + <% if q_type == 5 %> - <%= q.shixun_name&.html_safe %> + <% q_name = q.shixun_name&.gsub("src='","src='/#{@request_url}") %> + <%= q_name&.html_safe %>
- <%= q.question_title&.html_safe %> + <%= q_title&.html_safe %>
- <% elsif q_type == 4 %> - <%= q.question_title&.html_safe %> <% else %> - <%= q.question_title&.html_safe %> + <%= q_title&.html_safe %> <% end %>
From 7dd8189f17368b01d1e9647512364692a5b6259a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 18:08:03 +0800 Subject: [PATCH 35/44] fix bug --- app/templates/exercise_export/exercise_user.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 269237520..df9c4c6ab 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -9,7 +9,6 @@
-
<%= request.url %>

<%= @exercise.try(:exercise_name) %>

From 51dc8ae124d3e5eca4921d5f0134782de39bb94e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 19:31:45 +0800 Subject: [PATCH 36/44] =?UTF-8?q?=E5=AF=BC=E5=87=BApdf=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E5=9B=BE=E7=89=87=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 1 + app/controllers/zips_controller.rb | 5 ++--- app/services/exercise_user_pdf_service.rb | 4 ++-- app/templates/exercise_export/blank_exercise.html.erb | 8 +++++--- app/templates/exercise_export/exercise_user.html.erb | 5 ++--- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 8b65d7c70..2377f411b 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1334,6 +1334,7 @@ class ExercisesController < ApplicationController #导出空白试卷 def export_exercise @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") + @request_url = request.base_url filename = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index c1ff95abd..b23a3e033 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -42,7 +42,6 @@ class ZipsController < ApplicationController begin @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) @request_url = request.base_url - logger.info("######################____________@request_url____________##########################{@request_url}") group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") @@ -50,12 +49,12 @@ class ZipsController < ApplicationController @course = @exercise.course default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed - @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 + @ex_users = default_ex_users.limit 1 #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 if group_id.present? exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq - @ex_users = @ex_users.where(user_id: user_ids) + @ex_users = @ex_users.where(user_id: user_ids).limit 1 end default_ex_users_size = @ex_users.size diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 913d0cfbc..9b96cd70c 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -38,10 +38,10 @@ class ExerciseUserPdfService kit = PDFKit.new(html) base_css = %w(app/templates/exercise_export/exercise_export.css) base_css.each { |css| kit.stylesheets << Rails.root.join(css) } - #-----正式需删掉 + # #-----正式需删掉 # aa = File.open(Rails.root.join("public/123.html"),"w+") # aa.syswrite(kit.source) - #正式需删掉------- + # #正式需删掉------- file = Tempfile.new(filename) kit.to_pdf(file.path) file diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 2745f8cbe..95a92358f 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -68,13 +68,15 @@ (<%= q&.question_score %>分)
+ <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}") : q.question_title %> <% if q.question_type == 5 %> - <%= q.shixun_name.present? ? q.shixun_name&.html_safe : "" %> + <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}") : q.shixun_name %> + <%= q_name&.html_safe %>
- <%= q.question_title.present? ? q.question_title&.html_safe : "" %> + <%= q_title&.html_safe %>
<% else %> - <%= q.question_title.present? ? q.question_title&.html_safe : "" %> + <%= q_title&.html_safe %> <% end %>
diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index df9c4c6ab..42758af77 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -167,10 +167,9 @@ <% end %>
- <% q_title = q.question_title&.gsub("src='","src='/#{@request_url}") %> - + <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}") : q.question_title %> <% if q_type == 5 %> - <% q_name = q.shixun_name&.gsub("src='","src='/#{@request_url}") %> + <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}") : q.shixun_name %> <%= q_name&.html_safe %>
<%= q_title&.html_safe %> From fba4bf318488bcd1df5eeea72e55048062625e91 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 19:33:33 +0800 Subject: [PATCH 37/44] fix bug --- app/controllers/zips_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index b23a3e033..77a41d065 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -49,12 +49,12 @@ class ZipsController < ApplicationController @course = @exercise.course default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed - @ex_users = default_ex_users.limit 1 #仅导出已提交的,截止后则是全部为提交的。 + @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 if group_id.present? exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq - @ex_users = @ex_users.where(user_id: user_ids).limit 1 + @ex_users = @ex_users.where(user_id: user_ids) end default_ex_users_size = @ex_users.size From e3dbe6c5734fe337a48fe6df350b5704bbf38e98 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 09:11:08 +0800 Subject: [PATCH 38/44] fix bug --- app/templates/exercise_export/blank_exercise.html.erb | 10 +++++----- app/templates/exercise_export/exercise_user.html.erb | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 95a92358f..74cea75f1 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -68,15 +68,15 @@ (<%= q&.question_score %>分)
- <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}") : q.question_title %> + <% q_title = q.question_title&.html_safe %> <% if q.question_type == 5 %> - <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}") : q.shixun_name %> - <%= q_name&.html_safe %> + <% q_name = q.shixun_name&.html_safe %> + <%= q_name&.include?("src=\"") ? q_name&.gsub("src=\"","src=\"#{@request_url}") : q_name %>
- <%= q_title&.html_safe %> + <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %>
<% else %> - <%= q_title&.html_safe %> + <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> <% end %>
diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 42758af77..5770c5921 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -167,15 +167,15 @@ <% end %>
- <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}") : q.question_title %> + <% q_title = q.question_title&.html_safe %> <% if q_type == 5 %> - <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}") : q.shixun_name %> - <%= q_name&.html_safe %> + <% q_name = q.shixun_name&.html_safe %> + <%= q_name&.include?("src=\"") ? q_name&.gsub("src=\"","src=\"#{@request_url}") : q_name %>
- <%= q_title&.html_safe %> + <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %>
<% else %> - <%= q_title&.html_safe %> + <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> <% end %>
From b29d4063a87c1fcbc09c7c46bfcc8c2639b3cdcd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 09:53:58 +0800 Subject: [PATCH 39/44] fix bug --- .../exercise_export/blank_exercise.html.erb | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 74cea75f1..995d04995 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -57,7 +57,7 @@
- <% @exercise_questions.each do |q| %> + <% @exercise_questions.each_with_index do |q,index| %>
@@ -68,15 +68,27 @@ (<%= q&.question_score %>分)
- <% q_title = q.question_title&.html_safe %> + <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.question_title&.html_safe %> <% if q.question_type == 5 %> - <% q_name = q.shixun_name&.html_safe %> - <%= q_name&.include?("src=\"") ? q_name&.gsub("src=\"","src=\"#{@request_url}") : q_name %> + <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.shixun_name&.html_safe %> + <%= q_name %>
- <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= q_title %>
+ <% else %> - <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= q_title %> + <% end %>
@@ -134,4 +146,6 @@
+<%= ApplicationController.helpers.pdf_load_sources(*%w(react/public/js/jquery-1.8.3.min.js react/public/js/editormd/marked.min.js))%> + \ No newline at end of file From 93d18fac5dbba3bd15d925dcc958c42b681b06dd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:12:26 +0800 Subject: [PATCH 40/44] fix bug --- Gemfile | 2 ++ Gemfile.lock | 2 ++ app/helpers/application_helper.rb | 12 +++++++++++ .../exercise_export/blank_exercise.html.erb | 21 +++++-------------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index 31af87f14..b8b174a6f 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,8 @@ gem 'pdfkit' gem 'wkhtmltopdf-binary' #gem 'iconv' +# markdown 转html +gem 'redcarpet', '~> 3.4' gem 'rqrcode', '~> 0.10.1' gem 'rqrcode_png' diff --git a/Gemfile.lock b/Gemfile.lock index 83bd79628..86f524bc2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -193,6 +193,7 @@ GEM rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) rchardet (1.8.0) + redcarpet (3.4.0) redis (4.1.0) redis-actionpack (5.0.2) actionpack (>= 4.0, < 6) @@ -328,6 +329,7 @@ DEPENDENCIES rails (~> 5.2.0) rails-i18n (~> 5.1) rchardet (~> 1.8) + redcarpet (~> 3.4) redis-rails roo-xls rqrcode (~> 0.10.1) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d8ea8cd60..8d92362cc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -334,6 +334,18 @@ module ApplicationHelper raw arr.join('') end + def to_markdown(text) + nil if text.blank? + html_render_options = { + fenced_code_blocks: true, + tables: true, + autolink: true + } + + markdown = Redcarpet::Markdown.new(html_render_options) + raw markdown.render(h(text)).html_safe + end + end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 995d04995..bdb86d9d9 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -57,7 +57,7 @@
- <% @exercise_questions.each_with_index do |q,index| %> + <% @exercise_questions.each do |q| %>
@@ -68,27 +68,17 @@ (<%= q&.question_score %>分)
- <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.question_title&.html_safe %> + <% q_markdown = to_markdown(q.question_title) %> + <% q_title = q_markdown&.include?("src=\"") ? q_markdown&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown %> <% if q.question_type == 5 %> - <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.shixun_name&.html_safe %> + <% q_markdown_name = to_markdown(q.shixun_name) %> + <% q_name = q_markdown_name&.include?("src=\"") ? q_markdown_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown_name %> <%= q_name %>
<%= q_title %>
- <% else %> <%= q_title %> - <% end %>
@@ -146,6 +136,5 @@
-<%= ApplicationController.helpers.pdf_load_sources(*%w(react/public/js/jquery-1.8.3.min.js react/public/js/editormd/marked.min.js))%> \ No newline at end of file From 4f21bcb3bb479f43b08ba755dbcd3e5e947a2255 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:17:09 +0800 Subject: [PATCH 41/44] fix bug --- app/helpers/application_helper.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8d92362cc..34848fd51 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -335,15 +335,19 @@ module ApplicationHelper end def to_markdown(text) - nil if text.blank? - html_render_options = { - fenced_code_blocks: true, - tables: true, - autolink: true + return nil if text.blank? + options = { + :autolink => true, + :no_intra_emphasis => true, + :fenced_code_blocks => true, + :lax_html_blocks => true, + :strikethrough => true, + :superscript => true, + :tables => true } - markdown = Redcarpet::Markdown.new(html_render_options) - raw markdown.render(h(text)).html_safe + markdown = Redcarpet::Markdown.new(options) + markdown.render(h(text)).html_safe end end From 5bfd514211a3ab67621230684ef04c3990373bb4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:22:03 +0800 Subject: [PATCH 42/44] fix bug --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 34848fd51..acb1089ec 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -346,7 +346,7 @@ module ApplicationHelper :tables => true } - markdown = Redcarpet::Markdown.new(options) + markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) markdown.render(h(text)).html_safe end From a6ea8d139a1c9861701d28bfbfa498f76e46d3f9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:23:02 +0800 Subject: [PATCH 43/44] fix bug --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index acb1089ec..055731168 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -347,7 +347,7 @@ module ApplicationHelper } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) - markdown.render(h(text)).html_safe + markdown.render(text).html_safe end end From 1044209d4f995b3c6bee369b183986d53e9f1160 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 1 Jul 2019 10:25:14 +0800 Subject: [PATCH 44/44] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 18 ++++++++++++++++++ app/controllers/challenges_controller.rb | 4 ++-- app/controllers/games_controller.rb | 6 +++--- app/controllers/myshixuns_controller.rb | 2 +- app/controllers/shixuns_controller.rb | 16 ++++++++++++++++ app/models/challenge.rb | 2 +- app/models/shixun.rb | 2 ++ app/models/shixun_service_config.rb | 4 ++++ app/views/challenges/edit.json.jbuilder | 2 +- spec/models/shixun_service_config_spec.rb | 5 +++++ 10 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 app/models/shixun_service_config.rb create mode 100644 spec/models/shixun_service_config_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index afe2129a9..cbd2962b6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -427,6 +427,24 @@ class ApplicationController < ActionController::Base container.to_json end + # 实训中间层pod配置 + def shixun_container_limit shixun + container = [] + shixun.shixun_service_configs.each do |config| + mirror = config.mirror_repository + if mirror.name.present? + container << {:image => mirror.name, + :cpuLimit => config.cpu_limit, + :cpuRequest => config.lower_cpu_limit, + :memoryLimit => "#{config.memory_limit}M", + :memoryRequest => "#{config.request_limit}M", + :resourceLimit => "#{config.resource_limit}K", + :type => mirror.try(:main_type) == "1" ? "main" : "sub"} + end + end + container.to_json + end + # 毕设任务列表的赛选 def course_work(task, **option) logger.info("#############{option}") diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index d56c3ecbd..856afeb01 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -154,7 +154,7 @@ class ChallengesController < ApplicationController current_myshixun = @shixun.current_myshixun(current_user.id) @challenges = @shixun.challenges.includes(:games).where("games.user_id" => (current_myshixun ? current_user.id : nil)) - @editable = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 + @editable = @shixun.status == 0 # before_action:有判断权限,如果没发布,则肯定是管理人员 @user = current_user end @@ -290,7 +290,7 @@ class ChallengesController < ApplicationController def challenge_params params.require(:challenge).permit(:subject, :task_pass, :difficulty, :score, :st, :modify_time, :test_set_average, :path, :exec_path, :show_type, :original_picture_path, :test_set_score, - :expect_picture_path, :picture_path, :web_route, :answer) + :expect_picture_path, :picture_path, :web_route, :answer, :exec_time) end def chooce_params diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 76e15f9e2..7e7b6e082 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -33,7 +33,7 @@ class GamesController < ApplicationController is_teacher = @user.is_teacher? # 实训超时设置 - time_limit = @shixun.exec_time + time_limit = game_challenge.exec_time # 上一关、下一关 prev_game = @game.prev_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position) @@ -66,7 +66,7 @@ class GamesController < ApplicationController shixun_tomcat = edu_setting('cloud_bridge') service_host = edu_setting('vnc_url') uri = "#{shixun_tomcat}/bridge/vnc/getvnc" - params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}"} + params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}"} res = uri_post uri, params if res && res['code'].to_i != 0 raise("实训云平台繁忙(繁忙等级:99)") @@ -547,7 +547,7 @@ class GamesController < ApplicationController br_params = {:tpiID => "#{@myshixun.id}", :tpiGitURL => "#{gitUrl}", :buildID => "#{@game.id}", :instanceChallenge => "#{step}", :testCases => "#{testCases}", :resubmit => "#{resubmit}", :times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified, - :containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}", + :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}", :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", :timeLimit => "#{@shixun.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) } diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index a4a3b7222..909533301 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -217,7 +217,7 @@ class MyshixunsController < ApplicationController shixun_tomcat = edu_setting('tomcat_webssh') uri = "#{shixun_tomcat}/bridge/webssh/getConnectInfo" params = {tpiID:@myshixun.id, podType:@myshixun.shixun.try(:webssh), - containers:(Base64.urlsafe_encode64(container_limit @myshixun.shixun.mirror_repositories))} + containers:(Base64.urlsafe_encode64(shixun_container_limit @myshixun.shixun))} res = uri_post uri, params if res && res['code'].to_i != 0 tip_exception("实训云平台繁忙(繁忙等级:92)") diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b3069bc5d..f079aed1e 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -315,9 +315,13 @@ class ShixunsController < ApplicationController # 镜像-实训关联表 ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => main_type.to_i) if main_type.present? + # 实训主镜像服务配置 + ShixunServiceConfig.create!(:shixun_id => @shixun.id, :mirror_repository_id => main_type.to_i) if sub_type.present? sub_type.each do |mirror| ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror) + # 实训子镜像服务配置 + ShixunServiceConfig.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror) end end @@ -395,6 +399,18 @@ class ShixunsController < ApplicationController use_scope = 0 end @shixun.update_attributes!(:use_scope => use_scope) + # 超级管理员和运营人员才能保存 中间层服务器pod信息的配置 + if current_user.admin? || current_user.business? + @shixun.shixun_service_configs.destroy_all + params[:mirror_id].each_with_index do |mirror_id, index| + ShixunServiceConfig.create!(:shixun_id => @shixun.id, + :cpu_limit => params[:cpu_limit][index], + :lower_cpu_limit => params[:lower_cpu_limit][index], + :memory_limit => params[:memory_limit][index], + :request_limit => params[:request_limit][index], + :mirror_repository_id => mirror_id) + end + end rescue Exception => e uid_logger_error(e.message) tip_exception("实训保存失败") diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 07a49196d..18b177e1c 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -20,7 +20,7 @@ class Challenge < ApplicationRecord # acts_as_attachable scope :base_attrs, -> { select([:id, :subject, :position, :shixun_id, :st, :score, :path, :task_pass, :modify_time, - :web_route, :answer]) } + :web_route, :answer, :exec_time]) } scope :choose_type, -> { where(st: 1) } scope :practice_type, -> { where(st: 0) } diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 556a4400f..18d5c5fae 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -30,6 +30,8 @@ class Shixun < ApplicationRecord has_one :shixun_info, dependent: :destroy belongs_to :user + # 实训服务配置 + has_many :shixun_service_configs, :dependent => :destroy scope :search_by_name, ->(keyword) { where("name like ? or description like ? ", diff --git a/app/models/shixun_service_config.rb b/app/models/shixun_service_config.rb new file mode 100644 index 000000000..6d106fc07 --- /dev/null +++ b/app/models/shixun_service_config.rb @@ -0,0 +1,4 @@ +class ShixunServiceConfig < ApplicationRecord + belongs_to :shixun + belongs_to :mirror_repository +end diff --git a/app/views/challenges/edit.json.jbuilder b/app/views/challenges/edit.json.jbuilder index 64848a4e6..2774b5a05 100644 --- a/app/views/challenges/edit.json.jbuilder +++ b/app/views/challenges/edit.json.jbuilder @@ -7,7 +7,7 @@ json.chooses do end if @tab == 0 # 本关任务tab的编辑模式 - json.(@challenge, :id, :subject, :task_pass, :difficulty, :score) + json.(@challenge, :id, :subject, :task_pass, :difficulty, :score, :exec_time) json.tags @challenge.challenge_tags.map(&:name) elsif @tab == 1 # 评测设置的编辑模式 diff --git a/spec/models/shixun_service_config_spec.rb b/spec/models/shixun_service_config_spec.rb new file mode 100644 index 000000000..d79cd19f7 --- /dev/null +++ b/spec/models/shixun_service_config_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ShixunServiceConfig, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end