Move some DB logic from helper to controller
This commit is contained in:
parent
bc874e92cd
commit
8f5358e68f
4 changed files with 28 additions and 25 deletions
|
|
@ -5,7 +5,6 @@
|
||||||
class NotificationsController < VannaController
|
class NotificationsController < VannaController
|
||||||
include NotificationsHelper
|
include NotificationsHelper
|
||||||
|
|
||||||
|
|
||||||
def update(opts=params)
|
def update(opts=params)
|
||||||
note = Notification.where(:recipient_id => current_user.id, :id => opts[:id]).first
|
note = Notification.where(:recipient_id => current_user.id, :id => opts[:id]).first
|
||||||
if note
|
if note
|
||||||
|
|
@ -31,8 +30,16 @@ class NotificationsController < VannaController
|
||||||
|
|
||||||
pager.replace(result)
|
pager.replace(result)
|
||||||
end
|
end
|
||||||
|
notifications.each do |n|
|
||||||
notifications.each{|n| n[:actors] = n.actors}
|
n[:actors] = n.actors
|
||||||
|
n[:translation_key] = n.popup_translation_key
|
||||||
|
if n.translation_key == "notifications.mentioned"
|
||||||
|
n[:post] = Mention.find(n.target_id).post
|
||||||
|
else
|
||||||
|
n[:post] = Post.find(n.target_id)
|
||||||
|
end
|
||||||
|
# Go find out if the post exists, and set the target_id to nil if it doesn't
|
||||||
|
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')) }
|
||||||
{:group_days => group_days, :notifications => notifications}
|
{:group_days => group_days, :notifications => notifications}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,11 @@ module ApplicationHelper
|
||||||
object = object.model if object.instance_of? PostsFake::Fake
|
object = object.model if object.instance_of? PostsFake::Fake
|
||||||
if object.respond_to?(:activity_streams?) && object.activity_streams?
|
if object.respond_to?(:activity_streams?) && object.activity_streams?
|
||||||
class_name = object.class.name.underscore.split('/')
|
class_name = object.class.name.underscore.split('/')
|
||||||
eval("#{class_name.first}_#{class_name.last}_path(object, opts)")
|
method_sym = "#{class_name.first}_#{class_name.last}_path".to_sym
|
||||||
else
|
else
|
||||||
eval("#{object.class.name.underscore}_path(object, opts)")
|
method_sym = "#{object.class.name.underscore}_path".to_sym
|
||||||
end
|
end
|
||||||
|
self.send(method_sym, object, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def object_fields(object)
|
def object_fields(object)
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,25 @@
|
||||||
|
|
||||||
module NotificationsHelper
|
module NotificationsHelper
|
||||||
def object_link(note, actors)
|
def object_link(translation_key, post)
|
||||||
target_type = note.popup_translation_key
|
if translation_key == "notifications.mentioned"
|
||||||
actors_count = note.actors.count
|
|
||||||
if note.instance_of?(Notifications::Mentioned)
|
|
||||||
post = Mention.find(note.target_id).post
|
|
||||||
if post
|
if post
|
||||||
translation(target_type, :actors => actors, :count => actors_count, :post_link => link_to(t('notifications.post'), object_path(post)).html_safe)
|
"#{translation(translation_key)} #{link_to t('notifications.post'), object_path(post)}".html_safe
|
||||||
else
|
else
|
||||||
t('notifications.mentioned_deleted', :actors => actors, :count => actors_count).html_safe
|
"#{translation(translation_key)} #{t('notifications.deleted')} #{t('notifications.post')}"
|
||||||
end
|
end
|
||||||
elsif note.instance_of?(Notifications::CommentOnPost)
|
elsif translation_key == "notifications.comment_on_post"
|
||||||
post = Post.where(:id => note.target_id).first
|
|
||||||
if post
|
if post
|
||||||
translation(target_type, :actors => actors, :count => actors_count, :post_link => link_to(t('notifications.post'), object_path(post), 'data-ref' => post.id, :class => 'hard_object_link').html_safe)
|
"#{translation(translation_key)} #{link_to t('notifications.post'), object_path(post), 'data-ref' => post.id, :class => 'hard_object_link'}".html_safe
|
||||||
|
else
|
||||||
|
"#{translation(translation_key)} #{t('notifications.deleted')} #{t('notifications.post')}"
|
||||||
|
end
|
||||||
|
elsif translation_key == "notifications.also_commented"
|
||||||
|
if post
|
||||||
|
"#{translation(translation_key, post.author.name)} #{link_to t('notifications.post'), object_path(post), 'data-ref' => post.id, :class => 'hard_object_link'}".html_safe
|
||||||
else
|
else
|
||||||
t('notifications.also_commented_deleted', :actors => actors, :count => actors_count).html_safe
|
t('notifications.also_commented_deleted', :actors => actors, :count => actors_count).html_safe
|
||||||
end
|
end
|
||||||
elsif note.instance_of?(Notifications::AlsoCommented)
|
elsif translation_key == "notifications.liked"
|
||||||
post = Post.where(:id => note.target_id).first
|
|
||||||
if post
|
|
||||||
translation(target_type, :actors => actors, :count => actors_count, :post_author => h(post.author.name), :post_link => link_to(t('notifications.post'), object_path(post), 'data-ref' => post.id, :class => 'hard_object_link').html_safe)
|
|
||||||
else
|
|
||||||
t('notifications.also_commented_deleted', :actors => actors, :count => actors_count).html_safe
|
|
||||||
end
|
|
||||||
elsif note.instance_of?(Notifications::Liked)
|
|
||||||
post = note.target
|
|
||||||
post = post.post if post.is_a? Like
|
post = post.post if post.is_a? Like
|
||||||
if post
|
if post
|
||||||
translation(target_type, :actors => actors, :count => actors_count, :post_author => h(post.author.name), :post_link => link_to(t('notifications.post'), object_path(post), 'data-ref' => post.id, :class => 'hard_object_link').html_safe)
|
translation(target_type, :actors => actors, :count => actors_count, :post_author => h(post.author.name), :post_link => link_to(t('notifications.post'), object_path(post), 'data-ref' => post.id, :class => 'hard_object_link').html_safe)
|
||||||
|
|
|
||||||
|
|
@ -3063,7 +3063,7 @@ ul#left_nav
|
||||||
:color white
|
:color white
|
||||||
:width 700px
|
:width 700px
|
||||||
:padding 10px
|
:padding 10px
|
||||||
:top 75.5px
|
:top 275.5px
|
||||||
:left 217.5px
|
:left 217.5px
|
||||||
a.close
|
a.close
|
||||||
:float right
|
:float right
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue