From b73aab1cf6a83e4514edd2794a88cfe9101e9458 Mon Sep 17 00:00:00 2001 From: cxt Date: Wed, 13 Jan 2016 16:32:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E8=AE=A8=E8=AE=BA=E5=8C=BA?= =?UTF-8?q?=E7=9A=84=E7=82=B9=E8=B5=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/praise_tread_controller.rb | 34 ++++++++----- app/views/praise_tread/_praise.html.erb | 7 +++ app/views/praise_tread/praise_minus.js.erb | 13 +++-- app/views/praise_tread/praise_plus.js.erb | 5 ++ app/views/users/_course_message.html.erb | 59 ++++++++++++---------- config/routes.rb | 1 + 6 files changed, 77 insertions(+), 42 deletions(-) diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index acfd785d9..be8cbc9a6 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -6,38 +6,46 @@ class PraiseTreadController < ApplicationController def praise_plus @obj = nil # @is_in_list = nil - if request.get? + if @pt = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id).first + + end + if request.get? @obj_id = params[:obj_id] @obj_type = params[:obj_type] - @horizontal = params[:horizontal].downcase == "false" ? false:true + #@horizontal = params[:horizontal].downcase == "false" ? false:true @obj = find_object_by_type_and_id(@obj_type,@obj_id) unless @obj.author_id == User.current.id praise_tread_plus(@obj_type,@obj_id,1) end - + @user_activity_id = params[:user_activity_id] if params[:user_activity_id] + @type = params[:type] if params[:type] end end def praise_minus @obj = nil if request.get? - @obj = params[:obj] # 传的是对象,最后变成id了 - + #@obj = params[:obj] # 传的是对象,最后变成id了 + @obj_id = params[:obj_id] + @obj_type = params[:obj_type] #首先更新praise_tread 表 删除关注记录 - @pt = PraiseTread.find_by_user_id_and_praise_tread_object_id_and_praise_tread_object_type(User.current.id,@obj,"user") - @pt.delete + #@pt = PraiseTread.find_by_user_id_and_praise_tread_object_id_and_praise_tread_object_type(User.current.id,@obj,"user") + @pt = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id).first + @pt.delete if !@pt.nil? #再更新praise_tread_cache表 使相应的记录减1 当为0时删除 - @ptc = PraiseTreadCache.find_by_object_id(@obj) - @ptc.minus(1) + @ptc = PraiseTreadCache.where("object_id=? and object_type=?",@obj_id,@obj_type.to_s).first + @ptc.minus(1) if !@ptc.nil? if @ptc.praise_num == 0 - @ptc.delete + @ptc.delete end end - @obj = User.find_by_id(@obj) + #@obj = User.find_by_id(@obj) + @obj = find_object_by_type_and_id(@obj_type,@obj_id) + @user_activity_id = params[:user_activity_id] if params[:user_activity_id] + @type = params[:type] if params[:type] respond_to do |format| - format.html format.js end end @@ -48,7 +56,7 @@ class PraiseTreadController < ApplicationController if request.get? @obj_id = params[:obj_id] @obj_type = params[:obj_type] - @horizontal = params[:horizontal].downcase == "false" ? false:true + #@horizontal = params[:horizontal].downcase == "false" ? false:true @obj = find_object_by_type_and_id(@obj_type,@obj_id) unless @obj.author_id == User.current.id praise_tread_plus(@obj_type,@obj_id,0) diff --git a/app/views/praise_tread/_praise.html.erb b/app/views/praise_tread/_praise.html.erb index e69de29bb..9059f1628 100644 --- a/app/views/praise_tread/_praise.html.erb +++ b/app/views/praise_tread/_praise.html.erb @@ -0,0 +1,7 @@ +<% if PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",activity.id,activity.class.to_s,User.current.id).empty? %> + + <%= get_praise_num(activity) > 0 ? "(#{get_praise_num(activity)})" : "" %> +<% else %> + + <%= get_praise_num(activity) > 0 ? "(#{get_praise_num(activity)})" : "" %> +<% end %> \ No newline at end of file diff --git a/app/views/praise_tread/praise_minus.js.erb b/app/views/praise_tread/praise_minus.js.erb index ab298ba2e..63efe303c 100644 --- a/app/views/praise_tread/praise_minus.js.erb +++ b/app/views/praise_tread/praise_minus.js.erb @@ -1,3 +1,10 @@ -$('#praise_tread').html('<%= j( -render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:show_flag => false,:user_id => User.current.id,:horizontal=>@horizontal} -)%>'); +<% if @user_activity_id %> + <% if @type.to_s == 'activity' %> + $('#praise_count_<%=@user_activity_id %>').html('<%= j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>'); + <% else %> + <% end %> +<% else %> + $('#praise_tread').html('<%= j( + render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:show_flag => false,:user_id => User.current.id,:horizontal=>@horizontal} + )%>'); +<% end %> \ No newline at end of file diff --git a/app/views/praise_tread/praise_plus.js.erb b/app/views/praise_tread/praise_plus.js.erb index 30a53723e..30b28fff1 100644 --- a/app/views/praise_tread/praise_plus.js.erb +++ b/app/views/praise_tread/praise_plus.js.erb @@ -2,6 +2,11 @@ $('#praise_tread_<%= @obj.id %>').html('<%= j( render :partial => "/memos/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id,:horizontal => @horizontal} )%>'); +<% elsif @user_activity_id %> + <% if @type.to_s == 'activity' %> + $('#praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>'); + <% else %> + <% end %> <% else %> $('#praise_tread_<%= @obj.id %>').html('<%= j( render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id,:horizontal => @horizontal} diff --git a/app/views/users/_course_message.html.erb b/app/views/users/_course_message.html.erb index 21a3ff076..21bf87c9b 100644 --- a/app/views/users/_course_message.html.erb +++ b/app/views/users/_course_message.html.erb @@ -22,7 +22,7 @@ <% end %> <% if activity.sticky == 1%> - 置顶 + 置顶 <% end%> <% if activity.locked%>        @@ -92,11 +92,17 @@ <% count=activity.children.count%> <% end %>
-
-
-
回复( - <%= count %> - )
+
+
回复 + <%= count>0 ? "(#{count})" : "" %>▪ + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
<%#=format_date(activity.updated_on)%>
<%if count > 3 %>
@@ -114,9 +120,9 @@
    <% activity.children.reorder("created_on desc").each do |reply|%> <% replies_all_i=replies_all_i+1 %>
  • @@ -131,6 +137,7 @@ <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> <% end %> <%= format_time(reply.created_on) %> +
<%= reply.content.html_safe %> @@ -144,26 +151,26 @@ <% end %> <% if !activity.locked? && authorize_for_course('messages', 'reply') %> -
-
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
-
-
- <%= form_for('new_form',:url => {:controller=>'messages',:action => 'reply', :id => activity.id, :board_id => activity.board_id, :is_board => is_board,is_course=>is_course},:method => "post", :remote => true) do |f|%> - - - -
- +
+
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
+
+
+ <%= form_for('new_form',:url => {:controller=>'messages',:action => 'reply', :id => activity.id, :board_id => activity.board_id, :is_board => is_board,is_course=>is_course},:method => "post", :remote => true) do |f|%> + + + +
+ +
+

+ <% end%>
-

- <% end%> +
+
+
-
-
-
-
- <% end %> + <% end %>