增加判断:作业总数大于4份时才可以开启匿评

增加不可重复开启匿评
This commit is contained in:
sw 2014-11-04 14:53:49 +08:00
parent e7a1e9b325
commit 0f14fbef98
2 changed files with 35 additions and 19 deletions

View File

@ -1004,27 +1004,37 @@ class BidsController < ApplicationController
# 启动匿评
def start_anonymous_comment
@bid = Bid.find(params[:id])
homeworks = @bid.homeworks
users = homeworks.map { |h| h.user }
@start_index = rand(homeworks.size)
while users[0] == homeworks[@start_index].user
@start_index = rand(homeworks.size)
end
if(@bid.comment_status == 1)
homeworks = @bid.homeworks
if(homeworks && homeworks.count >= 4)
@bid.update_column('comment_status', 1)
users = homeworks.map { |h| h.user }
3.times do |i|
homework_start_index = @start_index + i
users.each_with_index do |user, index|
actual_index = homework_start_index + index
actual_index = (actual_index < homeworks.size ? actual_index : actual_index - homeworks.size)
if user != homeworks[actual_index]
@homework_evaluation = HomeworkEvaluation.new(user_id: user.id, homework_attach_id: homeworks[actual_index].id)
@homework_evaluation.save
@start_index = rand(homeworks.size)
while users[0] == homeworks[@start_index].user
@start_index = rand(homeworks.size)
end
3.times do |i|
homework_start_index = @start_index + i
users.each_with_index do |user, index|
actual_index = homework_start_index + index
actual_index = (actual_index < homeworks.size ? actual_index : actual_index - homeworks.size)
if user != homeworks[actual_index]
@homework_evaluation = HomeworkEvaluation.new(user_id: user.id, homework_attach_id: homeworks[actual_index].id)
@homework_evaluation.save
end
end
end
# 修改状态为 '启动匿评'
#@bid.update_column('comment_status', 1)
@statue = 1
else
@statue = 2
end
else
@statue = 3
end
# 修改状态为 '启动匿评'
@bid.update_column('comment_status', 1)
respond_to do |format|
format.js

View File

@ -1,2 +1,8 @@
alert('启动成功')
$("#<%= @bid.id %>_start_anonymous_comment").html('<%= link_to "关闭匿评", stop_anonymous_comment_bid_path(@bid), remote: true %>')
<% if @statue == 1%>
alert('启动成功');
$("#<%= @bid.id %>_start_anonymous_comment").html('<%= link_to "关闭匿评", stop_anonymous_comment_bid_path(@bid), remote: true %>');
<% elsif @statue == 2 %>
alert('启动失败\n作业总数大于4份时才能启动匿评');
<% elsif @statue == 3%>
alert("已开启匿评,请务重复开启");
<% end %>