From 4c0f85650ec90bc1bbe23d9feb2ad577d6415917 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Wed, 16 Apr 2014 15:52:21 +0530 Subject: [PATCH] Display badge count in the user admin page. --- .../javascripts/admin/templates/user_index.js.handlebars | 2 +- app/models/user.rb | 4 ++++ app/serializers/admin_detailed_user_serializer.rb | 3 ++- app/serializers/user_serializer.rb | 3 --- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/admin/templates/user_index.js.handlebars b/app/assets/javascripts/admin/templates/user_index.js.handlebars index bdbdde76194..89ce976275d 100644 --- a/app/assets/javascripts/admin/templates/user_index.js.handlebars +++ b/app/assets/javascripts/admin/templates/user_index.js.handlebars @@ -81,7 +81,7 @@
{{i18n admin.badges.title}}
- TODO featured badges + {{i18n badges.badge_count count=badge_count}}
{{#link-to 'adminUser.badges' this class="btn"}}{{i18n admin.badges.edit_badges}}{{/link-to}} diff --git a/app/models/user.rb b/app/models/user.rb index de6db4cc337..238a2a0f6c1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -492,6 +492,10 @@ class User < ActiveRecord::Base Summarize.new(bio_cooked).summary end + def badge_count + user_badges.count + end + def featured_user_badges user_badges.joins(:badge).order('badges.badge_type_id ASC, badges.grant_count ASC').includes(:granted_by, badge: :badge_type).limit(3) end diff --git a/app/serializers/admin_detailed_user_serializer.rb b/app/serializers/admin_detailed_user_serializer.rb index 685c34c1c45..32ba08cff34 100644 --- a/app/serializers/admin_detailed_user_serializer.rb +++ b/app/serializers/admin_detailed_user_serializer.rb @@ -15,7 +15,8 @@ class AdminDetailedUserSerializer < AdminUserSerializer :can_delete_all_posts, :can_be_deleted, :suspend_reason, - :primary_group_id + :primary_group_id, + :badge_count has_one :approved_by, serializer: BasicUserSerializer, embed: :objects has_one :api_key, serializer: ApiKeySerializer, embed: :objects diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index df35418f94e..fc597762a98 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -131,7 +131,4 @@ class UserSerializer < BasicUserSerializer CategoryUser.lookup(object, :watching).pluck(:category_id) end - def badge_count - object.user_badges.count - end end