This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/controllers/badges/index.js.es6
Sam c8284170ad FEATURE: badge grouping UI
FIX: not loading more badges on badge show page
2014-07-18 15:46:36 +10:00

33 lines
875 B
JavaScript

export default Ember.Controller.extend({
badgeGroups: function(){
var sorted = _.sortBy(this.get('model'), function(badge){
var pos = badge.get('badge_grouping.position');
var type = badge.get('badge_type_id');
var name = badge.get('displayName');
return ("000" + pos).slice(-4) + (10-type) + name;
});
var grouped = [];
var group = [], groupId;
sorted.forEach(function(badge){
if(groupId !== badge.badge_grouping_id){
if(group && group.length > 0){
grouped.push({badges: group, badgeGrouping: group[0].badge_grouping});
}
group = [];
groupId = badge.badge_grouping_id;
}
group.push(badge);
});
if(group && group.length > 0){
grouped.push({badges: group, badgeGrouping: group[0].badge_grouping});
}
return grouped;
}.property('model')
});