添加“我的动态”

This commit is contained in:
cxt 2015-09-07 15:01:08 +08:00
parent d667e6359c
commit aa0c0dab83
6 changed files with 52 additions and 3 deletions

View File

@ -800,11 +800,13 @@ class UsersController < ApplicationController
@user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('created_at desc').limit(10).offset(@page * 10)
when "project_message"
@user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('created_at desc').limit(10).offset(@page * 10)
when "current_user"
@user_activities = UserActivity.where("user_id = #{User.current.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('created_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}").order('created_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})").order('created_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}").order('created_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})").order('created_at desc').limit(10).offset(@page * 10)
end
# @user_activities = paginateHelper @user_activities,500
@type = params[:type]

View File

@ -19,6 +19,7 @@ class CourseActivity < ActiveRecord::Base
user_activity.act_type = self.course_act_type
user_activity.container_type = "Course"
user_activity.container_id = self.course_id
user_activity.user_id = self.user_id
user_activity.save
end
end

View File

@ -29,6 +29,7 @@
<li>
<ul class="homepagePostTypeProject fl">
<li class="f14">更多</li>
<li class="mt-4"><%= link_to "我的动态", {:controller => "users", :action => "show", :type => "current_user"}, :class =>"homepagePostTypeAll postTypeGrey"%>
<li class="mt-4"><%= link_to "全部动态", {:controller => "users", :action => "show", :type => nil}, :class =>"homepagePostTypeAll postTypeGrey"%>
</ul>
</li>

View File

@ -0,0 +1,5 @@
class AddUserIdToUserActivities < ActiveRecord::Migration
def change
add_column :user_activities, :user_id, :int
end
end

View File

@ -0,0 +1,40 @@
class UpdateUserActivities < ActiveRecord::Migration
def up
count = UserActivity.all.count / 30 + 2
transaction do
for i in 1 ... count do i
UserActivity.page(i).per(30).each do |activity|
if activity.container_type.to_s == 'Project'
forge_activity = ForgeActivity.where("forge_act_type = '#{activity.act_type.to_s}' and forge_act_id = #{activity.act_id}").first
if forge_activity
activity.user_id = forge_activity.user_id
else
activity.user_id = 0
end
elsif activity.container_type.to_s == 'Course'
course_activity = CourseActivity.where("course_act_type = '#{activity.act_type.to_s}' and course_act_id = #{activity.act_id}").first
if course_activity
activity.user_id = course_activity.user_id
else
activity.user_id = 0
end
end
activity.save
end
end
end
end
def down
count = UserActivity.all.count / 30 + 2
transaction do
for i in 1 ... count do i
UserActivity.page(i).per(30).each do |activity|
activity.user_id = nil
activity.save
end
end
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20150906091045) do
ActiveRecord::Schema.define(:version => 20150907064547) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false