Merge pull request #2329 from techAPJ/speech-bubble-updates

Speech bubble waiting for an ajax response prior to rendering
This commit is contained in:
Robin Ward 2014-05-09 14:40:17 -04:00
commit 6b5d9a1ede
7 changed files with 46 additions and 20 deletions

View File

@ -10,6 +10,7 @@ export default Discourse.Controller.extend({
topic: null, topic: null,
showExtraInfo: null, showExtraInfo: null,
notifications: null, notifications: null,
loading_notifications: null,
showStarButton: function() { showStarButton: function() {
return Discourse.User.current() && !this.get('topic.isPrivateMessage'); return Discourse.User.current() && !this.get('topic.isPrivateMessage');
@ -25,11 +26,17 @@ export default Discourse.Controller.extend({
showNotifications: function(headerView) { showNotifications: function(headerView) {
var self = this; var self = this;
Discourse.ajax("/notifications").then(function(result) { if (self.get('currentUser.unread_notifications') || self.get('currentUser.unread_private_messages') || !self.get('notifications')) {
self.set("notifications", result); self.set("loading_notifications", true);
self.set("currentUser.unread_notifications", 0); Discourse.ajax("/notifications").then(function(result) {
headerView.showDropdownBySelector("#user-notifications"); self.setProperties({
}); notifications: result,
loading_notifications: false,
'currentUser.unread_notifications': 0
});
});
}
headerView.showDropdownBySelector("#user-notifications");
}, },
jumpToTopPost: function () { jumpToTopPost: function () {
@ -41,5 +48,3 @@ export default Discourse.Controller.extend({
} }
}); });

View File

@ -1,3 +1,4 @@
Discourse.NotificationsController = Ember.ArrayController.extend(Discourse.HasCurrentUser, { Discourse.NotificationsController = Ember.ArrayController.extend(Discourse.HasCurrentUser, {
needs: ['header'],
itemController: "notification" itemController: "notification"
}); });

View File

@ -1,14 +1,18 @@
<section class="d-dropdown" id="notifications-dropdown"> <section class="d-dropdown" id="notifications-dropdown">
{{#if content}} {{#unless controllers.header.loading_notifications}}
<ul> {{#if content}}
{{#each}} <ul>
<li {{bind-attr class="read"}}>{{unbound boundI18n scope linkBinding="link" usernameBinding="username"}}</li> {{#each}}
{{/each}} <li {{bind-attr class="read"}}>{{unbound boundI18n scope linkBinding="link" usernameBinding="username"}}</li>
<li class="read last"> {{/each}}
<a {{bind-attr href="currentUser.path"}}>{{i18n notifications.more}} &hellip;</a> <li class="read last">
</li> <a {{bind-attr href="currentUser.path"}}>{{i18n notifications.more}} &hellip;</a>
</ul> </li>
</ul>
{{else}}
<div class="none">{{i18n notifications.none}}</div>
{{/if}}
{{else}} {{else}}
<div class="none">{{i18n notifications.none}}</div> <div class='loading'><i class='fa fa-spinner fa-spin'></i></div>
{{/if}} {{/unless}}
</section> </section>

View File

@ -204,6 +204,13 @@
.none { .none {
padding: 5px; padding: 5px;
} }
.loading {
padding: 10px;
display: block;
color: scale-color($primary, $lightness: 50%);
font-size: 24px;
text-align: center;
}
} }
// Search // Search

View File

@ -194,6 +194,13 @@
.none { .none {
padding: 5px; padding: 5px;
} }
.loading {
padding: 10px;
display: block;
color: #777;
font-size: 24px;
text-align: center;
}
} }
// Search // Search

View File

@ -23,7 +23,7 @@ test("showNotifications action", function() {
equal(controller.get("notifications"), null, "notifications are null before data has finished loading"); equal(controller.get("notifications"), null, "notifications are null before data has finished loading");
equal(Discourse.User.current().get("unread_notifications"), 1, "current user's unread notifications count is not zeroed before data has finished loading"); equal(Discourse.User.current().get("unread_notifications"), 1, "current user's unread notifications count is not zeroed before data has finished loading");
ok(viewSpy.showDropdownBySelector.notCalled, "dropdown with notifications is not shown before data has finished loading"); ok(viewSpy.showDropdownBySelector.calledWith("#user-notifications"), "dropdown with loading glyph is shown before data has finished loading");
Ember.run(function() { Ember.run(function() {

View File

@ -17,7 +17,9 @@ module("Discourse.NotificationsController", {
return [scope, options.username, options.link].join(" ").trim(); return [scope, options.username, options.link].join(" ").trim();
}); });
controller = Discourse.NotificationsController.create(); controller = Discourse.NotificationsController.create({
container: Discourse.__container__
});
view = Ember.View.create({ view = Ember.View.create({
container: Discourse.__container__, container: Discourse.__container__,