putting a link to notifications, make them unread in the controller when you view the index

This commit is contained in:
maxwell 2010-12-17 15:24:49 -08:00
parent 807187ded9
commit c749d81fe9
5 changed files with 11 additions and 4 deletions

View file

@ -17,7 +17,7 @@ class ApplicationController < ActionController::Base
@aspect = nil @aspect = nil
@aspects = current_user.aspects.fields(:name) @aspects = current_user.aspects.fields(:name)
@aspects_dropdown_array = @aspects.collect{|x| [x.to_s, x.id]} @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
end end

View file

@ -4,6 +4,7 @@
class NotificationsController < ApplicationController class NotificationsController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
respond_to :html
def destroy def destroy
note = Notification.find_by_user_id_and_id(current_user.id, params[:id]) note = Notification.find_by_user_id_and_id(current_user.id, params[:id])
@ -16,6 +17,9 @@ class NotificationsController < ApplicationController
end end
def index def index
@notifications = Notification.for(current_user)
@group_days = @notifications.group_by{|note| note.created_at.strftime("%B %d") } @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
end end

View file

@ -7,16 +7,17 @@ class Notification
key :object_id, ObjectId key :object_id, ObjectId
key :kind, String key :kind, String
key :unread, Boolean, :default => true
belongs_to :user belongs_to :user
belongs_to :person belongs_to :person
timestamps! 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={}) 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 end
def self.notify(user, object, person) def self.notify(user, object, person)

View file

@ -44,6 +44,7 @@
= link_for_aspect aspect = link_for_aspect aspect
%li %li
= link_to '+', '#add_aspect_pane', :class => "add_aspect_button", :title => t('aspects.manage.add_a_new_aspect') = 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 .fancybox_content
#add_aspect_pane #add_aspect_pane

View file

@ -139,7 +139,8 @@ header
.right .right
:top 10px :top 10px
:height 45px :height 45px
ul#notifications,
ul#user_menu ul#user_menu
:overflow hidden :overflow hidden
:white-space nowrap :white-space nowrap