Class: Integral::Notification::NotificationDecorator

Inherits:
Draper::Decorator
  • Object
show all
Defined in:
app/decorators/integral/notification/notification_decorator.rb

Instance Method Summary collapse

Instance Method Details

#action_verbObject



10
11
12
# File 'app/decorators/integral/notification/notification_decorator.rb', line 10

def action_verb
  h.t("integral.actions.tense.past.#{object.action}")
end

#decorated_itemObject

Returns Associated Item.

Returns:

  • (Object)

    Associated Item



60
61
62
# File 'app/decorators/integral/notification/notification_decorator.rb', line 60

def decorated_item
  @decorated_item ||= item&.decorate
end

#formatted_actionObject



6
7
8
# File 'app/decorators/integral/notification/notification_decorator.rb', line 6

def formatted_action
  h.t("integral.actions.#{object.action}")
end

#itemObject



50
51
52
# File 'app/decorators/integral/notification/notification_decorator.rb', line 50

def item
  @item ||= item_klass.unscoped.find_by_id(subscribable_id)
end

#item_klassObject



69
70
71
# File 'app/decorators/integral/notification/notification_decorator.rb', line 69

def item_klass
  subscribable_type.constantize
end

#item_titleString

Returns formatted title.

Returns:

  • (String)

    formatted title



55
56
57
# File 'app/decorators/integral/notification/notification_decorator.rb', line 55

def item_title
  decorated_item.present? ? decorated_item.title : '<deleted>'
end

#item_urlString

Returns Item URL.

Returns:

  • (String)

    Item URL



15
16
17
# File 'app/decorators/integral/notification/notification_decorator.rb', line 15

def item_url
  decorated_item&.backend_url
end

#model_nameString

Returns formatted item type.

Returns:

  • (String)

    formatted item type



65
66
67
# File 'app/decorators/integral/notification/notification_decorator.rb', line 65

def model_name
  item_klass.model_name.human
end

#whodunnitIntegral::User

Returns who carried out the version (if one exists).

Returns:



24
25
26
27
28
29
30
# File 'app/decorators/integral/notification/notification_decorator.rb', line 24

def whodunnit
  user_id = object.actor_id.to_i

  return '' if user_id.zero?

  @user = Integral::User.unscoped.find_by_id(object.actor_id)&.decorate
end

#whodunnit_avatar_urlString

Returns image linked to whodunnit.

Returns:

  • (String)

    image linked to whodunnit



33
34
35
36
37
38
39
# File 'app/decorators/integral/notification/notification_decorator.rb', line 33

def whodunnit_avatar_url
  if whodunnit.present?
    whodunnit.avatar_url
  else
    ActionController::Base.helpers.asset_path('integral/defaults/user_avatar.jpg')
  end
end

#whodunnit_nameString

Returns name linked to whodunnit.

Returns:

  • (String)

    name linked to whodunnit



42
43
44
45
46
47
48
# File 'app/decorators/integral/notification/notification_decorator.rb', line 42

def whodunnit_name
  if whodunnit.present?
    whodunnit.name
  else
    'System'
  end
end

#whodunnit_urlObject



19
20
21
# File 'app/decorators/integral/notification/notification_decorator.rb', line 19

def whodunnit_url
  Integral::Engine.routes.url_helpers.backend_user_url(whodunnit.id) if whodunnit.present?
end