change component implementation
This commit is contained in:
parent
05b85eb37f
commit
d82ff49359
|
@ -7,25 +7,8 @@ export default Ember.Component.extend({
|
||||||
tagName: 'span',
|
tagName: 'span',
|
||||||
classNames: ['avatar'],
|
classNames: ['avatar'],
|
||||||
|
|
||||||
gravatarUrl: function() {
|
|
||||||
if (!this.get('isAuthor') && !this.get('isComitter')) {
|
|
||||||
if (this.get('user.type') === 'organization') {
|
|
||||||
return this.get('user.avatarUrl');
|
|
||||||
} else {
|
|
||||||
return gravatarImage(this.get('user.email'), 36);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (this.get('isAuthor')) {
|
|
||||||
return this.user.get('authorAvatarUrlOrGravatar');
|
|
||||||
} else if (this.get('isCommitter')) {
|
|
||||||
return this.user.get('committerAvatarUrlorGravatar');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.property('gravatarUrl'),
|
|
||||||
|
|
||||||
userInitials: function() {
|
userInitials: function() {
|
||||||
var name = this.get('user.name') || this.get('user.login') ||
|
var name = this.get('name');
|
||||||
this.get('user.authorName') || this.get('user.committerName');
|
|
||||||
var arr = name.split(' ');
|
var arr = name.split(' ');
|
||||||
var initials;
|
var initials;
|
||||||
|
|
||||||
|
|
|
@ -38,12 +38,12 @@
|
||||||
</ul>
|
</ul>
|
||||||
<p class="commit-author">
|
<p class="commit-author">
|
||||||
{{#if commit.authorName}}
|
{{#if commit.authorName}}
|
||||||
{{user-avatar user=commit isAuthor=true}}
|
{{user-avatar url=commit.authorAvatarUrlOrGravatar name=commit.authorName}}
|
||||||
<span class="label-align">{{commit.authorName}} authored{{#if commit.authorIsCommitter}} and committed{{/if}}</span>
|
<span class="label-align">{{commit.authorName}} authored{{#if commit.authorIsCommitter}} and committed{{/if}}</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#unless commit.authorIsCommitter}}
|
{{#unless commit.authorIsCommitter}}
|
||||||
{{#if commit.committerName}}
|
{{#if commit.committerName}}
|
||||||
{{user-avatar user=commit isComitter=true}}
|
{{user-avatar url=commit.committerAvatarUrlOrGravatar name=commit.committerName}}
|
||||||
<span class="label-align">{{commit.committerName}} committed</span>
|
<span class="label-align">{{commit.committerName}} committed</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
</div>
|
</div>
|
||||||
<div class="row-item row-committer">
|
<div class="row-item row-committer">
|
||||||
{{user-avatar user=build.commit isAuthor=true}}
|
{{user-avatar url=build.commit.authorAvatarUrlOrGravatar name=build.commit.authorName}}
|
||||||
<span class="label-align">{{build.commit.authorName}}</span>
|
<span class="label-align">{{build.commit.authorName}}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<div class="media-elem">
|
<div class="media-elem">
|
||||||
{{user-avatar user=account}}
|
{{user-avatar url=account.avatarUrl name=name}}
|
||||||
</div>
|
</div>
|
||||||
<div class="media-body">
|
<div class="media-body">
|
||||||
{{#link-to "account" account.login}}
|
{{#link-to "account" account.login}}
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
<span class="pseudo-avatar" aria-hidden="true" data-initials="{{userInitials}}"></span>
|
<span class="pseudo-avatar" aria-hidden="true" data-initials="{{userInitials}}"></span>
|
||||||
<img class="real-avatar" src="{{gravatarUrl}}" alt="avatar">
|
{{#if url}}
|
||||||
|
<img class="real-avatar" src="{{url}}" alt="avatar">
|
||||||
|
{{/if}}
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
{{#if auth.signedIn}}
|
{{#if auth.signedIn}}
|
||||||
{{#link-to "profile" class="navigation-anchor signed-in"}}
|
{{#link-to "profile" class="navigation-anchor signed-in"}}
|
||||||
{{userName}}
|
{{userName}}
|
||||||
{{user-avatar user=user}}
|
{{user-avatar url=user.avatarUrl name=user.fullName}}
|
||||||
{{/link-to}}
|
{{/link-to}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if auth.signingIn}}
|
{{#if auth.signingIn}}
|
||||||
|
|
|
@ -7,55 +7,15 @@ moduleForComponent('user-avatar', 'UserAvatarComponent | Unit', {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it renders', function() {
|
test('it renders', function() {
|
||||||
// Set any properties with this.set('myProperty', 'value');
|
|
||||||
// Handle any actions with this.on('myAction', function(val) { ... });"
|
|
||||||
|
|
||||||
var attributes = {
|
var name = "Hello Test";
|
||||||
type: 'organization',
|
var url = "https://someurl.com/someimage.jpg";
|
||||||
login: 'testuser',
|
|
||||||
name: 'Test User',
|
|
||||||
avatarUrl: 'https://0.gravatar.com/avatar/595cf623f3cde2fa64fc784884c4bfec'
|
|
||||||
};
|
|
||||||
|
|
||||||
var org = Ember.Object.create(attributes);
|
var component = this.subject({url: url, name: name});
|
||||||
var component = this.subject({user: org});
|
|
||||||
this.append();
|
this.append();
|
||||||
|
|
||||||
ok(component.$().hasClass('avatar'), 'component should have right class');
|
ok(component.$().hasClass('avatar'), 'component should have right class');
|
||||||
equal(component.$('.pseudo-avatar').data('initials'), 'TU', 'initials should be correct');
|
equal(component.$('.pseudo-avatar').data('initials'), 'HT', 'initials should be correct');
|
||||||
equal(component.$('.real-avatar').attr('src'), 'https://0.gravatar.com/avatar/595cf623f3cde2fa64fc784884c4bfec', 'avatar shoudl be right');
|
equal(component.$('.real-avatar').attr('src'), 'https://someurl.com/someimage.jpg', 'avatar should be right');
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
test('it handles a missing user name', function() {
|
|
||||||
|
|
||||||
var attr = {
|
|
||||||
type: 'organization',
|
|
||||||
login: 'testorg'
|
|
||||||
};
|
|
||||||
|
|
||||||
var org = Ember.Object.create(attr);
|
|
||||||
var component = this.subject({user: org});
|
|
||||||
this.append();
|
|
||||||
|
|
||||||
equal(component.$('.pseudo-avatar').data('initials'), 'T', 'only one letter if there is no name');
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
test('can get avatars from commits', function() {
|
|
||||||
|
|
||||||
|
|
||||||
var attr = {
|
|
||||||
authorName: 'This is Author'
|
|
||||||
};
|
|
||||||
|
|
||||||
var user = Ember.Object.create(attr);
|
|
||||||
var component = this.subject({user: user});
|
|
||||||
this.append();
|
|
||||||
|
|
||||||
equal(component.$('.real-avatar').attr('src'), 'https://www.gravatar.com/avatar/5e543256c480ac577d30f76f9120eb74?s=36&d=blank', 'get the right avatar url');
|
|
||||||
|
|
||||||
equal(component.$('.pseudo-avatar').data('initials'), 'TI', 'gets right initials');
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user