FEATURE: group avatar flair shows on topic participants list, and participant avatars can have custom styles

This commit is contained in:
Neil Lalonde
2017-01-18 11:37:43 -05:00
parent 01c8974c36
commit 61d4c1203e
7 changed files with 63 additions and 14 deletions

View File

@@ -38,7 +38,10 @@ createWidget('avatar-flair', {
html(attrs) { html(attrs) {
if (this.isIcon(attrs)) { if (this.isIcon(attrs)) {
return [h('i', { className: 'fa ' + attrs.primary_group_flair_url })]; return [h('i', {
className: 'fa ' + attrs.primary_group_flair_url,
attributes: { style: attrs.primary_group_flair_color ? 'color: #' + Handlebars.Utils.escapeExpression(attrs.primary_group_flair_color) + '; ' : '' }
})];
} else { } else {
return []; return [];
} }

View File

@@ -27,6 +27,10 @@ createWidget('topic-map-show-links', {
}); });
createWidget('topic-participant', { createWidget('topic-participant', {
buildClasses(attrs) {
if (attrs.primary_group_name) { return `group-${attrs.primary_group_name}`; }
},
html(attrs, state) { html(attrs, state) {
const linkContents = [avatarImg('medium', { username: attrs.username, template: attrs.avatar_template })]; const linkContents = [avatarImg('medium', { username: attrs.username, template: attrs.avatar_template })];
@@ -34,6 +38,10 @@ createWidget('topic-participant', {
linkContents.push(h('span.post-count', attrs.post_count.toString())); linkContents.push(h('span.post-count', attrs.post_count.toString()));
} }
if (attrs.primary_group_flair_url || attrs.primary_group_flair_bg_color) {
linkContents.push(this.attach('avatar-flair', attrs));
}
return h('a.poster.trigger-user-card', { return h('a.poster.trigger-user-card', {
className: state.toggled ? 'toggled' : null, className: state.toggled ? 'toggled' : null,
attributes: { title: attrs.username, 'data-user-card': attrs.username } attributes: { title: attrs.username, 'data-user-card': attrs.username }

View File

@@ -158,7 +158,8 @@ aside.quote {
position: relative; position: relative;
} }
.topic-avatar .avatar-flair, .avatar-flair-preview .avatar-flair, .user-card-avatar .avatar-flair { .topic-avatar, .avatar-flair-preview, .user-card-avatar, .topic-map .poster {
.avatar-flair {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
@@ -168,6 +169,7 @@ aside.quote {
bottom: 0; bottom: 0;
right: -6px; right: -6px;
} }
}
.topic-avatar .avatar-flair, .avatar-flair-preview .avatar-flair { .topic-avatar .avatar-flair, .avatar-flair-preview .avatar-flair {
background-size: 20px 20px; background-size: 20px 20px;
width: 20px; width: 20px;
@@ -197,6 +199,24 @@ aside.quote {
font-size: 24px; font-size: 24px;
} }
} }
.topic-map .poster .avatar-flair {
right: 0;
background-size: 12px 12px;
width: 16px;
height: 16px;
bottom: -3px;
&.rounded {
background-size: 12px 12px;
border-radius: 8px;
width: 16px;
height: 16px;
bottom: -2px;
right: 0;
}
.fa {
font-size: 14px;
}
}
.topic-avatar .poster-avatar-extra { .topic-avatar .poster-avatar-extra {
display: none; display: none;
} }

View File

@@ -329,7 +329,7 @@ a.star {
} }
.post-count { .post-count {
position: absolute; position: absolute;
right: 3px; right: 0;
border-radius: 100px; border-radius: 100px;
padding: 4px 5px 2px 5px; padding: 4px 5px 2px 5px;
text-align: center; text-align: center;

View File

@@ -221,7 +221,7 @@ a.star {
} }
.post-count { .post-count {
position: absolute; position: absolute;
right: 3px; right: 0;
border-radius: 100px; border-radius: 100px;
padding: 4px 5px 2px 5px; padding: 4px 5px 2px 5px;
text-align: center; text-align: center;

View File

@@ -1,6 +1,7 @@
class TopicPostCountSerializer < BasicUserSerializer class TopicPostCountSerializer < BasicUserSerializer
attributes :post_count attributes :post_count, :primary_group_name,
:primary_group_flair_url, :primary_group_flair_color, :primary_group_flair_bg_color
def id def id
object[:user].id object[:user].id
@@ -14,4 +15,21 @@ class TopicPostCountSerializer < BasicUserSerializer
object[:post_count] object[:post_count]
end end
def primary_group_name
return nil unless object[:user].primary_group_id
object[:user]&.primary_group&.name
end
def primary_group_flair_url
object[:user]&.primary_group&.flair_url
end
def primary_group_flair_bg_color
object[:user]&.primary_group&.flair_bg_color
end
def primary_group_flair_color
object[:user]&.primary_group&.flair_color
end
end end

View File

@@ -280,7 +280,7 @@ class TopicView
def participants def participants
@participants ||= begin @participants ||= begin
participants = {} participants = {}
User.where(id: post_counts_by_user.map {|k,v| k}).each {|u| participants[u.id] = u} User.where(id: post_counts_by_user.map {|k,v| k}).includes(:primary_group).each {|u| participants[u.id] = u}
participants participants
end end
end end