This commit is contained in:
z9hang 2014-06-06 08:35:10 +08:00
commit 09368442c6
20 changed files with 196 additions and 119 deletions

View File

@ -14,7 +14,7 @@ gem "i18n", "~> 0.6.0"
gem "coderay", "~> 1.0.6"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
gem 'acts-as-taggable-on'
gem 'acts-as-taggable-on', '2.4.1'
group :development do
gem 'better_errors', path: 'lib/better_errors'

View File

@ -190,7 +190,8 @@ class BidsController < ApplicationController
@homework.budget = 0
@homework.author_id = User.current.id
@homework.commit = 0
@homework.homework_type = params[:bid][:homework_type]
@homework.homework_type = 1
@homework.is_evaluation = params[:bid][:is_evaluation]
@homework.parent_id = @bid.id
@homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
# @bid.
@ -421,7 +422,9 @@ class BidsController < ApplicationController
if @bid.homework_type == 1
@homework = HomeworkAttach.new
@homework_list = @bid.homeworks
#@homework_list = @bid.homeworks
#增加作业按评分排序,
@homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC')
if params[:student_id].present?
@temp = []
@homework_list.each do |pro|
@ -704,6 +707,7 @@ class BidsController < ApplicationController
@bid = Bid.new
@bid.name = params[:bid][:name]
@bid.description = params[:bid][:description]
@bid.is_evaluation = params[:bid][:is_evaluation]
@bid.reward_type = 3
# @bid.budget = params[:bid][:budget]
@bid.deadline = params[:bid][:deadline]
@ -887,7 +891,7 @@ class BidsController < ApplicationController
def find_bid
if params[:id]
@bid = Bid.find(params[:id])
@bid = Bid.find(params[:id], :include => [{:homeworks => :user}])
@user = @bid.author
end
rescue

View File

@ -36,7 +36,8 @@ class HomeworkAttachController < ApplicationController
end
def create
#if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0)
bid = Bid.find params[:bid_id]
if User.current.admin? || User.current.member_of?(bid.courses.first)
user_id = params[:user_id]
bid_id = params[:bid_id]
sta = 0
@ -50,7 +51,7 @@ class HomeworkAttachController < ApplicationController
:bid_id => bid_id
}
#@bid = Bid.find bid_id
#@homework_list = @bid.homeworks
@homework = HomeworkAttach.new(options)
@ -63,27 +64,37 @@ class HomeworkAttachController < ApplicationController
format.json { head :no_content }
end
else
render_403 :message => :notice_not_authorized
end
else
end
#end
end
def new
@homework = HomeworkAttach.new
@bid = Bid.find(params[:id])
if User.current.admin? || User.current.member_of?(@bid.courses.first)
@homework = HomeworkAttach.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @homework }
end
else
render_403 :message => :notice_not_authorized
end
end
def edit
@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
else
render_403 :message => :notice_not_authorized
end
end
def update
@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
name = params[:homework_name]
description = params[:homework_description]
@homework.name = name
@ -98,10 +109,14 @@ class HomeworkAttachController < ApplicationController
end
else
end
else
render_403 :message => :notice_not_authorized
end
end
def destroy
@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
if @homework.destroy
respond_to do |format|
format.html { redirect_to project_for_bid_path @homework.bid }
@ -109,11 +124,15 @@ class HomeworkAttachController < ApplicationController
end
else
end
else
render_403 :message => :notice_not_authorized
end
end
#显示作业信息
def show
@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current.member_of?(@homework.bid.courses.first)
# 打分统计
stars_reates = @homework.
rates(:quality)
@ -127,6 +146,10 @@ class HomeworkAttachController < ApplicationController
@stars_status_map["star#{star_status.stars.to_i}".to_sym] =
percent_m.to_s + "%"
end
#是否已经进行过评价
@has_evaluation = stars_reates.where("rater_id = ?",User.current).count > 0
#是否开启互评功能
@is_evaluation = @homework.bid.is_evaluation == 1 || @homework.bid.is_evaluation == nil
@limit = 10
@jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC")
@feedback_count = @jours.count
@ -134,6 +157,9 @@ class HomeworkAttachController < ApplicationController
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
else
render_403 :message => :notice_not_authorized
end
end
#删除留言

