教师开启匿评功能完成

This commit is contained in:
sw 2015-05-26 10:22:16 +08:00
parent f3597d9aa5
commit 96354a1c00
2 changed files with 39 additions and 2 deletions

View File

@ -1,7 +1,7 @@
class HomeworkCommonController < ApplicationController
layout "base_courses"
before_filter :find_course, :only => [:index,:new,:create]
before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment]
before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment]
before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment]
def index
@ -124,8 +124,30 @@ class HomeworkCommonController < ApplicationController
end
#开启匿评
#statue 1:启动成功2启动失败作业总数大于等于2份时才能启动匿评3:已开启匿评,请务重复开启,4:没有开启匿评的权限
def start_anonymous_comment
@statue =4 and return unless User.current.admin? || User.current.allowed_to?(:as_teacher,@course)
if @homework_detail_manual.comment_status == 1
student_works = @homework.student_works
if student_works && student_works.size >=2
student_works.each_with_index do |work, index|
user = work.user
n = @homework_detail_manual.evaluation_num
n = n < student_works.size ? n : student_works.size - 1
assigned_homeworks = get_assigned_homeworks(student_works, n, index)
assigned_homeworks.each do |h|
student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id)
student_works_evaluation_distributions.save
end
end
@homework_detail_manual.update_column('comment_status', 2)
@statue = 1
else
@statue = 2
end
else
@statue = 3
end
end
#关闭匿评
@ -170,4 +192,9 @@ class HomeworkCommonController < ApplicationController
def teacher_of_course
render_403 unless User.current.allowed_to?(:as_teacher,@course)
end
def get_assigned_homeworks(student_works, n, index)
student_works += student_works
student_works[index + 1 .. index + n]
end
end

View File

@ -0,0 +1,10 @@
<% if @statue == 1%>
alert('启动成功');
$("#<%= @homework.id %>_start_anonymous_comment").replaceWith('<%= escape_javascript(link_to "关闭匿评", alert_anonymous_comment_homework_common_path(@homework), remote: true, id:"#{@homework.id}_stop_anonymous_comment",:class => "fr mr10 work_edit")%>');
<% elsif @statue == 2 %>
alert('启动失败\n作业总数大于等于2份时才能启动匿评');
<% elsif @statue == 3%>
alert("已开启匿评,请务重复开启");
<% elsif @statue == 3%>
alert("您没有权限开启匿评");
<% end %>