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

use the user presenter, luke

parent d1301dc2
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
inflection_method :grammatical_gender => :gender
helper_method :notification_count,
:unread_message_count,
:all_aspects,
helper_method :all_aspects,
:all_contacts_count,
:my_contacts_count,
:only_sharing_count,
......@@ -38,15 +36,6 @@ class ApplicationController < ActionController::Base
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
@all_aspects ||= current_user.aspects
end
......
......@@ -41,6 +41,8 @@ class NotificationsController < ApplicationController
end
@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|
format.html
format.xml { render :xml => @notifications.to_xml }
......
......@@ -36,16 +36,11 @@ module LayoutHelper
def set_current_user_in_javascript
return unless current_user
current_user_presenter = UserPresenter.new(current_user)
content_tag(:script) do
<<-JS.html_safe
app.user(
_.extend(#{current_user.person.as_api_response(:backbone).to_json}, {
notifications_count : #{notification_count},
unread_messages_count : #{unread_message_count},
admin : #{current_user.admin?}
})
);
app.user(#{current_user_presenter.to_json});
JS
end
end
......
......@@ -98,6 +98,14 @@ class User < ActiveRecord::Base
where('last_sign_in_at > ?', time)
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]
def self.find_by_invitation(invitation)
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
.span-13
%h2
%span.notification_count{:class => ('unread' if notification_count > 0)}
= notification_count
%span.notification_count{:class => ('unread' if @unread_notification_count >0 )}
= @unread_notification_count
= t('.notifications')
.span-8.last
= 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