作业匿评功能
This commit is contained in:
parent
27aca11715
commit
e8e7708d6e
|
@ -998,6 +998,46 @@ class BidsController < ApplicationController
|
|||
|
||||
end
|
||||
|
||||
# 启动匿评
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def stop_anonymous_comment
|
||||
@bid = Bid.find(params[:id])
|
||||
|
||||
@bid.update_column('comment_status', 2)
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_bid
|
||||
|
|
|
@ -3,4 +3,7 @@ class HomeworkEvaluation < ActiveRecord::Base
|
|||
|
||||
belongs_to :homework_attach
|
||||
belongs_to :user
|
||||
|
||||
validate :user, presence: true
|
||||
validate :homework_attach, presence: true
|
||||
end
|
||||
|
|
|
@ -34,6 +34,16 @@
|
|||
<% end %>
|
||||
<% end %>
|
||||
<% if (User.current.admin?||User.current.id==bid.author_id) %>
|
||||
<span id="<%=bid.id %>_anonymous_comment">
|
||||
<% case bid.comment_status %>
|
||||
<% when 0 %>
|
||||
<%= link_to '启动匿评', start_anonymous_comment_bid_path(bid), id: "#{bid.id}_start_anonymous_comment", remote: true %>
|
||||
<% when 1 %>
|
||||
<%= link_to '关闭匿评', stop_anonymous_comment_bid_path(bid), id: "#{bid.id}_stop_anonymous_comment", remote: true %>
|
||||
<% when 2 %>
|
||||
已关闭匿评
|
||||
<% end %>
|
||||
</span>
|
||||
<%= link_to(
|
||||
l(:button_edit),
|
||||
{:action => 'edit', :controller=>'bids', :course_id =>@course.id, :bid_id => bid.id},
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
alert('启动成功')
|
||||
$("#<%= @bid.id %>_start_anonymous_comment").html('<%= link_to "关闭匿评", stop_anonymous_comment_bid_path(@bid), remote: true %>')
|
|
@ -0,0 +1,2 @@
|
|||
alert('关闭成功')
|
||||
$("#<%= @bid.id %>_anonymous_comment").html('已关闭匿评')
|
|
@ -329,6 +329,8 @@ RedmineApp::Application.routes.draw do
|
|||
resources :bids, :only=>[:edit,:update,:show] do
|
||||
member do
|
||||
match 'homework_ajax_modal'
|
||||
get 'start_anonymous_comment', as: 'start_anonymous_comment'
|
||||
get 'stop_anonymous_comment', as: 'stop_anonymous_comment'
|
||||
end
|
||||
end
|
||||
resources :projects do
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddCommentStatusToBid < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :bids, :comment_status, :integer, default: 0
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20141031111632) do
|
||||
ActiveRecord::Schema.define(:version => 20141102054414) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
@ -108,6 +108,7 @@ ActiveRecord::Schema.define(:version => 20141031111632) do
|
|||
t.string "password"
|
||||
t.integer "is_evaluation"
|
||||
t.integer "proportion", :default => 60
|
||||
t.integer "comment_status", :default => 0
|
||||
end
|
||||
|
||||
create_table "boards", :force => true do |t|
|
||||
|
|
Loading…
Reference in New Issue