putting a link to notifications, make them unread in the controller when you view the index
This commit is contained in:
parent
807187ded9
commit
c749d81fe9
5 changed files with 11 additions and 4 deletions
|
|
@ -17,7 +17,7 @@ class ApplicationController < ActionController::Base
|
|||
@aspect = nil
|
||||
@aspects = current_user.aspects.fields(:name)
|
||||
@aspects_dropdown_array = @aspects.collect{|x| [x.to_s, x.id]}
|
||||
@notifications = Notification.for(current_user).all
|
||||
@notification_count = Notification.for(current_user, :unread =>true).all.count
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
class NotificationsController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
respond_to :html
|
||||
|
||||
def destroy
|
||||
note = Notification.find_by_user_id_and_id(current_user.id, params[:id])
|
||||
|
|
@ -16,6 +17,9 @@ class NotificationsController < ApplicationController
|
|||
end
|
||||
|
||||
def index
|
||||
@notifications = Notification.for(current_user)
|
||||
@group_days = @notifications.group_by{|note| note.created_at.strftime("%B %d") }
|
||||
respond_with @notifications
|
||||
@notifications.find_all{|x| x.unread ==true}.each{|x| x.update_attributes(:unread => false)}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,16 +7,17 @@ class Notification
|
|||
|
||||
key :object_id, ObjectId
|
||||
key :kind, String
|
||||
key :unread, Boolean, :default => true
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :person
|
||||
|
||||
timestamps!
|
||||
|
||||
attr_accessible :object_id, :kind, :user_id, :person_id
|
||||
attr_accessible :object_id, :kind, :user_id, :person_id, :unread
|
||||
|
||||
def self.for(user, opts={})
|
||||
self.where(opts.merge(:user_id => user.id)).order('created_at desc')
|
||||
self.where(opts.merge!(:user_id => user.id)).order('created_at desc')
|
||||
end
|
||||
|
||||
def self.notify(user, object, person)
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
= link_for_aspect aspect
|
||||
%li
|
||||
= link_to '+', '#add_aspect_pane', :class => "add_aspect_button", :title => t('aspects.manage.add_a_new_aspect')
|
||||
= link_to "notifications (#{@notification_count})", notifications_path
|
||||
|
||||
.fancybox_content
|
||||
#add_aspect_pane
|
||||
|
|
|
|||
|
|
@ -140,6 +140,7 @@ header
|
|||
:top 10px
|
||||
:height 45px
|
||||
|
||||
ul#notifications,
|
||||
ul#user_menu
|
||||
:overflow hidden
|
||||
:white-space nowrap
|
||||
|
|
|
|||
Loading…
Reference in a new issue