mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 07:09:48 +03:00
c41c184762
no issue - We have a need to create a member manually, this changeset solves this problem. - Added new member button to the member's screen - Needed to be able to perform add member action - Fixed inconsistent `createAt` naming. All models use consistent `createdAtUTC`, fixed it up so that members model follows the same pattern. If we want to change this pattern should probably happen for all models at once - Fixed member avatar when creating a new member. If the values are completely empty the screen ends up being filled with empty space. Added some dummy initials which are recalculated once the member enters the name or an email - Refactored DS naming for consistency. Nowhere else in the codebase 'DS' name is ever used, made this consistent - Added missing validations in members form - Simplified if conditions in the member list template. When using the if/esle statements unnecessary new-line symbols were inserted which made it hard to test. Also by using computed property view is much cleaner - Updated member's model default value for `subscribed` to "true". It is turned on by default in the model layer on the backend (ref: https://github.com/TryGhost/Ghost/blob/3.1.0/core/server/data/schema/schema.js#L330), this behavior is intended and should be the same on the frontend
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
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({
|
|
tagName: '',
|
|
|
|
member: null,
|
|
initialsClass: computed('sizeClass', function () {
|
|
return this.sizeClass || 'gh-member-list-avatar';
|
|
}),
|
|
|
|
backgroundStyle: computed('member.{name,email}', function () {
|
|
let name = this.member.name || this.member.email || 'NM';
|
|
if (name) {
|
|
let color = stringToHslColor(name, 55, 55);
|
|
return htmlSafe(`background-color: ${color}`);
|
|
}
|
|
|
|
return htmlSafe('');
|
|
}),
|
|
|
|
initials: computed('member.{name,email}', function () {
|
|
let name = this.member.name || this.member.email;
|
|
if (name) {
|
|
let names = name.split(' ');
|
|
let intials = names.length > 1 ? [names[0][0], names[names.length - 1][0]] : [names[0][0]];
|
|
return intials.join('').toUpperCase();
|
|
}
|
|
|
|
// New Member initials
|
|
return 'NM';
|
|
})
|
|
});
|