Skip to content
Extraits de code Groupes Projets
Valider 06391228 rédigé par Maxwell Salzberg's avatar Maxwell Salzberg
Parcourir les fichiers

use the user presenter, luke

parent 40413a6b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -13,9 +13,7 @@ class ApplicationController < ActionController::Base ...@@ -13,9 +13,7 @@ class ApplicationController < ActionController::Base
inflection_method :grammatical_gender => :gender inflection_method :grammatical_gender => :gender
helper_method :notification_count, helper_method :all_aspects,
:unread_message_count,
:all_aspects,
:all_contacts_count, :all_contacts_count,
:my_contacts_count, :my_contacts_count,
:only_sharing_count, :only_sharing_count,
...@@ -38,15 +36,6 @@ class ApplicationController < ActionController::Base ...@@ -38,15 +36,6 @@ class ApplicationController < ActionController::Base
end end
end 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 def all_aspects
@all_aspects ||= current_user.aspects @all_aspects ||= current_user.aspects
end end
......
...@@ -41,6 +41,8 @@ class NotificationsController < ApplicationController ...@@ -41,6 +41,8 @@ class NotificationsController < ApplicationController
end end
@group_days = @notifications.group_by{|note| I18n.l(note.created_at, :format => I18n.t('date.formats.fullmonth_day')) } @group_days = @notifications.group_by{|note| I18n.l(note.created_at, :format => I18n.t('date.formats.fullmonth_day')) }
@unread_notification_count = current_user.unread_notifications.count
respond_to do |format| respond_to do |format|
format.html format.html
format.xml { render :xml => @notifications.to_xml } format.xml { render :xml => @notifications.to_xml }
......
...@@ -36,16 +36,11 @@ module LayoutHelper ...@@ -36,16 +36,11 @@ module LayoutHelper
def set_current_user_in_javascript def set_current_user_in_javascript
return unless current_user return unless current_user
current_user_presenter = UserPresenter.new(current_user)
content_tag(:script) do content_tag(:script) do
<<-JS.html_safe <<-JS.html_safe
app.user( app.user(#{current_user_presenter.to_json});
_.extend(#{current_user.person.as_api_response(:backbone).to_json}, {
notifications_count : #{notification_count},
unread_messages_count : #{unread_message_count},
admin : #{current_user.admin?}
})
);
JS JS
end end
end end
......
...@@ -98,6 +98,14 @@ class User < ActiveRecord::Base ...@@ -98,6 +98,14 @@ class User < ActiveRecord::Base
where('last_sign_in_at > ?', time) where('last_sign_in_at > ?', time)
end end
def unread_notifications
notifications.where(:unread => true)
end
def unread_message_count
ConversationVisibility.sum(:unread, :conditions => "person_id = #{self.person.id}")
end
# @return [User] # @return [User]
def self.find_by_invitation(invitation) def self.find_by_invitation(invitation)
service = invitation.service service = invitation.service
......
class UserPresenter
attr_accessor :user
def initialize(user)
self.user = user
end
def to_json(options = {})
self.user.person.as_api_response(:backbone).update(
{ :notifications_count => notifications_count,
:unread_messages_count => unread_messages_count,
:admin => admin
}
).to_json(options)
end
protected
def notifications_count
@notification_count ||= user.unread_notifications.count
end
def unread_messages_count
@unread_message_count ||= user.unread_message_count
end
def admin
user.admin?
end
end
\ No newline at end of file
#notifications_content #notifications_content
.span-13 .span-13
%h2 %h2
%span.notification_count{:class => ('unread' if notification_count > 0)} %span.notification_count{:class => ('unread' if @unread_notification_count >0 )}
= notification_count = @unread_notification_count
= t('.notifications') = t('.notifications')
.span-8.last .span-8.last
= link_to t('.mark_all_as_read'), notifications_read_all_path, :class => 'button' = link_to t('.mark_all_as_read'), notifications_read_all_path, :class => 'button'
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter