announcements_helper.rb 582 B

12345678910111213141516171819
  1. module AnnouncementsHelper
  2. def unread_announcements(user)
  3. last_announcement = Announcement.order(published_at: :desc).first
  4. return if last_announcement.nil?
  5. # Highlight announcements for anyone not logged in, cuz tempting
  6. if user.nil? || user.announcements_last_read_at.nil? || user.announcements_last_read_at < last_announcement.published_at
  7. "unread-announcements"
  8. end
  9. end
  10. def announcement_class(type)
  11. {
  12. "new" => "text-success",
  13. "update" => "text-warning",
  14. "fix" => "text-danger",
  15. }.fetch(type, "text-success")
  16. end
  17. end