mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 09:34:17 +08:00
Cosmetic changes.
This commit is contained in:
parent
d4cf0a58e3
commit
67a2b2598d
|
@ -8,6 +8,8 @@
|
||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
var RESERVED_BADGE_COUNT = 100;
|
||||||
|
|
||||||
Discourse.AdminBadgeController = Discourse.ObjectController.extend({
|
Discourse.AdminBadgeController = Discourse.ObjectController.extend({
|
||||||
/**
|
/**
|
||||||
Whether this badge has been selected.
|
Whether this badge has been selected.
|
||||||
|
@ -31,5 +33,5 @@ Discourse.AdminBadgeController = Discourse.ObjectController.extend({
|
||||||
@property readOnly
|
@property readOnly
|
||||||
@type {Boolean}
|
@type {Boolean}
|
||||||
**/
|
**/
|
||||||
readOnly: Ember.computed.lt('model.id', 100)
|
readOnly: Ember.computed.lt('model.id', RESERVED_BADGE_COUNT)
|
||||||
});
|
});
|
||||||
|
|
|
@ -84,8 +84,8 @@ Discourse.UserBadge.reopenClass({
|
||||||
**/
|
**/
|
||||||
findByUsername: function(username, options) {
|
findByUsername: function(username, options) {
|
||||||
var url = "/user_badges.json?username=" + username;
|
var url = "/user_badges.json?username=" + username;
|
||||||
if (options && options.aggregated) {
|
if (options && options.grouped) {
|
||||||
url += "&aggregated=true";
|
url += "&grouped=true";
|
||||||
}
|
}
|
||||||
return Discourse.ajax(url).then(function(json) {
|
return Discourse.ajax(url).then(function(json) {
|
||||||
return Discourse.UserBadge.createFromJson(json);
|
return Discourse.UserBadge.createFromJson(json);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
**/
|
**/
|
||||||
Discourse.UserBadgesRoute = Discourse.Route.extend({
|
Discourse.UserBadgesRoute = Discourse.Route.extend({
|
||||||
model: function() {
|
model: function() {
|
||||||
return Discourse.UserBadge.findByUsername(this.modelFor('user').get('username_lower'), {aggregated: true});
|
return Discourse.UserBadge.findByUsername(this.modelFor('user').get('username_lower'), {grouped: true});
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController: function(controller, model) {
|
setupController: function(controller, model) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ class UserBadgesController < ApplicationController
|
||||||
|
|
||||||
user_badges = user_badges.includes(:user, :granted_by, badge: :badge_type)
|
user_badges = user_badges.includes(:user, :granted_by, badge: :badge_type)
|
||||||
|
|
||||||
if params[:aggregated]
|
if params[:grouped]
|
||||||
user_badges = user_badges.group(:badge_id).select(UserBadge.attribute_names.map {|x| "MAX(#{x}) as #{x}" }, 'COUNT(*) as count')
|
user_badges = user_badges.group(:badge_id).select(UserBadge.attribute_names.map {|x| "MAX(#{x}) as #{x}" }, 'COUNT(*) as count')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ describe UserBadgesController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'includes counts when passed the aggregate argument' do
|
it 'includes counts when passed the aggregate argument' do
|
||||||
xhr :get, :index, username: user.username, aggregated: true
|
xhr :get, :index, username: user.username, grouped: true
|
||||||
|
|
||||||
response.status.should == 200
|
response.status.should == 200
|
||||||
parsed = JSON.parse(response.body)
|
parsed = JSON.parse(response.body)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user