diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 18248331c..69e8ebd80 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -374,7 +374,7 @@ class ExerciseController < ApplicationController ea.answer_text = params[:answer_text] if ea.save @percent = get_percent(@exercise,User.current) - render :json => {:text => pv.vote_text,:percent => format("%.2f",@percent)} + render :json => {:text => ea.answer_text,:percent => format("%.2f",@percent)} else render :json => {:text => "failure"} end @@ -416,13 +416,13 @@ class ExerciseController < ApplicationController # 答题过程中需要统计完成量 @uncomplete_question = get_uncomplete_question(@exercise, User.current) # 获取改学生的考试得分 - score = calculate_student_score(@exercise, User.current) + @score = calculate_student_score(@exercise, User.current) if @uncomplete_question.count < 1 # 查看是否有已提交记录 eu = get_exercise_user(@exercise.id, User.current.id) eu.user_id = User.current.id eu.exercise_id = @exercise.id - eu.score = score + eu.score = @score if eu.save #redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course') @status = 0 #提交成功 diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index 7f3d1862e..5b28234e8 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -72,4 +72,23 @@ module ExerciseHelper return score end + def answer_be_selected?(answer,user) + pv = answer.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id} ") + if !pv.nil? && pv.count > 0 + true + else + false + end + end + + #获取文本题答案 + def get_anwser_vote_text(question_id,user_id) + pv = ExerciseAnswer.find_by_exercise_question_id_and_user_id(question_id,user_id) + if pv.nil? + '' + else + pv.answer_text + end + end + end \ No newline at end of file diff --git a/app/views/exercise/_commit_alert.html.erb b/app/views/exercise/_commit_alert.html.erb new file mode 100644 index 000000000..d92ca51fb --- /dev/null +++ b/app/views/exercise/_commit_alert.html.erb @@ -0,0 +1,12 @@ +
+ <% if status == 0 %> +

提交成功!您的分数是:<%=@score %>分。

+ <%= link_to "确定", exercise_path(),:class => 'commit'%> + <% elsif status == 1 %> +

您还有尚未作答的题目请完成后再提交!

+ <%= link_to "确定", "javascript:void(0)",:onclick => 'hidden_atert_form();',:class => 'commit'%> + <% else %> +

发生未知错误,请检查您的网络。

+ <%= link_to "确定", "javascript:void(0)",:onclick => 'hidden_atert_form();',:class => 'commit'%> + <% end %> +
diff --git a/app/views/exercise/_exercise_student.html.erb b/app/views/exercise/_exercise_student.html.erb index 5a139fd5d..0cc34958f 100644 --- a/app/views/exercise/_exercise_student.html.erb +++ b/app/views/exercise/_exercise_student.html.erb @@ -4,33 +4,15 @@ $("#homework_page_right").css("min-height",$("#LSide").height()-30); $("#Container").css("width","1000px"); }); - function click_<%= pa.id %>(obj) - { - $.ajax({ - type: "post", - url: "<%= commit_answer_poll_path(@poll) %>", - data: { - poll_answer_id: <%= pa.id %>, - poll_question_id: <%= pq.id %> - }, - success: function (data) { - var dataObj = eval(data); - obj.checked = true; - var span = $('#percent'); - span.html(dataObj.percent); - } - }); - } - function student_submit_exercise(){ - - }

<%= exercise.exercise_name%>

