FIX: Don't link to notifications without URLs

This commit is contained in:
Robin Ward 2014-08-06 15:22:12 -04:00
parent 4589bce21b
commit 417d287813
6 changed files with 24 additions and 22 deletions

View file

@ -14,6 +14,11 @@ export default Ember.Component.extend({
var notification = this.get('notification'),
text = I18n.t(this.get('scope'), Em.getProperties(notification, 'description', 'username'));
var url = notification.get('url');
if (url) {
buffer.push('<a href="' + notification.get('url') + '">' + text + '</a>');
} else {
buffer.push(text);
}
}
});

View file

@ -10,13 +10,13 @@ export default Discourse.Controller.extend({
topic: null,
showExtraInfo: null,
notifications: null,
loading_notifications: null,
loadingNotifications: false,
showStarButton: function() {
return Discourse.User.current() && !this.get('topic.isPrivateMessage');
}.property('topic.isPrivateMessage'),
resetCachedNotifications: function(){
_resetCachedNotifications: function(){
// a bit hacky, but if we have no focus, hide notifications first
var visible = $("#notifications-dropdown").is(":visible");
@ -36,18 +36,16 @@ export default Discourse.Controller.extend({
refreshNotifications: function(){
var self = this;
if (self.get("loadingNotifications")) { return; }
if(self.get("loading_notifications")){return;}
self.set("loading_notifications", true);
self.set("loadingNotifications", true);
Discourse.ajax("/notifications").then(function(result) {
self.set('currentUser.unread_notifications', 0);
self.setProperties({
notifications: result,
loading_notifications: false
'currentUser.unread_notifications': 0,
notifications: result
});
}, function(){
self.set("loading_notifications", false);
}).finally(function(){
self.set("loadingNotifications", false);
});
},

View file

@ -17,15 +17,18 @@ export default Discourse.ObjectController.extend({
if (badgeId) {
var badgeName = this.safe("data.badge_name");
return '/badges/' + badgeId + '/' + badgeName.replace(/[^A-Za-z0-9_]+/g, '-').toLowerCase();
} else {
return Discourse.Utilities.postUrl(this.safe("slug"), this.safe("topic_id"), this.safe("post_number"));
}
}.property("data.@{badge_id, badge_name}", "slug", "topic_id", "post_number"),
var topicId = this.safe('topic_id');
if (topicId) {
return Discourse.Utilities.postUrl(this.safe("slug"), topicId, this.safe("post_number"));
}
}.property("data.{badge_id, badge_name}", "slug", "topic_id", "post_number"),
description: function () {
var badgeName = this.safe("data.badge_name");
if (badgeName) { return badgeName; }
return this.blank("data.topic_title") ? "" : this.safe("data.topic_title");
}.property("data.@{badge_name, topic_title}")
}.property("data.{badge_name, topic_title}")
});

View file

@ -1,4 +1,4 @@
export default Ember.ArrayController.extend(Discourse.HasCurrentUser, {
needs: ['header'],
itemController: "notification"
loadingNotifications: Em.computed.alias('controllers.header.loadingNotifications')
});

View file

@ -1,8 +1,8 @@
<section class="d-dropdown" id="notifications-dropdown">
{{#unless controllers.header.loading_notifications}}
{{#unless loadingNotifications}}
{{#if content}}
<ul>
{{#each}}
{{#each itemController="notification"}}
{{notification-item notification=this scope=scope}}
{{/each}}
<li class="read last">

View file

@ -5,7 +5,3 @@ moduleFor('controller:notifications', 'controller:notifications', {
test("mixes in HasCurrentUser", function() {
ok(Discourse.HasCurrentUser.detect(this.subject()));
});
test("by default uses NotificationController as its item controller", function() {
equal(this.subject().get("itemController"), "notification");
});