mirror of
https://github.com/discourse/discourse.git
synced 2025-04-28 20:14:35 +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">
|
<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>
|
||||||
|
|
||||||
<div class="user-detail">
|
<div class="user-detail">
|
||||||
|
@ -62,6 +62,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
|
||||||
.d-icon {
|
.d-icon {
|
||||||
height: $icon-size;
|
height: $icon-size;
|
||||||
|
@ -228,6 +228,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
|
||||||
.d-icon {
|
.d-icon {
|
||||||
height: $icon-size;
|
height: $icon-size;
|
||||||
|
@ -7,6 +7,12 @@
|
|||||||
.user-image {
|
.user-image {
|
||||||
float: left;
|
float: left;
|
||||||
padding-right: 4px;
|
padding-right: 4px;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-image-inner {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.user-detail {
|
.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 {
|
&.small {
|
||||||
width: 333px;
|
width: 333px;
|
||||||
@media screen and (max-width: $small-width) {
|
@media screen and (max-width: $small-width) {
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
}
|
}
|
||||||
.user-image {
|
.user-image {
|
||||||
width: 55px;
|
width: 55px;
|
||||||
|
margin-right: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,12 @@ class DirectoryItemsController < ApplicationController
|
|||||||
period = params.require(:period)
|
period = params.require(:period)
|
||||||
period_type = DirectoryItem.period_types[period.to_sym]
|
period_type = DirectoryItem.period_types[period.to_sym]
|
||||||
raise Discourse::InvalidAccess.new(:period_type) unless period_type
|
raise Discourse::InvalidAccess.new(:period_type) unless period_type
|
||||||
|
|
||||||
result = DirectoryItem.where(period_type: period_type).includes(:user)
|
result = DirectoryItem.where(period_type: period_type).includes(:user)
|
||||||
|
|
||||||
if params[:group]
|
if params[:group]
|
||||||
result = result.includes(user: :groups).where(users: { groups: { name: params[:group] } })
|
result = result.includes(user: :groups).where(users: { groups: { name: params[:group] } })
|
||||||
|
else
|
||||||
|
result = result.includes(user: :primary_group)
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:exclude_usernames]
|
if params[:exclude_usernames]
|
||||||
|
@ -241,11 +241,13 @@ class GroupsController < ApplicationController
|
|||||||
.order(username_lower: dir)
|
.order(username_lower: dir)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
|
.includes(:primary_group)
|
||||||
|
|
||||||
owners = users
|
owners = users
|
||||||
.order(order)
|
.order(order)
|
||||||
.order(username_lower: dir)
|
.order(username_lower: dir)
|
||||||
.where('group_users.owner')
|
.where('group_users.owner')
|
||||||
|
.includes(:primary_group)
|
||||||
|
|
||||||
render json: {
|
render json: {
|
||||||
members: serialize_data(members, GroupUserSerializer),
|
members: serialize_data(members, GroupUserSerializer),
|
||||||
|
@ -6,7 +6,7 @@ class UserBadgesController < ApplicationController
|
|||||||
|
|
||||||
badge = fetch_badge_from_params
|
badge = fetch_badge_from_params
|
||||||
user_badges = badge.user_badges.order('granted_at DESC, id DESC').limit(96)
|
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
|
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 DirectoryItemSerializer < ApplicationSerializer
|
||||||
|
|
||||||
|
class UserSerializer < UserNameSerializer
|
||||||
|
include UserPrimaryGroupMixin
|
||||||
|
end
|
||||||
|
|
||||||
attributes :id,
|
attributes :id,
|
||||||
:time_read
|
:time_read
|
||||||
|
|
||||||
has_one :user, embed: :objects, serializer: UserNameSerializer
|
has_one :user, embed: :objects, serializer: UserSerializer
|
||||||
attributes *DirectoryItem.headings
|
attributes *DirectoryItem.headings
|
||||||
|
|
||||||
def id
|
def id
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
class GroupUserSerializer < BasicUserSerializer
|
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
|
def include_added_at
|
||||||
object.respond_to? :added_at
|
object.respond_to? :added_at
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
class UserBadgeSerializer < ApplicationSerializer
|
class UserBadgeSerializer < ApplicationSerializer
|
||||||
|
|
||||||
class UserSerializer < BasicUserSerializer
|
class UserSerializer < BasicUserSerializer
|
||||||
attributes :name, :moderator, :admin
|
include UserPrimaryGroupMixin
|
||||||
|
|
||||||
|
attributes :name,
|
||||||
|
:moderator,
|
||||||
|
:admin
|
||||||
end
|
end
|
||||||
|
|
||||||
attributes :id, :granted_at, :count, :post_id, :post_number
|
attributes :id, :granted_at, :count, :post_id, :post_number
|
||||||
|
Loading…
x
Reference in New Issue
Block a user