1
0
mirror of https://github.com/flarum/core.git synced 2025-10-08 21:46:25 +02:00

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

@@ -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;