From 788e900d4afa91882fa9801116c70fc7dab0d50f Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Wed, 28 Oct 2015 10:58:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E5=8D=9A=E5=AE=A2=E5=8F=91?= =?UTF-8?q?=E5=8D=9A=E6=96=87=E4=B9=9F=E8=A6=81=E6=98=BE=E7=A4=BA=E5=8A=A8?= =?UTF-8?q?=E6=80=81=20=E4=B8=AA=E4=BA=BA=E5=8D=9A=E5=AE=A2=20=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E8=AE=BE=E7=BD=AE=E8=8F=9C=E5=8D=95=E8=A6=81=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E5=8D=9A=E5=AE=A2=E5=88=97=E8=A1=A8=E7=9A=84?= =?UTF-8?q?=E5=8F=B3=E4=B8=8A=E6=96=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/blog_comments_controller.rb | 3 + app/controllers/users_controller.rb | 13 ++- app/models/blog_comment.rb | 28 ++++- app/views/blog_comments/reply.js.erb | 7 +- app/views/blogs/_article.html.erb | 33 +++++- app/views/users/_user_activities.html.erb | 7 ++ app/views/users/_user_blog.html.erb | 119 ++++++++++++++++++++ 7 files changed, 203 insertions(+), 7 deletions(-) create mode 100644 app/views/users/_user_blog.html.erb diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index 95790a68d..f9cb3c3ad 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -89,6 +89,9 @@ class BlogCommentsController < ApplicationController #回复 def reply + if params[:in_user_center] + @in_user_center = true + end @article = BlogComment.find(params[:id]).root @quote = params[:quote][:quote] @blogComment = BlogComment.new diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6d049783e..175c8ce51 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -949,10 +949,19 @@ class UsersController < ApplicationController when "current_user" @user_activities = UserActivity.where("user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))").order('updated_at desc').limit(10).offset(@page * 10) else - @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) + blog_ids = "("+@user.blog.id.to_s+","+User.watched_by(@user.id).map{|u| u.blog.id}.join(',')+")" + @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) end else - @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) + # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) + blog_ids = "("+@user.blog.id.to_s+","+User.watched_by(@user.id).map{|u| u.blog.id}.join(',')+")" + @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) end # @user_activities = paginateHelper @user_activities,500 @type = params[:type] diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index 92970b663..9bb28ddd8 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -7,7 +7,8 @@ class BlogComment < ActiveRecord::Base acts_as_tree :counter_cache => :comments_count, :order => "#{BlogComment.table_name}.sticky desc ,#{BlogComment.table_name}.created_on ASC" acts_as_attachable belongs_to :last_reply, :class_name => 'BlogComment', :foreign_key => 'last_comment_id' - + # 虚拟关联 + has_many :user_acts, :class_name => 'UserAcivity',:as =>:act acts_as_watchable validates_presence_of :title, :content @@ -15,6 +16,31 @@ class BlogComment < ActiveRecord::Base #validate :cannot_reply_to_locked_comment, :on => :create safe_attributes 'title', 'content',"sticky", "locked" + after_save :add_user_activity + before_destroy :destroy_user_activity + + #在个人动态里面增加当前动态 + def add_user_activity + if self.parent_id.nil? #只有发博文才插入动态 + user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'").first + if user_activity + user_activity.save + else + user_activity = UserActivity.new + user_activity.act_id = self.id + user_activity.act_type = self.class.to_s + user_activity.container_type = "Blog" + user_activity.container_id = self.blog_id + user_activity.user_id = self.author_id + user_activity.save + end + end + end + + def destroy_user_activity + user_activity = UserActivity.where("act_type = '#{self.class.to_s}' and act_id = '#{self.id}'") + user_activity.destroy_all + end def deleted_attach_able_by? user (user && user.logged? && (self.author == user) ) || user.admin? end diff --git a/app/views/blog_comments/reply.js.erb b/app/views/blog_comments/reply.js.erb index 7ebe4d077..f8ed4bb24 100644 --- a/app/views/blog_comments/reply.js.erb +++ b/app/views/blog_comments/reply.js.erb @@ -1,2 +1,7 @@ +<% if @in_user_center%> + $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/user_blog', :locals => {:activity => @article,:user_activity_id =>@user_activity_id}) %>"); + init_activity_KindEditor_data(<%= @user_activity_id%>,"","87%"); +<% else%> $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'blogs/article', :locals => {:activity => @article,:user_activity_id =>@user_activity_id,:first_user_activity =>@first_user_activity,:page => @page}) %>"); -init_activity_KindEditor_data(<%= @user_activity_id%>,"","87%"); \ No newline at end of file +init_activity_KindEditor_data(<%= @user_activity_id%>,"","87%"); +<% end %> \ No newline at end of file diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index 943d21852..33a3201c0 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -1,10 +1,36 @@ -
-
+
+
<%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id,:host=>Setting.host_user), :alt => "用户头像" %>
-
+ <% if activity.author.id == User.current.id%> + + <%end%> +
<% if activity.try(:author).try(:realname) == ' ' %> <%= link_to activity.try(:author), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> <% else %> @@ -13,6 +39,7 @@ TO <%= link_to activity.blog.name+" | 博客", user_blogs_path(:user_id=>activity.author_id,:host=>Setting.host_user), :class => "newsBlue ml15 mr5"%>
+