From 2016e1cda1d1bd8247f1b285e3ec955a04ebe556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 20 Apr 2016 22:58:30 +0200 Subject: [PATCH] UX: show topics where the top links are extracted from in user summary --- .../javascripts/discourse/models/user.js.es6 | 23 +++++++-------- .../discourse/templates/user/summary.hbs | 28 ++++++------------- app/models/user_summary.rb | 8 +++--- app/serializers/user_summary_serializer.rb | 14 +++++++--- 4 files changed, 34 insertions(+), 39 deletions(-) diff --git a/app/assets/javascripts/discourse/models/user.js.es6 b/app/assets/javascripts/discourse/models/user.js.es6 index 2853625ab45..b74c2cd2cc0 100644 --- a/app/assets/javascripts/discourse/models/user.js.es6 +++ b/app/assets/javascripts/discourse/models/user.js.es6 @@ -390,17 +390,14 @@ const User = RestModel.extend({ summary() { return Discourse.ajax(`/users/${this.get("username_lower")}/summary.json`) .then(json => { - const topicMap = {}; - - json.topics.forEach(t => { - topicMap[t.id] = Topic.create(t); - }); - - const badgeMap = {}; - Badge.createFromJson(json).forEach(b => { - badgeMap[b.id] = b; - }); const summary = json["user_summary"]; + const topicMap = {}; + const badgeMap = {}; + + json.topics.forEach(t => topicMap[t.id] = Topic.create(t)); + Badge.createFromJson(json).forEach(b => badgeMap[b.id] = b ); + + summary.topics = summary.topic_ids.map(id => topicMap[id]); summary.replies.forEach(r => { r.topic = topicMap[r.topic_id]; @@ -408,7 +405,10 @@ const User = RestModel.extend({ r.createdAt = new Date(r.created_at); }); - summary.topics = summary.topic_ids.map(id => topicMap[id]); + summary.links.forEach(l => { + l.topic = topicMap[l.topic_id]; + l.post_url = l.topic.urlForPostNumber(l.post_number); + }); if (summary.badges) { summary.badges = summary.badges.map(ub => { @@ -417,6 +417,7 @@ const User = RestModel.extend({ return badge; }); } + return summary; }); } diff --git a/app/assets/javascripts/discourse/templates/user/summary.hbs b/app/assets/javascripts/discourse/templates/user/summary.hbs index b8d433a9171..ee6fc10c820 100644 --- a/app/assets/javascripts/discourse/templates/user/summary.hbs +++ b/app/assets/javascripts/discourse/templates/user/summary.hbs @@ -30,9 +30,7 @@ {{/if}}
- - {{{reply.topic.fancyTitle}}} - + {{{reply.topic.fancyTitle}}} {{/each}} @@ -57,9 +55,7 @@ {{/if}}
- - {{{topic.fancyTitle}}} - + {{{topic.fancyTitle}}} {{/each}} @@ -79,16 +75,10 @@ @@ -102,12 +92,10 @@ diff --git a/app/models/user_summary.rb b/app/models/user_summary.rb index 170a5cbd1fb..a95094e0e5d 100644 --- a/app/models/user_summary.rb +++ b/app/models/user_summary.rb @@ -19,15 +19,14 @@ class UserSummary .visible .where(user: @user) .order('like_count DESC, created_at ASC') - .includes(:user, :category) .limit(MAX_SUMMARY_RESULTS) end def replies Post + .joins(:topic) + .includes(:topic) .secured(@guardian) - .includes(:user, topic: :category) - .references(:topic) .merge(Topic.listable_topics.visible.secured(@guardian)) .where(user: @user) .where('post_number > 1') @@ -39,10 +38,11 @@ class UserSummary def links TopicLink .joins(:topic, :post) + .includes(:topic, :post) .where('topics.archetype <> ?', Archetype.private_message) .where(user: @user) .where(internal: false, reflection: false, quote: false) - .order('clicks DESC, created_at ASC') + .order('clicks DESC, topic_links.created_at ASC') .limit(MAX_SUMMARY_RESULTS) end diff --git a/app/serializers/user_summary_serializer.rb b/app/serializers/user_summary_serializer.rb index b67834a3e84..aa5d4ec6b47 100644 --- a/app/serializers/user_summary_serializer.rb +++ b/app/serializers/user_summary_serializer.rb @@ -1,6 +1,7 @@ class UserSummarySerializer < ApplicationSerializer - class TopicSerializer < BasicTopicSerializer - attributes :like_count, :slug, :created_at + + class TopicSerializer < ApplicationSerializer + attributes :id, :created_at, :fancy_title, :slug, :like_count end class ReplySerializer < ApplicationSerializer @@ -9,7 +10,12 @@ class UserSummarySerializer < ApplicationSerializer end class LinkSerializer < ApplicationSerializer - attributes :url, :title, :clicks, :domain + attributes :url, :title, :clicks, :post_number + has_one :topic, serializer: TopicSerializer + + def post_number + object.post.post_number + end end class MostLikedByUserSerializer < BasicUserSerializer @@ -18,9 +24,9 @@ class UserSummarySerializer < ApplicationSerializer 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 + has_many :badges, serializer: UserBadgeSerializer, embed: :object attributes :likes_given, :likes_received,