diff --git a/app/assets/javascripts/discourse/models/badge.js b/app/assets/javascripts/discourse/models/badge.js index 3a4ad3b8753..7fa14bf6142 100644 --- a/app/assets/javascripts/discourse/models/badge.js +++ b/app/assets/javascripts/discourse/models/badge.js @@ -164,7 +164,7 @@ Discourse.Badge.reopenClass({ @returns {Promise} a promise that resolves to an array of `Discourse.Badge` **/ findAll: function() { - return Discourse.ajax('/admin/badges').then(function(badgesJson) { + return Discourse.ajax('/badges.json').then(function(badgesJson) { return Discourse.Badge.createFromJson(badgesJson); }); } diff --git a/app/assets/javascripts/discourse/routes/application_routes.js b/app/assets/javascripts/discourse/routes/application_routes.js index 0dcc467aeb6..53fc50ef30c 100644 --- a/app/assets/javascripts/discourse/routes/application_routes.js +++ b/app/assets/javascripts/discourse/routes/application_routes.js @@ -94,4 +94,6 @@ Discourse.Route.buildRoutes(function() { this.route('signup', {path: '/signup'}); this.route('login', {path: '/login'}); + + this.route('badges'); }); diff --git a/app/assets/javascripts/discourse/routes/badges_route.js b/app/assets/javascripts/discourse/routes/badges_route.js new file mode 100644 index 00000000000..4852fc4bea6 --- /dev/null +++ b/app/assets/javascripts/discourse/routes/badges_route.js @@ -0,0 +1,13 @@ +/** + Shows a list of all badges. + + @class BadgesRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.BadgesRoute = Discourse.Route.extend({ + model: function() { + return Discourse.Badge.findAll(); + } +}); diff --git a/app/assets/javascripts/discourse/templates/badges.js.handlebars b/app/assets/javascripts/discourse/templates/badges.js.handlebars new file mode 100644 index 00000000000..334ce7c59d9 --- /dev/null +++ b/app/assets/javascripts/discourse/templates/badges.js.handlebars @@ -0,0 +1,13 @@ +
+

{{i18n badges.title}}

+ + + {{#each}} + + + + + + {{/each}} +
{{user-badge badge=this}}{{description}}{{i18n badges.awarded count=grant_count}}
+
diff --git a/app/assets/stylesheets/desktop/user-badges.scss b/app/assets/stylesheets/desktop/user-badges.scss index 66b4ac2024f..9141d4f0ecc 100644 --- a/app/assets/stylesheets/desktop/user-badges.scss +++ b/app/assets/stylesheets/desktop/user-badges.scss @@ -1,14 +1,16 @@ .user-badge { padding: 3px 8px; border: 1px solid $secondary-border-color; - font-size: 12px; + font-size: $base-font-size * 0.86; line-height: 16px; margin: 0; display: inline-block; + background-color: $primary_background_color; .fa { - padding-right: 5px; - font-size: 16px; + padding-right: 3px; + font-size: 1.4em; + vertical-align: bottom; } &.badge-type-gold .fa { @@ -23,3 +25,29 @@ color: #cd7f32; } } + +table.badges-listing { + margin-top: 20px; + border-bottom: 1px solid $primary-border-color; + + .user-badge { + font-size: $base-font-size; + } + + td { + padding: 10px 20px; + } + + td.grant-count { + font-size: 0.8em; + color: $secondary_text_color; + } + + td.badge, td.grant-count { + white-space: nowrap; + } + + tr { + border-top: 1px solid $primary-border-color; + } +} diff --git a/app/controllers/admin/badges_controller.rb b/app/controllers/admin/badges_controller.rb index 1cfb1ef8edb..92b119af80c 100644 --- a/app/controllers/admin/badges_controller.rb +++ b/app/controllers/admin/badges_controller.rb @@ -1,9 +1,4 @@ class Admin::BadgesController < Admin::AdminController - def index - badges = Badge.all.to_a - render_serialized(badges, BadgeSerializer, root: "badges") - end - def badge_types badge_types = BadgeType.all.to_a render_serialized(badge_types, BadgeTypeSerializer, root: "badge_types") diff --git a/app/controllers/badges_controller.rb b/app/controllers/badges_controller.rb new file mode 100644 index 00000000000..c256cbed60f --- /dev/null +++ b/app/controllers/badges_controller.rb @@ -0,0 +1,6 @@ +class BadgesController < ApplicationController + def index + badges = Badge.all.to_a + render_serialized(badges, BadgeSerializer, root: "badges") + end +end diff --git a/app/serializers/badge_serializer.rb b/app/serializers/badge_serializer.rb index 05173cc30cf..34b72959846 100644 --- a/app/serializers/badge_serializer.rb +++ b/app/serializers/badge_serializer.rb @@ -1,5 +1,5 @@ class BadgeSerializer < ApplicationSerializer - attributes :id, :name, :description + attributes :id, :name, :description, :grant_count has_one :badge_type end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 0820df06c56..f35abee7636 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1768,12 +1768,16 @@ en: mark_watching: 'm then w Mark topic as watching' badges: + title: Badges badge_count: one: "1 Badge" other: "%{count} Badges" more_badges: one: "+1 More" other: "+%{count} More" + awarded: + one: "1 awarded" + other: "%{count} awarded" example_badge: name: Example Badge description: This is a generic example badge. diff --git a/config/routes.rb b/config/routes.rb index 89fd083787b..3afb6af3722 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -242,6 +242,7 @@ Discourse::Application.routes.draw do end resources :user_actions + resources :badges, only: [:index] resources :user_badges, only: [:index, :create, :destroy] # We've renamed popular to latest. If people access it we want a permanent redirect. diff --git a/spec/controllers/admin/badges_controller_spec.rb b/spec/controllers/admin/badges_controller_spec.rb index 5359c278f74..62674af346a 100644 --- a/spec/controllers/admin/badges_controller_spec.rb +++ b/spec/controllers/admin/badges_controller_spec.rb @@ -9,18 +9,6 @@ describe Admin::BadgesController do let!(:user) { log_in(:admin) } let!(:badge) { Fabricate(:badge) } - context '.index' do - it 'returns success' do - xhr :get, :index - response.should be_success - end - - it 'returns JSON' do - xhr :get, :index - ::JSON.parse(response.body)["badges"].should be_present - end - end - context '.badge_types' do it 'returns success' do xhr :get, :badge_types diff --git a/spec/controllers/badges_controller_spec.rb b/spec/controllers/badges_controller_spec.rb new file mode 100644 index 00000000000..60bd0ed368a --- /dev/null +++ b/spec/controllers/badges_controller_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe BadgesController do + let!(:badge) { Fabricate(:badge) } + + context 'index' do + it 'should return a list of all badges' do + xhr :get, :index + + response.status.should == 200 + parsed = JSON.parse(response.body) + parsed["badges"].length.should == 1 + end + end +end