proof of concept for notifications overlay
This commit is contained in:
parent
ef7580a698
commit
d6ba3c970c
8 changed files with 70 additions and 22 deletions
|
|
@ -3,19 +3,20 @@
|
|||
# the COPYRIGHT file.
|
||||
|
||||
class NotificationsController < VannaController
|
||||
include NotificationsHelper
|
||||
|
||||
|
||||
def update
|
||||
note = Notification.where(:recipient_id => current_user.id, :id => params[:id]).first
|
||||
def update(opts=params)
|
||||
note = Notification.where(:recipient_id => current_user.id, :id => opts[:id]).first
|
||||
if note
|
||||
note.update_attributes(:unread => false)
|
||||
render :nothing => true
|
||||
{}
|
||||
else
|
||||
render :nothing => true, :status => 404
|
||||
Response.new :status => 404
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
def index(opts=params)
|
||||
@aspect = :notification
|
||||
conditions = {:recipient_id => current_user.id}
|
||||
page = params[:page] || 1
|
||||
|
|
@ -31,12 +32,17 @@ class NotificationsController < VannaController
|
|||
pager.replace(result)
|
||||
end
|
||||
|
||||
notifications.each{|n| n[:actors] = n.actors}
|
||||
group_days = notifications.group_by{|note| I18n.l(note.created_at, :format => I18n.t('date.formats.fullmonth_day')) }
|
||||
{:group_days => group_days, :current_user => current_user, :notifications => notifications}
|
||||
{:group_days => group_days, :notifications => notifications}
|
||||
end
|
||||
|
||||
def read_all
|
||||
def read_all(opts=params)
|
||||
Notification.where(:recipient_id => current_user.id).update_all(:unread => false)
|
||||
redirect_to aspects_path
|
||||
end
|
||||
post_process :html do
|
||||
def post_read_all
|
||||
Response.new(:status => 302, :location => aspects_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ module NotificationsHelper
|
|||
number_of_actors = actors.count
|
||||
sentence_translations = {:two_words_connector => " #{t('notifications.index.and')} ", :last_word_connector => ", #{t('notifications.index.and')} " }
|
||||
actor_links = actors.collect{ |person| link_to("#{h(person.name.titlecase.strip)}", person_path(person))}
|
||||
|
||||
if number_of_actors < 4
|
||||
message = actor_links.to_sentence(sentence_translations)
|
||||
else
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
- if @notification_count
|
||||
#notification_badge
|
||||
= link_to "", notifications_path, :title => new_notification_text(@notification_count)
|
||||
= image_tag 'icons/monotone_flag.png', :height => 20, :width => 20
|
||||
= image_tag 'icons/monotone_flag.png', :height => 20, :width => 20, :id => "notification-flag"
|
||||
.badge_count{:class => ("hidden" if @notification_count == 0)}
|
||||
= @notification_count
|
||||
#message_inbox_badge
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@
|
|||
= yield
|
||||
|
||||
.clearfix
|
||||
=render :partial => 'notifications/overlay'
|
||||
/=render :partial => 'layouts/debug.haml'
|
||||
|
||||
%footer
|
||||
|
|
|
|||
15
app/views/notifications/_overlay.html.haml
Normal file
15
app/views/notifications/_overlay.html.haml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
.span-24.last#notifications_overlay
|
||||
.stream.notifications
|
||||
.day_group.span-24.last
|
||||
.span-3
|
||||
.date
|
||||
.day
|
||||
.month
|
||||
.span-8.notifications_for_day
|
||||
.stream_element{:data=>{:guid => nil}}
|
||||
.right
|
||||
%span.from
|
||||
= link_to("", "#", :class => "actor")
|
||||
= link_to("", "#", :class => "object")
|
||||
|
||||
%br
|
||||
|
|
@ -27,7 +27,6 @@
|
|||
|
||||
%span.from
|
||||
= notification_message_for(note)
|
||||
|
||||
%br
|
||||
%time= timeago(note.created_at)
|
||||
.span-13.last
|
||||
|
|
|
|||
|
|
@ -34,7 +34,32 @@
|
|||
if(typeof this.collection[widgetId].start !== "undefined") {
|
||||
this.collection[widgetId].start();
|
||||
}
|
||||
}
|
||||
};
|
||||
$("#notification_badge a").click(function(event){
|
||||
event.preventDefault();
|
||||
$.ajax({
|
||||
"url":"/notifications",
|
||||
"success":function(data){
|
||||
$("#notifications_overlay").show();
|
||||
var hash = eval("(" + data + ")");
|
||||
$.each(hash["group_days"], function(day){
|
||||
$("#notifications_overlay .month").text(day.split(" ")[0])
|
||||
$("#notifications_overlay .day").text(day.split(" ")[1])
|
||||
var notifications_for_day = hash["group_days"][day]
|
||||
console.log(notifications_for_day);
|
||||
$.each(notifications_for_day, function(i, notification_hash){
|
||||
$.each(notification_hash, function(notification_type, notification){
|
||||
console.log(notification_type);
|
||||
console.log(notification);
|
||||
$("#notifications_overlay .actor").
|
||||
text(notification["actors"][0]["name"]).
|
||||
attr("href", notification["actors"][0]["url"]);
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Diaspora.WidgetCollection.prototype.subscribe = function(id, callback, context) {
|
||||
|
|
|
|||
|
|
@ -5,16 +5,18 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe NotificationsController do
|
||||
render_views(false)
|
||||
before do
|
||||
@user = alice
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
sign_in :user, @user
|
||||
@controller = NotificationsController.new
|
||||
@controller.stub!(:current_user).and_return(@user)
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
it 'marks a notification as read' do
|
||||
note = Factory(:notification, :recipient => @user)
|
||||
put :update, :id => note.id
|
||||
@controller.update :id => note.id
|
||||
Notification.first.unread.should == false
|
||||
end
|
||||
|
||||
|
|
@ -24,7 +26,7 @@ describe NotificationsController do
|
|||
Factory(:notification, :recipient => @user)
|
||||
note = Factory(:notification, :recipient => user2)
|
||||
|
||||
put :update, :id => note.id
|
||||
@controller.update :id => note.id
|
||||
|
||||
Notification.find(note.id).unread.should == true
|
||||
end
|
||||
|
|
@ -37,7 +39,7 @@ describe NotificationsController do
|
|||
Factory(:notification, :recipient => @user)
|
||||
|
||||
Notification.where(:unread => true).count.should == 2
|
||||
get :read_all
|
||||
@controller.read_all({})
|
||||
Notification.where(:unread => true).count.should == 0
|
||||
end
|
||||
end
|
||||
|
|
@ -50,11 +52,12 @@ describe NotificationsController do
|
|||
end
|
||||
|
||||
it 'paginates the notifications' do
|
||||
get :index
|
||||
assigns[:notifications].count.should == 25
|
||||
|
||||
get :index, :page => 2
|
||||
assigns[:notifications].count.should == 1
|
||||
@controller.index({})[:notifications].count.should == 25
|
||||
@controller.index(:page => 2)[:notifications].count.should == 1
|
||||
end
|
||||
it "includes the actors" do
|
||||
notification = Factory(:notification, :recipient => @user)
|
||||
@controller.index({})[:notifications].first[:actors].should == notification.actors
|
||||
end
|
||||
|
||||
it 'eager loads the target' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue