notifications wip
This commit is contained in:
parent
922ccd8423
commit
05688c2f43
7 changed files with 102 additions and 40 deletions
|
|
@ -32,6 +32,7 @@ class NotificationsController < VannaController
|
||||||
end
|
end
|
||||||
notifications.each do |n|
|
notifications.each do |n|
|
||||||
n[:actors] = n.actors
|
n[:actors] = n.actors
|
||||||
|
n[:translation] = object_link(n, n.actors.map { |a| person_link(a) })
|
||||||
n[:translation_key] = n.popup_translation_key
|
n[:translation_key] = n.popup_translation_key
|
||||||
n[:target] = n.translation_key == "notifications.mentioned" ? n.target.post : n.target
|
n[:target] = n.translation_key == "notifications.mentioned" ? n.target.post : n.target
|
||||||
end
|
end
|
||||||
|
|
@ -42,9 +43,14 @@ class NotificationsController < VannaController
|
||||||
def read_all(opts=params)
|
def read_all(opts=params)
|
||||||
Notification.where(:recipient_id => current_user.id).update_all(:unread => false)
|
Notification.where(:recipient_id => current_user.id).update_all(:unread => false)
|
||||||
end
|
end
|
||||||
|
|
||||||
post_process :html do
|
post_process :html do
|
||||||
def post_read_all(json)
|
def post_read_all(json)
|
||||||
Response.new(:status => 302, :location => aspects_path)
|
Response.new(:status => 302, :location => aspects_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def controller
|
||||||
|
Object.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
module NotificationsHelper
|
module NotificationsHelper
|
||||||
|
include ERB::Util
|
||||||
|
include ActionView::Helpers::TranslationHelper
|
||||||
|
include ActionView::Helpers::UrlHelper
|
||||||
|
include ApplicationHelper
|
||||||
def object_link(note, actors)
|
def object_link(note, actors)
|
||||||
target_type = note.popup_translation_key
|
target_type = note.popup_translation_key
|
||||||
actors_count = note.actors.count
|
actors_count = note.actors.count
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@
|
||||||
.badge_count{:class => ("hidden" if @unread_message_count == 0)}
|
.badge_count{:class => ("hidden" if @unread_message_count == 0)}
|
||||||
= @unread_message_count
|
= @unread_message_count
|
||||||
|
|
||||||
|
#notification_dropdown
|
||||||
|
|
||||||
%ul#user_menu.dropdown
|
%ul#user_menu.dropdown
|
||||||
%li
|
%li
|
||||||
.right
|
.right
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,14 @@ Background:
|
||||||
|
|
||||||
And I go to the destroy user session page
|
And I go to the destroy user session page
|
||||||
|
|
||||||
Scenario: someone shares with me
|
Scenario: someone shares with me
|
||||||
When I sign in as "alice@alice.alice"
|
When I sign in as "alice@alice.alice"
|
||||||
And I follow "notifications" in the header
|
And I follow "notifications" in the header
|
||||||
|
|
||||||
Then I should see "started sharing with you"
|
Then I should see "started sharing with you"
|
||||||
|
|
||||||
|
Scenario: notification popup
|
||||||
|
When I sign in as "alice@alice.alice"
|
||||||
|
And I click the notification badge
|
||||||
|
And I wait for the ajax to finish
|
||||||
|
Then the notification dropdown should be visible
|
||||||
|
|
|
||||||
|
|
@ -194,3 +194,11 @@ end
|
||||||
When /^I wait for (\d+) seconds$/ do |seconds|
|
When /^I wait for (\d+) seconds$/ do |seconds|
|
||||||
sleep seconds.to_i
|
sleep seconds.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
When /^I click the notification badge$/ do
|
||||||
|
evaluate_script("$('#notification_badge a').click();");
|
||||||
|
end
|
||||||
|
|
||||||
|
Then /^the notification dropdown should be visible$/ do
|
||||||
|
evaluate_script("$('#notification_dropdown').css('display') === 'block'")
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,67 @@
|
||||||
$(function() {
|
(function() {
|
||||||
$("#notification_badge a").live("_click", function(event){
|
var NotificationDropdown = function() {
|
||||||
event.preventDefault();
|
this.start = function() {
|
||||||
$.getJSON("/notifications", function(hash) {
|
this.badge = $("#notification_badge a");
|
||||||
$("#notifications_overlay").show();
|
this.documentBody = $(document.body);
|
||||||
var notificationsElement = $("#notifications_overlay .notifications");
|
this.dropdown = $("#notification_dropdown");
|
||||||
var dayElementTemplate = $("#notifications_overlay .day_group").clone();
|
|
||||||
dayElementTemplate.find(".notifications_for_day").empty();
|
|
||||||
var streamElementTemplate = $("#notifications_overlay .stream_element").clone();
|
|
||||||
notificationsElement.empty();
|
|
||||||
$.each(hash["group_days"], function(day){
|
|
||||||
var dayElement = dayElementTemplate.clone();
|
|
||||||
var dayParts = day.split(" ");
|
|
||||||
dayElement.find(".month").text(dayParts[0])
|
|
||||||
dayElement.find(".day").text(dayParts[1])
|
|
||||||
var notificationsForDay = hash["group_days"][day],
|
|
||||||
notificationsForDayElement = dayElement.find('.notifications_for_day');
|
|
||||||
|
|
||||||
$.each(notificationsForDay, function(i, notificationHash) {
|
this.badge.click($.proxy(function(evt) {
|
||||||
$.each(notificationHash, function(notificationType, notification) {
|
evt.preventDefault();
|
||||||
var actor = notification.actors[0];
|
evt.stopPropagation();
|
||||||
var streamElement = streamElementTemplate.clone().appendTo(notificationsForDayElement);
|
|
||||||
streamElement.find(".actor")
|
if(!this.dropdownShowing()) {
|
||||||
.text(actor.name)
|
this.getNotifications(function() {
|
||||||
.attr("href", notification.actors[0]["url"]);
|
this.toggleDropdown();
|
||||||
streamElement.find('time').attr("datetime", notification["created_at"]);
|
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
notificationsElement.append(dayElement)
|
else {
|
||||||
|
this.toggleDropdown();
|
||||||
|
}
|
||||||
|
}, this));
|
||||||
|
|
||||||
Diaspora.widgets.timeago.updateTimeAgo("time");
|
this.documentBody.click($.proxy(function(evt) {
|
||||||
});
|
if(this.dropdownShowing()) {
|
||||||
});
|
this.toggleDropdown(evt);
|
||||||
});
|
}
|
||||||
|
}, this));
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
$("#notifications_overlay").delegate('a.close', 'click', function() {
|
NotificationDropdown.prototype.dropdownShowing = function() {
|
||||||
console.log("hi!");
|
return this.dropdown.css("display") === "block";
|
||||||
$('#notifications_overlay').hide();
|
}
|
||||||
});
|
|
||||||
|
|
||||||
});
|
NotificationDropdown.prototype.toggleDropdown = function() {
|
||||||
|
if(!this.dropdownShowing()) {
|
||||||
|
this.renderNotifications();
|
||||||
|
this.showDropdown();
|
||||||
|
} else {
|
||||||
|
this.hideDropdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationDropdown.prototype.showDropdown = function() {
|
||||||
|
this.dropdown.css("display", "block");
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationDropdown.prototype.hideDropdown = function() {
|
||||||
|
this.dropdown.css("display", "none");
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationDropdown.prototype.getNotifications = function(callback) {
|
||||||
|
$.getJSON("/notifications", $.proxy(function(notifications) {
|
||||||
|
this.notifications = notifications;
|
||||||
|
callback.apply(this, [notifications]);
|
||||||
|
}, this));
|
||||||
|
};
|
||||||
|
|
||||||
|
NotificationDropdown.prototype.renderNotifications = function() {
|
||||||
|
$.each(this.notifications.notifications, $.proxy(function(index, notifications) {
|
||||||
|
$.each(notifications, $.proxy(function(index, notification) {
|
||||||
|
this.dropdown.append(notification.translation);
|
||||||
|
}, this));
|
||||||
|
}, this));
|
||||||
|
};
|
||||||
|
|
||||||
|
Diaspora.widgets.add("notificationDropdown", NotificationDropdown);
|
||||||
|
})();
|
||||||
|
|
|
||||||
|
|
@ -2828,7 +2828,7 @@ ul#requested-scopes
|
||||||
img
|
img
|
||||||
:height 30px
|
:height 30px
|
||||||
:width 30px
|
:width 30px
|
||||||
|
|
||||||
.scope-description
|
.scope-description
|
||||||
:display none
|
:display none
|
||||||
|
|
||||||
|
|
@ -3061,3 +3061,13 @@ ul.left_nav
|
||||||
|
|
||||||
.big_stream_photo
|
.big_stream_photo
|
||||||
:display block
|
:display block
|
||||||
|
|
||||||
|
#notification_dropdown
|
||||||
|
:background white
|
||||||
|
:border solid #000 1px
|
||||||
|
:padding 25px
|
||||||
|
:position absolute
|
||||||
|
:top 29px
|
||||||
|
:left 540px
|
||||||
|
:display none
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue