diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b34d46fbc3360055ac171c7390a3113043dfd58a..870e94c3f9afcb5ba1b8435695ed9e32a0f78c16 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 1dea77dc87cde9c264772abfd354a6152129360e..59d72bfe3714566d91230b3b19b49890d935320c 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 ab096ece9b7742345306ec1e9c905988beac4e1a..a4b4f3a266b78792c5603ccc924232a5aa1b897b 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'