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({
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')
});

View file

@ -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"),

View file

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

View file

@ -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);
});

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