From e0fd1f6f5e8254f838d71528a3c9f9db01844cb9 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Tue, 10 Jun 2014 13:02:22 +0530 Subject: [PATCH] Add ability to specify custom font awesome icon for badges. --- .../javascripts/admin/templates/badges.js.handlebars | 7 ++++++- .../javascripts/discourse/components/user-badge.js.es6 | 6 +++++- app/assets/javascripts/discourse/models/badge.js | 3 ++- .../templates/components/user-badge.js.handlebars | 4 +++- app/controllers/admin/badges_controller.rb | 1 + app/serializers/badge_serializer.rb | 2 +- config/locales/client.en.yml | 1 + db/migrate/20140610012833_add_icon_to_badges.rb | 5 +++++ 8 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20140610012833_add_icon_to_badges.rb diff --git a/app/assets/javascripts/admin/templates/badges.js.handlebars b/app/assets/javascripts/admin/templates/badges.js.handlebars index ae0524deff2..f9c08422ae4 100644 --- a/app/assets/javascripts/admin/templates/badges.js.handlebars +++ b/app/assets/javascripts/admin/templates/badges.js.handlebars @@ -23,7 +23,7 @@
- {{input type="text" name="name" value=name disabled=readOnly}} + {{input type="text" name="name" value=name disabled=readonly}}
{{#if showDisplayName}} @@ -33,6 +33,11 @@ {{/if}} +
+ + {{input type="text" name="name" value=icon disabled=readonly}} +
+
{{view Ember.Select name="badge_type_id" value=badge_type_id diff --git a/app/assets/javascripts/discourse/components/user-badge.js.es6 b/app/assets/javascripts/discourse/components/user-badge.js.es6 index b4e97ecb0d1..bc63ace449e 100644 --- a/app/assets/javascripts/discourse/components/user-badge.js.es6 +++ b/app/assets/javascripts/discourse/components/user-badge.js.es6 @@ -7,5 +7,9 @@ export default Ember.Component.extend({ showGrantCount: function() { return this.get('count') && this.get('count') > 1; - }.property('count') + }.property('count'), + + isIcon: function() { + return this.get('badge.icon').match(/^fa-/); + }.property('badge.icon') }); diff --git a/app/assets/javascripts/discourse/models/badge.js b/app/assets/javascripts/discourse/models/badge.js index f709ef29c1a..682534d3875 100644 --- a/app/assets/javascripts/discourse/models/badge.js +++ b/app/assets/javascripts/discourse/models/badge.js @@ -116,7 +116,8 @@ Discourse.Badge = Discourse.Model.extend({ description: this.get('description'), badge_type_id: this.get('badge_type_id'), allow_title: !!this.get('allow_title'), - multiple_grant: !!this.get('multiple_grant') + multiple_grant: !!this.get('multiple_grant'), + icon: this.get('icon') } }).then(function(json) { self.updateFromJson(json); diff --git a/app/assets/javascripts/discourse/templates/components/user-badge.js.handlebars b/app/assets/javascripts/discourse/templates/components/user-badge.js.handlebars index 1e749080a87..dceafcda789 100644 --- a/app/assets/javascripts/discourse/templates/components/user-badge.js.handlebars +++ b/app/assets/javascripts/discourse/templates/components/user-badge.js.handlebars @@ -1,6 +1,8 @@ {{#link-to 'badges.show' badge}} - + {{#if isIcon}} + + {{/if}} {{badge.displayName}} {{#if showGrantCount}} (× {{count}}) diff --git a/app/controllers/admin/badges_controller.rb b/app/controllers/admin/badges_controller.rb index 2715f4cdf49..33d7f7645fe 100644 --- a/app/controllers/admin/badges_controller.rb +++ b/app/controllers/admin/badges_controller.rb @@ -36,6 +36,7 @@ class Admin::BadgesController < Admin::AdminController badge.badge_type = BadgeType.find(params[:badge_type_id]) badge.allow_title = params[:allow_title] badge.multiple_grant = params[:multiple_grant] + badge.icon = params[:icon] badge end end diff --git a/app/serializers/badge_serializer.rb b/app/serializers/badge_serializer.rb index ac6e2fcc092..22111deee61 100644 --- a/app/serializers/badge_serializer.rb +++ b/app/serializers/badge_serializer.rb @@ -1,5 +1,5 @@ class BadgeSerializer < ApplicationSerializer - attributes :id, :name, :description, :grant_count, :allow_title, :multiple_grant + attributes :id, :name, :description, :grant_count, :allow_title, :multiple_grant, :icon has_one :badge_type end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 9be4a236d16..d10cb8fe7a1 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1856,6 +1856,7 @@ en: no_badges: There are no badges that can be granted. allow_title: Allow badge to be used as a title multiple_grant: Can be granted multiple times + icon: Icon lightbox: download: "download" diff --git a/db/migrate/20140610012833_add_icon_to_badges.rb b/db/migrate/20140610012833_add_icon_to_badges.rb new file mode 100644 index 00000000000..7610385079d --- /dev/null +++ b/db/migrate/20140610012833_add_icon_to_badges.rb @@ -0,0 +1,5 @@ +class AddIconToBadges < ActiveRecord::Migration + def change + add_column :badges, :icon, :string, default: "fa-certificate" + end +end