diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index a97f75f1..ba707e67 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -9,11 +9,11 @@ class ExerciseController < ApplicationController :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, - :update_shixun_block, :delete_shixun_question] + :update_shixun_block, :delete_shixun_question, :delete_choose_shixun] 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, - :choose_shixuns, :shixun_question, :update_shixun_block, :delete_shixun_question] + :choose_shixuns, :shixun_question, :update_shixun_block, :delete_shixun_question, :delete_choose_shixun] before_filter :require_login, :only => [:student_exercise_list, :show] include ExerciseHelper include ApplicationHelper @@ -76,12 +76,12 @@ class ExerciseController < ApplicationController if @exercise_user.nil? @exercise_user = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false, :commit_status => 0) if @exercise.exercise_level_settings.where("num != exercise_questions_count").count > 0 - @exercise.create_user_question_list(@exercise_user) + @exercise.create_user_question_list(@exercise_user.id) end # @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first elsif @exercise_user.start_at.nil? if @exercise.exercise_level_settings.where("num != exercise_questions_count").count > 0 - @exercise.create_user_question_list(@exercise_user) + @exercise.create_user_question_list(@exercise_user.id) end @exercise_user.update_attributes(:start_at => Time.now) end @@ -112,7 +112,7 @@ class ExerciseController < ApplicationController @can_edit_excercise = false end - @exercise_questions = user_question_list @exercise_user.id + @exercise_questions = @exercise.user_question_list @exercise_user.id # @percent = get_percent(@exercise,User.current) #@exercise_questions = @exercise.exercise_questions @@ -221,6 +221,10 @@ class ExerciseController < ApplicationController @exercise.exercise_level_settings.destroy_all end + def delete_choose_shixun + @exercise.exercise_questions.where(question_type: 5, exercise_level_setting_id: 0).destroy_all + end + def create if params[:exercise] exercise = Exercise.new @@ -1315,7 +1319,7 @@ class ExerciseController < ApplicationController if @is_teacher || (User.current.member_of_course?(@exercise.course) && @exercise.exercise_status > 2) @user = User.find params[:user_id] @exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", @user.id, @exercise.id).first - @exercise_questions = @exercise.user_question_list @exercise_user.id + @exercise_questions = (@exercise.user_question_list @exercise_user.id).reorder("question_number = 0 asc, question_number asc") respond_to do |format| if params[:pdf] format.html { render :layout => "pdf" } diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index ea5eae8f..28ebf46f 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -314,7 +314,7 @@ module ExerciseHelper all_questions = questions.where("question_type = 5") uncomplete_shixun = [] all_questions.each do |question| - myshixun = Myshixun.where(:shixun_id => question.shixun_id, :user_id => user.id).first + myshixun = Myshixun.where(:shixun_id => question.shixun_id, :user_id => exercise_user.user_id).first unless myshixun && myshixun.is_complete? uncomplete_shixun << question end diff --git a/app/models/exercise.rb b/app/models/exercise.rb index af81e7e9..f0343311 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -31,14 +31,12 @@ class Exercise < ActiveRecord::Base def create_user_question_list exercise_user_id self.exercise_questions.where("question_type != 5").each do |question| - self.exercise_user_questions << ExerciseUserQuestion.new(exercise_user_id: exercise_user_id, - exercise_question_id: question) + ExerciseUserQuestion.create(exercise_id: self.id, exercise_user_id: exercise_user_id, exercise_question_id: question.id) end self.exercise_level_settings.each do |setting| # 每个级别中随机挑选num个实训题 setting.exercise_questions.pluck(:id).sample(setting.num).each do |question_id| - self.exercise_user_questions << ExerciseUserQuestion.new(exercise_user_id: exercise_user_id, - exercise_question_id: question_id) + ExerciseUserQuestion.create(exercise_id: self.id, exercise_user_id: exercise_user_id, exercise_question_id: question_id) end end end diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index 63d9cdf9..e7e34146 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -6,11 +6,11 @@ class ExerciseQuestion < ActiveRecord::Base belongs_to :exercise belongs_to :shixun has_many :exercise_shixun_challenges, :order => "#{ExerciseShixunChallenge.table_name}.position",:dependent => :destroy - has_many :exercise_shixun_answers, :dependent => :destroy + has_many :exercise_shixun_answers has_many :exercise_choices, :dependent => :destroy - has_many :exercise_answers, :dependent => :destroy - has_many :exercise_answer_comments, :dependent => :destroy - has_many :exercise_standard_answers, :dependent => :destroy + has_many :exercise_answers + has_many :exercise_answer_comments + has_many :exercise_standard_answers belongs_to :exercise_level_setting, counter_cache: true has_many :exercise_user_questions, :dependent => :destroy @@ -29,4 +29,12 @@ class ExerciseQuestion < ActiveRecord::Base "实训题" end end + + def ques_number index + question_number = self.question_number + if self.question_type == 5 + question_number = exercise.exercise_questions.where("question_type != 5").count + index + end + question_number + end end diff --git a/app/models/exercise_shixun_answer.rb b/app/models/exercise_shixun_answer.rb index b5962dd1..984be1c0 100644 --- a/app/models/exercise_shixun_answer.rb +++ b/app/models/exercise_shixun_answer.rb @@ -2,7 +2,7 @@ class ExerciseShixunAnswer < ActiveRecord::Base belongs_to :exercise_question belongs_to :user belongs_to :exercise_shixun_challenge - has_many :exercise_answer_comments, :dependent => :destroy + has_many :exercise_answer_comments # status 0: 未通过, 1:通过 # attr_accessible :answer_text, :score, :status end diff --git a/app/views/exercise/_exercise_student.html.erb b/app/views/exercise/_exercise_student.html.erb index 5d12c301..a61d745c 100644 --- a/app/views/exercise/_exercise_student.html.erb +++ b/app/views/exercise/_exercise_student.html.erb @@ -161,9 +161,9 @@

