From b73e55d1d87ec22558876640a8f6f0a9b417b3db Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 18 Apr 2019 09:30:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 8 +- app/models/exercise.rb | 20 ++++ app/models/exercise_level_setting.rb | 2 +- app/views/exercise/_edit_shixun.html.erb | 2 +- app/views/exercise/_exercise_content.html.erb | 16 +-- app/views/exercise/_new_question.html.erb | 2 +- app/views/exercise/_new_shixun.html.erb | 15 ++- app/views/exercise/_show_MC.html.erb | 2 +- app/views/exercise/_show_MCQ.html.erb | 2 +- app/views/exercise/_show_multi.html.erb | 2 +- app/views/exercise/_show_shixun.html.erb | 101 +++++++----------- app/views/exercise/_show_single.html.erb | 2 +- .../exercise/_total_questions_score.html.erb | 29 +++-- .../exercise/delete_shixun_question.js.erb | 2 + app/views/exercise/shixun_question.js.erb | 4 +- config/routes.rb | 1 + 16 files changed, 107 insertions(+), 103 deletions(-) create mode 100644 app/views/exercise/delete_shixun_question.js.erb diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 24bee1f8..a97f75f1 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] + :update_shixun_block, :delete_shixun_question] 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] + :choose_shixuns, :shixun_question, :update_shixun_block, :delete_shixun_question] before_filter :require_login, :only => [:student_exercise_list, :show] include ExerciseHelper include ApplicationHelper @@ -217,6 +217,10 @@ class ExerciseController < ApplicationController redirect_to edit_exercise_path(@exercise) end + def delete_shixun_question + @exercise.exercise_level_settings.destroy_all + end + def create if params[:exercise] exercise = Exercise.new diff --git a/app/models/exercise.rb b/app/models/exercise.rb index c5992382..af81e7e9 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -55,4 +55,24 @@ class Exercise < ActiveRecord::Base def level_setting level self.exercise_level_settings.where(level: level).first end + + def shixun_question_count + self.exercise_level_settings.sum(:num) + end + + def shixun_question_score + score = 0 + self.exercise_level_settings.each do |setting| + score += setting.num * setting.score.to_i + end + score + end + + def has_shixun_questions? + self.exercise_questions.where("question_type = 5 and exercise_level_setting_id != 0").count > 0 + end + + def exercise_question_size + self.exercise_questions.where("question_type != 5").count + self.shixun_question_count + end end diff --git a/app/models/exercise_level_setting.rb b/app/models/exercise_level_setting.rb index 3e687d8c..72ea225b 100644 --- a/app/models/exercise_level_setting.rb +++ b/app/models/exercise_level_setting.rb @@ -1,5 +1,5 @@ class ExerciseLevelSetting < ActiveRecord::Base belongs_to :exercise - has_many :exercise_questions + has_many :exercise_questions, :dependent => :destroy # attr_accessible :level, :num, :score end diff --git a/app/views/exercise/_edit_shixun.html.erb b/app/views/exercise/_edit_shixun.html.erb index 6a84fe17..ebd77574 100644 --- a/app/views/exercise/_edit_shixun.html.erb +++ b/app/views/exercise/_edit_shixun.html.erb @@ -28,7 +28,7 @@ - + diff --git a/app/views/exercise/_exercise_content.html.erb b/app/views/exercise/_exercise_content.html.erb index e9915c5b..2c1b2afd 100644 --- a/app/views/exercise/_exercise_content.html.erb +++ b/app/views/exercise/_exercise_content.html.erb @@ -29,13 +29,13 @@ - <% when 5 %> -
- <%= render :partial => 'show_shixun', :locals => {:exercise_question => eq} %> -
- <% end %> -<% end %> \ No newline at end of file +<% end %> + +
+ <%= render :partial => 'show_shixun' %> +
+ \ No newline at end of file diff --git a/app/views/exercise/_new_question.html.erb b/app/views/exercise/_new_question.html.erb index 739f0870..4c0e298f 100644 --- a/app/views/exercise/_new_question.html.erb +++ b/app/views/exercise/_new_question.html.erb @@ -6,7 +6,7 @@ + 多选题 + 填空题 + 简答题 -<% if @exercise.try(:id).nil? || @exercise.exercise_questions.where("question_type = 5 and exercise_level_setting_id != 0").count == 0 %> +<% if @exercise.try(:id).nil? || !@exercise.has_shixun_questions? %> + 实训题 <% end %> diff --git a/app/views/exercise/_new_shixun.html.erb b/app/views/exercise/_new_shixun.html.erb index 8e69004a..5bb0e405 100644 --- a/app/views/exercise/_new_shixun.html.erb +++ b/app/views/exercise/_new_shixun.html.erb @@ -1,8 +1,8 @@ -<% if exercise.id %> +<% if @exercise.id %>
<%= form_for('', :html => { :multipart => true, :id => "new_shixun_question"}, - :url=>update_shixun_block_exercise_path(exercise.id)) do |f| %> + :url=>update_shixun_block_exercise_path(@exercise.id)) do |f| %> @@ -44,7 +44,7 @@
<% end %> - - <% end %> \ No newline at end of file diff --git a/app/views/exercise/_show_single.html.erb b/app/views/exercise/_show_single.html.erb index 675ed49f..8c66c30c 100644 --- a/app/views/exercise/_show_single.html.erb +++ b/app/views/exercise/_show_single.html.erb @@ -3,7 +3,7 @@

