mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:13:38 +08:00
FEATURE: show avatar flair on group, badges and directory pages (#6732)
This commit is contained in:
parent
43cfdb1cb9
commit
1d649e147b
|
@ -1,5 +1,14 @@
|
|||
<div class="user-image">
|
||||
<a href="{{unbound userPath}}" data-user-card="{{unbound user.username}}">{{avatar user imageSize="large"}}</a>
|
||||
<div class="user-image-inner">
|
||||
<a href="{{unbound userPath}}" data-user-card="{{unbound user.username}}">{{avatar user imageSize="large"}}</a>
|
||||
{{#if user.primary_group_name}}
|
||||
{{avatar-flair
|
||||
flairURL=user.primary_group_flair_url
|
||||
flairBgColor=user.primary_group_flair_bg_color
|
||||
flairColor=user.primary_group_flair_color
|
||||
groupName=user.primary_group_name}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="user-detail">
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-repeat: no-repeat;
|
||||
|
||||
.d-icon {
|
||||
height: $icon-size;
|
||||
|
|
|
@ -228,6 +228,7 @@
|
|||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-repeat: no-repeat;
|
||||
|
||||
.d-icon {
|
||||
height: $icon-size;
|
||||
|
|
|
@ -7,6 +7,12 @@
|
|||
.user-image {
|
||||
float: left;
|
||||
padding-right: 4px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.user-image-inner {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.user-detail {
|
||||
|
@ -39,6 +45,18 @@
|
|||
}
|
||||
}
|
||||
|
||||
.avatar-flair {
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
position: absolute;
|
||||
bottom: -2px;
|
||||
right: -8px;
|
||||
background-size: 18px 18px;
|
||||
border-radius: 12px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
|
||||
&.small {
|
||||
width: 333px;
|
||||
@media screen and (max-width: $small-width) {
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
}
|
||||
.user-image {
|
||||
width: 55px;
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,12 @@ class DirectoryItemsController < ApplicationController
|
|||
period = params.require(:period)
|
||||
period_type = DirectoryItem.period_types[period.to_sym]
|
||||
raise Discourse::InvalidAccess.new(:period_type) unless period_type
|
||||
|
||||
result = DirectoryItem.where(period_type: period_type).includes(:user)
|
||||
|
||||
if params[:group]
|
||||
result = result.includes(user: :groups).where(users: { groups: { name: params[:group] } })
|
||||
else
|
||||
result = result.includes(user: :primary_group)
|
||||
end
|
||||
|
||||
if params[:exclude_usernames]
|
||||
|
|
|
@ -241,11 +241,13 @@ class GroupsController < ApplicationController
|
|||
.order(username_lower: dir)
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
.includes(:primary_group)
|
||||
|
||||
owners = users
|
||||
.order(order)
|
||||
.order(username_lower: dir)
|
||||
.where('group_users.owner')
|
||||
.includes(:primary_group)
|
||||
|
||||
render json: {
|
||||
members: serialize_data(members, GroupUserSerializer),
|
||||
|
|
|
@ -6,7 +6,7 @@ class UserBadgesController < ApplicationController
|
|||
|
||||
badge = fetch_badge_from_params
|
||||
user_badges = badge.user_badges.order('granted_at DESC, id DESC').limit(96)
|
||||
user_badges = user_badges.includes(:user, :granted_by, badge: :badge_type, post: :topic)
|
||||
user_badges = user_badges.includes(:user, :granted_by, badge: :badge_type, post: :topic, user: :primary_group)
|
||||
|
||||
grant_count = nil
|
||||
|
||||
|
|
42
app/serializers/concerns/user_primary_group_mixin.rb
Normal file
42
app/serializers/concerns/user_primary_group_mixin.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
module UserPrimaryGroupMixin
|
||||
|
||||
def self.included(klass)
|
||||
klass.attributes :primary_group_name,
|
||||
:primary_group_flair_url,
|
||||
:primary_group_flair_bg_color,
|
||||
:primary_group_flair_color
|
||||
end
|
||||
|
||||
def primary_group_name
|
||||
object&.primary_group&.name
|
||||
end
|
||||
|
||||
def include_primary_group_name?
|
||||
object&.primary_group.present?
|
||||
end
|
||||
|
||||
def primary_group_flair_url
|
||||
object&.primary_group&.flair_url
|
||||
end
|
||||
|
||||
def include_primary_group_flair_url?
|
||||
object&.primary_group&.flair_url.present?
|
||||
end
|
||||
|
||||
def primary_group_flair_bg_color
|
||||
object&.primary_group&.flair_bg_color
|
||||
end
|
||||
|
||||
def include_primary_group_flair_bg_color?
|
||||
object&.primary_group&.flair_bg_color.present?
|
||||
end
|
||||
|
||||
def primary_group_flair_color
|
||||
object&.primary_group&.flair_color
|
||||
end
|
||||
|
||||
def include_primary_group_flair_color?
|
||||
object&.primary_group&.flair_color.present?
|
||||
end
|
||||
|
||||
end
|
|
@ -1,9 +1,13 @@
|
|||
class DirectoryItemSerializer < ApplicationSerializer
|
||||
|
||||
class UserSerializer < UserNameSerializer
|
||||
include UserPrimaryGroupMixin
|
||||
end
|
||||
|
||||
attributes :id,
|
||||
:time_read
|
||||
|
||||
has_one :user, embed: :objects, serializer: UserNameSerializer
|
||||
has_one :user, embed: :objects, serializer: UserSerializer
|
||||
attributes *DirectoryItem.headings
|
||||
|
||||
def id
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
class GroupUserSerializer < BasicUserSerializer
|
||||
attributes :name, :title, :last_posted_at, :last_seen_at, :added_at
|
||||
include UserPrimaryGroupMixin
|
||||
|
||||
attributes :name,
|
||||
:title,
|
||||
:last_posted_at,
|
||||
:last_seen_at,
|
||||
:added_at
|
||||
|
||||
def include_added_at
|
||||
object.respond_to? :added_at
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
class UserBadgeSerializer < ApplicationSerializer
|
||||
|
||||
class UserSerializer < BasicUserSerializer
|
||||
attributes :name, :moderator, :admin
|
||||
include UserPrimaryGroupMixin
|
||||
|
||||
attributes :name,
|
||||
:moderator,
|
||||
:admin
|
||||
end
|
||||
|
||||
attributes :id, :granted_at, :count, :post_id, :post_number
|
||||
|
|
Loading…
Reference in New Issue
Block a user