mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
TWEAK: Sum new and unread in the site map category list
This commit is contained in:
parent
06c681b0de
commit
d29822e4cb
5 changed files with 42 additions and 30 deletions
|
@ -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')
|
||||||
});
|
});
|
||||||
|
|
|
@ -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"),
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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);
|
||||||
});
|
});
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue