Skip to content

Instantly share code, notes, and snippets.

@charlesdemers
Created May 4, 2018 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlesdemers/a5709c1fc97b2ea8850588b113ca83cb to your computer and use it in GitHub Desktop.
Save charlesdemers/a5709c1fc97b2ea8850588b113ca83cb to your computer and use it in GitHub Desktop.
// Vendor
import Service, {inject as service} from '@ember/service';
import EmberObject, {computed} from '@ember/object';
import {readOnly} from '@ember/object/computed';
export const UserPresenter = EmberObject.extend({
id: readOnly('user.id'),
firstName: readOnly('user.firstname'),
lastName: readOnly('user.lastname'),
email: readOnly('user.email'),
userName: readOnly('user.username'),
company: readOnly('user.company'),
roles: readOnly('user.roles'),
fullName: computed('firstName', 'lastName', function() {
return `${this.get('firstName')} ${this.get('lastName')}`;
}),
roleNames: computed('roles.[]', function() {
return this.get('roles')
.map((role) => this.get('i18n').t(`roles.${role}`))
})
});
export default Service.extend({
i18n: service('i18n'),
present(user) {
const i18n = this.get('i18n');
return UserPresenter.create({i18n, user});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment