1.整理踩、赞页面代码

2.增加作业点赞功能
3.作业列表界面增加是否已经点赞判断
This commit is contained in:
sw 2014-11-02 09:39:18 +08:00
parent 2ac89fcdbc
commit 8a7757f3c2
7 changed files with 121 additions and 71 deletions

View File

@ -8,7 +8,7 @@ class HomeworkAttachController < ApplicationController
#判断当前角色权限时需先找到当前操作的project
before_filter :find_course_by_bid_id, :only => [:new]
before_filter :find_bid_and_course,:only => [:get_not_batch_homework,:get_batch_homeworks,:get_homeworks,:get_homework_jours, :get_student_batch_homework, :get_my_homework]
before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users]
before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users, :praise_homework]
#判断当前角色是否有操作权限
#勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy]
@ -121,6 +121,25 @@ class HomeworkAttachController < ApplicationController
end
end
#为作业点赞
def praise_homework
pt = PraiseTread.new
pt.user_id = User.current.id
pt.praise_tread_object_id = @homework.id
pt.praise_tread_object_type = "HomeworkAttach"
pt.praise_or_tread = 1
@is_my_homework = params[:is_my_homework]
@is_student_batch_homework = params[:is_student_batch_homework]
@is_teacher = params[:is_teacher]
if pt.save
respond_to do |format|
format.js
end
else
render_404
end
end
#获取作业的成员
def get_homework_member homework
@hoemwork_users = users_for_homework(@homework)

View File

@ -74,4 +74,14 @@ module HomeworkAttachHelper
end
type
end
#判断指定用户是不是已经赞过该作业
def is_praise_homework user_id, obj_id
PraiseTread.where("user_id = #{user_id} AND praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'HomeworkAttach'").empty?
end
#获取赞的总数
def praise_homework_count obj_id
PraiseTread.where("praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'HomeworkAttach'").count
end
end

View File

@ -47,7 +47,7 @@
<div class="cl"></div>
<div class="ctt">
<div class="dis" id="tbc_01">
<%= render :partial => 'homework_attach/homeworks_list', :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => false, :is_student_batch_homework => @is_student_batch_homework}%>
<%= render :partial => 'homework_attach/homeworks_list', :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :remote => false, :is_student_batch_homework => @is_student_batch_homework}%>
</div>
</div>
</div>

View File

@ -0,0 +1,81 @@
<li class="pic_head">
<%= link_to image_tag(url_to_avatar(homework.user), :width => "40", :height => "40"), user_path(homework.user) %>
<span>
<% user_realname = homework.user.lastname.to_s + homework.user.firstname.to_s %>
<% user_name = is_teacher ? (user_realname.empty? ? homework.user.login : user_realname) : homework.user.login %>
<%= link_to user_name, user_path(homework.user), :title => user_name %>
</span>
</li>
<li class="wname">
<% if homework.name == nil || homework.name == "" %>
<% homework_filename = homework.user.name + "提交的作业" %>
<% else %>
<% homework_filename = homework.name %>
<% end %>
<%= link_to homework_filename , homework_attach_path(homework), :title => homework_filename, :remote => true%>
</li>
<li class="wdown">
<%= link_to "(#{homework.attachments.count.to_s}个附件)", zipdown_download_user_homework_path(:homework => homework)%>
</li>
<li class="wscore">
<%= l(:label_teacher_score)%>:
<span class="c_red">
<%= homework.t_score.nil? ? l(:label_without_score) : format("%.2f",homework.t_score)%>
</span>
&nbsp;&nbsp;
</li>
<li class="wscore">
<%= l(:label_student_score)%>:
<span class="c_red">
<%= homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score) %>
</span>
</li>
<% if is_teacher %>
<!-- 是老师,所有列表正常显示 -->
<li class="wping">
<%= link_to l(:label_work_rating),homework_attach_path(homework),:remote => true %>
<% if Time.parse(@bid.deadline.to_s).strftime("%Y-%m-%d") < Time.parse(homework.created_at.to_s).strftime("%Y-%m-%d") %>
<span class="c_red">&nbsp;&nbsp;迟交!</span>
<% end %>
</li>
<% else %>
<!-- 是学生 -->
<% if is_my_homework %>
<!-- 我的作品,显示为编辑和删除 -->
<li class="wmine">
<%= link_to l(:button_edit), edit_homework_attach_path(homework) %>
<% if homework.user == User.current || User.current.admin? %>
<%= link_to(l(:label_bid_respond_delete), homework,
method: :delete, :confirm => l(:text_are_you_sure), :remote => true ) %>
<% end %>
</li>
<% elsif is_student_batch_homework%>
<!-- 学生匿评列表,正常显示 -->
<li class="wping">
<%= link_to l(:label_work_rating),homework_attach_path(homework),:remote => true %>
<% if Time.parse(@bid.deadline.to_s).strftime("%Y-%m-%d") < Time.parse(homework.created_at.to_s).strftime("%Y-%m-%d") %>
<span class="c_red">&nbsp;&nbsp;迟交!</span>
<% end %>
</li>
<% else %>
<!-- 学生众评列表,显示为点赞 -->
<% if is_praise_homework User.current.id,homework.id %>
<li class="wzan" title="点赞">
<%= link_to "",praise_homework_homework_attach_path(homework,:is_my_homework => is_my_homework,
:is_student_batch_homework => is_student_batch_homework,
:is_teacher => is_teacher),
:class => "wzan_img wzan_visited", :remote => true%>
<a>
<%= praise_homework_count homework.id %>
</a>
</li>
<% else %>
<li class="wzan" title="您已经赞过该作业">
<a href="#" target="_blank" class="wzan_img"></a>
<a>
<%= praise_homework_count homework.id %>
</a>
</li>
<% end %>
<% end %>
<% end %>

View File

@ -40,75 +40,10 @@
<% end %>
<% homeworks.each do |homework| %>
<ul>
<li class="pic_head">
<%= link_to image_tag(url_to_avatar(homework.user), :width => "40", :height => "40"), user_path(homework.user) %>
<span>
<% user_realname = homework.user.lastname.to_s + homework.user.firstname.to_s %>
<% user_name = is_teacher ? (user_realname.empty? ? homework.user.login : user_realname) : homework.user.login %>
<%= link_to user_name, user_path(homework.user), :title => user_name %>
</span>
</li>
<li class="wname">
<% if homework.name == nil || homework.name == "" %>
<% homework_filename = homework.user.name + "提交的作业" %>
<% else %>
<% homework_filename = homework.name %>
<% end %>
<%= link_to homework_filename , homework_attach_path(homework), :title => homework_filename, :remote => true%>
</li>
<li class="wdown">
<%= link_to "(#{homework.attachments.count.to_s}个附件)", zipdown_download_user_homework_path(:homework => homework)%>
</li>
<li class="wscore">
<%= l(:label_teacher_score)%>:
<span class="c_red">
<%= homework.t_score.nil? ? l(:label_without_score) : format("%.2f",homework.t_score)%>
</span>
&nbsp;&nbsp;
</li>
<li class="wscore">
<%= l(:label_student_score)%>:
<span class="c_red">
<%= homework.s_score.nil? ? l(:label_without_score) : format("%.2f",homework.s_score) %>
</span>
</li>
<% if is_teacher %>
<!-- 是老师,所有列表正常显示 -->
<li class="wping">
<%= link_to l(:label_work_rating),homework_attach_path(homework),:remote => true %>
<% if Time.parse(bid.deadline.to_s).strftime("%Y-%m-%d") < Time.parse(homework.created_at.to_s).strftime("%Y-%m-%d") %>
<span class="c_red">&nbsp;&nbsp;迟交!</span>
<% end %>
</li>
<% else %>
<!-- 是学生 -->
<% if is_my_homework %>
<!-- 我的作品,显示为编辑和删除 -->
<li class="wmine">
<%= link_to l(:button_edit), edit_homework_attach_path(homework) %>
<% if homework.user == User.current || User.current.admin? %>
<%= link_to(l(:label_bid_respond_delete), homework,
method: :delete, :confirm => l(:text_are_you_sure), :remote => true ) %>
<% end %>
</li>
<% elsif is_student_batch_homework%>
<!-- 学生匿评列表,正常显示 -->
<li class="wping">
<%= link_to l(:label_work_rating),homework_attach_path(homework),:remote => true %>
<% if Time.parse(bid.deadline.to_s).strftime("%Y-%m-%d") < Time.parse(homework.created_at.to_s).strftime("%Y-%m-%d") %>
<span class="c_red">&nbsp;&nbsp;迟交!</span>
<% end %>
</li>
<% else %>
<!-- 学生众评列表,显示为点赞 -->
<li class="wzan" title="点赞">
<a href="#" target="_blank" class="wzan_img wzan_visited">
</a>
<a href="#" target="_blank">15</a>
</li>
<% end %>
<% end %>
<ul id="homework_li_<%= homework.id%>">
<%= render :partial => 'homework_attach/homework',
:locals => {:homework => homework, :is_student_batch_homework => is_student_batch_homework,
:is_my_homework => is_my_homework, :is_teacher => is_teacher}%>
</ul>
<div class="cl"></div>
<% end %>

View File

@ -0,0 +1,4 @@
$('#homework_li_<%= @homework.id%>').
html('<%= escape_javascript(render :partial => 'homework_attach/homework',
:locals => {:homework => @homework, :is_student_batch_homework => @is_student_batch_homework,
:is_my_homework => @is_my_homework, :is_teacher => @is_teacher})%>');

View File

@ -54,6 +54,7 @@ RedmineApp::Application.routes.draw do
member do
match 'add_homework_users', :via => [:get,:post]
match 'destory_homework_users', :via => [:get,:post]
get 'praise_homework'
end
end