change component implementation

This commit is contained in:
Lisa P 2016-01-26 14:50:58 +01:00
parent 05b85eb37f
commit d82ff49359
7 changed files with 14 additions and 69 deletions

View File

@ -7,25 +7,8 @@ export default Ember.Component.extend({
tagName: 'span',
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() {
var name = this.get('user.name') || this.get('user.login') ||
this.get('user.authorName') || this.get('user.committerName');
var name = this.get('name');
var arr = name.split(' ');
var initials;

View File

@ -38,12 +38,12 @@
</ul>
<p class="commit-author">
{{#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>
{{/if}}
{{#unless commit.authorIsCommitter}}
{{#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>
{{/if}}
{{/unless}}

View File

@ -20,7 +20,7 @@
{{/unless}}
</div>
<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>
</div>
</div>

View File

@ -1,5 +1,5 @@
<div class="media-elem">
{{user-avatar user=account}}
{{user-avatar url=account.avatarUrl name=name}}
</div>
<div class="media-body">
{{#link-to "account" account.login}}

View File

@ -1,2 +1,4 @@
<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}}

View File

@ -58,7 +58,7 @@
{{#if auth.signedIn}}
{{#link-to "profile" class="navigation-anchor signed-in"}}
{{userName}}
{{user-avatar user=user}}
{{user-avatar url=user.avatarUrl name=user.fullName}}
{{/link-to}}
{{/if}}
{{#if auth.signingIn}}

View File

@ -7,55 +7,15 @@ moduleForComponent('user-avatar', 'UserAvatarComponent | Unit', {
});
test('it renders', function() {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });"
var attributes = {
type: 'organization',
login: 'testuser',
name: 'Test User',
avatarUrl: 'https://0.gravatar.com/avatar/595cf623f3cde2fa64fc784884c4bfec'
};
var name = "Hello Test";
var url = "https://someurl.com/someimage.jpg";
var org = Ember.Object.create(attributes);
var component = this.subject({user: org});
var component = this.subject({url: url, name: name});
this.append();
ok(component.$().hasClass('avatar'), 'component should have right class');
equal(component.$('.pseudo-avatar').data('initials'), 'TU', 'initials should be correct');
equal(component.$('.real-avatar').attr('src'), 'https://0.gravatar.com/avatar/595cf623f3cde2fa64fc784884c4bfec', 'avatar shoudl 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');
equal(component.$('.pseudo-avatar').data('initials'), 'HT', 'initials should be correct');
equal(component.$('.real-avatar').attr('src'), 'https://someurl.com/someimage.jpg', 'avatar should be right');
});