第<%= exercise_question.question_number%>题:[填空题]<%= exercise_question.question_score %>

<% if @exercise.exercise_status == 1 %>

- <% if exercise_question.question_number < @exercise.exercise_questions.count %> + <% if exercise_question.question_number < @exercise.exercise_questions.where("question_type != 5").count %> <% end %> <% unless exercise_question.question_number == 1 %> diff --git a/app/views/exercise/_total_questions_score.html.erb b/app/views/exercise/_total_questions_score.html.erb index d812fad1..9a6b4e17 100644 --- a/app/views/exercise/_total_questions_score.html.erb +++ b/app/views/exercise/_total_questions_score.html.erb @@ -2,23 +2,30 @@

">

<% exercise_questions = @exercise.exercise_questions %> - <% if exercise_questions.select{|e| e.question_type==1}.count > 0 %> - 单选题 <%= exercise_questions.select{|e| e.question_type==1}.count %> 题,共 <%= current_score[1] %>  + <% mc_count = exercise_questions.select{|e| e.question_type==1}.count %> + <% mcq_count = exercise_questions.select{|e| e.question_type==2}.count %> + <% single_count = exercise_questions.select{|e| e.question_type==3}.count %> + <% multi_count = exercise_questions.select{|e| e.question_type==4}.count %> + + <% if mc_count > 0 %> + 单选题 <%= mc_count %> 题,共 <%= current_score[1] %>  <% end %> - <% if exercise_questions.select{|e| e.question_type==2}.count > 0 %> - 多选题 <%= exercise_questions.select{|e| e.question_type==2}.count %> 题,共 <%= current_score[2] %>  + <% if mcq_count > 0 %> + 多选题 <%= mcq_count %> 题,共 <%= current_score[2] %>  <% end %> - <% if exercise_questions.select{|e| e.question_type==3}.count > 0 %> - 填空题 <%= exercise_questions.select{|e| e.question_type==3}.count %> 题,共 <%= current_score[3] %>  + <% if single_count > 0 %> + 填空题 <%= single_count %> 题,共 <%= current_score[3] %>  <% end %> - <% if exercise_questions.select{|e| e.question_type==4}.count > 0 %> - 简答题 <%= exercise_questions.select{|e| e.question_type==4}.count %> 题,共 <%= current_score[4] %>  + <% if multi_count > 0 %> + 简答题 <%= multi_count %> 题,共 <%= current_score[4] %>  <% end %> - <% if exercise_questions.select{|e| e.question_type==5}.count > 0 %> - 实训题 <%= exercise_questions.select{|e| e.question_type==5}.count %> 题,共 <%= current_score[5] %>  + <% if @exercise.shixun_question_count > 0 %> + 实训题 <%= @exercise.shixun_question_count %> 题,共 <%= @exercise.shixun_question_score %>  <% end %>

- 合计 <%= @exercise.exercise_questions.size %> 题,共 <%= current_score[0] %>  + <% count = mc_count + mcq_count + single_count + multi_count + @exercise.shixun_question_count %> + <% score = current_score[1] + current_score[2] + current_score[3] + current_score[4] + @exercise.shixun_question_score %> + 合计 <%= count %> 题,共 <%= score %> 
\ 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 new file mode 100644 index 00000000..0f8f4678 --- /dev/null +++ b/app/views/exercise/delete_shixun_question.js.erb @@ -0,0 +1,2 @@ +$("#exercise_question_list").html("<%= escape_javascript(render :partial => 'exercise/exercise_content') %>"); +$("#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 52d03e55..616258c6 100644 --- a/app/views/exercise/shixun_question.js.erb +++ b/app/views/exercise/shixun_question.js.erb @@ -1,6 +1,6 @@ -<% if @exercise.exercise_questions.where("question_type = 5 and exercise_level_setting_id != 0").count > 0 %> +<% 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', :locals => {:exercise=>@exercise}) %>"); +$("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_shixun') %>"); <% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 6043af76..194478f4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1049,6 +1049,7 @@ RedmineApp::Application.routes.draw do ## oauth相关 get 'cancel_commit_confirm' get 'adjust_question_score' post 'update_shixun_block' + get 'delete_shixun_question' end collection do #生成路径为 /exercise/方法名