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

View File

@ -91,6 +91,11 @@ module HomeworkAttachHelper
@m_score = temp.nil? ? 0:temp.stars.to_i @m_score = temp.nil? ? 0:temp.stars.to_i
end 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 def convert_array array
ary = "(" ary = "("
if array.nil? || array.count == 0 if array.nil? || array.count == 0

View File

@ -1,35 +1,4 @@
<style> <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 { textarea:focus {
border: #d5dee9 1px solid; border: #d5dee9 1px solid;
} }
@ -61,16 +30,13 @@
<%= form_for('new_form', :remote => true, :method => :post, <%= form_for('new_form', :remote => true, :method => :post,
:url => {:controller => 'homework_attach', :url => {:controller => 'homework_attach',
:action => 'addjours', :action => 'addjours',
:jour_id => homework_attach.id, :homework_id => homework_attach.id,
:is_comprehensive_evaluation => is_comprehensive_evaluation,
:cur_page => cur_page, :cur_page => cur_page,
:cur_type => cur_type, :cur_type => cur_type
:sta => sta}) do |f|%> }) do |f|%>
<!-- 打分 --> <!-- 打分 -->
<div class="ping_star" id="star_score"> <div class="ping_star" id="star_score">
<% if @is_comprehensive_evaluation == 3 || User.current == homework_attach.user%> <% if @is_anonymous_comments || @is_teacher %>
<!-- 如果是留言,或者是作业创建者进入,不显示打星 -->
<% else @is_comprehensive_evaluation == 2 %>
<!-- 学生匿评或者教师评价 --> <!-- 学生匿评或者教师评价 -->
<%= l(:label_work_rating) %> <%= l(:label_work_rating) %>
<%= render :partial => 'show_star',:locals => {start_score:m_score} %> <%= render :partial => 'show_star',:locals => {start_score:m_score} %>
@ -79,18 +45,13 @@
<div class="cl"></div> <div class="cl"></div>
<!-- 打分js结束 --> <!-- 打分js结束 -->
<div id = 'pre_show'>
<%= render :partial => 'words/pre_show', :locals => {:content => @content} %>
</div>
<% if User.current.logged? %> <% if User.current.logged? %>
<%= f.text_area 'user_message', :rows => 3, :cols => 65, <%= f.text_area 'user_message', :rows => 3, :cols => 65,
:style => "resize: none;", :class => 'noline', :placeholder => l(:text_caracters_maximum,:count=>250), :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"%> <%= f.text_field :reference_user_id, :style=>"display:none"%>
<div style="float:right"> <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) %> <%= l(:label_confirmation) %>
</a> </a>
</div> </div>

View File

@ -1,24 +1,45 @@
<div class="ping_list"> <div class="ping_list">
<div id="ping_tb_" class="ping_tb_"> <div id="ping_tb_" class="ping_tb_">
<ul> <ul>
<li id="ping_tb_4" class="ping_normaltab" onclick="i:HoverLi(4);"> <li id="ping_tb_4" class="ping_normaltab" onclick="HoverLi(4);">
<%= l(:label_teacher_comments) %><span class="c_red" id="jour_count_4"><%= @comprehensive_evaluation.nil? ? 0 : @comprehensive_evaluation.count %></span></li> <%= l(:label_teacher_comments) %>
<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> <span class="c_red" id="jour_count_4">
<li id="ping_tb_3" class="ping_hovertab" onclick="x:HoverLi(3);"> <%= @teacher_stars.count %>
<%= l(:label_responses) %><span class="c_red" id="jour_count_3"><%= @jours.nil? ? 0 : @jours.count %></span></li> </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> </ul>
</div> </div>
<div class="cl"></div> <div class="cl"></div>
<div class="ping_ctt"> <div class="ping_ctt">
<div class="ping_dis" id="tbc_03"> <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>
<div class="ping_undis" id="tbc_04"> <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>
<div class="ping_undis" id="tbc_05"> <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> </div>
</div><!---ping_list end---> </div><!---ping_list end--->

View File

@ -1,33 +1,16 @@
<% jours.nil? || jours.count == 0 || jours.each do |jour| %> <% if !jours.nil? && jours.is_a?(Array)%>
<% jours.each do |jour| %>
<div class="ping_C"> <div class="ping_C">
<div class="ping_dispic"> <div class="ping_dispic">
<% if show_name %>
<%= link_to image_tag(url_to_avatar(jour.user)) , user_path(jour.user), :target =>"_blank" %> <%= 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>
<div class="ping_discon"> <div class="ping_discon">
<div class="ping_distop"> <div class="ping_distop">
<span> <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"%> <%= 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>
<span style="color:#a6a6a6; margin-right:30px; margin-left:10px;"><%= format_time(jour.created_on) %></span> <span style="color:#a6a6a6; margin-right:30px; margin-left:10px;">
<span style="font-weight:bold; color:#a6a6a6; float: right;"> <%= format_time(jour.created_on) %>
<% 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 } %>
</div>
<% end %>
</span> </span>
<div class="cl"></div> <div class="cl"></div>
<p><%= textilizable jour.notes%></p> <p><%= textilizable jour.notes%></p>
@ -35,31 +18,30 @@
<div class="ping_disfoot"> <div class="ping_disfoot">
<% ids = 'project_respond_form_'+ jour.id.to_s%> <% ids = 'project_respond_form_'+ jour.id.to_s%>
<span> <span>
<% if (jour.user==User.current|| User.current.admin?) && show_name && !show_score %> <% 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 }, <%= 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)) %> :remote => true, :confirm => l(:text_are_you_sure), :title => l(:button_delete)) %>
<% end %> <% end %>
<%= link_to l(:label_projects_feedback_respond),'', <%= 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}: {:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea'), ''); $('##{ids} textarea') ;return false;"}
%> %>
</span> </span>
</div> </div>
<div id='<%= ids %>' class="respond-form"> <div id='<%= ids %>' class="respond-form">
<%= render :partial => 'words/new_respond', :locals => {:journal => jour, :m_reply_id => jour,:show_name=> show_name} %> <%= render :partial => 'words/new_respond', :locals => {:journal => jour, :m_reply_id => jour,:show_name=> true} %>
</div> </div>
<div style="clear: both;"></div> <div style="clear: both;"></div>
<div> <div>
<%= render :partial => "words/journal_reply", :locals => {:journal => jour,:show_name=> show_name} %> <%= render :partial => "words/journal_reply", :locals => {:journal => jour,:show_name=> true} %>
</div> </div>
</div> </div>
<div class="cl"></div> <div class="cl"></div>
</div> </div>
<div class="cl"></div> <div class="cl"></div>
<% end %>
<% if is_jour%>
<div class="dis"> <div class="dis">
<ul class="wlist"><%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => true, :flag => true%></ul> <ul class="wlist">
<%= pagination_links_full obj_pages, obj_count, :per_page_links => false, :remote => true, :flag => true%>
</ul>
</div> </div>
<% end %> <% 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> <ul>
<li><%= l(:label_create_person) %> <li><%= l(:label_create_person) %>
<span class="c_grey"> <span class="c_grey">
<% if @is_anonymous_comments && @is_comprehensive_evaluation != 1 %> <% if @is_anonymous_comments %>
<%= l(:label_anonymous) %> <%= l(:label_anonymous) %>
<% else %> <% else %>
<%= link_to @homework.user, user_path(@homework.user)%> <%= link_to @homework.user, user_path(@homework.user)%>
@ -37,7 +37,7 @@
<% if @homework.users.count > 0 %> <% if @homework.users.count > 0 %>
<div> <div>
<%= l(:label_participation_person) %> <%= l(:label_participation_person) %>
<% if @is_anonymous_comments && @is_comprehensive_evaluation != 1 %> <% if @is_anonymous_comments %>
<%= l(:label_anonymous) %> <%= l(:label_anonymous) %>
<%else%> <%else%>
<% @homework.users.each do |homework_user| %> <% @homework.users.each do |homework_user| %>
@ -77,8 +77,7 @@
</span> </span>
</p> </p>
<div id="add_jour"> <div id="add_jour">
<%= render :partial => 'addjour', :locals => {:homework_attach => @homework, :sta => 0, <%= render :partial => 'addjour', :locals => {:homework_attach => @homework,
:is_comprehensive_evaluation => @is_comprehensive_evaluation,
:m_score => @m_score, :m_score => @m_score,
:cur_page => @cur_page, :cur_page => @cur_page,
:cur_type => @cur_type, :cur_type => @cur_type,
@ -88,6 +87,5 @@
</div><!---ping_con end---> </div><!---ping_con end--->
<%= render :partial => 'histoey_new' %> <%= render :partial => 'histoey_new' %>
</div> </div>
</div> </div>