|
|
@ -384,24 +384,22 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
opr = params[:opr]
|
|
|
|
opr = params[:opr]
|
|
|
|
current_q_p = @exercise_question.question_number.to_i #问题的当前位置
|
|
|
|
current_q_p = @exercise_question.question_number.to_i #问题的当前位置
|
|
|
|
# last_q_p = @exercise.exercise_questions.find_by_custom("question_number",(current_q_p - 1)).first # 当前问题的前一个问题
|
|
|
|
|
|
|
|
# next_q_p = @exercise.exercise_questions.find_by_custom("question_number",(current_q_p + 1)).first # 当前问题的后一个问题
|
|
|
|
|
|
|
|
last_q_p = @exercise.exercise_questions.last_exercise(current_q_p) # 当前问题的前一个问题
|
|
|
|
|
|
|
|
next_q_p = @exercise.exercise_questions.next_exercise(current_q_p) # 当前问题的后一个问题
|
|
|
|
|
|
|
|
if @exercise.exercise_status.to_i == 1
|
|
|
|
if @exercise.exercise_status.to_i == 1
|
|
|
|
if opr.present?
|
|
|
|
if opr.present?
|
|
|
|
if opr.to_s == "up"
|
|
|
|
if opr.to_s == "up"
|
|
|
|
|
|
|
|
last_q_p = @exercise.exercise_questions.find_by(question_number: (current_q_p - 1)) # 当前问题的前一个问题
|
|
|
|
if last_q_p.present?
|
|
|
|
if last_q_p.present?
|
|
|
|
@exercise_question.update_attribute('question_number', (current_q_p - 1))
|
|
|
|
@exercise_question.update_attribute('question_number', (current_q_p - 1))
|
|
|
|
last_q_p.update_attribute('question_number', (@exercise_question.question_number.to_i + 1)) # 重新获取当前问题的位置
|
|
|
|
last_q_p.update_attribute('question_number', current_q_p) # 重新获取当前问题的位置
|
|
|
|
normal_status(0, "问题上移成功!")
|
|
|
|
normal_status(0, "问题上移成功!")
|
|
|
|
else
|
|
|
|
else
|
|
|
|
normal_status(-1, "移动失败,已经是第一个问题了!")
|
|
|
|
normal_status(-1, "移动失败,已经是第一个问题了!")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elsif opr.to_s == "down"
|
|
|
|
elsif opr.to_s == "down"
|
|
|
|
|
|
|
|
next_q_p = @exercise.exercise_questions.find_by(question_number: (current_q_p + 1)) # 当前问题的前一个问题
|
|
|
|
if next_q_p.present?
|
|
|
|
if next_q_p.present?
|
|
|
|
@exercise_question.update_attribute('question_number', (current_q_p + 1))
|
|
|
|
@exercise_question.update_attribute('question_number', (current_q_p + 1))
|
|
|
|
next_q_p.update_attribute('question_number', (@exercise_question.question_number.to_i - 1))
|
|
|
|
next_q_p.update_attribute('question_number', current_q_p)
|
|
|
|
normal_status(0, "问题下移成功!")
|
|
|
|
normal_status(0, "问题下移成功!")
|
|
|
|
else
|
|
|
|
else
|
|
|
|
normal_status(-1, "移动失败,已经是最后一个问题了!")
|
|
|
|
normal_status(-1, "移动失败,已经是最后一个问题了!")
|
|
|
|