Add user group badges

This commit is contained in:
Toby Zerner
2015-05-06 11:25:19 +09:30
parent 707c60d3ab
commit 54f731942e
11 changed files with 78 additions and 43 deletions

View File

@ -3,6 +3,9 @@ import Model from 'flarum/model';
class Group extends Model {}
Group.prototype.id = Model.prop('id');
Group.prototype.name = Model.prop('name');
Group.prototype.nameSingular = Model.prop('nameSingular');
Group.prototype.namePlural = Model.prop('namePlural');
Group.prototype.color = Model.prop('color');
Group.prototype.icon = Model.prop('icon');
export default Group;

View File

@ -2,6 +2,7 @@ import Model from 'flarum/model'
import stringToColor from 'flarum/utils/string-to-color';
import ItemList from 'flarum/utils/item-list';
import computed from 'flarum/utils/computed';
import Badge from 'flarum/components/badge';
class User extends Model {}
@ -48,6 +49,22 @@ User.prototype.color = computed('username', 'avatarUrl', 'avatarColor', function
}
});
User.prototype.badges = () => new ItemList();
User.prototype.badges = function() {
var items = new ItemList();
this.groups().forEach(group => {
if (group.id() != 3) {
items.add('group'+group.id(),
Badge.component({
label: group.nameSingular(),
icon: group.icon(),
style: {backgroundColor: group.color()}
})
);
}
});
return items;
}
export default User;