Merge branch 'Homework' of http://repository.trustie.net/xianbo/trustie2 into Homework

Conflicts:
	app/views/layouts/base_homework.html.erb
This commit is contained in:
sw 2014-11-05 08:53:19 +08:00
commit 3f2aa9cad1
4 changed files with 19 additions and 23 deletions

View File

@ -1006,28 +1006,18 @@ class BidsController < ApplicationController
@bid = Bid.find(params[:id]) @bid = Bid.find(params[:id])
if(@bid.comment_status == 0) if(@bid.comment_status == 0)
homeworks = @bid.homeworks homeworks = @bid.homeworks
if(homeworks && homeworks.count >= 4) if(homeworks && homeworks.size > 2)
@bid.update_column('comment_status', 1) homeworks.each_with_index do |homework, index|
users = homeworks.map { |h| h.user } user = homework.user
n = 3 # TODO: this value should get from params, (老师设置)
@start_index = rand(homeworks.size) n = n < homeworks.size ? n : homeworks.size - 1
while users[0] == homeworks[@start_index].user assigned_homeworks = get_assigned_homeworks(homeworks, n, index)
@start_index = rand(homeworks.size) assigned_homeworks.each do |h|
end @homework_evaluation = HomeworkEvaluation.new(user_id: user.id, homework_attach_id: h.id)
@homework_evaluation.save
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
end end
# 修改状态为 '启动匿评' @bid.update_column('comment_status', 1)
#@bid.update_column('comment_status', 1)
@statue = 1 @statue = 1
else else
@statue = 2 @statue = 2
@ -1052,6 +1042,11 @@ class BidsController < ApplicationController
end end
private private
def get_assigned_homeworks(homeworks, n, index)
homeworks += homeworks
homeworks[index + 1 .. index + n]
end
def find_bid def find_bid
if params[:id] if params[:id]

View File

@ -37,7 +37,7 @@
<span id="<%=bid.id %>_anonymous_comment"> <span id="<%=bid.id %>_anonymous_comment">
<% case bid.comment_status %> <% case bid.comment_status %>
<% when 0 %> <% when 0 %>
<%= link_to '启动匿评', start_anonymous_comment_bid_path(bid), id: "#{bid.id}_start_anonymous_comment", remote: true, :confirm => "开启匿评后学生将不能对作业进行提交、修改、删除等操作\n是否确定开启匿评" %> <%= link_to '启动匿评', start_anonymous_comment_bid_path(bid), id: "#{bid.id}_start_anonymous_comment", remote: true, :confirm => "开启匿评后学生将不能对作业进行提交、修改、删除等操作\n是否确定开启匿评", disable_with: '加载中...' %>
<% when 1 %> <% when 1 %>
<%= link_to '关闭匿评', stop_anonymous_comment_bid_path(bid), id: "#{bid.id}_stop_anonymous_comment", remote: true, :confirm => "关闭匿评后学生将不能对作业进行评分\n是否确定关闭匿评" %> <%= link_to '关闭匿评', stop_anonymous_comment_bid_path(bid), id: "#{bid.id}_stop_anonymous_comment", remote: true, :confirm => "关闭匿评后学生将不能对作业进行评分\n是否确定关闭匿评" %>
<% when 2 %> <% when 2 %>

View File

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

View File

@ -107,7 +107,7 @@
<span id="<%=@bid.id %>_anonymous_comment"> <span id="<%=@bid.id %>_anonymous_comment">
<% case @bid.comment_status %> <% case @bid.comment_status %>
<% when 0 %> <% when 0 %>
<%= link_to '启动匿评', start_anonymous_comment_bid_path(@bid), id: "#{@bid.id}_start_anonymous_comment", remote: true, :confirm => "开启匿评后学生将不能对作业进行提交、修改、删除等操作\n是否确定开启匿评" %> <%= link_to '启动匿评', start_anonymous_comment_bid_path(@bid), id: "#{@bid.id}_start_anonymous_comment", remote: true, :confirm => "开启匿评后学生将不能对作业进行提交、修改、删除等操作\n是否确定开启匿评", disable_with: '加载中...' %>
<% when 1 %> <% when 1 %>
<%= link_to '关闭匿评', stop_anonymous_comment_bid_path(@bid), id: "#{@bid.id}_stop_anonymous_comment", remote: true, :confirm => "关闭匿评后学生将不能对作业进行评分\n是否确定关闭匿评" %> <%= link_to '关闭匿评', stop_anonymous_comment_bid_path(@bid), id: "#{@bid.id}_stop_anonymous_comment", remote: true, :confirm => "关闭匿评后学生将不能对作业进行评分\n是否确定关闭匿评" %>
<% when 2 %> <% when 2 %>