2019-01-24 22:34:32 +03:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import {computed} from '@ember/object';
|
|
|
|
import {htmlSafe} from '@ember/string';
|
|
|
|
|
|
|
|
const stringToHslColor = function (str, saturation, lightness) {
|
|
|
|
var hash = 0;
|
|
|
|
for (var i = 0; i < str.length; i++) {
|
|
|
|
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
var h = hash % 360;
|
|
|
|
return 'hsl(' + h + ', ' + saturation + '%, ' + lightness + '%)';
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Component.extend({
|
2019-01-24 22:50:23 +03:00
|
|
|
tagName: '',
|
2019-01-24 22:34:32 +03:00
|
|
|
|
|
|
|
member: null,
|
2019-06-18 13:47:21 +03:00
|
|
|
initialsClass: 'f6 fw4',
|
2019-01-24 22:34:32 +03:00
|
|
|
|
|
|
|
backgroundStyle: computed('member.name', function () {
|
|
|
|
let name = this.member.name;
|
2019-06-24 18:33:21 +03:00
|
|
|
|
2019-01-24 22:34:32 +03:00
|
|
|
if (name) {
|
2019-02-23 12:31:18 +03:00
|
|
|
let color = stringToHslColor(name, 55, 55);
|
2019-01-24 22:34:32 +03:00
|
|
|
return htmlSafe(`background-color: ${color}`);
|
|
|
|
}
|
2019-06-24 18:33:21 +03:00
|
|
|
|
|
|
|
return htmlSafe('');
|
2019-01-24 22:34:32 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
initials: computed('member.name', function () {
|
|
|
|
let names = this.member.name.split(' ');
|
|
|
|
let intials = [names[0][0], names[names.length - 1][0]];
|
|
|
|
return intials.join('').toUpperCase();
|
|
|
|
})
|
|
|
|
});
|