Modified behavior of mark all as read button
This commit is contained in:
parent
98c3a0a871
commit
6456a441fe
5 changed files with 67 additions and 35 deletions
|
|
@ -65,12 +65,21 @@ class NotificationsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_all
|
def read_all
|
||||||
Notification.where(:recipient_id => current_user.id).update_all(:unread => false)
|
if params[:type]
|
||||||
|
Notification.where(:recipient_id => current_user.id, :type => Notification.types[params[:type]]).update_all(:unread => false)
|
||||||
|
else
|
||||||
|
Notification.where(:recipient_id => current_user.id).update_all(:unread => false)
|
||||||
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to stream_path }
|
if current_user.unread_notifications.count > 0
|
||||||
format.mobile{ redirect_to stream_path}
|
format.html { redirect_to notifications_path}
|
||||||
format.xml { render :xml => {}.to_xml }
|
format.mobile{ redirect_to notifications_path}
|
||||||
format.json { render :json => {}.to_json }
|
else
|
||||||
|
format.html { redirect_to stream_path }
|
||||||
|
format.mobile{ redirect_to stream_path}
|
||||||
|
end
|
||||||
|
format.xml { render :xml => {}.to_xml }
|
||||||
|
format.json { render :json => {}.to_json }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@
|
||||||
= t('.show_all')
|
= t('.show_all')
|
||||||
%a.btn.btn-default{ :class => ('active' if params[:show] == 'unread'), :href => '/notifications?show=unread' + (params[:type] ? '&type=' + params[:type] : '') }
|
%a.btn.btn-default{ :class => ('active' if params[:show] == 'unread'), :href => '/notifications?show=unread' + (params[:type] ? '&type=' + params[:type] : '') }
|
||||||
= t('.show_unread')
|
= t('.show_unread')
|
||||||
%a.btn.btn-default{:href => notifications_read_all_path, :class => ('disabled' unless @unread_notification_count > 0)}
|
%a.btn.btn-default{:href => read_all_notifications_path(:type => params[:type] ), :class => ('disabled' unless @unread_notification_count > 0)}
|
||||||
= t('.mark_all_as_read')
|
= t('.mark_all_as_read')
|
||||||
- @group_days.each do |day, notes|
|
- @group_days.each do |day, notes|
|
||||||
.day_group.row-fluid
|
.day_group.row-fluid
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
= t('.notifications')
|
= t('.notifications')
|
||||||
|
|
||||||
.right
|
.right
|
||||||
= link_to t('.mark_all_as_read'), notifications_read_all_path, :class => 'btn'
|
= link_to t('.mark_all_as_read'), read_all_notifications_path, :class => 'btn'
|
||||||
|
|
||||||
%ul.notifications
|
%ul.notifications
|
||||||
- @group_days.each do |day, notes|
|
- @group_days.each do |day, notes|
|
||||||
|
|
|
||||||
|
|
@ -79,9 +79,12 @@ Diaspora::Application.routes.draw do
|
||||||
delete 'visibility' => 'conversation_visibilities#destroy'
|
delete 'visibility' => 'conversation_visibilities#destroy'
|
||||||
end
|
end
|
||||||
|
|
||||||
get 'notifications/read_all' => 'notifications#read_all'
|
|
||||||
resources :notifications, :only => [:index, :update] do
|
resources :notifications, :only => [:index, :update] do
|
||||||
|
collection do
|
||||||
|
get :read_all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
resources :tags, :only => [:index]
|
resources :tags, :only => [:index]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,33 +42,6 @@ describe NotificationsController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#read_all" do
|
|
||||||
it 'marks all notifications as read' do
|
|
||||||
request.env["HTTP_REFERER"] = "I wish I were spelled right"
|
|
||||||
FactoryGirl.create(:notification, :recipient => alice)
|
|
||||||
FactoryGirl.create(:notification, :recipient => alice)
|
|
||||||
|
|
||||||
Notification.where(:unread => true).count.should == 2
|
|
||||||
get :read_all
|
|
||||||
Notification.where(:unread => true).count.should == 0
|
|
||||||
end
|
|
||||||
it "should redirect to the stream in the html version" do
|
|
||||||
FactoryGirl.create(:notification, :recipient => alice)
|
|
||||||
get :read_all, :format => :html
|
|
||||||
response.should redirect_to(stream_path)
|
|
||||||
end
|
|
||||||
it "should redirect to the stream in the mobile version" do
|
|
||||||
FactoryGirl.create(:notification, :recipient => alice)
|
|
||||||
get :read_all, :format => :mobile
|
|
||||||
response.should redirect_to(stream_path)
|
|
||||||
end
|
|
||||||
it "should return a dummy value in the json version" do
|
|
||||||
FactoryGirl.create(:notification, :recipient => alice)
|
|
||||||
get :read_all, :format => :json
|
|
||||||
response.should_not be_redirect
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#index' do
|
describe '#index' do
|
||||||
before do
|
before do
|
||||||
@post = FactoryGirl.create(:status_message)
|
@post = FactoryGirl.create(:status_message)
|
||||||
|
|
@ -137,4 +110,51 @@ describe NotificationsController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#read_all" do
|
||||||
|
it 'marks all notifications as read' do
|
||||||
|
request.env["HTTP_REFERER"] = "I wish I were spelled right"
|
||||||
|
FactoryGirl.create(:notification, :recipient => alice)
|
||||||
|
FactoryGirl.create(:notification, :recipient => alice)
|
||||||
|
|
||||||
|
Notification.where(:unread => true).count.should == 2
|
||||||
|
get :read_all
|
||||||
|
Notification.where(:unread => true).count.should == 0
|
||||||
|
end
|
||||||
|
it 'marks all notifications in the current filter as read' do
|
||||||
|
request.env["HTTP_REFERER"] = "I wish I were spelled right"
|
||||||
|
FactoryGirl.create(:notification, :recipient => alice)
|
||||||
|
eve.share_with(alice.person, eve.aspects.first)
|
||||||
|
Notification.where(:unread => true).count.should == 2
|
||||||
|
get :read_all, "type" => "started_sharing"
|
||||||
|
Notification.where(:unread => true).count.should == 1
|
||||||
|
end
|
||||||
|
it "should redirect back in the html version if it has > 0 notifications" do
|
||||||
|
FactoryGirl.create(:notification, :recipient => alice)
|
||||||
|
eve.share_with(alice.person, eve.aspects.first)
|
||||||
|
get :read_all, :format => :html, "type" => "started_sharing"
|
||||||
|
response.should redirect_to(notifications_path)
|
||||||
|
end
|
||||||
|
it "should redirect back in the mobile version if it has > 0 notifications" do
|
||||||
|
FactoryGirl.create(:notification, :recipient => alice)
|
||||||
|
eve.share_with(alice.person, eve.aspects.first)
|
||||||
|
get :read_all, :format => :mobile, "type" => "started_sharing"
|
||||||
|
response.should redirect_to(notifications_path)
|
||||||
|
end
|
||||||
|
it "should redirect to stream in the html version if it has 0 notifications" do
|
||||||
|
FactoryGirl.create(:notification, :recipient => alice)
|
||||||
|
get :read_all, :format => :html
|
||||||
|
response.should redirect_to(stream_path)
|
||||||
|
end
|
||||||
|
it "should redirect back in the mobile version if it has 0 notifications" do
|
||||||
|
FactoryGirl.create(:notification, :recipient => alice)
|
||||||
|
get :read_all, :format => :mobile
|
||||||
|
response.should redirect_to(stream_path)
|
||||||
|
end
|
||||||
|
it "should return a dummy value in the json version" do
|
||||||
|
FactoryGirl.create(:notification, :recipient => alice)
|
||||||
|
get :read_all, :format => :json
|
||||||
|
response.should_not be_redirect
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue