From 6225b83f4ad437d634db2d183236870b72c1e850 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Mon, 19 May 2014 09:59:12 +0530 Subject: [PATCH 1/4] Show system badges in the admin interface but don't allow editing them. --- .../controllers/admin_badge_controller.js | 18 +++++++- .../controllers/admin_badges_controller.js | 12 +----- .../admin/routes/admin_badges_route.js | 6 +-- .../admin/templates/badges.js.handlebars | 41 ++++++++++--------- .../admin_badges_controller_test.js | 29 ++++--------- 5 files changed, 49 insertions(+), 57 deletions(-) diff --git a/app/assets/javascripts/admin/controllers/admin_badge_controller.js b/app/assets/javascripts/admin/controllers/admin_badge_controller.js index d45f280d1ed..cdc06cfe74c 100644 --- a/app/assets/javascripts/admin/controllers/admin_badge_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_badge_controller.js @@ -15,5 +15,21 @@ Discourse.AdminBadgeController = Discourse.ObjectController.extend({ @property selected @type {Boolean} **/ - selected: Discourse.computed.propertyEqual('model.name', 'parentController.selectedItem.name') + selected: Discourse.computed.propertyEqual('model.name', 'parentController.selectedItem.name'), + + /** + Show the displayName only if it is different from the name. + + @property showDisplayName + @type {Boolean} + **/ + showDisplayName: Discourse.computed.propertyNotEqual('selectedItem.name', 'selectedItem.displayName'), + + /** + Don't allow editing if this is a system badge. + + @property readOnly + @type {Boolean} + **/ + readOnly: Ember.computed.lt('model.id', 100) }); diff --git a/app/assets/javascripts/admin/controllers/admin_badges_controller.js b/app/assets/javascripts/admin/controllers/admin_badges_controller.js index 1cf2615ad61..c41479ca5bd 100644 --- a/app/assets/javascripts/admin/controllers/admin_badges_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_badges_controller.js @@ -10,16 +10,8 @@ Discourse.AdminBadgesController = Ember.ArrayController.extend({ itemController: 'adminBadge', /** - Show the displayName only if it is different from the name. - - @property showDisplayName - @type {Boolean} - **/ - showDisplayName: Discourse.computed.propertyNotEqual('selectedItem.name', 'selectedItem.displayName'), - - /** - We don't allow setting a description if a translation for the given badge name - exists. + We don't allow setting a description if a translation for the given badge + name exists. @property canEditDescription @type {Boolean} diff --git a/app/assets/javascripts/admin/routes/admin_badges_route.js b/app/assets/javascripts/admin/routes/admin_badges_route.js index 39b2f97e84d..1c606b5578e 100644 --- a/app/assets/javascripts/admin/routes/admin_badges_route.js +++ b/app/assets/javascripts/admin/routes/admin_badges_route.js @@ -1,11 +1,7 @@ Discourse.AdminBadgesRoute = Discourse.Route.extend({ model: function() { - return Discourse.Badge.findAll().then(function(badges) { - return badges.filter(function(badge) { - return badge.id >= 100; - }); - }); + return Discourse.Badge.findAll(); }, setupController: function(controller, model) { diff --git a/app/assets/javascripts/admin/templates/badges.js.handlebars b/app/assets/javascripts/admin/templates/badges.js.handlebars index 1ecdfe977b5..e888b2d8961 100644 --- a/app/assets/javascripts/admin/templates/badges.js.handlebars +++ b/app/assets/javascripts/admin/templates/badges.js.handlebars @@ -18,19 +18,19 @@ {{#if selectedItem}} - {{#with selectedItem}} + {{#with selectedItem controller='adminBadge'}}
- {{input type="text" name="name" value=name}} + {{input type="text" name="name" value=name disabled=readOnly}}
- {{#if controller.showDisplayName}} -
- {{i18n admin.badges.display_name}} - {{displayName}} -
+ {{#if showDisplayName}} +
+ {{i18n admin.badges.display_name}} + {{displayName}} +
{{/if}}
@@ -38,7 +38,8 @@ {{view Ember.Select name="badge_type_id" value=badge_type_id content=controller.badgeTypes optionValuePath="content.id" - optionLabelPath="content.name"}} + optionLabelPath="content.name" + disabled=readOnly}}
@@ -50,18 +51,20 @@ {{/if}}
-
- - {{input type="checkbox" checked=allow_title}} - {{i18n admin.badges.allow_title}} - -
+ {{#unless readOnly}} +
+ + {{input type="checkbox" checked=allow_title}} + {{i18n admin.badges.allow_title}} + +
-
- - {{savingStatus}} - {{i18n admin.badges.delete}} -
+
+ + {{savingStatus}} + {{i18n admin.badges.delete}} +
+ {{/unless}}
{{/with}} diff --git a/test/javascripts/admin/controllers/admin_badges_controller_test.js b/test/javascripts/admin/controllers/admin_badges_controller_test.js index 532c8cb3620..f310d785278 100644 --- a/test/javascripts/admin/controllers/admin_badges_controller_test.js +++ b/test/javascripts/admin/controllers/admin_badges_controller_test.js @@ -1,30 +1,15 @@ module("Discourse.AdminBadgesController"); -test("showDisplayName", function() { - var badge, controller; - - badge = Discourse.Badge.create({name: "Test Badge"}); - controller = testController(Discourse.AdminBadgesController, [badge]); - controller.send('selectBadge', badge); - ok(!controller.get('showDisplayName'), "does not show displayName when it is the same as the name"); - - this.stub(I18n, "t").returns("translated string"); - badge = Discourse.Badge.create({name: "Test Badge"}); - controller = testController(Discourse.AdminBadgesController, [badge]); - controller.send('selectBadge', badge); - ok(controller.get('showDisplayName'), "shows the displayName when it is different from the name"); -}); - test("canEditDescription", function() { var badge, controller; - badge = Discourse.Badge.create({name: "Test Badge"}); + badge = Discourse.Badge.create({id: 101, name: "Test Badge"}); controller = testController(Discourse.AdminBadgesController, [badge]); controller.send('selectBadge', badge); ok(controller.get('canEditDescription'), "allows editing description when a translation exists for the badge name"); this.stub(I18n, "t").returns("translated string"); - badge = Discourse.Badge.create({name: "Test Badge"}); + badge = Discourse.Badge.create({id: 102, name: "Test Badge"}); controller = testController(Discourse.AdminBadgesController, [badge]); controller.send('selectBadge', badge); ok(!controller.get('canEditDescription'), "shows the displayName when it is different from the name"); @@ -38,7 +23,7 @@ test("newBadge", function() { }); test("selectBadge", function() { - var badge = Discourse.Badge.create({name: "Test Badge"}), + var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}), controller = testController(Discourse.AdminBadgesController, [badge]); controller.send('selectBadge', badge); @@ -46,8 +31,8 @@ test("selectBadge", function() { }); test("save", function() { - var badge = Discourse.Badge.create({name: "Test Badge"}), - otherBadge = Discourse.Badge.create({name: "Other Badge"}), + var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}), + otherBadge = Discourse.Badge.create({id: 102, name: "Other Badge"}), controller = testController(Discourse.AdminBadgesController, [badge, otherBadge]); controller.send('selectBadge', badge); @@ -57,8 +42,8 @@ test("save", function() { }); test("destroy", function() { - var badge = Discourse.Badge.create({name: "Test Badge"}), - otherBadge = Discourse.Badge.create({name: "Other Badge"}), + var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}), + otherBadge = Discourse.Badge.create({id: 102, name: "Other Badge"}), controller = testController(Discourse.AdminBadgesController, [badge, otherBadge]); this.stub(badge, 'destroy').returns(Ember.RSVP.resolve({})); From 6b7b328c66a460c60e839b13c8111cfb2c0fd139 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Mon, 19 May 2014 10:23:11 +0530 Subject: [PATCH 2/4] Badges page ordering and titles. --- .../javascripts/discourse/controllers/badges/index.js.es6 | 4 ++++ .../javascripts/discourse/routes/badges_index_route.js | 5 +++++ app/assets/javascripts/discourse/routes/badges_show_route.js | 1 + 3 files changed, 10 insertions(+) create mode 100644 app/assets/javascripts/discourse/controllers/badges/index.js.es6 diff --git a/app/assets/javascripts/discourse/controllers/badges/index.js.es6 b/app/assets/javascripts/discourse/controllers/badges/index.js.es6 new file mode 100644 index 00000000000..7a52169dd08 --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/badges/index.js.es6 @@ -0,0 +1,4 @@ +export default Ember.ArrayController.extend({ + sortProperties: ['displayName'], + sortAscending: true +}); diff --git a/app/assets/javascripts/discourse/routes/badges_index_route.js b/app/assets/javascripts/discourse/routes/badges_index_route.js index 520677d24ee..f7bf2667471 100644 --- a/app/assets/javascripts/discourse/routes/badges_index_route.js +++ b/app/assets/javascripts/discourse/routes/badges_index_route.js @@ -15,5 +15,10 @@ Discourse.BadgesIndexRoute = Discourse.Route.extend({ } else { return Discourse.Badge.findAll(); } + }, + + setupController: function(controller, model) { + controller.set('model', model); + Discourse.set('title', I18n.t('badges.title')); } }); diff --git a/app/assets/javascripts/discourse/routes/badges_show_route.js b/app/assets/javascripts/discourse/routes/badges_show_route.js index a4c4cc83180..842bf36e324 100644 --- a/app/assets/javascripts/discourse/routes/badges_show_route.js +++ b/app/assets/javascripts/discourse/routes/badges_show_route.js @@ -27,6 +27,7 @@ Discourse.BadgesShowRoute = Ember.Route.extend({ controller.set('userBadgesLoaded', true); }); controller.set('model', model); + Discourse.set('title', model.get('displayName')); }, actions: { From 4de700b49ba3bef7657eb05c8d374fdd5402fc05 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Mon, 19 May 2014 10:32:59 +0530 Subject: [PATCH 3/4] Change badge user list limit to 96 so that it is divisible by 8. --- app/controllers/user_badges_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/user_badges_controller.rb b/app/controllers/user_badges_controller.rb index 1a928424c54..ad11f75f426 100644 --- a/app/controllers/user_badges_controller.rb +++ b/app/controllers/user_badges_controller.rb @@ -7,7 +7,7 @@ class UserBadgesController < ApplicationController user_badges = user.user_badges else badge = fetch_badge_from_params - user_badges = badge.user_badges.order('granted_at DESC').limit(100) + user_badges = badge.user_badges.order('granted_at DESC').limit(96) end if params[:granted_before] From a25087b62a2e78b6a0ab3341ac52e0fdca8d858a Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Mon, 19 May 2014 10:50:57 +0530 Subject: [PATCH 4/4] Badges admin UI improvements. * Query param to allow linking. * Better handling of deleting unsaved badges. * New badge list item style improvement. --- .../admin/controllers/admin_badges_controller.js | 16 ++++++++++++++++ .../admin/templates/badges.js.handlebars | 16 ++++++++-------- .../stylesheets/common/admin/admin_base.scss | 10 ++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/admin/controllers/admin_badges_controller.js b/app/assets/javascripts/admin/controllers/admin_badges_controller.js index c41479ca5bd..9ec65709a2b 100644 --- a/app/assets/javascripts/admin/controllers/admin_badges_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_badges_controller.js @@ -8,6 +8,15 @@ **/ Discourse.AdminBadgesController = Ember.ArrayController.extend({ itemController: 'adminBadge', + queryParams: ['badgeId'], + + /** + ID of the currently selected badge. + + @property badgeId + @type {Integer} + **/ + badgeId: Em.computed.alias('selectedItem.id'), /** We don't allow setting a description if a translation for the given badge @@ -68,6 +77,13 @@ Discourse.AdminBadgesController = Ember.ArrayController.extend({ @method destroy **/ destroy: function() { + // Delete immediately if the selected badge is new. + if (!this.get('selectedItem.id')) { + this.get('model').removeObject(this.get('selectedItem')); + this.set('selectedItem', null); + return; + } + var self = this; return bootbox.confirm(I18n.t("admin.badges.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) { if (result) { diff --git a/app/assets/javascripts/admin/templates/badges.js.handlebars b/app/assets/javascripts/admin/templates/badges.js.handlebars index e888b2d8961..6b1b513c023 100644 --- a/app/assets/javascripts/admin/templates/badges.js.handlebars +++ b/app/assets/javascripts/admin/templates/badges.js.handlebars @@ -8,7 +8,7 @@ {{displayName}} {{#if newBadge}} - ({{i18n filters.new.lower_title}}) + {{i18n filters.new.lower_title}} {{/if}} @@ -51,14 +51,14 @@ {{/if}} - {{#unless readOnly}} -
- - {{input type="checkbox" checked=allow_title}} - {{i18n admin.badges.allow_title}} - -
+
+ + {{input type="checkbox" checked=allow_title disabled=readOnly}} + {{i18n admin.badges.allow_title}} + +
+ {{#unless readOnly}}
{{savingStatus}} diff --git a/app/assets/stylesheets/common/admin/admin_base.scss b/app/assets/stylesheets/common/admin/admin_base.scss index a720a0f4574..2b24c3e26eb 100644 --- a/app/assets/stylesheets/common/admin/admin_base.scss +++ b/app/assets/stylesheets/common/admin/admin_base.scss @@ -326,6 +326,16 @@ section.details { .badges { .content-list ul { margin-bottom: 10px; + + .list-badge { + float: right; + font-size: 11px; + font-weight: normal; + padding: 0 6px; + color: $secondary; + background-color: scale-color($tertiary, $lightness: 50%); + border-radius: 3px; + } } .current-badge {