REFACTOR: Remove `_.sortBy`
This commit is contained in:
parent
2353794a30
commit
17bca14c4b
|
@ -52,15 +52,18 @@ export default Component.extend({
|
||||||
if (this.componentsTabActive) {
|
if (this.componentsTabActive) {
|
||||||
return themes.filter(theme => theme.get("parent_themes.length") > 0);
|
return themes.filter(theme => theme.get("parent_themes.length") > 0);
|
||||||
} else {
|
} else {
|
||||||
themes = themes.filter(
|
return themes
|
||||||
theme => theme.get("user_selectable") || theme.get("default")
|
.filter(theme => theme.get("user_selectable") || theme.get("default"))
|
||||||
);
|
.sort((a, b) => {
|
||||||
return _.sortBy(themes, t => {
|
if (a.get("default") && !b.get("default")) {
|
||||||
return [
|
return -1;
|
||||||
!t.get("default"),
|
} else if (b.get("default")) {
|
||||||
!t.get("user_selectable"),
|
return 1;
|
||||||
t.get("name").toLowerCase()
|
}
|
||||||
];
|
return a
|
||||||
|
.get("name")
|
||||||
|
.toLowerCase()
|
||||||
|
.localeCompare(b.get("name").toLowerCase());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
|
|
||||||
|
function badgeKey(badge) {
|
||||||
|
let pos = badge.get("badge_grouping.position");
|
||||||
|
let type = badge.get("badge_type_id");
|
||||||
|
let name = badge.get("name");
|
||||||
|
return ("000" + pos).slice(-4) + (10 - type) + name;
|
||||||
|
}
|
||||||
|
|
||||||
export default Controller.extend({
|
export default Controller.extend({
|
||||||
@discourseComputed("model")
|
@discourseComputed("model")
|
||||||
badgeGroups(model) {
|
badgeGroups(model) {
|
||||||
var sorted = _.sortBy(model, function(badge) {
|
let sorted = model.sort((a, b) => badgeKey(a).localeCompare(badgeKey(b)));
|
||||||
var pos = badge.get("badge_grouping.position");
|
let grouped = [];
|
||||||
var type = badge.get("badge_type_id");
|
let group = [];
|
||||||
var name = badge.get("name");
|
let groupId;
|
||||||
|
|
||||||
return ("000" + pos).slice(-4) + (10 - type) + name;
|
|
||||||
});
|
|
||||||
|
|
||||||
var grouped = [];
|
|
||||||
var group = [],
|
|
||||||
groupId;
|
|
||||||
|
|
||||||
sorted.forEach(function(badge) {
|
sorted.forEach(function(badge) {
|
||||||
if (groupId !== badge.badge_grouping_id) {
|
if (groupId !== badge.badge_grouping_id) {
|
||||||
|
|
|
@ -13,9 +13,9 @@ export default Mixin.create({
|
||||||
|
|
||||||
let userFields = this.site.get("user_fields");
|
let userFields = this.site.get("user_fields");
|
||||||
if (userFields) {
|
if (userFields) {
|
||||||
userFields = _.sortBy(userFields, "position").map(function(f) {
|
userFields = userFields
|
||||||
return EmberObject.create({ value: null, field: f });
|
.sortBy("position")
|
||||||
});
|
.map(f => EmberObject.create({ value: null, field: f }));
|
||||||
}
|
}
|
||||||
this.set("userFields", userFields);
|
this.set("userFields", userFields);
|
||||||
},
|
},
|
||||||
|
|
|
@ -544,9 +544,7 @@ Category.reopenClass({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _.sortBy(data, category => {
|
return data.sortBy("read_restricted");
|
||||||
return category.get("read_restricted");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue