UX: show full name on /latest page

This commit is contained in:
Arpit Jalan 2018-08-21 17:28:11 +05:30
parent 0f07494b12
commit 1a7cd6648b
8 changed files with 53 additions and 8 deletions

View File

@ -30,6 +30,7 @@ function renderAvatar(user, options) {
options = options || {};
if (user) {
const name = Em.get(user, options.namePath || "name");
const username = Em.get(user, options.usernamePath || "username");
const avatarTemplate = Em.get(
user,
@ -40,7 +41,7 @@ function renderAvatar(user, options) {
return "";
}
let displayName = Ember.get(user, "name") || formatUsername(username);
let displayName = name || formatUsername(username);
let title = options.title;
if (!title && !options.ignoreTitle) {

View File

@ -1,5 +1,5 @@
<td class='posters'>
{{#each posters as |poster|}}
<a href="{{poster.user.path}}" data-user-card="{{poster.user.username}}" class="{{poster.extraClasses}}">{{avatar poster avatarTemplatePath="user.avatar_template" usernamePath="user.username" imageSize="small"}}</a>
<a href="{{poster.user.path}}" data-user-card="{{poster.user.username}}" class="{{poster.extraClasses}}">{{avatar poster avatarTemplatePath="user.avatar_template" usernamePath="user.username" namePath="user.name" imageSize="small"}}</a>
{{/each}}
</td>

View File

@ -1,5 +1,9 @@
class BasicUserSerializer < ApplicationSerializer
attributes :id, :username, :avatar_template
attributes :id, :username, :name, :avatar_template
def name
Hash === user ? user[:name] : user.try(:name)
end
def include_name?
SiteSetting.enable_names?
@ -16,5 +20,4 @@ class BasicUserSerializer < ApplicationSerializer
def user
object[:user] || object
end
end

View File

@ -12,7 +12,7 @@ class AvatarLookup
private
def self.lookup_columns
@lookup_columns ||= %i{id user_emails.email username uploaded_avatar_id}
@lookup_columns ||= %i{id user_emails.email username name uploaded_avatar_id}
end
def users

View File

@ -4,7 +4,7 @@ require 'rails_helper'
require_dependency 'avatar_lookup'
describe AvatarLookup do
let!(:user) { Fabricate(:user) }
let!(:user) { Fabricate(:user, username: "john_doe", name: "John Doe") }
describe '#[]' do
before do
@ -20,7 +20,10 @@ describe AvatarLookup do
end
it 'returns user if user_id exists' do
expect(@avatar_lookup[user.id]).to eq(user)
avatar_lookup_user = @avatar_lookup[user.id]
expect(avatar_lookup_user).to eq(user)
expect(avatar_lookup_user.username).to eq("john_doe")
expect(avatar_lookup_user.name).to eq("John Doe")
end
end
end

View File

@ -0,0 +1,27 @@
require 'rails_helper'
require_dependency 'user'
describe BasicUserSerializer do
context "name" do
let(:user) { Fabricate.build(:user) }
let(:serializer) { BasicUserSerializer.new(user, scope: Guardian.new(user), root: false) }
let(:json) { serializer.as_json }
it "returns the username" do
expect(json[:username]).to be_present
end
it "returns the name it when `enable_names` is true" do
SiteSetting.enable_names = true
expect(json[:name]).to be_present
end
it "doesn't return the name it when `enable_names` is false" do
SiteSetting.enable_names = false
expect(json[:name]).to be_blank
end
end
end

View File

@ -7,6 +7,12 @@ QUnit.test("Visit Discovery Pages", async assert => {
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics");
assert.equal(
find("a[data-user-card=eviltrout]:first img.avatar").attr("title"),
"Evil Trout - Most Posts",
"it shows user's full name in avatar title"
);
await visit("/c/bug");
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics");

View File

@ -11,7 +11,12 @@ export default {
username: "stellarhopper",
avatar_template: "/images/avatar.png"
},
{ id: 19, username: "eviltrout", avatar_template: "/images/avatar.png" },
{
id: 19,
username: "eviltrout",
name: "Evil Trout",
avatar_template: "/images/avatar.png"
},
{ id: 14, username: "clay", avatar_template: "/images/avatar.png" },
{
id: 32,