diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index ec89b9bc2..02a8400a7 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -374,12 +374,13 @@ class ExerciseController < ApplicationController =end @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? @all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc") - @exercise_count = @exercise.exercise_users.where('score is not NULL').count - if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time <= Time.now) - @exercise_users_list = @exercise.exercise_users.where('score is not NULL') + student_id = @course.student.blank? ? "(-1)" : "(" + @course.student.map{|student| student.student_id}.join(",") + ")" + @exercise_count = @exercise.exercise_users.where("score is not NULL and user_id in #{student_id}").count + if @is_teacher || (!@exercise.exercise_users.where("user_id = #{User.current.id} and user_id in #{student_id}").empty? && @exercise.end_time <= Time.now) + @exercise_users_list = @exercise.exercise_users.where("score is not NULL and user_id in #{student_id}") @show_all = true; - elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time > Time.now - @exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id) + elsif !@exercise.exercise_users.where("user_id = #{User.current.id} and user_id in #{student_id}").empty? && @exercise.end_time > Time.now + @exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL and user_id in #{student_id}",User.current.id) else @exercise_users_list = [] end @@ -537,7 +538,7 @@ class ExerciseController < ApplicationController else # 更新提交状态 cur_exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", User.current, @exercise.id).first - cur_exercise_user.update_attributes(:status => 1) + cur_exercise_user.update_attributes(:status => 1, :commit_status => 1) # 答题过程中需要统计完成量 @uncomplete_question = get_uncomplete_question(@exercise, User.current) # 获取改学生的考试得分 diff --git a/app/models/exercise_user.rb b/app/models/exercise_user.rb index 2d5da5d95..c675f35a3 100644 --- a/app/models/exercise_user.rb +++ b/app/models/exercise_user.rb @@ -1,4 +1,5 @@ class ExerciseUser < ActiveRecord::Base + #commit_status 0:未交 1:已交 include Redmine::SafeAttributes belongs_to :user diff --git a/app/views/exercise/_exercise.html.erb b/app/views/exercise/_exercise.html.erb index 7a871591e..fbad24aed 100644 --- a/app/views/exercise/_exercise.html.erb +++ b/app/views/exercise/_exercise.html.erb @@ -3,13 +3,8 @@ <% if @is_teacher%>
-
- <%# if has_commit %> - <%#= link_to poll_name, poll_result_poll_path(poll.id), :class => "polls_title polls_title_w fl c_dblue"%> - <%# else %> - <%#= link_to poll_name, exercise_path(poll.id), :class => "polls_title polls_title_w fl c_dblue" %> - <%# end %> - <%= link_to (index.to_i+1).to_s+". "+exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_w fl c_dblue" %> +
+ <%= link_to (index.to_i+1).to_s+". "+exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_w fl c_dblue mw450", :title => "#{exercise_name}" %> <% if exercise.exercise_status == 1 %> <% elsif exercise.exercise_status == 2 %> @@ -20,19 +15,9 @@
- <%# if exercise.exercise_status == 2 %> - - <%# else %> - - <%# end%> - - <%# if exercise.exercise_status == 1%> - - <%# elsif exercise.exercise_status == 2 || exercise.exercise_status == 3 %> - - <%# end%> <% if exercise.exercise_status == 1 %> -
发布试卷
+ <% end_time_status = exercise.end_time.nil? ? 1 : (exercise.end_time <= Time.now ? 2 : 3) %> +
发布试卷
<% elsif exercise.exercise_status == 2%>
取消发布
<% else%> @@ -51,15 +36,15 @@ 测试时长:<%= exercise.time.nil? || exercise.time == -1 ? '不限' : exercise.time.to_s + "分钟" %> 截止时间:<%= exercise.end_time.nil? ? '未设置' : format_time(exercise.end_time) %> 发布时间:<%= exercise.publish_time.nil? ? '未设置' : format_time(exercise.publish_time) %> - <% if exercise.exercise_status > 2 %> - 已提交:<%= exercise.exercise_users.where("created_at >= #{exercise.end_time.to_i}").count %> - 未提交:<%= exercise.course.student.count - exercise.exercise_users.where("created_at >= #{exercise.end_time.to_i}").count %> + <% if @is_teacher && exercise.exercise_status > 2 %> + 已提交:<%= exercise.exercise_users.where("commit_status = 1").count %> + 未提交:<%= exercise.course.student.count - exercise.exercise_users.where("commit_status = 1").count %> <% end %>
- + <% if exercise.exercise_status == 1 %> - <%= link_to '', edit_exercise_path(exercise.id), :class => "ex_icon_edit mt0"%> + <%= link_to '', edit_exercise_path(exercise.id), :title => "编辑试卷", :class => "ex_icon_edit mt0"%> <% end%>
@@ -67,31 +52,50 @@ <% else%> <% if exercise.exercise_status != 1%> - <%# if has_commit%> - - <%#else%> - <%= link_to (index.to_i+1).to_s+". "+exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_st fl c_dblue"%> <% eu = ExerciseUser.where("exercise_id=? and user_id=? and status=?",exercise.id, User.current.id, true).first %> - <% if exercise.end_time <= Time.now && eu && exercise.end_time >= eu.created_at %> -
  • 已答
  • - <% end %> - <%#end%> +
    + <%= link_to (index.to_i+1).to_s+". "+exercise_name, exercise_path(exercise.id), :title => "#{exercise_name}", :class => "polls_title polls_title_st fl c_dblue "%> + <% if exercise.exercise_status == 1 %> + + <% elsif exercise.exercise_status == 2 %> + + <% else %> + + <% end%> + <% if eu && exercise.end_time >= eu.created_at %> + + <% else %> + + <% end %> +
    +
    +
    + 测试时长:<%= exercise.time.nil? || exercise.time == -1 ? '不限' : exercise.time.to_s + "分钟" %> + 截止时间:<%= exercise.end_time.nil? ? '未设置' : format_time(exercise.end_time) %> + 发布时间:<%= exercise.publish_time.nil? ? '未设置' : format_time(exercise.publish_time) %> + + <% exercise_end = exercise.end_time > Time.now + if exercise.time == -1 || exercise.time.nil? + can_edit_excercise = exercise_end + else + can_edit_excercise = !has_commit_exercise?(exercise.id,User.current.id)&& exercise_end + end%> + <% if can_edit_excercise && eu %> + 继续答题 + <% elsif can_edit_excercise %> + 开始答题 + <% else %> + 查看答题 + <% end %> + <% if exercise.show_result == 1 %> + <% if exercise.end_time <= Time.now %> + <%= link_to l(:label_statistical_results), student_exercise_list_exercise_path(exercise.id,:course_id => @course.id), :class => "pollsbtn fr mr10"%> + <% else %> +
    统计结果
    + <%end%> + <% end %> +
    +
    <% end%> -
  • 截止时间:<%= format_time(exercise.end_time.to_s)%>
  • - <% if exercise.show_result == 1 %> - <% if exercise.end_time <= Time.now %> -
  • <%= link_to l(:label_statistical_results), student_exercise_list_exercise_path(exercise.id,:course_id => @course.id), :class => "pollsbtn fr mr10"%>
  • - <% else %> -
  • 统计结果
  • - <%end%> - <% end %> -<% end%> - \ No newline at end of file + +<% end%> \ No newline at end of file diff --git a/app/views/exercise/_student_table.html.erb b/app/views/exercise/_student_table.html.erb index 13f928a0e..6d4b25a44 100644 --- a/app/views/exercise/_student_table.html.erb +++ b/app/views/exercise/_student_table.html.erb @@ -23,9 +23,9 @@ <%=exercise.user.show_name %> - - - + + + -- @@ -33,7 +33,7 @@ <% if exercise.created_at%> <%= Time.parse(format_time(exercise.created_at)).strftime("%m-%d %H:%M")%>  - <% if @exercise.end_time <= exercise.created_at %> + <% if exercise.commit_status == 0 %> [未答] <% end %> <% end %> diff --git a/app/views/exercise/index.html.erb b/app/views/exercise/index.html.erb index 68adfb4d4..c8ca72a59 100644 --- a/app/views/exercise/index.html.erb +++ b/app/views/exercise/index.html.erb @@ -5,31 +5,16 @@ }); function republish_exercise(exercise_id,index) { - $('#ajax-modal').html("
    " + - "
    " + - "
    " + - "

    取消发布后学生答题将会被清空
    是否确定取消发布该测验?

    " + - "
    " + - "确  定" + - "取  消" + - "
    " + - "
    " + - "
    " + - "
    " + - "
    "); - showModal('ajax-modal', '310px'); - $('#ajax-modal').css('height','120px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').before("" + - ""); - $('#ajax-modal').parent().removeClass("alert_praise"); - $('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); - $('#ajax-modal').parent().addClass("popbox_polls"); + var htmlvalue = '

    提示

    '+ + '

    取消发布后学生答题将会被清空
    是否确定取消发布该试卷?

    ' + + '取  消' + + '确  定
    '; + pop_box_new(htmlvalue, 400, 152); } function clickCanel(){hideModal("#popbox02");} - function exercise_submit(exercise_id,exercise_name,index) + function exercise_submit(status, exercise_id,exercise_name,index) { if(exercise_name == 0) { @@ -37,29 +22,31 @@ } else { - $('#ajax-modal').html("
    " + - "
    " + - "
    " + - "

    测验发布后将不能对测验进行修改,
    是否确定发布该测验?

    " + - "
    " + - "确  定" + - "取  消" + - "
    " + - "
    " + - "
    " + - "
    " + - "
    "); - showModal('ajax-modal', '310px'); - $('#ajax-modal').css('height','120px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').before("" + - ""); - $('#ajax-modal').parent().removeClass("alert_praise"); - $('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); - $('#ajax-modal').parent().addClass("popbox_polls"); + if (status == 1){ + var htmlvalue = '

    提示

    '+ + '

    您还没有设置截止时间,请先设置截止时间再发布

    ' + + '知道了
    '; + pop_box_new(htmlvalue, 400, 152); + } else if(status == 2){ + var htmlvalue = '

    提示

    '+ + '

    您设置的截止时间已过期,请重新设置

    ' + + '知道了
    '; + pop_box_new(htmlvalue, 400, 152); + } else{ + var htmlvalue = '

    提示

    '+ + '

    发布后不能再对试卷进行修改
    是否确定发布

    ' + + '取  消' + + '确  定
    '; + pop_box_new(htmlvalue, 400, 152); + } } } - + function delete_exercise(id){ + var htmlvalue = '

    提示

    '+ + '

    您是否确定删除

    确定'+ + '取消
    '; + pop_box_new(htmlvalue, 300, 140); + }
    diff --git a/app/views/exercise/publish_exercise.js.erb b/app/views/exercise/publish_exercise.js.erb index 004ca9625..70faa477b 100644 --- a/app/views/exercise/publish_exercise.js.erb +++ b/app/views/exercise/publish_exercise.js.erb @@ -1,10 +1,5 @@ $("#exercises_<%= @exercise.id %>").html("<%= escape_javascript(render :partial => 'exercise',:locals => {:exercise => @exercise,:index =>@index}) %>"); -$('#ajax-modal').html("<%= escape_javascript(render :partial => 'alert', locals: { :message => l(:label_memo_create_succ)}) %>"); -showModal('ajax-modal', '250px'); -//$('#ajax-modal').css('height','111px'); -$('#ajax-modal').siblings().remove(); -$('#ajax-modal').before("" + - ""); -$('#ajax-modal').parent().removeClass("alert_praise"); -$('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); -$('#ajax-modal').parent().addClass("poll_alert_form"); \ No newline at end of file +var htmlvalue = '

    提示

    '+ + '

    发布成功

    ' + + '知道了
    '; +pop_box_new(htmlvalue, 400, 152); \ No newline at end of file diff --git a/app/views/exercise/republish_exercise.js.erb b/app/views/exercise/republish_exercise.js.erb index a55cefbde..372cd08dc 100644 --- a/app/views/exercise/republish_exercise.js.erb +++ b/app/views/exercise/republish_exercise.js.erb @@ -1,10 +1,5 @@ $("#exercises_<%= @exercise.id %>").html("<%= escape_javascript(render :partial => 'exercise',:locals => {:exercise => @exercise,:index => @index}) %>"); -$('#ajax-modal').html("<%= escape_javascript(render :partial => 'alert', locals: { :message => l(:label_poll_republish_success)}) %>"); -showModal('ajax-modal', '250px'); -//$('#ajax-modal').css('height','80px'); -$('#ajax-modal').siblings().remove(); -$('#ajax-modal').before("" + - ""); -$('#ajax-modal').parent().removeClass("alert_praise"); -$('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); -$('#ajax-modal').parent().addClass("poll_alert_form"); \ No newline at end of file +var htmlvalue = '

    提示

    '+ + '

    取消成功

    ' + + '知道了
    '; +pop_box_new(htmlvalue, 400, 152); \ No newline at end of file diff --git a/db/migrate/20161117060138_add_column_to_exercise_users.rb b/db/migrate/20161117060138_add_column_to_exercise_users.rb new file mode 100644 index 000000000..02ef19007 --- /dev/null +++ b/db/migrate/20161117060138_add_column_to_exercise_users.rb @@ -0,0 +1,15 @@ +class AddColumnToExerciseUsers < ActiveRecord::Migration + def change + add_column :exercise_users, :commit_status, :integer, :default => 0 + count = ExerciseUser.all.count / 30 + 2 + transaction do + for i in 1 ... count do i + ExerciseUser.page(i).per(30).each do |eu| + if eu.exercise && eu.exercise.end_time < Time.now && eu.exercise.end_time > eu.created_at + eu.update_column('commit_status', 1) + end + end + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index fd75bb020..b645ba5ad 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20161114092115) do +ActiveRecord::Schema.define(:version => 20161117060138) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -806,10 +806,11 @@ ActiveRecord::Schema.define(:version => 20161114092115) do t.integer "exercise_id" t.integer "score" t.datetime "start_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.datetime "end_at" t.integer "status" + t.integer "commit_status", :default => 0 end create_table "exercises", :force => true do |t| @@ -1910,6 +1911,7 @@ ActiveRecord::Schema.define(:version => 20161114092115) do t.float "work_score" t.integer "work_status", :default => 0 t.datetime "commit_time" + t.integer "is_delete", :default => 0 end add_index "student_works", ["homework_common_id", "user_id"], :name => "index_student_works_on_homework_common_id_and_user_id" diff --git a/lib/tasks/exercise_publish.rake b/lib/tasks/exercise_publish.rake index de93b3861..3683847dd 100644 --- a/lib/tasks/exercise_publish.rake +++ b/lib/tasks/exercise_publish.rake @@ -24,8 +24,10 @@ namespace :exercise_publish do course = exercise.course exercise.update_column('exercise_status', 3) course.student.each do |student| - if ExerciseUser.where("user_id = ? && exercise_id = ?",student.student_id,exercise.id).empty? + if ExerciseUser.where("user_id = ? && exercise_id = ?",student.student_id,exercise.id).blank? ExerciseUser.create(:user_id => student.student_id, :exercise_id => exercise.id, :start_at => exercise.end_time, :status => true,:score=>0) + else + ExerciseUser.where("user_id = ? && exercise_id = ?",student.student_id,exercise.id).first.update_column('commit_status', 1) end =begin s_score = calculate_student_score(exercise, student.student) diff --git a/public/stylesheets/css/common.css b/public/stylesheets/css/common.css index 55617868f..e957e0127 100644 --- a/public/stylesheets/css/common.css +++ b/public/stylesheets/css/common.css @@ -181,6 +181,7 @@ h4{ font-size:14px;}/*color:#3b3b3b;*/ .mw20{ margin: 0 20px;} .mw380 {max-width: 380px !important;} .mw400 {max-width: 400px !important;} +.mw450 {max-width: 450px !important;} .mt-20 {margin-top:-20px;} .mt-10 {margin-top:-10px;} .mt-4 {margin-top:-4px;} diff --git a/public/stylesheets/css/moduel.css b/public/stylesheets/css/moduel.css index 97623c1d2..2161753b1 100644 --- a/public/stylesheets/css/moduel.css +++ b/public/stylesheets/css/moduel.css @@ -21,6 +21,8 @@ input.radio-width90{ width: 90px; } /*模板buttons 20161013byLB*/ .btn{display: inline-block;border:none; padding:0 10px;color: #333;background: #e1e1e1; text-align:center;font-size: 12px; height: 30px;line-height: 30px;-webkit-border-radius: 3px;-moz-border-radius: 3px; -o-border-radius: 3px; border-radius: 3px; } .btn:hover{background: #c3c3c3; color: #333;} +.btn-grey{background: #d9d9d9; color: #656565;} +.btn-grey:hover{background: #717171; color: #fff;} .btn-green{background: #60b25e; color: #fff;} .btn-green:hover{background: #51a74f; color: #fff;} .btn-blue{background: #3b94d6; color: #fff;}