From 778683f3e39222d0f2e2a53bd888f6a335074efe Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Sun, 22 Jan 2012 22:26:27 -0800 Subject: [PATCH] don't extend helpers in the notifications index view; make notification_count and unread_message_count controller helper methods (now that we're not using vanna) --- app/controllers/application_controller.rb | 20 +++++++++++--------- app/views/layouts/application.html.haml | 4 ++-- app/views/notifications/index.html.haml | 8 ++------ 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b34d46fbc..870e94c3f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -7,14 +7,15 @@ class ApplicationController < ActionController::Base protect_from_forgery :except => :receive before_filter :ensure_http_referer_is_set - before_filter :set_header_data, :except => [:create, :update, :destroy] before_filter :set_locale before_filter :set_git_header if (AppConfig[:git_update] && AppConfig[:git_revision]) before_filter :set_grammatical_gender inflection_method :grammatical_gender => :gender - helper_method :all_aspects, + helper_method :notification_count, + :unread_message_count, + :all_aspects, :all_contacts_count, :my_contacts_count, :only_sharing_count, @@ -22,13 +23,6 @@ class ApplicationController < ActionController::Base :tags, :open_publisher - def set_header_data - if user_signed_in? && request.format.html? && !params[:only_posts] - @notification_count = Notification.for(current_user, :unread =>true).count - @unread_message_count = ConversationVisibility.sum(:unread, :conditions => "person_id = #{current_user.person.id}") - end - end - def ensure_http_referer_is_set request.env['HTTP_REFERER'] ||= '/aspects' end @@ -45,6 +39,14 @@ class ApplicationController < ActionController::Base end ##helpers + def notification_count + @notification_count ||= Notification.for(current_user, :unread =>true).size + end + + def unread_message_count + @unread_message_count ||= ConversationVisibility.sum(:unread, :conditions => "person_id = #{current_user.person.id}") + end + def all_aspects @all_aspects ||= current_user.aspects end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 1dea77dc8..59d72bfe3 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -92,8 +92,8 @@ :javascript app.user({ current_user: _.extend(#{current_user.person.as_api_response(:backbone).to_json}, { - notifications_count : #{@notification_count}, - unread_messages_count : #{@unread_message_count}, + notifications_count : #{notification_count}, + unread_messages_count : #{unread_message_count}, admin : #{current_user.admin?} }) }); diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index ab096ece9..a4b4f3a26 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -1,12 +1,8 @@ --self.extend AspectGlobalHelper --self.extend AspectsHelper --self.extend ApplicationHelper --self.extend ErrorMessagesHelper #notifications_content .span-13 %h2 - %span.notification_count{:class => ('unread' if @notification_count > 0)} - = @notification_count + %span.notification_count{:class => ('unread' if notification_count > 0)} + = notification_count = t('.notifications') .span-8.last = link_to t('.mark_all_as_read'), notifications_read_all_path, :class => 'button'