parent
e7a1e9b325
commit
0f14fbef98
|
@ -1004,27 +1004,37 @@ class BidsController < ApplicationController
|
||||||
# 启动匿评
|
# 启动匿评
|
||||||
def start_anonymous_comment
|
def start_anonymous_comment
|
||||||
@bid = Bid.find(params[:id])
|
@bid = Bid.find(params[:id])
|
||||||
homeworks = @bid.homeworks
|
if(@bid.comment_status == 1)
|
||||||
users = homeworks.map { |h| h.user }
|
homeworks = @bid.homeworks
|
||||||
|
if(homeworks && homeworks.count >= 4)
|
||||||
|
@bid.update_column('comment_status', 1)
|
||||||
|
users = homeworks.map { |h| h.user }
|
||||||
|
|
||||||
@start_index = rand(homeworks.size)
|
@start_index = rand(homeworks.size)
|
||||||
while users[0] == homeworks[@start_index].user
|
while users[0] == homeworks[@start_index].user
|
||||||
@start_index = rand(homeworks.size)
|
@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
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
else
|
||||||
|
@statue = 3
|
||||||
end
|
end
|
||||||
# 修改状态为 '启动匿评'
|
|
||||||
@bid.update_column('comment_status', 1)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
format.js
|
||||||
|
|
|
@ -1,2 +1,8 @@
|
||||||
alert('启动成功')
|
<% if @statue == 1%>
|
||||||
$("#<%= @bid.id %>_start_anonymous_comment").html('<%= link_to "关闭匿评", stop_anonymous_comment_bid_path(@bid), remote: true %>')
|
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 %>
|
||||||
|
|
Loading…
Reference in New Issue