FEATURE: show user what badges they have

This commit is contained in:
Sam 2014-07-16 17:53:54 +10:00
parent 986747bfc4
commit e347eea629
4 changed files with 24 additions and 4 deletions

View File

@ -5,6 +5,7 @@
<tbody>
{{#each}}
<tr>
<td class='granted'>{{#if this.has_badge}}<i class='fa fa-check'></i>{{/if}}</td>
<td class='badge'>{{user-badge badge=this}}</td>
<td class='description'>{{displayDescription}}</td>
<td class='grant-count'>{{i18n badges.granted count=grant_count}}</td>

View File

@ -76,15 +76,23 @@ table.badges-listing {
}
td {
padding: 10px 20px;
padding: 10px 0px;
}
td.granted{
color: $success;
font-size: 120%;
}
td.grant-count {
text-align: right;
color: scale-color($primary, $lightness: 40%);
font-size: 90%;
}
td.badge, td.grant-count {
white-space: nowrap;
padding-right: 10px;
}
td.info {

View File

@ -5,7 +5,11 @@ class BadgesController < ApplicationController
badges = Badge.all
badges = badges.where(enabled: true, listable: true) if(params[:only_listable] == "true") || !request.xhr?
badges = badges.to_a
serialized = MultiJson.dump(serialize_data(badges, BadgeSerializer, root: "badges"))
user_badges = nil
if current_user
user_badges = Set.new(current_user.user_badges.select('distinct badge_id').pluck(:badge_id))
end
serialized = MultiJson.dump(serialize_data(badges, BadgeSerializer, root: "badges", user_badges: user_badges))
respond_to do |format|
format.html do
store_preloaded "badges", serialized

View File

@ -1,5 +1,12 @@
class BadgeSerializer < ApplicationSerializer
attributes :id, :name, :description, :grant_count, :allow_title, :multiple_grant, :icon, :listable, :enabled
attributes :id, :name, :description, :grant_count, :allow_title, :multiple_grant, :icon, :listable, :enabled, :has_badge
has_one :badge_type
def include_has_badge?
@options[:user_badges]
end
def has_badge
@options[:user_badges].include?(object.id)
end
end