User Summary improvements

Added "Top Links" list
Added "Most Liked By" list

Added "Bookmark count" stat

UX: Use fa heart icon instead of "like" text in stats

Change the order of the user stats
This commit is contained in:
Régis Hanol 2016-04-13 23:02:51 +02:00
parent b0803f7035
commit e808f7f41e
6 changed files with 143 additions and 23 deletions
app/models

View file

@ -2,8 +2,8 @@
class UserSummary
MAX_SUMMARY_RESULTS = 6
MAX_BADGES = 6
MAX_TOPICS = 6
alias :read_attribute_for_serialization :send
@ -20,7 +20,7 @@ class UserSummary
.where(user: @user)
.order('like_count DESC, created_at ASC')
.includes(:user, :category)
.limit(MAX_TOPICS)
.limit(MAX_SUMMARY_RESULTS)
end
def replies
@ -33,7 +33,47 @@ class UserSummary
.where('post_number > 1')
.where('topics.archetype <> ?', Archetype.private_message)
.order('posts.like_count DESC, posts.created_at ASC')
.limit(MAX_TOPICS)
.limit(MAX_SUMMARY_RESULTS)
end
def links
TopicLink
.where(user: @user)
.where(internal: false)
.where(reflection: false)
.order('clicks DESC, created_at ASC')
.limit(MAX_SUMMARY_RESULTS)
end
class LikedByUser < OpenStruct
include ActiveModel::SerializerSupport
end
def most_liked_by_users
likers_ids = []
counts = []
UserAction.where(user: @user)
.where(action_type: UserAction::WAS_LIKED)
.group(:acting_user_id)
.order("COUNT(*) DESC")
.limit(MAX_SUMMARY_RESULTS)
.pluck("acting_user_id, COUNT(*)")
.each do |i|
likers_ids << i[0]
counts << i[1]
end
User.where(id: likers_ids)
.pluck(:id, :username, :name, :uploaded_avatar_id)
.map.with_index do |u, i|
LikedByUser.new(
id: u[0],
username: u[1],
name: u[2],
avatar_template: User.avatar_template(u[1], u[3]),
likes: counts[i]
)
end
end
def badges
@ -44,6 +84,13 @@ class UserSummary
@user.user_stat
end
def bookmark_count
UserAction
.where(user: @user)
.where(action_type: UserAction::BOOKMARK)
.count
end
delegate :likes_given,
:likes_received,
:days_visited,