From 46c563afb24ab4d8e234a2afe1daa3fce04e935e Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 24 Nov 2016 11:07:57 -0500 Subject: [PATCH] start integrating notifications into account menu --- app/controllers/notifications_controller.rb | 3 +-- app/helpers/application_helper.rb | 8 ++++++++ app/models/user.rb | 8 ++++++++ app/views/layouts/_account.html.erb | 14 ++++++++++---- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index d1b752a9..f4fd1e8f 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -56,8 +56,7 @@ class NotificationsController < ApplicationController private def set_receipts - @receipts = current_user.mailbox.receipts - .includes(:notification).where(mailbox_type: nil) + @receipts = current_user.mailboxer_notification_receipts end def set_notification diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3221aa34..37e0007a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,4 +37,12 @@ module ApplicationHelper def invite_link "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '') end + + def user_has_unread_notifications? + return false if current_user.nil? + current_user.mailboxer_notification_receipts.each do |receipt| + return true if receipt.is_read == false + end + false + end end diff --git a/app/models/user.rb b/app/models/user.rb index e70114d5..f3169d1d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -114,4 +114,12 @@ class User < ApplicationRecord def mailboxer_email(object) nil # email end + + def mailboxer_notifications + mailbox.notifications + end + + def mailboxer_notification_receipts + mailbox.receipts.includes(:notification).where(mailbox_type: nil) + end end diff --git a/app/views/layouts/_account.html.erb b/app/views/layouts/_account.html.erb index 748e5f1b..ebb8658c 100644 --- a/app/views/layouts/_account.html.erb +++ b/app/views/layouts/_account.html.erb @@ -18,14 +18,20 @@ <%= link_to "Admin", metacodes_path %> <% end %> -
  • -
    - Share Invite -
  • <%= link_to "Apps", oauth_authorized_applications_path %>
  • + <% if current_user.present? %> +
  • +
    + <%= link_to "Notifications", notifications_path %> +
  • + <% end %> +
  • +
    + Share Invite +
  • <%= link_to "Sign Out", "/logout", id: "Logout" %>