-
开始时间:<%=format_time(exercise_student.start_at.to_s) %>测验时长:<%=exercise.time %>分钟 -
剩余时长:1 小时 30 分钟 0 秒
+
+ 开始时间:<%=format_time(exercise_user.start_at.to_s) %> + 测验时长:<%=exercise.time %>分钟 + 剩余时长:1 小时 30 分钟 0 秒
<%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%>
@@ -56,7 +38,31 @@ @@ -87,7 +93,31 @@ @@ -112,14 +142,35 @@
- + + >
<% end %> -
提交
+
+ <%= link_to l(:button_submit),commit_exercise_exercise_path(exercise), :method => :post,:class => "ur_button_submit",:style => "margin-left:80px;",:format => 'js',:remote=>true %> +
diff --git a/app/views/exercise/_exercise_student_result.html.erb b/app/views/exercise/_exercise_student_result.html.erb new file mode 100644 index 000000000..40f9b953b --- /dev/null +++ b/app/views/exercise/_exercise_student_result.html.erb @@ -0,0 +1,135 @@ + +
+
+
+

<%= exercise.exercise_name%>

+
+ 开始时间:<%=format_time(exercise_user.start_at.to_s) %> + 测验时长:<%=exercise.time %>分钟 + <% time = exercise_user.end_at - exercise_user.start_at %> + 测验用时:<%= (time % (24*60*60)) / (60*60)%> 小时 <%= ((time % (24*60*60)) % (60*60)) / 60%> 分钟 <%= ((time % (24*60*60)) % (60*60)) % 60%> 秒 +
+
<%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%>
+
+
+
得分:<%=exercise_user.score %>分
+ <% mc_question_list = exercise_questions.where("question_type=1") %> + <% mcq_question_list = exercise_questions.where("question_type=2") %> + <% single_question_list = exercise_questions.where("question_type=3") %> +
"> +

单选题

+ <% mc_question_list.each do |exercise_question| %> +
+
+
+
第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
+ <%= exercise_question.question_title %> + + <% if exercise_question.exercise_standard_answers.first.exercise_choice_id == exercise_question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{User.current.id}.first.exercise_choice_id ") %> + √ + <% else %> + × + <% end %>
+ 标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %> +
+
+
+ + + <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> + + + + <% end %> + +
+ +
+
+
+
+
+ <% end %> +
+
"> +

多选题

+ <% mcq_question_list.each do |exercise_question| %> +
+
+
+
第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
+ <%= exercise_question.question_title %> + + <% if exercise_question.exercise_standard_answers.first.exercise_choice_id == exercise_question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{User.current.id}.first.exercise_choice_id ") %> + √ + <% else %> + × + <% end %>
+ 标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %> +
+
+
+ + + <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> + + + + <% end %> + +
+ +
+
+
+
+
+ <% end %> +
+
"> +

填空题

+ <% single_question_list.each do |exercise_question| %> +
+
+
+
第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
+ <%= exercise_question.question_title %> + + <% if exercise_question.exercise_standard_answers.first.exercise_choice_id == exercise_question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{User.current.id}.first.exercise_choice_id ") %> + √ + <% else %> + × + <% end %>
+ 标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %> +
+
+
+ <% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %> + 候选答案:<%= exercise_choice.answer_text%>
+ <% end %> +
+
+ > +
+
+
+
+ <% end %> +
+
+ +
+ +
\ No newline at end of file diff --git a/app/views/exercise/_exercise_submit.html.erb b/app/views/exercise/_exercise_submit.html.erb index e242eacc7..a8892b27e 100644 --- a/app/views/exercise/_exercise_submit.html.erb +++ b/app/views/exercise/_exercise_submit.html.erb @@ -1,7 +1,8 @@ <%= form_for("", :html => { :multipart => true }, :url => {:controller => 'exercise', - :action => 'commit_exercise' + :action => 'commit_exercise', + :id => exercise.id },:remote=>true ) do |f| %>
提交 diff --git a/app/views/exercise/_exercise_teacher.html.erb b/app/views/exercise/_exercise_teacher.html.erb new file mode 100644 index 000000000..18f62e403 --- /dev/null +++ b/app/views/exercise/_exercise_teacher.html.erb @@ -0,0 +1,117 @@ + +
+
+
+

<%= exercise.exercise_name%>

