diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ee3aba32d..6ec900d1b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1995,6 +1995,61 @@ class UsersController < ApplicationController # 项目社区 def project_community + # 看别人的主页显示动态 + #更新用户申请成为课程老师或教辅消息的状态 + shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id) + @page = params[:page] ? params[:page].to_i + 1 : 0 + user_project_ids = (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" + project_types = "('Message','Issue','Project')" + principal_types = "JournalsForMessage" + container_type = '' + act_type = '' + if params[:type].present? + case params[:type] + when "project_issue" + container_type = 'Project' + act_type = 'Issue' + when "project_message" + container_type = 'Project' + act_type = 'Message' + when "user_journals" + container_type = 'Principal' + act_type = 'JournalsForMessage' + when "current_user" + container_type = 'Principal' + act_type = 'Principal' + when "all" + container_type = 'all' + act_type = 'all' + end + end + if container_type != '' && container_type != 'all' + if container_type == 'Project' + sql = "container_type = '#{container_type}' and container_id in #{user_project_ids} and act_type = '#{act_type}'" + elsif container_type == 'Principal' && act_type == 'JournalsForMessage' + sql = "container_type = '#{container_type}' and act_type= '#{act_type}' and container_id = #{@user.id}" + elsif container_type == 'Principal' && act_type == 'Principal' + sql = "user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}))" + end + if User.current != @user + sql += " and user_id = #{@user.id}" + end + else + if User.current != @user + blog_ids = "("+@user.blog.id.to_s+")" + else + blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" + end + sql = "(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_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})" + if container_type != 'all' && User.current != @user + sql = "user_id = #{@user.id} and(" + sql + ")" + end + end + @user_activities_count = UserActivity.where("#{sql}").order('updated_at desc').count + @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) + @type = params[:type] respond_to do |format| format.js format.html {render :layout => 'base_project_community'} @@ -3792,7 +3847,7 @@ class UsersController < ApplicationController @my_joined_projects_count = @my_joined_projects.count respond_to do |format| - format.html {render :layout => 'new_base_user'} + format.html {render :layout => 'base_project_community'} end end diff --git a/app/views/users/_user_activities.html.erb b/app/views/users/_user_activities.html.erb index eccae0059..8675cb9e7 100644 --- a/app/views/users/_user_activities.html.erb +++ b/app/views/users/_user_activities.html.erb @@ -109,7 +109,8 @@ - <%= link_to "点击展开更多",user_activities_path(@user.id,:type => type,:page => page),:id => "show_more_activities",:remote => "true",:class => "loadMore mt10 f_grey"%> + <%= link_to "点击展开更多", action == "project_community" ? user_project_community_path(@user.id, :type => type, :page => page) : user_course_community_path(@user.id, :type => type,:page => page), + :id => "show_more_activities", :remote => "true", :class => "loadMore mt10 f_grey" %> <% end%> +<%# if @user.blog.homepage_id and BlogComment.where("id=?", @user.blog.homepage_id).count > 0 %> +<%# homepage = BlogComment.find(@user.blog.homepage_id) %> +<%#= render :partial => 'blogs/homepage', :locals => {:activity => homepage, :user_activity_id => homepage.id} %> +<%# end %> +<% if @user_activities_count > 0 %> + <%= render :partial => 'users/user_activities', :locals => { :user_activities => @user_activities, :page => 0, :type => @type, + :user_id => (@user.type == "AnonymousUser" ? User.current.id : @user.id), :action => params[:action] } %> +<% else %> +
+ <%= render :partial => 'users/no_data' %> +
+<% end %> diff --git a/app/views/users/project_community.js.erb b/app/views/users/project_community.js.erb new file mode 100644 index 000000000..e3fda3f6e --- /dev/null +++ b/app/views/users/project_community.js.erb @@ -0,0 +1,6 @@ +$("#show_more_activities").replaceWith("<%= escape_javascript( render :partial => 'users/user_activities', + :locals => {:user_activities => @user_activities, + :page => @page, + :type => @type, + :user_id => (@user.type == "AnonymousUser" ? User.current.id : @user.id), + :action => "project_community"} )%>"); \ No newline at end of file