From d29822e4cb7a0838c16956058fa7b89588047210 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 5 Aug 2014 16:01:49 -0400 Subject: [PATCH] TWEAK: Sum new and unread in the site map category list --- .../controllers/site-map-category.js.es6 | 13 +++++-- .../discourse/controllers/site-map.js.es6 | 2 - .../templates/site_map.js.handlebars | 16 ++++---- .../controllers/site-map-category-test.js.es6 | 37 +++++++++++++------ .../controllers/site-map-test.js.es6 | 4 -- 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/site-map-category.js.es6 b/app/assets/javascripts/discourse/controllers/site-map-category.js.es6 index ce46fa102..cf10e9d6b 100644 --- a/app/assets/javascripts/discourse/controllers/site-map-category.js.es6 +++ b/app/assets/javascripts/discourse/controllers/site-map-category.js.es6 @@ -1,5 +1,10 @@ -export default Ember.ObjectController.extend({ - showBadges: function() { - return !!Discourse.User.current(); - }.property().volatile() +export default Ember.ObjectController.extend(Discourse.HasCurrentUser, { + needs: ['site-map'], + + unreadTotal: function() { + return parseInt(this.get('unreadTopics'), 10) + + parseInt(this.get('newTopics'), 10); + }.property('unreadTopics', 'newTopics'), + + showTopicCount: Em.computed.not('currentUser') }); diff --git a/app/assets/javascripts/discourse/controllers/site-map.js.es6 b/app/assets/javascripts/discourse/controllers/site-map.js.es6 index 9e96862d1..385b1afb9 100644 --- a/app/assets/javascripts/discourse/controllers/site-map.js.es6 +++ b/app/assets/javascripts/discourse/controllers/site-map.js.es6 @@ -1,6 +1,4 @@ export default Ember.ArrayController.extend(Discourse.HasCurrentUser, { - itemController: "site-map-category", - showBadgesLink: function(){return Discourse.SiteSettings.enable_badges;}.property(), showAdminLinks: Em.computed.alias('currentUser.staff'), flaggedPostsCount: Em.computed.alias("currentUser.site_flagged_posts_count"), diff --git a/app/assets/javascripts/discourse/templates/site_map.js.handlebars b/app/assets/javascripts/discourse/templates/site_map.js.handlebars index 9f2f2b087..94490e602 100644 --- a/app/assets/javascripts/discourse/templates/site_map.js.handlebars +++ b/app/assets/javascripts/discourse/templates/site_map.js.handlebars @@ -38,17 +38,15 @@ {{#link-to "discovery.categories"}}{{i18n filters.categories.title}}{{/link-to}} - {{#each categories itemController=itemController}} + {{#each categories itemController='site-map-category'}}
  • {{category-link this allowUncategorized=true showParent=true}} - {{#if showBadges}} - {{#if unreadTopics}} - {{unreadTopics}} - {{/if}} - {{#if newTopics}} - {{newTopics}} {{i18n filters.new.title.zero}} - {{/if}} - {{else}} + + {{#if unreadTotal}} + {{unreadTotal}} + {{/if}} + + {{#if showTopicCount}} {{unbound topic_count}} {{/if}}
  • diff --git a/test/javascripts/controllers/site-map-category-test.js.es6 b/test/javascripts/controllers/site-map-category-test.js.es6 index 2c7eef736..897779978 100644 --- a/test/javascripts/controllers/site-map-category-test.js.es6 +++ b/test/javascripts/controllers/site-map-category-test.js.es6 @@ -1,12 +1,27 @@ -moduleFor("controller:site-map-category"); - -test("showBadges", function() { - sandbox.stub(Discourse.User, "current"); - var controller = this.subject(); - - Discourse.User.current.returns(null); - ok(!controller.get("showBadges"), "returns false when no user is logged in"); - - Discourse.User.current.returns({}); - ok(controller.get("showBadges"), "returns true when an user is logged in"); +moduleFor("controller:site-map-category", 'controller:site-map-category', { + needs: ['controller:site-map'] +}); + +test("showTopicCount anonymous", function() { + var controller = this.subject(); + ok(controller.get("showTopicCount"), 'true when anonymous'); +}); + +test("showTopicCount logged in", function() { + var controller = this.subject({ currentUser: Discourse.User.create() }); + ok(!controller.get("showTopicCount"), 'false when logged in'); +}); + +test("unreadTotal default", function() { + var controller = this.subject({ currentUser: Discourse.User.create() }); + ok(!controller.get('unreadTotal'), "empty by default"); +}); + +test("unreadTotal with values", function() { + var controller = this.subject({ + currentUser: Discourse.User.create(), + unreadTopics: 1, + newTopics: 3 + }); + equal(controller.get('unreadTotal'), 4); }); diff --git a/test/javascripts/controllers/site-map-test.js.es6 b/test/javascripts/controllers/site-map-test.js.es6 index 34a722fd9..5baf83c94 100644 --- a/test/javascripts/controllers/site-map-test.js.es6 +++ b/test/javascripts/controllers/site-map-test.js.es6 @@ -10,10 +10,6 @@ moduleFor("controller:site-map", "controller:site-map", { } }); -test("itemController", function() { - equal(this.subject().get("itemController"), "site-map-category", "defaults to site-map-category"); -}); - test("showAdminLinks", function() { var currentUserStub = Ember.Object.create(); sandbox.stub(Discourse.User, "current").returns(currentUserStub);