View File

@ -26,6 +26,8 @@ class ZipdownController < ApplicationController
obj_id = params[:obj_id]
user_id = params[:user_id]
obj = obj_class.constantize.find(obj_id)
if User.current.admin? || User.current.member_of?(obj.courses.first)
zipfile = nil
case obj.class.to_s.to_sym
when :Bid
@ -34,6 +36,9 @@ class ZipdownController < ApplicationController
logger.error "[ZipDown#assort] ===> #{obj.class.to_s.to_sym} unKown !!"
end
send_file zipfile, :filename => obj.name, :type => detect_content_type(zipfile) if zipfile
else
render_403 :message => :notice_not_authorized
end
end
private

View File

@ -158,7 +158,7 @@ module BidsHelper
#当前用户是不是指定课程的学生
def is_cur_course_student? course
people = []
course.members.each do |member|
course.members.includes(:user, :roles).each do |member|
if [5,10].include? member.roles.first.id
people << member.user
end

View File

@ -139,7 +139,7 @@ module CoursesHelper
#判断制定用户是不是当前课程的老师
def is_course_teacher user,course
people = []
course.members.each do |member|
course.members.includes(:roles, :user).each do |member|
role_id = member.roles.first.id
if TeacherRoles.include? role_id
people << member.user
@ -159,7 +159,13 @@ module CoursesHelper
end
#获取当前用户在指定作业下提交的作业的集合
def cur_user_homework_for_bid bid
cur_user_homework = HomeworkAttach.where("user_id = ? and bid_id = ?",User.current,params[:id])
cur_user_homework = HomeworkAttach.where("user_id = ? and bid_id = ?",User.current,bid.id)
cur_user_homework
end
#判断当前用户对指定作业是否已经评价过
def has_evaluation? homework
seem_count = homework.rates(:quality).where("rater_id = ?",User.current).count
seem_count > 0
end
end

View File

@ -227,6 +227,19 @@ module ProjectsHelper
type << option2
end
#是否启动互评下拉框
def is_evaluation_option
type = []
option1 = []
option2 = []
option1 << l(:lable_start_mutual_evaluation)
option1 << 1
option2 << l(:lable_close_mutual_evaluation)
option2 << 2
type << option1
type << option2
end
# 用来判断用户是否是项目的管理员
# added by william
def is_manager?(user_id,project_id)

View File

@ -137,7 +137,7 @@ class User < Principal
has_one :user_extensions,:dependent => :destroy
## end
#default_scope -> { includes(:user_extensions, :user_score) }
default_scope -> { includes(:user_extensions, :user_score) }
scope :teacher, -> {
joins(:user_extensions).where('user_extensions.identity = ?', UserExtensions::TEACHER)
}

View File

@ -15,7 +15,13 @@
<span style="float: right">
<% if(User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0)) %>
<%# 提交作业按钮 %>
<%= link_to l(:label_commit_homework), '#OpenWindow', rel: 'leanModal', onclick: "showSubH(#{bid.id}, '#{bid.name}');" if User.current.member_of?(@project) %>
<!--<%= link_to l(:label_commit_homework), '#OpenWindow', rel: 'leanModal', onclick: "showSubH(#{bid.id}, '#{bid.name}');" if User.current.member_of?(@project) %>-->
<% cur_user_homework = cur_user_homework_for_bid(bid) %>
<% if cur_user_homework!= nil && cur_user_homework.count == 0 %>
<%= link_to l(:label_commit_homework),new_homework_attach_path(bid) %>
<% else %>
<span style="color: green; float: right"><%= l(:lable_has_commit_homework)%></span>
<% end %>
<% end %>
<% if (User.current.admin?||User.current.id==bid.author_id) %>
<%= link_to(

View File

@ -19,6 +19,7 @@
<p><%= f.select :homework_type, homework_type_option %>
</p>
-->
<p><%= f.select :is_evaluation, is_evaluation_option %>
<fieldset><legend><%= l(:label_attachment_plural) %></legend>
<p><%= render :partial => 'attachments/form', :locals => {:container => @homework} %></p>
</fieldset>

View File

@ -36,6 +36,7 @@
<p><%= f.select :homework_type, homework_type_option %>
</p>
-->
<p><%= f.select :is_evaluation, is_evaluation_option %>
<p><%= hidden_field_tag 'course_id', @project_id %>
</p>
<fieldset><legend><%= l(:label_attachment_plural) %></legend>

View File

@ -1,6 +1,8 @@
<!-- fq -->
<% is_student = is_cur_course_student? @bid.courses.first %>
<% is_teacher = is_course_teacher User.current,@bid.courses.first %>
<!-- 当is_evaluation为1或者null(null主要是为了兼容前面数据)时代表启用互评功能2表示未启用 -->
<% is_evaluation = @bid.is_evaluation == 1 || @bid.is_evaluation == nil %>
<%= form_tag(:controller => 'bids', :action => "show_project", :method => :get) do %>
<div class="project-search-block">
@ -53,11 +55,21 @@
<% else %>
<% homework_filename = homework.name %>
<% end %>
<strong><%= link_to homework_filename, :controller => "zipdown", :action => "download_user_homework",:obj_class => @bid.class,:obj_id => @bid, :user_id =>homework.user%></strong>
<strong>
<% if is_evaluation || is_teacher%>
<%= link_to homework_filename, :controller => "zipdown", :action => "download_user_homework",:obj_class => @bid.class,:obj_id => @bid, :user_id =>homework.user%>
<% else %>
<%= homework_filename %>
<% end %>
</strong>
</td>
<td style="vertical-align: top">
<% if is_student %>
<% if is_evaluation %>
<%= link_to "互评>>" , homework_attach_path(homework)%>
<% else %>
<%= link_to "查看详细" , homework_attach_path(homework)%>
<% end %>
<% else %>
<% if is_teacher %>
<%= link_to "综评>>" , homework_attach_path(homework)%>
@ -71,13 +83,8 @@
</td>
<td>
<strong>作业评分:</strong>
<% stars_reates = homework.rates(:quality) %>
<% sum = 0 %>
<% stars_reates.each do |star_reates| %>
<% sum = sum + star_reates.stars %>
<% end %>
<% stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count %>
<%= format("%.2f", sum * 1.0 / stars_reates_count) %>
<%= format("%.2f", homework.rate_averages.first.try(:avg).to_i ) %>
</td>
<td valign="top" align="right">
<% if Time.parse(@bid.deadline.to_s) < Time.parse(homework.created_at.to_s) %>
@ -87,8 +94,8 @@
</tr>
<tr>
<td valign="top">&nbsp;
<% if is_cur_course_user? @bid %>
<strong><%= l(:label_bidding_user_studentcode) %>&nbsp; &nbsp;<%= homework.user.user_extensions.student_id%></strong>
<% if User.current.member_of?(@bid.courses.first) %>
<strong><%= l(:label_bidding_user_studentcode) %>&nbsp; &nbsp;<%= homework.user.student_id%></strong>
<% end %>
</td>
<td>
@ -100,20 +107,6 @@
<% end %>
</td>
</tr>
<!--
<tr>
<td colspan="2" width="580px" >
<% if (User.current == homework.user) || (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',3,7, 9)).size >0) %>
<p class="font_description">
<% options = {:author => true, :deletable => attach_delete(homework)} %>
<%= render :partial => 'attachments/links',
:locals => {:attachments => homework.attachments, :options => options} %>
</p>
<% end %>
</td>
</tr>
-->
</table>
</td>
</tr>

View File

@ -22,12 +22,6 @@
<div style="font-size: 14px;">
<div style="margin-left: 20px;margin-bottom: 10px;margin-top: 10px;"> <%= comprehensive_evaluation.first.notes%> </div>
</div>
<% if is_teacher %>
<div style="text-align: center;">评分:
<%= rating_for homework, dimension: :quality, class: 'rateable div_inline' %>
<span style="font-size: 11px">(您可以重新打分,打分结果以最后一次打分为主!)</span>
</div>
<% end %>
</div>
<% else %>
<% if is_teacher %>
@ -35,10 +29,7 @@
<div style="font-size: 15px">
<strong>作业综评:</strong>
</div>
<div style="text-align: center;">评分:
<%= rating_for homework, dimension: :quality, class: 'rateable div_inline' %>
<span style="font-size: 11px">(您可以重新打分,打分结果以最后一次打分为主!)</span>
</div>
<%= render :partial => 'evaluation', :locals => {:homework => homework} %>
<div>
<%= render :partial => 'addjour', :locals => {:homework_attach => homework, :sta => 0,:is_comprehensive_evaluation => 1} %>
</div>

View File

@ -0,0 +1,4 @@
<div style="text-align: center;">评分:
<%= rating_for homework, dimension: :quality, class: 'rateable div_inline' %>
<span style="font-size: 11px">(每个用户对每份作业只能进行一次评价!)</span>
</div>

View File

@ -8,7 +8,6 @@
</style>
<% is_student = is_cur_course_student? @homework.bid.courses.first %>
<% is_teacher = is_course_teacher User.current,@homework.bid.courses.first %>
<p id="notice"><%= notice %></p>
<!-- <%= image_tag(url_to_avatar(@user), :class => "avatar2") %> -->
<div style="height: auto; padding-bottom: 10px">
@ -29,8 +28,12 @@
<tr>
<td style="padding-left: 40px">
<span>作业下载:</span>
<% if @is_evaluation || is_teacher%>
<% options = {:author => true } %>
<%= render :partial => 'app_link', :locals => {:attachments => @homework.attachments, :options => options} %>
<% else %>
<%= l(:label_cant_download) %>
<% end %>
</td>
<td style="width: 240px; word-wrap: break-word; word-break: break-all">
所属任务:<%= link_to(@homework.bid.name, project_for_bid_path(@homework.bid))%>
@ -133,10 +136,19 @@
<div style="height: 50px">
<div style="font-size: 15px"><strong>作业评论:</strong></div>
<% if is_student %>
<div style="text-align: center;">评分:
<%= rating_for @homework, dimension: :quality, class: 'rateable div_inline' %>
<span style="font-size: 11px">(您可以重新打分,打分结果以最后一次打分为主!)</span>
<% if @is_evaluation %>
<% if @has_evaluation %>
<div style="text-align: center;">
<%= l(:lable_has_evaluation)%>
</div>
<% else %>
<%= render :partial => 'evaluation', :locals => {:homework => @homework} %>
<% end %>
<% else %>
<div style="text-align: center;">
<%= l(:lable_close_evaluation)%>
</div>
<% end %>
<% end %>
</div>

View File

@ -18,8 +18,8 @@
<%= yield :header_tags -%>
</head>
<body class="<%= h body_css_classes %>">
<% project = @bid.courses.first %>
<% course = Course.find_by_extra(project.identifier) %>
<% project = @bid.courses.includes(:course_extra).first %>
<% course = project.course_extra %>
<div id="wrapper">
<div id="wrapper2">
<div id="wrapper3">
@ -47,27 +47,31 @@
<div class="main_context">
<div class="spaceleft">
<div>
<table style="width: 250px ; line-height: 1.5em;font-size: 12px">
<table>
<tr>
<td style="width: 40px">
<td style="padding-left:8px ">
<% if get_avatar?(project) %>
<%= image_tag(url_to_avatar(project),:style => "width:60px;height:60px" ) %>
<%= image_tag(url_to_avatar(project),:style => "width:80px;height:80px" ) %>
<% else %>
<%= image_tag('../images/avatars/Project/course.jpg', :style => "width:60px;height:60px") %>
<%= image_tag('../images/avatars/Project/course.jpg', :style => "width:80px;height:80px") %>
<% end %>
</td>
<td>
<table>
<tr valign="top">
<td style="width: 50px;vertical-align: top;" ><strong>课程名:</strong></td>
<td style="text-align: left">
<span style=" word-wrap: break-word; word-break: break-all"><strong> <%= link_to @bid.courses.first.name.to_s, homework_project_path(@bid.courses.first) if @bid.courses.first %></strong></span>
<tr>
<td style="vertical-align: top;font-size: 16px;text-align: center;" >
<span style=" word-wrap: break-word; word-break: break-all">
<strong>
<%= link_to @bid.courses.first.name.to_s, homework_project_path(@bid.courses.first) if @bid.courses.first %>
</strong>
</span>
</td>
</tr>
<tr>
<td style="width: 50px;vertical-align: top;"><strong>作业名:</strong></td>
<td style="text-align: left">
<span style="color:#ed8924"><strong><%= h @bid.name %></strong></span>
<td style=" word-wrap: break-word; word-break: break-all;font-size: 16px;text-align: center">
<span style=" color:#ed8924">
<strong><%= h @bid.name %></strong>
</span>
</td>
</tr>
<!-- <tr>
@ -175,7 +179,7 @@
<tr>
<td style="padding-top: 5px"> <% if @bid.homework_type == 1%>
<% if @bid.homeworks.size>0 %>
<% for homework in @bid.homeworks %>
<% for homework in @bid.homeworks.eager_load(:user) %>
<%= link_to image_tag(url_to_avatar(homework.user), :class => "avatar", :title => homework.user.name), user_path(homework.user), :class => "avatar" %> <% end %>
<% else %>
<p class="font_lighter">

View File

@ -32,10 +32,8 @@
</p> -->
<p><%= f.text_field :deadline, :required => true, :size => 60, :style => "width:150px;" %><%= calendar_for('bid_deadline')%>
</p>
<!--
<p><%= f.select :homework_type, homework_type_option %>
<p><%= f.select :is_evaluation, is_evaluation_option %>
</p>
-->
<p><%= hidden_field_tag 'course_id', @project.id %>
</p>
<fieldset><legend><%= l(:label_attachment_plural) %></legend>

View File

@ -1297,6 +1297,7 @@ zh:
label_current_contributors: 位当前贡献者
label_commit_limit: 作业提交时间已过!
label_commit_ar: 作业提交截止时间快到了!
lable_has_commit_homework: 您已提交过作业
#modify by men
label_x_current_contributors:
zero: 位当前贡献者
@ -1565,6 +1566,7 @@ zh:
label_bids_credit_number:
field_budget: 奖励
field_deadline: 截止日期
field_is_evaluation: 是否启动互评
label_tags_selected: 已选标签
label_tags_related: 相关标签
button_project_tags_add: 增加
@ -1619,6 +1621,9 @@ zh:
label_have_feedback: 有了
label_of_feedback:
label_welcome_participate: 参与了
label_cant_download: 未开启互评功能作业不允许下载
lable_close_evaluation: 该作业未开启互评功能
lable_has_evaluation: 您已进行过评价
#modify by men
label_x_welcome_participate:
zero: 参与了
@ -1808,6 +1813,8 @@ zh:
label_new_join_order: 请输入课程密码
label_task_submit_form_accessory: 作业最终以附件形式提交
label_task_submit_form_project: 作业最终以项目形式提交
lable_start_mutual_evaluation: 启动互评
lable_close_mutual_evaluation: 关闭互评
label_has_been: 已经被
label_course_userd_by: 个课程引用

View File

@ -0,0 +1,5 @@
class AddEvaluationToBid < ActiveRecord::Migration
def change
add_column :bids, :is_evaluation, :integer
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140527060344) do
ActiveRecord::Schema.define(:version => 20140605025247) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -105,6 +105,7 @@ ActiveRecord::Schema.define(:version => 20140527060344) do
t.integer "homework_type"
t.integer "parent_id"
t.string "password"
t.integer "is_evaluation"
end
create_table "boards", :force => true do |t|