mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 15:32:26 +08:00
REFACTOR: Remove _.groupBy
This commit is contained in:
parent
1265a5f7c0
commit
b4444070b3
|
@ -24,13 +24,17 @@ export default Controller.extend(GrantBadgeController, {
|
||||||
groupedBadges() {
|
groupedBadges() {
|
||||||
const allBadges = this.model;
|
const allBadges = this.model;
|
||||||
|
|
||||||
var grouped = _.groupBy(allBadges, badge => badge.badge_id);
|
let grouped = {};
|
||||||
|
allBadges.forEach(b => {
|
||||||
|
grouped[b.badge_id] = grouped[b.badge_id] || [];
|
||||||
|
grouped[b.badge_id].push(b);
|
||||||
|
});
|
||||||
|
|
||||||
var expanded = [];
|
let expanded = [];
|
||||||
const expandedBadges = allBadges.get("expandedBadges") || [];
|
const expandedBadges = allBadges.get("expandedBadges") || [];
|
||||||
|
|
||||||
_(grouped).each(function(badges) {
|
Object.values(grouped).forEach(function(badges) {
|
||||||
var lastGranted = badges[0].granted_at;
|
let lastGranted = badges[0].granted_at;
|
||||||
|
|
||||||
badges.forEach(badge => {
|
badges.forEach(badge => {
|
||||||
lastGranted =
|
lastGranted =
|
||||||
|
@ -42,7 +46,7 @@ export default Controller.extend(GrantBadgeController, {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = {
|
let result = {
|
||||||
badge: badges[0].badge,
|
badge: badges[0].badge,
|
||||||
granted_at: lastGranted,
|
granted_at: lastGranted,
|
||||||
badges: badges,
|
badges: badges,
|
||||||
|
@ -53,10 +57,7 @@ export default Controller.extend(GrantBadgeController, {
|
||||||
expanded.push(result);
|
expanded.push(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
return _(expanded)
|
return expanded.sortBy("granted_at").reverse();
|
||||||
.sortBy(group => group.granted_at)
|
|
||||||
.reverse()
|
|
||||||
.value();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user