Class: Integral::VersionDecorator

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

Overview

Page view-level logic

Instance Method Summary collapse

Instance Method Details

#decorated_itemObject

Returns Associated Item.

Returns:

  • (Object)

    Associated Item



71
72
73
# File 'app/decorators/integral/version_decorator.rb', line 71

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

#eventString

Returns formatted event.

Returns:

  • (String)

    formatted event



12
13
14
# File 'app/decorators/integral/version_decorator.rb', line 12

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

#event_verbString

Returns formatted event verb (past).

Returns:

  • (String)

    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

#itemObject



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_classObject



57
58
59
# File 'app/decorators/integral/version_decorator.rb', line 57

def item_class
  item_type.constantize
end

#item_iconString

Returns Font Awesome icon.

Returns:

  • (String)

    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_titleString

Returns formatted title.

Returns:

  • (String)

    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_urlString

Returns Item URL.

Returns:

  • (String)

    Item URL



22
23
24
# File 'app/decorators/integral/version_decorator.rb', line 22

def item_url
  decorated_item&.backend_url
end

#model_nameString

Returns formatted item type.

Returns:

  • (String)

    formatted item type



81
82
83
# File 'app/decorators/integral/version_decorator.rb', line 81

def model_name
  item_class.model_name.human
end

#urlString

Returns URL to view version screen.

Returns:

  • (String)

    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

#whodunnitIntegral::User

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

Returns:



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_urlString

Returns image linked to whodunnit.

Returns:

  • (String)

    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_nameString

Returns name linked to whodunnit.

Returns:

  • (String)

    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

#whodunnit_urlObject



26
27
28
# File 'app/decorators/integral/version_decorator.rb', line 26

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