Cosmetic changes.

This commit is contained in:
Vikhyat Korrapati 2014-06-10 06:53:18 +05:30
parent d4cf0a58e3
commit 67a2b2598d
5 changed files with 8 additions and 6 deletions

View File

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

View File

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

View File

@ -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) {

View File

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

View File

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