Created
May 4, 2018 18:28
-
-
Save charlesdemers/a5709c1fc97b2ea8850588b113ca83cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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