Class: Decidim::AuthorizationTransferPresenter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
app/presenters/decidim/authorization_transfer_presenter.rb

Overview

Decorator for authorization transfer.

Instance Method Summary collapse

Instance Method Details

#records_list_htmlString

Generates a HTML list of the record counts with the translated.

Returns:

  • (String)

    An HTML formatted list of the record names with their counts.



49
50
51
52
53
54
55
# File 'app/presenters/decidim/authorization_transfer_presenter.rb', line 49

def records_list_html
  items = translated_record_texts.map do |description|
    "<li>#{CGI.escapeHTML(description)}</li>"
  end

  "<ul>#{items.join}</ul>".html_safe
end

#translated_record_countsHash<String => String>

Simplifies the informational hash returned by the ‘#information` for the display in the user interface. Returns a hash containing the record types (their class names as strings) as its keys and the translated amount of the records as its values.

The record names are always in plural format for maximum language compatibility, as otherwise we would have to specify the translatable strings for all records in singular and plural formats.

Examples:

Format of the returned hash

{
   "Decidim::Foo" => "Foos: 123",
   "Decidim::Bar" => "Bars: 456"
}

Returns:

  • (Hash<String => String>)

    The translated resource counts with the resource type as its keys and the translated text with the record count as its values.



26
27
28
29
30
31
32
33
34
35
# File 'app/presenters/decidim/authorization_transfer_presenter.rb', line 26

def translated_record_counts
  resources = information.map do |type, info|
    resource_class = info[:class]
    name = resource_class.model_name

    [type, "#{name.human(count: 2)}: #{info[:count]}"]
  end

  resources.sort_by { |v| v[1] }.to_h
end

#translated_record_textsArray<String>

Returns an array of the translated record counts containing only the texts to be displayed for the user.

Returns:

  • (Array<String>)

    The translated records names with their counts.



41
42
43
# File 'app/presenters/decidim/authorization_transfer_presenter.rb', line 41

def translated_record_texts
  translated_record_counts.values
end