diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e2c93b86..5acd5940 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -47,6 +47,14 @@ module ApplicationHelper count.count end + def notification_count + return 0 unless user_signed_in? + count = Notification.for(current_user).where(new: true) + return nil if count.nil? + return nil unless count.count > 0 + count.count + end + def privileged?(user) (current_user && (current_user == user || current_user.admin?)) ? true : false end diff --git a/app/views/layouts/_notifications.html.haml b/app/views/layouts/_notifications.html.haml index 772586db..83cdd889 100644 --- a/app/views/layouts/_notifications.html.haml +++ b/app/views/layouts/_notifications.html.haml @@ -1 +1 @@ -= nav_entry "Notifications", "/notifications/index" \ No newline at end of file += nav_entry "Notifications", "/notifications/index", badge: notification_count \ No newline at end of file diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 1d483343..feebdd70 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -59,4 +59,5 @@ = time_ago_in_words notification.target.created_at ago .notification--icon - %i.fa.fa-comments \ No newline at end of file + %i.fa.fa-comments +- Notification.for(current_user).update_all(new: false) \ No newline at end of file