1.重写homework_attach的show方法,优化弹出框的弹出效率

2.修改相关的view层代码
3.增加获取指定评分的评论的方法
This commit is contained in:
sw 2014-12-04 18:01:53 +08:00
parent 803847585e
commit 4bbc76a217
7 changed files with 212 additions and 168 deletions

View File

@ -284,11 +284,6 @@ class HomeworkAttachController < ApplicationController
end
end
#获取指定作业的所有成员
def users_for_homework homework
homework.nil? ? [] : (homework.users + [homework.user])
end
#获取可选成员列表
#homework作业
#users该作业所有成员
@ -359,53 +354,69 @@ class HomeworkAttachController < ApplicationController
#显示作业信息
def show
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
# 打分统计
#stars_reates = @homework. rates(:quality)
#是否已经进行过评价
temp = HomeworkAttach.find_by_sql("SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{@homework.id} AND rater_id = #{User.current.id}").first
@m_score = temp.nil? ? 0:temp.stars
@has_evaluation = @homework.has_rated?( User.current,:quality)
#@jours留言 is null条件用以兼容历史数据
@jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")
if User.current.admin? || User.current.member_of_course?(@course)
# 作业打分列表
@stars_reates = @homework.rates(:quality)
#我的评分
@has_evaluation = @stars_reates.where("rater_id = #{User.current.id}").first
@m_score = @has_evaluation.nil? ? 0 : @has_evaluation.stars
teachers = find_course_teachers(@course)
@teacher_stars = @stars_reates.where("rater_id in (#{teachers})") #老师评分列表
@student_stars = @stars_reates.where("rater_id not in (#{teachers})") #学生评分列表
@is_teacher = is_course_teacher User.current,@course
@is_anonymous_comments = @bid.comment_status == 1 && !@homework.users.include?(User.current) && @homework.user != User.current && !@is_teacher #判断是不是匿评(开启匿评,当前用户不是作业的创建者或者参与者,不是老师)
jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")#jours留言 is null条件用以兼容历史数据
@jour = paginateHelper jours,5 #留言
@cur_page = params[:cur_page] || 1
@cur_type = params[:cur_type] || 5
@jour = paginateHelper @jours,5
teachers = searchTeacherAndAssistant @course
@comprehensive_evaluation = []
#JourForMessage的is_comprehensive_evaluation字段
#1老师评价
#2学生评价
#3 || null学生留言
teachers.each do|teacher|
temp = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{teacher.user_id}").order("created_on DESC").first
@comprehensive_evaluation << temp if temp
end
annymous_users = @homework.homework_evaluations.map { |homework_evaluation| homework_evaluation.user.id}.join(',')
unless annymous_users.nil? || annymous_users == ""
@anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in (#{annymous_users})").order("created_on DESC")
end
#@totle_score = score_for_homework @homework
#@teaher_score = teacher_score_for_homework @homework
#is_student = is_cur_course_student @homework.bid.courses.first
@is_teacher = is_course_teacher User.current,@homework.bid.courses.first
@is_anonymous_comments = @homework.bid.comment_status == 1 #是否开启了匿评
#@is_comprehensive_evaluation 1教师评论2学生匿评3学生留言
if User.current.member_of_course?(@homework.bid.courses.first)
if @is_teacher
@is_comprehensive_evaluation = 1 #教师评论
else
if @is_anonymous_comments && !@has_evaluation #是学生且开启了匿评且未进行评分
@is_comprehensive_evaluation = 2 #匿评
else #是学生未开启匿评或者已经进行评分
@is_comprehensive_evaluation = 3 #留言
end
end
else
@is_comprehensive_evaluation = 3
end
#if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
# # 打分统计
# #stars_reates = @homework. rates(:quality)
# #是否已经进行过评价
# temp = HomeworkAttach.find_by_sql("SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{@homework.id} AND rater_id = #{User.current.id}").first
# @m_score = temp.nil? ? 0:temp.stars
# @has_evaluation = @homework.has_rated?( User.current,:quality)
# #@jours留言 is null条件用以兼容历史数据
# @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")
# @cur_page = params[:cur_page] || 1
# @cur_type = params[:cur_type] || 5
# @jour = paginateHelper @jours,5
#
# teachers = searchTeacherAndAssistant @course
# @comprehensive_evaluation = []
# #JourForMessage的is_comprehensive_evaluation字段
# #1老师评价
# #2学生评价
# #3 || null学生留言
# teachers.each do|teacher|
# temp = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{teacher.user_id}").order("created_on DESC").first
# @comprehensive_evaluation << temp if temp
# end
# annymous_users = @homework.homework_evaluations.map { |homework_evaluation| homework_evaluation.user.id}.join(',')
# unless annymous_users.nil? || annymous_users == ""
# @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in (#{annymous_users})").order("created_on DESC")
# end
# #@totle_score = score_for_homework @homework
# #@teaher_score = teacher_score_for_homework @homework
#
# #is_student = is_cur_course_student @homework.bid.courses.first
# @is_teacher = is_course_teacher User.current,@homework.bid.courses.first
# @is_anonymous_comments = @homework.bid.comment_status == 1 #是否开启了匿评
# #@is_comprehensive_evaluation 1教师评论2学生匿评3学生留言
# if User.current.member_of_course?(@homework.bid.courses.first)
# if @is_teacher
# @is_comprehensive_evaluation = 1 #教师评论
# else
# if @is_anonymous_comments && !@has_evaluation #是学生且开启了匿评且未进行评分
# @is_comprehensive_evaluation = 2 #匿评
# else #是学生未开启匿评或者已经进行评分
# @is_comprehensive_evaluation = 3 #留言
# end
# end
# else
# @is_comprehensive_evaluation = 3
# end
respond_to do |format|
format.html
@ -622,5 +633,10 @@ class HomeworkAttachController < ApplicationController
WHERE table1.t_score IS NULL")
@homework_list = paginateHelper all_homework_list,10
end
#获取指定作业的所有成员
def users_for_homework homework
homework.nil? ? [] : (homework.users + [homework.user])
end
end

View File

@ -91,6 +91,11 @@ module HomeworkAttachHelper
@m_score = temp.nil? ? 0:temp.stars.to_i
end
#获取评分对应的评论
def get_homework_review homework,is_teacher,user
homework.journals_for_messages.where("is_comprehensive_evaluation = #{is_teacher ? 1 : 2} and user_id = #{user.id}").order("created_on DESC").first
end
def convert_array array
ary = "("
if array.nil? || array.count == 0

View File

@ -1,35 +1,4 @@
<style>
input[type="submit"].bid_btn {
vertical-align: middle;
width: 60px;/*modified by ming*/
height: 25px;
line-height: 19px;
font-size: 14px;
color: rgb(0, 0, 0);
background: buttonface;/*url("/images/button/bg103.jpg") no-repeat scroll left top transparent;*/
padding: 0px 0px 4px 0px;
border-radius: 2px;
border: 1px solid rgb(148, 148, 148);
box-shadow: none;
text-shadow: none;
margin-top: -10px;
/*margin-right: -4px;*/
}
input[type="button"].bid_btn {
width: 60px;/*modified by ming*/
height: 25px;
line-height: 19px;
font-size: 14px;
color: rgb(0, 0, 0);
background: buttonface;/*url("/images/button/bg103.jpg") no-repeat scroll left top transparent;*/
padding: 0px 0px 4px 0px;
border-radius: 2px;
border: 1px solid rgb(148, 148, 148);
box-shadow: none;
text-shadow: none;
margin-top: -10px;
margin-right: -2px;
}
textarea:focus {
border: #d5dee9 1px solid;
}
@ -61,16 +30,13 @@
<%= form_for('new_form', :remote => true, :method => :post,
:url => {:controller => 'homework_attach',
:action => 'addjours',
:jour_id => homework_attach.id,
:is_comprehensive_evaluation => is_comprehensive_evaluation,
:homework_id => homework_attach.id,
:cur_page => cur_page,
:cur_type => cur_type,
:sta => sta}) do |f|%>
:cur_type => cur_type
}) do |f|%>
<!-- 打分 -->
<div class="ping_star" id="star_score">
<% if @is_comprehensive_evaluation == 3 || User.current == homework_attach.user%>
<!-- 如果是留言,或者是作业创建者进入,不显示打星 -->
<% else @is_comprehensive_evaluation == 2 %>
<% if @is_anonymous_comments || @is_teacher %>
<!-- 学生匿评或者教师评价 -->
<%= l(:label_work_rating) %>
<%= render :partial => 'show_star',:locals => {start_score:m_score} %>
@ -79,18 +45,13 @@
<div class="cl"></div>
<!-- 打分js结束 -->
<div id = 'pre_show'>
<%= render :partial => 'words/pre_show', :locals => {:content => @content} %>
</div>
<% if User.current.logged? %>
<%= f.text_area 'user_message', :rows => 3, :cols => 65,
:style => "resize: none;", :class => 'noline', :placeholder => l(:text_caracters_maximum,:count=>250),
:maxlength => 250
%>
:maxlength => 250 %>
<%= f.text_field :reference_user_id, :style=>"display:none"%>
<div style="float:right">
<a href="#" class="ping_sub1" id="jours_submit" onclick="submit1(<%= is_teacher%>);">
<a href="#" class="ping_sub1" id="jours_submit" onclick="submit1(<%= @is_teacher%>);">
<%= l(:label_confirmation) %>
</a>
</div>

View File

@ -1,24 +1,45 @@
<div class="ping_list">
<div id="ping_tb_" class="ping_tb_">
<ul>
<li id="ping_tb_4" class="ping_normaltab" onclick="i:HoverLi(4);">
<%= l(:label_teacher_comments) %><span class="c_red" id="jour_count_4"><%= @comprehensive_evaluation.nil? ? 0 : @comprehensive_evaluation.count %></span></li>
<li id="ping_tb_5" class="ping_normaltab" onclick="i:HoverLi(5);">
<%= l(:label_anonymous_comments) %><span class="c_red" id="jour_count_5" ><%= @anonymous_comments.nil? ? 0 : @anonymous_comments.count %></span></li>
<li id="ping_tb_3" class="ping_hovertab" onclick="x:HoverLi(3);">
<%= l(:label_responses) %><span class="c_red" id="jour_count_3"><%= @jours.nil? ? 0 : @jours.count %></span></li>
<li id="ping_tb_4" class="ping_normaltab" onclick="HoverLi(4);">
<%= l(:label_teacher_comments) %>
<span class="c_red" id="jour_count_4">
<%= @teacher_stars.count %>
</span>
</li>
<li id="ping_tb_5" class="ping_normaltab" onclick="HoverLi(5);">
<%= l(:label_anonymous_comments) %>
<span class="c_red" id="jour_count_5" >
<%= @student_stars.count %>
</span>
</li>
<li id="ping_tb_3" class="ping_hovertab" onclick="HoverLi(3);">
<%= l(:label_responses) %>
<span class="c_red" id="jour_count_3">
<%= @obj_count %>
</span>
</li>
</ul>
</div>
<div class="cl"></div>
<div class="ping_ctt">
<div class="ping_dis" id="tbc_03">
<%= render :partial => 'homework_attach/jour',:locals => {:jours => @jour,:show_score => false,:show_name => true,:is_jour => true} %>
<!-- 留言列表 -->
<%= render :partial => 'homework_attach/jour',:locals => {:jours => @jour, :obj_pages => @obj_pages, :obj_count => @obj_count, :homework => @homework} %>
</div>
<div class="ping_undis" id="tbc_04">
<%= render :partial => 'homework_attach/jour',:locals => {:jours => @comprehensive_evaluation,:show_score => true,:show_name => true,:is_jour => false} %>
<!-- 老师评价列表 -->
<%= render :partial => 'homework_attach/review',:locals => {:review_list => @teacher_stars,:show_name => true} %>
</div>
<div class="ping_undis" id="tbc_05">
<%= render :partial => 'homework_attach/jour',:locals => {:jours => @anonymous_comments,:show_score => true,:show_name => false,:is_jour => false} %>
<!-- 学生匿评列表 -->
<%= render :partial => 'homework_attach/review',:locals => {:review_list => @student_stars,:show_name => false} %>
</div>
</div>
</div><!---ping_list end--->

View File

@ -1,65 +1,47 @@
<% jours.nil? || jours.count == 0 || jours.each do |jour| %>
<div class="ping_C">
<div class="ping_dispic">
<% if show_name %>
<%= link_to image_tag(url_to_avatar(jour.user)) , user_path(jour.user), :target =>"_blank" %>
<% else %>
<a><%= image_tag(url_to_avatar(nil))%></a>
<% end %>
</div>
<div class="ping_discon">
<div class="ping_distop">
<span>
<% if show_name %>
<%= link_to jour.user, user_path(jour.user),:style => " font-weight:bold; color:#15bccf; margin-right:5px; background:none;", :target => "_blank"%>
<% else%>
<span style=" font-weight:bold; color:#15bccf; margin-right:5px; background:none;"><%= l(:label_anonymous) %></span>
<% end %>
</span>
<span style="color:#a6a6a6; margin-right:30px; margin-left:10px;"><%= format_time(jour.created_on) %></span>
<span style="font-weight:bold; color:#a6a6a6; float: right;">
<% if show_score %>
<span style="float:left">
<%= l(:label_work_rating) %>
</span>
<div class="ping_star">
<% star = get_homework_score(jour.user,@homework)%>
<%= render :partial => 'homework_attach/show_static_star', :locals => {:start_score => star } %>
<% if !jours.nil? && jours.is_a?(Array)%>
<% jours.each do |jour| %>
<div class="ping_C">
<div class="ping_dispic">
<%= link_to image_tag(url_to_avatar(jour.user)) , user_path(jour.user), :target =>"_blank" %>
</div>
<% end %>
</span>
<div class="cl"></div>
<p><%= textilizable jour.notes%></p>
</div>
<div class="ping_disfoot">
<% ids = 'project_respond_form_'+ jour.id.to_s%>
<span>
<% if (jour.user==User.current|| User.current.admin?) && show_name && !show_score %>
<%= link_to(l(:label_bid_respond_delete), {:controller => 'homework_attach', :action => 'destroy_jour', :object_id => jour, :user_id => jour.user,:jour_id =>@homework.id },
<div class="ping_discon">
<div class="ping_distop">
<span>
<%= link_to jour.user, user_path(jour.user),:style => " font-weight:bold; color:#15bccf; margin-right:5px; background:none;", :target => "_blank"%>
</span>
<span style="color:#a6a6a6; margin-right:30px; margin-left:10px;">
<%= format_time(jour.created_on) %>
</span>
<div class="cl"></div>
<p><%= textilizable jour.notes%></p>
</div>
<div class="ping_disfoot">
<% ids = 'project_respond_form_'+ jour.id.to_s%>
<span>
<% if jour.user==User.current|| User.current.admin? %>
<%= link_to(l(:label_bid_respond_delete), {:controller => 'homework_attach', :action => 'destroy_jour', :object_id => jour, :user_id => jour.user,:jour_id =>homework.id },
:remote => true, :confirm => l(:text_are_you_sure), :title => l(:button_delete)) %>
<% end %>
<%= link_to l(:label_projects_feedback_respond),'',
{:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea'), ''); $('##{ids} textarea') ;return false;"} ##{l(:label_reply_plural)} #{jour.user.name}:
%>
<%= link_to l(:label_projects_feedback_respond),'',
{:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea'), ''); $('##{ids} textarea') ;return false;"}
%>
</span>
</div>
<div id='<%= ids %>' class="respond-form">
<%= render :partial => 'words/new_respond', :locals => {:journal => jour, :m_reply_id => jour,:show_name=> show_name} %>
</div>
<div style="clear: both;"></div>
<div>
<%= render :partial => "words/journal_reply", :locals => {:journal => jour,:show_name=> show_name} %>
</div>
</div>
<div class="cl"></div>
</div>
<div class="cl"></div>
<% end %>
<% if is_jour%>
<div class="dis">
<ul class="wlist"><%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => true, :flag => true%></ul>
</div>
</div>
<div id='<%= ids %>' class="respond-form">
<%= render :partial => 'words/new_respond', :locals => {:journal => jour, :m_reply_id => jour,:show_name=> true} %>
</div>
<div style="clear: both;"></div>
<div>
<%= render :partial => "words/journal_reply", :locals => {:journal => jour,:show_name=> true} %>
</div>
</div>
<div class="cl"></div>
</div>
<div class="cl"></div>
<div class="dis">
<ul class="wlist">
<%= pagination_links_full obj_pages, obj_count, :per_page_links => false, :remote => true, :flag => true%>
</ul>
</div>
<% end %>
<% end %>

View File

@ -0,0 +1,61 @@
<!-- 评论列表,包括老师评论和学生匿评 -->
<% if !review_list.nil?%>
<% review_list.each do |review|%>
<% user = review.rater %>
<% jour = get_homework_review @homework,@is_teacher,user %>
<div class="ping_C">
<div class="ping_dispic">
<% if show_name %>
<%= link_to image_tag(url_to_avatar(user)) , user_path(user), :target =>"_blank" %>
<% else %>
<a><%= image_tag(url_to_avatar(nil))%></a>
<% end %>
</div>
<div class="ping_discon">
<div class="ping_distop">
<span>
<% if show_name %>
<%= link_to user, user_path(user),:style => " font-weight:bold; color:#15bccf; margin-right:5px; background:none;", :target => "_blank"%>
<% else%>
<span style=" font-weight:bold; color:#15bccf; margin-right:5px; background:none;">
<%= l(:label_anonymous) %>
</span>
<% end %>
</span>
<span style="color:#a6a6a6; margin-right:30px; margin-left:10px;">
<%= format_time(review.created_at) %>
</span>
<span style="font-weight:bold; color:#a6a6a6; float: right;">
<span style="float:left">
<%= l(:label_work_rating) %>
</span>
<div class="ping_star">
<%= render :partial => 'homework_attach/show_static_star', :locals => {:start_score => review.stars } %>
</div>
</span>
<div class="cl"></div>
<p><%= textilizable jour.nil? ? "" : jour.notes%></p>
</div>
<% unless jour.nil? %>
<% ids = 'project_respond_form_'+ jour.id.to_s%>
<div class="ping_disfoot">
<span>
<%= link_to l(:label_projects_feedback_respond),'',
{:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea'), ''); $('##{ids} textarea') ;return false;"}
%>
</span>
</div>
<div id='<%= ids %>' class="respond-form">
<%= render :partial => 'words/new_respond', :locals => {:journal => jour, :m_reply_id => jour,:show_name=> show_name} %>
</div>
<div style="clear: both;"></div>
<div>
<%= render :partial => "words/journal_reply", :locals => {:journal => jour,:show_name=> show_name} %>
</div>
<% end %>
</div>
<div class="cl"></div>
</div>
<div class="cl"></div>
<% end %>
<% end %>

View File

@ -18,7 +18,7 @@
<ul>
<li><%= l(:label_create_person) %>
<span class="c_grey">
<% if @is_anonymous_comments && @is_comprehensive_evaluation != 1 %>
<% if @is_anonymous_comments %>
<%= l(:label_anonymous) %>
<% else %>
<%= link_to @homework.user, user_path(@homework.user)%>
@ -37,7 +37,7 @@
<% if @homework.users.count > 0 %>
<div>
<%= l(:label_participation_person) %>
<% if @is_anonymous_comments && @is_comprehensive_evaluation != 1 %>
<% if @is_anonymous_comments %>
<%= l(:label_anonymous) %>
<%else%>
<% @homework.users.each do |homework_user| %>
@ -77,8 +77,7 @@
</span>
</p>
<div id="add_jour">
<%= render :partial => 'addjour', :locals => {:homework_attach => @homework, :sta => 0,
:is_comprehensive_evaluation => @is_comprehensive_evaluation,
<%= render :partial => 'addjour', :locals => {:homework_attach => @homework,
:m_score => @m_score,
:cur_page => @cur_page,
:cur_type => @cur_type,
@ -88,6 +87,5 @@
</div><!---ping_con end--->
<%= render :partial => 'histoey_new' %>
</div>
</div>