Class: Integral::VersionDecorator
- Inherits:
-
Draper::Decorator
- Object
- Draper::Decorator
- Integral::VersionDecorator
- Defined in:
- app/decorators/integral/version_decorator.rb
Overview
Page view-level logic
Instance Method Summary collapse
-
#decorated_item ⇒ Object
Associated Item.
-
#event ⇒ String
Formatted event.
-
#event_verb ⇒ String
Formatted event verb (past).
- #item ⇒ Object
- #item_class ⇒ Object
-
#item_icon ⇒ String
Font Awesome icon.
-
#item_title ⇒ String
Formatted title.
-
#item_url ⇒ String
Item URL.
-
#model_name ⇒ String
Formatted item type.
-
#url ⇒ String
URL to view version screen.
-
#whodunnit ⇒ Integral::User
Who carried out the version (if one exists).
-
#whodunnit_avatar_url ⇒ String
Image linked to whodunnit.
-
#whodunnit_name ⇒ String
Name linked to whodunnit.
- #whodunnit_url ⇒ Object
Instance Method Details
#decorated_item ⇒ Object
Returns Associated Item.
71 72 73 |
# File 'app/decorators/integral/version_decorator.rb', line 71 def decorated_item @decorated_item ||= item&.decorate end |
#event ⇒ String
Returns formatted event.
12 13 14 |
# File 'app/decorators/integral/version_decorator.rb', line 12 def event h.t("integral.actions.#{object.event}") end |
#event_verb ⇒ String
Returns formatted event verb (past).
17 18 19 |
# File 'app/decorators/integral/version_decorator.rb', line 17 def event_verb h.t("integral.actions.tense.past.#{object.event}") end |
#item ⇒ Object
61 62 63 |
# File 'app/decorators/integral/version_decorator.rb', line 61 def item @item ||= item_class.unscoped.find_by_id(item_id) end |
#item_class ⇒ Object
57 58 59 |
# File 'app/decorators/integral/version_decorator.rb', line 57 def item_class item_type.constantize end |
#item_icon ⇒ String
Returns Font Awesome icon.
76 77 78 |
# File 'app/decorators/integral/version_decorator.rb', line 76 def item_icon item_class.respond_to?(:integral_icon) ? item_class.integral_icon : 'ellipsis-v' end |
#item_title ⇒ String
Returns formatted title.
66 67 68 |
# File 'app/decorators/integral/version_decorator.rb', line 66 def item_title decorated_item.present? ? decorated_item.title : '<deleted>' end |
#item_url ⇒ String
Returns Item URL.
22 23 24 |
# File 'app/decorators/integral/version_decorator.rb', line 22 def item_url decorated_item&.backend_url end |
#model_name ⇒ String
Returns formatted item type.
81 82 83 |
# File 'app/decorators/integral/version_decorator.rb', line 81 def model_name item_class.model_name.human end |
#url ⇒ String
Returns URL to view version screen.
7 8 9 |
# File 'app/decorators/integral/version_decorator.rb', line 7 def url decorated_item&.activity_url(object.id) end |
#whodunnit ⇒ Integral::User
Returns who carried out the version (if one exists).
31 32 33 34 35 36 37 |
# File 'app/decorators/integral/version_decorator.rb', line 31 def whodunnit user_id = object.whodunnit.to_i return '' if user_id.zero? @user = Integral::User.unscoped.find_by_id(object.whodunnit)&.decorate end |
#whodunnit_avatar_url ⇒ String
Returns image linked to whodunnit.
40 41 42 43 44 45 46 |
# File 'app/decorators/integral/version_decorator.rb', line 40 def whodunnit_avatar_url if whodunnit.present? whodunnit.decorate.avatar_url else ActionController::Base.helpers.asset_path('integral/defaults/user_avatar.jpg') end end |
#whodunnit_name ⇒ String
Returns name linked to whodunnit.
49 50 51 52 53 54 55 |
# File 'app/decorators/integral/version_decorator.rb', line 49 def whodunnit_name if whodunnit.present? whodunnit.name else 'System' end end |