From 1b11734f6c6c46331bcd03e7fb4c746485504e43 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 17 Apr 2019 17:09:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E6=9B=B4=E6=96=B0=E5=AE=9E?= =?UTF-8?q?=E8=AE=AD=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 40 ++++++++++++++++--- app/views/exercise/update_shixun_block.js.erb | 0 config/routes.rb | 1 + 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 app/views/exercise/update_shixun_block.js.erb diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 15998dbf..4dff2c56 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -8,10 +8,12 @@ class ExerciseController < ApplicationController :student_exercise_list, :update_question_num, :cancel_publish, :send_to_course, :get_student_uncomplete_question, :edit_question_score, :setting, :set_public, :ex_setting, :add_to_exercise_bank, :choose_shixuns, :shixun_question, :back_to_answer, :export_blank_exercise, :export_student_result, - :choose_student, :redo_exercise, :cancel_commit_confirm, :cancel_commit] + :choose_student, :redo_exercise, :cancel_commit_confirm, :cancel_commit, + :update_shixun_block] before_filter :find_course, :only => [:index,:new,:create] before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :create_exercise_question, :publish_exercise, :publish_notice, :end_exercise, :cancel_publish, - :update_question_num, :send_to_course, :edit_question_score, :set_public, :ex_setting, :export_blank_exercise, :export_student_result] + :update_question_num, :send_to_course, :edit_question_score, :set_public, :ex_setting, :export_blank_exercise, :export_student_result, + :choose_shixuns, :shixun_question, :update_shixun_block] before_filter :require_login, :only => [:student_exercise_list, :show] include ExerciseHelper include ApplicationHelper @@ -161,7 +163,35 @@ class ExerciseController < ApplicationController end def shixun_question - @shixun = Shixun.find params[:shixun_exercise] + @shixuns = Shixun.where(id: params[:shixun_exercise]) + end + + def update_shixun_block + ActiveRecord::Base.transaction do + if params[:shixun_ids] && params[:shixun_ids].length > 0 && params[:ques_nums] && params[:ques_nums].length == 4 && + params[:ques_scores] && params[:ques_scores].length == 4 + shixuns = Shixun.where(id: params[:shixun_ids], status: 2, challenges_count: 1) + params[:ques_nums].each_with_index do |ques_num, index| + level_setting = @exercise.exercise_level_settings.where(level: index + 1).first || + ExerciseLevelSetting.create(exercise_id: @exercise.id) + level_setting.update_attributes(score: params[:ques_scores][index], num: ques_num) + shixuns.where(trainee: index + 1).each do |shixun| + ex_question = @exercise.exercise_questions.where(shixun_id: shixun.id).first + if ex_question.present? + ex_question.update_attributes(question_score: params[:ques_scores][index]) + else + ex_question = ExerciseQuestion.create(exercise_id: @exercise.id, question_score: arams[:ques_scores][index], + shixun_id: shixun.id, question_title: shixun.name, question_type: 5, question_number: 0) + shixun.challenges.each_with_index do |challenge, index| + ex_shixun_challenge = ExerciseShixunChallenge.new(challenge_id: challenge.id, shixun_id: shixun.id, exercise_question_id: ex_question.id, + question_score: params[:ques_scores][index], position: index + 1) + ex_shixun_challenge.save + end + end + end + end + end + end end def create @@ -385,7 +415,7 @@ class ExerciseController < ApplicationController option = { :question_title => question_title, :question_type => params[:question_type] || 1, - :question_number => @exercise.exercise_questions.count + 1, + :question_number => @exercise.exercise_questions.where("question_type != 5").count + 1, :question_score => params[:question_score], :shixun_id => params[:shixun] } @@ -579,7 +609,7 @@ class ExerciseController < ApplicationController #题目上移/下移 def update_question_num @exercise_question = ExerciseQuestion.find params[:ques_id] - exercise_questions = @exercise.exercise_questions + exercise_questions = @exercise.exercise_questions.where("question_type != 5") if @exercise_question if params[:opr] == 'up' && @exercise_question.question_number > 1 @before_que = exercise_questions.where("question_number = #{@exercise_question.question_number - 1}").first diff --git a/app/views/exercise/update_shixun_block.js.erb b/app/views/exercise/update_shixun_block.js.erb new file mode 100644 index 00000000..e69de29b diff --git a/config/routes.rb b/config/routes.rb index 65ab3d15..6043af76 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1048,6 +1048,7 @@ RedmineApp::Application.routes.draw do ## oauth相关 get 'cancel_commit' get 'cancel_commit_confirm' get 'adjust_question_score' + post 'update_shixun_block' end collection do #生成路径为 /exercise/方法名