From b55734da911227e2db53d13e49fef98894357ee6 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Thu, 17 Apr 2014 00:19:28 +0530 Subject: [PATCH] Add badges tab to user profile. --- .../discourse/controllers/user_controller.js | 4 +++ .../discourse/routes/application_routes.js | 2 ++ .../discourse/routes/user_badges_route.js | 25 +++++++++++++++++++ .../templates/user/badges.js.handlebars | 5 ++++ .../templates/user/user.js.handlebars | 10 ++++++++ .../stylesheets/desktop/user-badges.scss | 21 ++++++++++++++++ config/routes.rb | 1 + 7 files changed, 68 insertions(+) create mode 100644 app/assets/javascripts/discourse/routes/user_badges_route.js create mode 100644 app/assets/javascripts/discourse/templates/user/badges.js.handlebars diff --git a/app/assets/javascripts/discourse/controllers/user_controller.js b/app/assets/javascripts/discourse/controllers/user_controller.js index 65b03627449..1054198763b 100644 --- a/app/assets/javascripts/discourse/controllers/user_controller.js +++ b/app/assets/javascripts/discourse/controllers/user_controller.js @@ -18,6 +18,10 @@ Discourse.UserController = Discourse.ObjectController.extend({ return this.get('viewingSelf') || Discourse.User.currentProp('admin'); }.property('viewingSelf'), + showBadges: function() { + return Discourse.SiteSettings.enable_badges; + }.property(), + privateMessageView: function() { return (this.get('userActionType') === Discourse.UserAction.TYPES.messages_sent) || (this.get('userActionType') === Discourse.UserAction.TYPES.messages_received); diff --git a/app/assets/javascripts/discourse/routes/application_routes.js b/app/assets/javascripts/discourse/routes/application_routes.js index 261b9291749..fb739f58587 100644 --- a/app/assets/javascripts/discourse/routes/application_routes.js +++ b/app/assets/javascripts/discourse/routes/application_routes.js @@ -78,6 +78,8 @@ Discourse.Route.buildRoutes(function() { }); }); + this.route('badges'); + this.resource('userPrivateMessages', { path: '/private-messages' }, function() { this.route('mine'); this.route('unread'); diff --git a/app/assets/javascripts/discourse/routes/user_badges_route.js b/app/assets/javascripts/discourse/routes/user_badges_route.js new file mode 100644 index 00000000000..97ad6ddf92f --- /dev/null +++ b/app/assets/javascripts/discourse/routes/user_badges_route.js @@ -0,0 +1,25 @@ +/** + This route shows a user's badges. + + @class UserBadgesRoute + @extends Discourse.Route + @namespace Discourse + @module Discourse +**/ +Discourse.UserBadgesRoute = Discourse.Route.extend({ + model: function() { + return Discourse.UserBadge.findByUsername(this.modelFor('user').get('username_lower')); + }, + + setupController: function(controller, model) { + this.controllerFor('user').set('indexStream', false); + if (this.controllerFor('user_activity').get('content')) { + this.controllerFor('user_activity').set('userActionType', -1); + } + controller.set('model', model); + }, + + renderTemplate: function() { + this.render('user/badges', {into: 'user', outlet: 'userOutlet'}); + } +}); diff --git a/app/assets/javascripts/discourse/templates/user/badges.js.handlebars b/app/assets/javascripts/discourse/templates/user/badges.js.handlebars new file mode 100644 index 00000000000..6cbf2003cf9 --- /dev/null +++ b/app/assets/javascripts/discourse/templates/user/badges.js.handlebars @@ -0,0 +1,5 @@ +
+ {{#each}} + {{user-badge badge=badge}} + {{/each}} +
diff --git a/app/assets/javascripts/discourse/templates/user/user.js.handlebars b/app/assets/javascripts/discourse/templates/user/user.js.handlebars index 882f9999c08..0cf25536aad 100644 --- a/app/assets/javascripts/discourse/templates/user/user.js.handlebars +++ b/app/assets/javascripts/discourse/templates/user/user.js.handlebars @@ -13,6 +13,16 @@ {{#each stat in statsExcludingPms}} {{discourse-activity-filter content=stat user=model userActionType=userActionType indexStream=indexStream}} {{/each}} + {{#if showBadges}} + {{#link-to 'user.badges' tagName="li"}} + {{#link-to 'user.badges'}} + + {{i18n badges.title}} + ({{badge_count}}) + + {{/link-to}} + {{/link-to}} + {{/if}} {{#if canSeePrivateMessages}} diff --git a/app/assets/stylesheets/desktop/user-badges.scss b/app/assets/stylesheets/desktop/user-badges.scss index 941e715a2a0..2be02acb1fb 100644 --- a/app/assets/stylesheets/desktop/user-badges.scss +++ b/app/assets/stylesheets/desktop/user-badges.scss @@ -1,3 +1,4 @@ +/* Default badge styles. */ .user-badge { padding: 3px 8px; color: $primary_text_color; @@ -27,6 +28,26 @@ } } +/* User badge listing. */ +.user-badges-list { + text-align: center; + + .user-badge { + max-width: 80px; + text-align: center; + vertical-align: top; + margin: 10px; + border: none; + + .fa { + display: block; + font-size: 50px; + margin-bottom: 5px; + } + } +} + +/* Badge listing in /badges. */ table.badges-listing { margin: 20px 0; border-bottom: 1px solid $primary-border-color; diff --git a/config/routes.rb b/config/routes.rb index 2bf6bfa3565..bb3b6e64b75 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -195,6 +195,7 @@ Discourse::Application.routes.draw do post "users/:username/send_activation_email" => "users#send_activation_email", constraints: {username: USERNAME_ROUTE_FORMAT} get "users/:username/activity" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT} get "users/:username/activity/:filter" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT} + get "users/:username/badges" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT} delete "users/:username" => "users#destroy", constraints: {username: USERNAME_ROUTE_FORMAT} get "uploads/:site/:id/:sha.:extension" => "uploads#show", constraints: {site: /\w+/, id: /\d+/, sha: /[a-z0-9]{15,16}/i, extension: /\w{2,}/}