diff --git a/app/assets/javascripts/discourse/controllers/user-summary.js.es6 b/app/assets/javascripts/discourse/controllers/user-summary.js.es6 index b40d027b605..d41962d96ca 100644 --- a/app/assets/javascripts/discourse/controllers/user-summary.js.es6 +++ b/app/assets/javascripts/discourse/controllers/user-summary.js.es6 @@ -1,7 +1,7 @@ import computed from 'ember-addons/ember-computed-decorators'; -// should be kept in sync with 'UserSummary::MAX_TOPICS' -const MAX_TOPICS = 6; +// should be kept in sync with 'UserSummary::MAX_SUMMARY_RESULTS' +const MAX_SUMMARY_RESULTS = 6; // should be kept in sync with 'UserSummary::MAX_BADGES' const MAX_BADGES = 6; @@ -10,10 +10,10 @@ export default Ember.Controller.extend({ user: Ember.computed.alias('controllers.user.model'), @computed("model.topics.length") - moreTopics(topicsLength) { return topicsLength >= MAX_TOPICS; }, + moreTopics(topicsLength) { return topicsLength >= MAX_SUMMARY_RESULTS; }, @computed("model.replies.length") - moreReplies(repliesLength) { return repliesLength >= MAX_TOPICS; }, + moreReplies(repliesLength) { return repliesLength >= MAX_SUMMARY_RESULTS; }, @computed("model.badges.length") moreBadges(badgesLength) { return badgesLength >= MAX_BADGES; }, diff --git a/app/assets/javascripts/discourse/templates/user/summary.hbs b/app/assets/javascripts/discourse/templates/user/summary.hbs index e59658a628d..9b0b02bae7e 100644 --- a/app/assets/javascripts/discourse/templates/user/summary.hbs +++ b/app/assets/javascripts/discourse/templates/user/summary.hbs @@ -1,21 +1,22 @@

{{i18n "user.summary.stats"}}

-
+

{{i18n "user.summary.top_replies"}}

{{#if model.replies.length}}
    @@ -42,7 +43,7 @@

    {{i18n "user.summary.no_replies"}}

    {{/if}}
-
+

{{i18n "user.summary.top_topics"}}

{{#if model.topics.length}}
    @@ -71,6 +72,51 @@
+
+ + +
+

{{i18n "user.summary.top_badges"}}

{{#each badge in model.badges}} diff --git a/app/assets/stylesheets/common/base/user.scss b/app/assets/stylesheets/common/base/user.scss index c7dacb7082e..fd06ec67957 100644 --- a/app/assets/stylesheets/common/base/user.scss +++ b/app/assets/stylesheets/common/base/user.scss @@ -199,7 +199,9 @@ .top-section, .replies-section, -.topics-section { +.topics-section, +.links-section, +.likes-section { margin-bottom: 20px; } @@ -235,7 +237,9 @@ } .replies-section, -.topics-section { +.topics-section, +.links-section, +.likes-section { width: 50%; ul { @@ -253,12 +257,17 @@ } } -.replies-section { - float: left; +.links-section { + .domain { + font-size: 0.714em; + color: dark-light-choose(scale-color($primary, $lightness: 40%), scale-color($secondary, $lightness: 40%)); + } } -.topics-section { - float: right; +.likes-section { + li { + height: 40px; + } } @media all diff --git a/app/models/user_summary.rb b/app/models/user_summary.rb index 9c9b5605358..01863e51ab0 100644 --- a/app/models/user_summary.rb +++ b/app/models/user_summary.rb @@ -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, diff --git a/app/serializers/user_summary_serializer.rb b/app/serializers/user_summary_serializer.rb index 2f65995cc91..b67834a3e84 100644 --- a/app/serializers/user_summary_serializer.rb +++ b/app/serializers/user_summary_serializer.rb @@ -8,9 +8,19 @@ class UserSummarySerializer < ApplicationSerializer has_one :topic, serializer: TopicSerializer end + class LinkSerializer < ApplicationSerializer + attributes :url, :title, :clicks, :domain + end + + class MostLikedByUserSerializer < BasicUserSerializer + attributes :likes, :name + end + has_many :topics, serializer: TopicSerializer has_many :replies, serializer: ReplySerializer, embed: :object has_many :badges, serializer: UserBadgeSerializer, embed: :object + has_many :links, serializer: LinkSerializer, embed: :object + has_many :most_liked_by_users, serializer: MostLikedByUserSerializer, embed: :object attributes :likes_given, :likes_received, @@ -18,7 +28,8 @@ class UserSummarySerializer < ApplicationSerializer :days_visited, :topic_count, :post_count, - :time_read + :time_read, + :bookmark_count def include_badges? SiteSetting.enable_badges diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index e13167fd308..216e8394eed 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -742,17 +742,20 @@ en: one: "post created" other: "posts created" likes_given: - one: "like given" - other: "likes given" + one: " given" + other: " given" likes_received: - one: "like received" - other: "likes received" + one: " received" + other: " received" days_visited: one: "day visited" other: "days visited" posts_read: one: "post read" other: "posts read" + bookmark_count: + one: "bookmark" + other: "bookmarks" top_replies: "Top Replies" no_replies: "No replies yet." more_replies: "More Replies" @@ -762,6 +765,10 @@ en: top_badges: "Top Badges" no_badges: "No badges yet." more_badges: "More Badges" + top_links: "Top Links" + no_links: "No links yet." + most_liked_by: "Most Liked By" + no_likes: "No likes yet." associated_accounts: "Logins"