Class: Decidim::DecidimAwesome::RoleBasePresenter

Inherits:
PaperTrailBasePresenter show all
Includes:
TranslatableAttributes
Defined in:
app/presenters/decidim/decidim_awesome/role_base_presenter.rb

Instance Attribute Summary

Attributes inherited from PaperTrailBasePresenter

#entry, #html

Instance Method Summary collapse

Methods inherited from PaperTrailBasePresenter

#initialize, #item, #item_id, #item_type

Constructor Details

This class inherits a constructor from Decidim::DecidimAwesome::PaperTrailBasePresenter

Instance Method Details

#created_atObject



62
63
64
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 62

def created_at
  entry.changeset["created_at"]&.last || entry&.created_at
end

#created_dateObject



66
67
68
69
70
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 66

def created_date
  I18n.l(created_at, format: :short)
rescue I18n::ArgumentError
  ""
end

#destroy_entryObject Also known as: destroyed?

Finds the destroyed entry if exists



9
10
11
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 9

def destroy_entry
  nil
end

#destroy_itemObject

try to reconstruct a destroyed event



16
17
18
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 16

def destroy_item
  @destroy_item ||= destroy_entry&.reify
end

#destroyed_atObject



72
73
74
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 72

def destroyed_at
  destroy_entry&.created_at
end

#last_sign_in_dateObject



82
83
84
85
86
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 82

def 
  I18n.l(user&., format: :short)
rescue I18n::ArgumentError
  info_text("never_logged")
end

#participatory_spaceObject



28
29
30
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 28

def participatory_space
  nil
end

#participatory_space_nameObject



32
33
34
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 32

def participatory_space_name
  participatory_space_type.present? ? "#{participatory_space_type} > #{translated_attribute participatory_space&.title}" : ""
end

#participatory_space_pathObject

try to link to the user roles page or to the participatory space if not existing



41
42
43
44
45
46
47
48
49
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 41

def participatory_space_path
  proxy.send("#{participatory_space.manifest.route_name}_user_roles_path")
rescue NoMethodError
  begin
    proxy.send("#{participatory_space.manifest.route_name}_path", participatory_space)
  rescue NoMethodError
    ""
  end
end

#participatory_space_typeObject



36
37
38
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 36

def participatory_space_type
  I18n.t(participatory_space&.manifest&.name, scope: "decidim.admin.menu") if participatory_space.present?
end

#removal_dateObject



76
77
78
79
80
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 76

def removal_date
  I18n.l(destroyed_at, format: :short)
rescue I18n::ArgumentError
  info_text("currently_active", klass: "text-success")
end

#role_nameObject



24
25
26
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 24

def role_name
  raise "Please implement this method to return the role text"
end

#userObject



20
21
22
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 20

def user
  raise "Please implement this method to return the user object"
end

#user_emailObject



58
59
60
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 58

def user_email
  user&.email || entry.changeset["email"]&.last
end

#user_nameObject



51
52
53
54
55
56
# File 'app/presenters/decidim/decidim_awesome/role_base_presenter.rb', line 51

def user_name
  return I18n.t("missing_user", scope: "decidim.decidim_awesome.admin.admin_accountability") unless user
  return I18n.t("deleted_user", scope: "decidim.decidim_awesome.admin.admin_accountability") if user.deleted?

  user&.name
end