2018-04-04 10:48:47 -07:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { IAvatar } from 'wherehows-web/typings/app/avatars';
|
|
|
|
import { set, get, computed } from '@ember/object';
|
|
|
|
import ComputedProperty from '@ember/object/computed';
|
|
|
|
import { action } from 'ember-decorators/object';
|
2018-04-04 23:32:21 -07:00
|
|
|
import { singularize, pluralize } from 'ember-inflector';
|
2018-04-04 10:48:47 -07:00
|
|
|
|
|
|
|
export default class extends Component {
|
|
|
|
tagName = 'span';
|
|
|
|
|
|
|
|
classNames = ['avatar-rollup'];
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
|
|
|
|
this.avatars || (this.avatars = []);
|
2018-04-04 23:32:21 -07:00
|
|
|
this.avatarType || (this.avatarType = 'entity');
|
2018-04-04 10:48:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* References the full list of avatars
|
|
|
|
* @type {Array<IAvatar>}
|
|
|
|
*/
|
|
|
|
avatars: Array<IAvatar>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag indicating if the avatars detail view should be rendered
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
isShowingAvatars = false;
|
|
|
|
|
2018-04-04 23:32:21 -07:00
|
|
|
/**
|
|
|
|
* The type of avatars being shown
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
avatarType: string;
|
|
|
|
|
2018-04-04 10:48:47 -07:00
|
|
|
/**
|
|
|
|
* Returns the text to be shown in the avatar detail page header
|
|
|
|
* @type {ComputedProperty<string>}
|
|
|
|
*/
|
|
|
|
header: ComputedProperty<string> = computed('avatars.length', function(): string {
|
2018-04-04 23:32:21 -07:00
|
|
|
const count = get(this, 'avatars').length;
|
|
|
|
const suffix = get(this, 'avatarType');
|
|
|
|
|
|
|
|
return `${count} ${count > 1 ? pluralize(suffix) : singularize(suffix)}`;
|
2018-04-04 10:48:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the component click event
|
|
|
|
*/
|
|
|
|
click() {
|
|
|
|
set(this, 'isShowingAvatars', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the flag indicating if the view should be rendered
|
|
|
|
*/
|
|
|
|
@action
|
|
|
|
dismissAvatars() {
|
|
|
|
set(this, 'isShowingAvatars', false);
|
|
|
|
}
|
|
|
|
}
|