<% end %> - <% if exercise_question.question_type == 5 %> -

<%= exercise_question.shixun.name %>

- <% end %> + <%# if exercise_question.question_type == 5 %> + + <%# end %>
<%= sanitize exercise_question.question_title %>
<% case exercise_question.question_type %> <% when 1 %> diff --git a/app/views/exercise/_exercise_student_result.html.erb b/app/views/exercise/_exercise_student_result.html.erb index 8c1de5ea..66396c35 100644 --- a/app/views/exercise/_exercise_student_result.html.erb +++ b/app/views/exercise/_exercise_student_result.html.erb @@ -76,9 +76,10 @@

- <% exercise_questions.where(:question_type => [1, 2, 3, 5]).each do |eq| %> + <% que_count = exercise_questions.where(:question_type => [1, 2, 3]).count %> + <% exercise_questions.where(:question_type => [1, 2, 3, 5]).each_with_index do |eq, index| %> <% is_correct = answer_is_correct(eq, user) %> - <%= eq.question_number %> + <%= eq.ques_number(index-que_count + 1) %> <% end %>
@@ -90,16 +91,16 @@
<% exercise_questions.where(:question_type => 4).each do |eq| %> <% ea = @exercise_user.user.exercise_answer.where(:exercise_question_id => eq.id).first %> - <%= eq.question_number %> + <%= eq.question_number %> <% end %>
<% question_list = exercise_questions.includes(:exercise_shixun_answers, :exercise_choices => [:exercise_answers]) %> - <% question_list.each do |exercise_question| %> + <% question_list.each_with_index do |exercise_question, index| %>
-

第<%= exercise_question.question_number %> +

第<%= index + 1 %> 题:[<%= exercise_question.question_type_name %> ]<%= exercise_question.question_score %> 分<%= question_commit_status exercise_question, @exercise_user.user %> diff --git a/app/views/exercise/_new_shixun.html.erb b/app/views/exercise/_new_shixun.html.erb index 5bb0e405..e4e26db9 100644 --- a/app/views/exercise/_new_shixun.html.erb +++ b/app/views/exercise/_new_shixun.html.erb @@ -1,5 +1,5 @@ <% if @exercise.id %> -

+
<%= form_for('', :html => { :multipart => true, :id => "new_shixun_question"}, :url=>update_shixun_block_exercise_path(@exercise.id)) do |f| %> @@ -41,7 +41,7 @@
实训题
-
    +
      <% for i in 1..4 %> <% questions_list = @exercise.exercise_questions.where(question_type: 5, level: i) %> @@ -98,8 +98,8 @@
    • - 保存 - 取消 + 保存 + 取消 温馨提示:[实训题]属于客观题将由系统自动评分 @@ -114,13 +114,14 @@ diff --git a/app/views/exercise/_show_shixun.html.erb b/app/views/exercise/_show_shixun.html.erb index f42f2da5..eb014d99 100644 --- a/app/views/exercise/_show_shixun.html.erb +++ b/app/views/exercise/_show_shixun.html.erb @@ -1,5 +1,6 @@ -

      -
      +<% if false %> + + <%# if @exercise.exercise_status == 1 %> @@ -26,6 +27,7 @@ <%# end %> +<% end %>
      @@ -34,7 +36,7 @@ <% if @exercise.exercise_status == 1 %> - + <% end %> @@ -75,12 +77,17 @@
      -
      -
      + + \ No newline at end of file diff --git a/app/views/exercise/delete_choose_shixun.js.erb b/app/views/exercise/delete_choose_shixun.js.erb new file mode 100644 index 00000000..7ee59a3a --- /dev/null +++ b/app/views/exercise/delete_choose_shixun.js.erb @@ -0,0 +1,2 @@ +$("#exercise_question_list").html("<%= escape_javascript(render :partial => 'exercise/exercise_content') %>"); +$("#shixun_question_block").remove(); \ No newline at end of file diff --git a/app/views/exercise/delete_shixun_question.js.erb b/app/views/exercise/delete_shixun_question.js.erb index 0f8f4678..c431c710 100644 --- a/app/views/exercise/delete_shixun_question.js.erb +++ b/app/views/exercise/delete_shixun_question.js.erb @@ -1,2 +1,3 @@ $("#exercise_question_list").html("<%= escape_javascript(render :partial => 'exercise/exercise_content') %>"); +$("#new_exercise_question").html('<%= escape_javascript(render :partial => 'new_question') %>'); $("#total_questions_score").html("<%= escape_javascript(render :partial => 'exercise/total_questions_score') %>"); \ No newline at end of file diff --git a/app/views/exercise/shixun_question.js.erb b/app/views/exercise/shixun_question.js.erb index 616258c6..17cbea4e 100644 --- a/app/views/exercise/shixun_question.js.erb +++ b/app/views/exercise/shixun_question.js.erb @@ -1,6 +1,2 @@ -<% if @exercise.has_shixun_questions? %> -$("#insert_new_poll_question_<%= params[:quest_id] %>").html("<%= escape_javascript(render :partial => 'new_shixun', :locals => {:exercise=>@exercise}) %>"); -$("#quest_id").val(<%= params[:quest_id] %>); -<% else %> -$("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_shixun') %>"); -<% end %> \ No newline at end of file +$("#show_shixun_questions").hide(); +$("#edit_shixun_questions").html("<%= escape_javascript(render :partial => 'new_shixun') %>").show(); \ No newline at end of file diff --git a/app/views/exercise/student_exercise_list.html.erb b/app/views/exercise/student_exercise_list.html.erb index d47db23a..676e0903 100644 --- a/app/views/exercise/student_exercise_list.html.erb +++ b/app/views/exercise/student_exercise_list.html.erb @@ -243,7 +243,7 @@
- <% @exercise.exercise_questions.includes(:exercise_choices, :exercise_standard_answers, exercise_shixun_challenges: :challenge).each_with_index do |exercise_question, i| %> + <% @exercise.exercise_questions.where("question_type != 5").includes(:exercise_choices, :exercise_standard_answers, exercise_shixun_challenges: :challenge).each_with_index do |exercise_question, i| %>

第<%= exercise_question.question_number %> @@ -328,19 +328,59 @@ });

- <% when 5 %> -
- <% exercise_question.exercise_shixun_challenges.each_with_index do |exercise_challenge, index| %> -
- 第<%= index + 1 %>关 - <%= exercise_challenge.challenge.subject %> - <%= exercise_challenge.question_score %>分 -
- <% end %> -
+ <%# when 5 %> + + <%# exercise_question.exercise_shixun_challenges.each_with_index do |exercise_challenge, index| %> + + + + + + <%# end %> + <% end %>
<% end %> + +
+ +
+ [实训题](<%= @exercise.shixun_question_score %>分) +
+ +
    + <% for i in 1..4 %> + <% questions_list = @exercise.exercise_questions.where(question_type: 5, level: i) %> + +
  • +
    + + <%= shixun_question_level i %> + +
    + 分值:<%= @exercise.level_setting(i).try(:score) %> 分/题 +
    + +
    + 随机出题量:<%= @exercise.level_setting(i).try(:num) || questions_list.try(:count) %> +
    +
    + +
    + <% questions_list.each_with_index do |question| %> +
    + <%= question.question_title %> + + + 实训详情 + +
    + <% end %> +
    +
  • + <% end %> +
+
+
diff --git a/config/routes.rb b/config/routes.rb index 194478f4..1306f774 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1049,7 +1049,8 @@ RedmineApp::Application.routes.draw do ## oauth相关 get 'cancel_commit_confirm' get 'adjust_question_score' post 'update_shixun_block' - get 'delete_shixun_question' + delete 'delete_shixun_question' + delete 'delete_choose_shixun' end collection do #生成路径为 /exercise/方法名 diff --git a/public/javascripts/edu/course.js b/public/javascripts/edu/course.js index b377643a..3428011b 100644 --- a/public/javascripts/edu/course.js +++ b/public/javascripts/edu/course.js @@ -1716,7 +1716,7 @@ function copy_course(url){ pop_box_new(htmlvalue, 550, 300); } -function new_shixun_exercise(id){ +function new_shixun_exercise(){ if($("input[name='shixun_exercise[]']:checked").length == 0){ $("#exercise_type_notice").show(); } else{