+
+ 发布时间:<%=format_time(exercise.publish_time.to_s) %> + 截止时间:<%=format_time(exercise.end_time.to_s) %> + <% time = exercise_user.end_at - exercise_user.start_at %> + 测验时长:<%=exercise.time %>分钟 +
+
<%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%>
+
+
+ <% mc_question_list = exercise_questions.where("question_type=1") %> + <% mcq_question_list = exercise_questions.where("question_type=2") %> + <% single_question_list = exercise_questions.where("question_type=3") %> +
"> +

单选题

+ <% mc_question_list.each do |exercise_question| %> +
+
+
+
第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
+ <%= exercise_question.question_title %>
+ 标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %> +
+
+
+ + + <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> + + + + <% end %> + +
+ +
+
+
+
+
+ <% end %> +
+
"> +

多选题

+ <% mcq_question_list.each do |exercise_question| %> +
+
+
+
第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
+ <%= exercise_question.question_title %>
+ 标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %> +
+
+
+ + + <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> + + + + <% end %> + +
+ +
+
+
+
+
+ <% end %> +
+
"> +

填空题

+ <% single_question_list.each do |exercise_question| %> +
+
+
+
第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
+ <%= exercise_question.question_title %>
+ 标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %> +
+
+
+ <% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %> + 候选答案:<%= exercise_choice.answer_text%>
+ <% end %> +
+
+
+
+ <% end %> +
+
+ <%= link_to l(:button_submit),exercise_index_path(:course_id => @course.id),:class => "ur_button_submit" %> + <%= link_to l(:button_edit), edit_exercise_path(exercise.id), :class => "ur_button_submit fr"%> +
+
+ +
+ +
\ No newline at end of file diff --git a/app/views/exercise/_new_MC.html.erb b/app/views/exercise/_new_MC.html.erb index 3da0021ce..0b9543009 100644 --- a/app/views/exercise/_new_MC.html.erb +++ b/app/views/exercise/_new_MC.html.erb @@ -1,9 +1,7 @@ <%= form_for(ExerciseQuestion.new, :html => { :multipart => true }, - :url => {:controller => 'exercise', - :action => 'create_exercise_question', - :course_id => @course.id - },:remote=>true ) do |f| %> + :url=>create_exercise_question_exercise_path(exercise_question.id), + :remote=>true ) do |f| %>
diff --git a/app/views/exercise/_new_MCQ.html.erb b/app/views/exercise/_new_MCQ.html.erb index 044ecd629..2f1f28395 100644 --- a/app/views/exercise/_new_MCQ.html.erb +++ b/app/views/exercise/_new_MCQ.html.erb @@ -1,9 +1,7 @@ <%= form_for(ExerciseQuestion.new, :html => { :multipart => true }, - :url => {:controller => 'exercise', - :action => 'create_exercise_question', - :course_id => @course.id - },:remote=>true ) do |f| %> + :url=>create_exercise_question_exercise_path(exercise_question.id), + :remote=>true ) do |f| %>
diff --git a/app/views/exercise/_new_single.html.erb b/app/views/exercise/_new_single.html.erb index 6e088cd74..ec52fbcad 100644 --- a/app/views/exercise/_new_single.html.erb +++ b/app/views/exercise/_new_single.html.erb @@ -1,9 +1,7 @@ <%= form_for(ExerciseQuestion.new, :html => { :multipart => true }, - :url => {:controller => 'exercise', - :action => 'create_exercise_question', - :course_id => @course.id - },:remote=>true ) do |f| %> + :url=>create_exercise_question_exercise_path(exercise_question.id), + :remote=>true ) do |f| %>
diff --git a/app/views/exercise/_show_MC.html.erb b/app/views/exercise/_show_MC.html.erb index 21d6ef4bb..0883995dc 100644 --- a/app/views/exercise/_show_MC.html.erb +++ b/app/views/exercise/_show_MC.html.erb @@ -39,7 +39,7 @@ } else{ <% score =exercise_question.question_score %> $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( - '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>{:controller=> 'exercise',:action=>'create_exercise_question',:course_id=>@course.id},:remote=>true) do |f|%>'+ + '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>create_exercise_question_exercise_path(exercise_question.id),:remote=>true) do |f|%>'+ '
'+ '
'+ ''+ diff --git a/app/views/exercise/_show_MCQ.html.erb b/app/views/exercise/_show_MCQ.html.erb index a6ffbeb82..52f01e6c7 100644 --- a/app/views/exercise/_show_MCQ.html.erb +++ b/app/views/exercise/_show_MCQ.html.erb @@ -38,7 +38,7 @@ } else { <% score =exercise_question.question_score %> $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( - '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>{:controller=> 'exercise',:action=>'create_exercise_question',:course_id=>@course.id},:remote=>true) do |f|%>'+ + '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>create_exercise_question_exercise_path(exercise_question.id),:remote=>true) do |f|%>'+ '
'+ '
'+ ''+ diff --git a/app/views/exercise/_show_single.html.erb b/app/views/exercise/_show_single.html.erb index 30a0e354c..933f2edcc 100644 --- a/app/views/exercise/_show_single.html.erb +++ b/app/views/exercise/_show_single.html.erb @@ -26,7 +26,7 @@ } else { <% score =exercise_question.question_score %> $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( - '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>{:controller=> 'exercise',:action=>'create_exercise_question',:course_id=>@course.id},:remote=>true) do |f|%>'+ + '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>create_exercise_question_exercise_path(exercise_question.id),:remote=>true) do |f|%>'+ '
'+ '
'+ ''+ diff --git a/app/views/exercise/commit_exercise.js.erb b/app/views/exercise/commit_exercise.js.erb new file mode 100644 index 000000000..2a40df2a5 --- /dev/null +++ b/app/views/exercise/commit_exercise.js.erb @@ -0,0 +1,9 @@ +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'commit_alert',:locals => {:status => @status}) %>'); +showModal('ajax-modal', '270px'); +$('#ajax-modal').css('height','110px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before("" + + ""); +$('#ajax-modal').parent().removeClass("alert_praise"); +$('#ajax-modal').parent().css("top","").css("left",""); +$('#ajax-modal').parent().addClass("alert_box"); \ No newline at end of file diff --git a/app/views/exercise/show.html.erb b/app/views/exercise/show.html.erb index 6638020d1..cee9b084c 100644 --- a/app/views/exercise/show.html.erb +++ b/app/views/exercise/show.html.erb @@ -1,5 +1,9 @@ <% if @is_teacher %> - + <%= render :partial => 'exercise_teacher', :locals =>{:exercise =>@exercise, :exercise_questions => @exercise_questions} %> <% else %> - <%=render :partial => 'exercise_student', :locals => {:exercise =>@exercise, :exercise_questions => @exercise_questions,:exercise_student => @exercise_student} %> + <% if @can_edit_excercise %> + <%=render :partial => 'exercise_student', :locals => {:exercise =>@exercise, :exercise_questions => @exercise_questions,:exercise_user => @exercise_user} %> + <% else %> + <%=render :partial => 'exercise_student_result', :locals => {:exercise =>@exercise, :exercise_questions => @exercise_questions,:exercise_user => @exercise_user} %> + <% end %> <% end %> \ No newline at end of file diff --git a/app/views/exercise/update_exercise_question.js.erb b/app/views/exercise/update_exercise_question.js.erb index 73aea3140..ef9004c06 100644 --- a/app/views/exercise/update_exercise_question.js.erb +++ b/app/views/exercise/update_exercise_question.js.erb @@ -17,4 +17,4 @@ $("#poll_questions_<%= @exercise_question.id%>").html("
{:exercise => @exercise}) %>"); +$("#exercise_submit").html("<%= escape_javascript(render :partial => 'exercise_submit', :locals => {:exercise => @exercise_question.exercise}) %>");