TWEAK: Sum new and unread in the site map category list

This commit is contained in:
Robin Ward 2014-08-05 16:01:49 -04:00
parent 06c681b0de
commit d29822e4cb
5 changed files with 42 additions and 30 deletions

View file

@ -1,5 +1,10 @@
export default Ember.ObjectController.extend({ export default Ember.ObjectController.extend(Discourse.HasCurrentUser, {
showBadges: function() { needs: ['site-map'],
return !!Discourse.User.current();
}.property().volatile() unreadTotal: function() {
return parseInt(this.get('unreadTopics'), 10) +
parseInt(this.get('newTopics'), 10);
}.property('unreadTopics', 'newTopics'),
showTopicCount: Em.computed.not('currentUser')
}); });

View file

@ -1,6 +1,4 @@
export default Ember.ArrayController.extend(Discourse.HasCurrentUser, { export default Ember.ArrayController.extend(Discourse.HasCurrentUser, {
itemController: "site-map-category",
showBadgesLink: function(){return Discourse.SiteSettings.enable_badges;}.property(), showBadgesLink: function(){return Discourse.SiteSettings.enable_badges;}.property(),
showAdminLinks: Em.computed.alias('currentUser.staff'), showAdminLinks: Em.computed.alias('currentUser.staff'),
flaggedPostsCount: Em.computed.alias("currentUser.site_flagged_posts_count"), flaggedPostsCount: Em.computed.alias("currentUser.site_flagged_posts_count"),

View file

@ -38,17 +38,15 @@
{{#link-to "discovery.categories"}}{{i18n filters.categories.title}}{{/link-to}} {{#link-to "discovery.categories"}}{{i18n filters.categories.title}}{{/link-to}}
</li> </li>
{{#each categories itemController=itemController}} {{#each categories itemController='site-map-category'}}
<li class="category"> <li class="category">
{{category-link this allowUncategorized=true showParent=true}} {{category-link this allowUncategorized=true showParent=true}}
{{#if showBadges}}
{{#if unreadTopics}} {{#if unreadTotal}}
<a href={{unbound unreadUrl}} class='badge unread-posts badge-notification' title='{{i18n topic.unread_topics count="unreadTopics"}}'>{{unreadTopics}}</a> <a href={{unbound url}} class='badge badge-notification'>{{unreadTotal}}</a>
{{/if}} {{/if}}
{{#if newTopics}}
<a href={{unbound newUrl}} class='badge new-posts badge-notification' title='{{i18n topic.new_topics count="newTopics"}}'>{{newTopics}} {{i18n filters.new.title.zero}}</a> {{#if showTopicCount}}
{{/if}}
{{else}}
<b class="topics-count">{{unbound topic_count}}</b> <b class="topics-count">{{unbound topic_count}}</b>
{{/if}} {{/if}}
</li> </li>

View file

@ -1,12 +1,27 @@
moduleFor("controller:site-map-category"); moduleFor("controller:site-map-category", 'controller:site-map-category', {
needs: ['controller:site-map']
test("showBadges", function() { });
sandbox.stub(Discourse.User, "current");
var controller = this.subject(); test("showTopicCount anonymous", function() {
var controller = this.subject();
Discourse.User.current.returns(null); ok(controller.get("showTopicCount"), 'true when anonymous');
ok(!controller.get("showBadges"), "returns false when no user is logged in"); });
Discourse.User.current.returns({}); test("showTopicCount logged in", function() {
ok(controller.get("showBadges"), "returns true when an user is logged in"); 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);
}); });

View file

@ -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() { test("showAdminLinks", function() {
var currentUserStub = Ember.Object.create(); var currentUserStub = Ember.Object.create();
sandbox.stub(Discourse.User, "current").returns(currentUserStub); sandbox.stub(Discourse.User, "current").returns(currentUserStub);