UX: show topics where the top links are extracted from in user summary
This commit is contained in:
parent
850f5c3472
commit
2016e1cda1
|
@ -390,17 +390,14 @@ const User = RestModel.extend({
|
||||||
summary() {
|
summary() {
|
||||||
return Discourse.ajax(`/users/${this.get("username_lower")}/summary.json`)
|
return Discourse.ajax(`/users/${this.get("username_lower")}/summary.json`)
|
||||||
.then(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 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 => {
|
summary.replies.forEach(r => {
|
||||||
r.topic = topicMap[r.topic_id];
|
r.topic = topicMap[r.topic_id];
|
||||||
|
@ -408,7 +405,10 @@ const User = RestModel.extend({
|
||||||
r.createdAt = new Date(r.created_at);
|
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) {
|
if (summary.badges) {
|
||||||
summary.badges = summary.badges.map(ub => {
|
summary.badges = summary.badges.map(ub => {
|
||||||
|
@ -417,6 +417,7 @@ const User = RestModel.extend({
|
||||||
return badge;
|
return badge;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return summary;
|
return summary;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,7 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</span>
|
</span>
|
||||||
<br>
|
<br>
|
||||||
<span>
|
<a href="{{unbound reply.url}}">{{{reply.topic.fancyTitle}}}</a>
|
||||||
<a href="{{reply.url}}">{{{reply.topic.fancyTitle}}}</a>
|
|
||||||
</span>
|
|
||||||
</li>
|
</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -57,9 +55,7 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</span>
|
</span>
|
||||||
<br>
|
<br>
|
||||||
<span>
|
<a href="{{unbound topic.url}}">{{{topic.fancyTitle}}}</a>
|
||||||
<a href="{{topic.url}}">{{{topic.fancyTitle}}}</a>
|
|
||||||
</span>
|
|
||||||
</li>
|
</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -79,16 +75,10 @@
|
||||||
<ul>
|
<ul>
|
||||||
{{#each link in model.links}}
|
{{#each link in model.links}}
|
||||||
<li>
|
<li>
|
||||||
|
<a class='domain' href='{{unbound link.url}}' title='{{unbound link.title}}' target='_blank'>{{shorten-url link.url}}</a>
|
||||||
<span class='badge badge-notification clicks' title='{{i18n 'topic_map.clicks' count=link.clicks}}'>{{link.clicks}}</span>
|
<span class='badge badge-notification clicks' title='{{i18n 'topic_map.clicks' count=link.clicks}}'>{{link.clicks}}</span>
|
||||||
<span class='domain'>{{unbound link.domain}}</span>
|
|
||||||
<br>
|
<br>
|
||||||
<a href="{{unbound link.url}}" target="_blank" title="{{unbound link.url}}">
|
<a href="{{unbound link.post_url}}">{{{link.topic.fancyTitle}}}</a>
|
||||||
{{#if link.title}}
|
|
||||||
{{link.title}}
|
|
||||||
{{else}}
|
|
||||||
{{shorten-url link.url}}
|
|
||||||
{{/if}}
|
|
||||||
</a>
|
|
||||||
</li>
|
</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -102,12 +92,10 @@
|
||||||
<ul>
|
<ul>
|
||||||
{{#each user in model.most_liked_by_users}}
|
{{#each user in model.most_liked_by_users}}
|
||||||
<li>
|
<li>
|
||||||
<span>
|
{{#user-info user=user}}
|
||||||
{{#user-info user=user}}
|
{{fa-icon "heart"}}
|
||||||
{{fa-icon "heart"}}
|
<span class='likes'>{{user.likes}}</span>
|
||||||
<span class='likes'>{{user.likes}}</span>
|
{{/user-info}}
|
||||||
{{/user-info}}
|
|
||||||
</span>
|
|
||||||
</li>
|
</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -19,15 +19,14 @@ class UserSummary
|
||||||
.visible
|
.visible
|
||||||
.where(user: @user)
|
.where(user: @user)
|
||||||
.order('like_count DESC, created_at ASC')
|
.order('like_count DESC, created_at ASC')
|
||||||
.includes(:user, :category)
|
|
||||||
.limit(MAX_SUMMARY_RESULTS)
|
.limit(MAX_SUMMARY_RESULTS)
|
||||||
end
|
end
|
||||||
|
|
||||||
def replies
|
def replies
|
||||||
Post
|
Post
|
||||||
|
.joins(:topic)
|
||||||
|
.includes(:topic)
|
||||||
.secured(@guardian)
|
.secured(@guardian)
|
||||||
.includes(:user, topic: :category)
|
|
||||||
.references(:topic)
|
|
||||||
.merge(Topic.listable_topics.visible.secured(@guardian))
|
.merge(Topic.listable_topics.visible.secured(@guardian))
|
||||||
.where(user: @user)
|
.where(user: @user)
|
||||||
.where('post_number > 1')
|
.where('post_number > 1')
|
||||||
|
@ -39,10 +38,11 @@ class UserSummary
|
||||||
def links
|
def links
|
||||||
TopicLink
|
TopicLink
|
||||||
.joins(:topic, :post)
|
.joins(:topic, :post)
|
||||||
|
.includes(:topic, :post)
|
||||||
.where('topics.archetype <> ?', Archetype.private_message)
|
.where('topics.archetype <> ?', Archetype.private_message)
|
||||||
.where(user: @user)
|
.where(user: @user)
|
||||||
.where(internal: false, reflection: false, quote: false)
|
.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)
|
.limit(MAX_SUMMARY_RESULTS)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
class UserSummarySerializer < ApplicationSerializer
|
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
|
end
|
||||||
|
|
||||||
class ReplySerializer < ApplicationSerializer
|
class ReplySerializer < ApplicationSerializer
|
||||||
|
@ -9,7 +10,12 @@ class UserSummarySerializer < ApplicationSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
class LinkSerializer < ApplicationSerializer
|
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
|
end
|
||||||
|
|
||||||
class MostLikedByUserSerializer < BasicUserSerializer
|
class MostLikedByUserSerializer < BasicUserSerializer
|
||||||
|
@ -18,9 +24,9 @@ class UserSummarySerializer < ApplicationSerializer
|
||||||
|
|
||||||
has_many :topics, serializer: TopicSerializer
|
has_many :topics, serializer: TopicSerializer
|
||||||
has_many :replies, serializer: ReplySerializer, embed: :object
|
has_many :replies, serializer: ReplySerializer, embed: :object
|
||||||
has_many :badges, serializer: UserBadgeSerializer, embed: :object
|
|
||||||
has_many :links, serializer: LinkSerializer, embed: :object
|
has_many :links, serializer: LinkSerializer, embed: :object
|
||||||
has_many :most_liked_by_users, serializer: MostLikedByUserSerializer, embed: :object
|
has_many :most_liked_by_users, serializer: MostLikedByUserSerializer, embed: :object
|
||||||
|
has_many :badges, serializer: UserBadgeSerializer, embed: :object
|
||||||
|
|
||||||
attributes :likes_given,
|
attributes :likes_given,
|
||||||
:likes_received,
|
:likes_received,
|
||||||
|
|
Loading…
Reference in New Issue