diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 8f28fc564..0b506203c 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -23,4 +23,8 @@ class NotificationsController < ApplicationController respond_with @notifications end + def read_all + Notification.where(:recipient_id => current_user.id).update_all(:unread => false) + redirect_to :back + end end diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 2e6e307b4..d347ebdd1 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -1,4 +1,14 @@ :javascript + $('.mark_all_read').live('click', function(){ + $.ajax({ + url: 'notifications/read_all', + success: function(data, status, xhr) { + $('.message').removeClass('unread'); + $("#notification_badge_number").addClass("hidden"); + } + }); + }); + $('.message').live('click', function(evt){ var note = $(this).closest('.message'), note_id = note.attr('data-guid'), @@ -23,9 +33,12 @@ .span-1 = image_tag 'icons/mail_big.png', :height => 30, :width => 30, :style=>"margin-top:3px;" -.span-23.last +.span-10 %h2 = t('.notifications') +.span-13.last.left + .button.mark_all_read + = link_to "Mark All as Read", "#" .span-24.last %ul.stream.notifications diff --git a/config/routes.rb b/config/routes.rb index a9f3e9145..708b25600 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,11 +8,10 @@ Diaspora::Application.routes.draw do resources :requests, :only => [:destroy, :create] resources :services - resources :notifications + match 'notifications/read_all' => 'notifications#read_all' + resources :notifications, :only => [:index, :update] resources :posts, :only => [:show], :path => '/p/' - - match '/people/share_with' => 'people#share_with', :as => 'share_with' resources :people do resources :status_messages diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index a14d9b856..678f63f46 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -2142,3 +2142,6 @@ ul.show_comments :margin :left 0.5em :right 0.5em +.mark_all_read + :position relative + :top 10px diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index c88347c3e..507115d2c 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -32,4 +32,17 @@ describe NotificationsController do Notification.find(note.id).unread.should == true end end + + describe "#read_all" do + it 'marks all notifications as read' do + Notification.create(:recipient_id => user.id) + Notification.create(:recipient_id => user.id) + + Notification.where(:unread => true).count.should == 2 + get :read_all + Notification.where(:unread => true).count.should == 0 + + + end + end end