Module: Gera::CurrencyRateModesHelper
- Defined in:
- app/helpers/gera/currency_rate_modes_helper.rb
Constant Summary collapse
- ICON_CLASS =
{ 'draft' => 'battery-half', 'active' => 'battery-charging', 'deactive' => 'battery-empty' }.freeze
- STATUS_CLASS =
{ 'draft' => 'label-info', 'active' => 'label-success', 'deactive' => 'label-default' }.freeze
Instance Method Summary collapse
- #crms_cell_data_attr(crm) ⇒ Object
- #crms_status_label(status) ⇒ Object
- #currencies_enum ⇒ Object
- #currency_rate_mode_build_result_details(build_result) ⇒ Object
- #currency_rate_mode_detailed(currency_rate, level = 0) ⇒ Object
- #currency_rate_mode_snapshot_icon(crms) ⇒ Object
- #currency_rate_modes_enum ⇒ Object
Instance Method Details
#crms_cell_data_attr(crm) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/gera/currency_rate_modes_helper.rb', line 39 def crms_cell_data_attr(crm) url = crm.persisted? ? edit_currency_rate_mode_path(crm, back: request.url) : new_currency_rate_mode_path( currency_rate_mode: crm.attributes.slice('currency_rate_mode_snapshot_id', 'cur_from', 'cur_to'), back: request.url ) { toggle: :popover, container: :body, content: currency_rate_mode_build_result_details(crm.build_result), trigger: :hover, html: 'true', placement: :bottom, animation: false, delay: 0, href: url } end |
#crms_status_label(status) ⇒ Object
58 59 60 |
# File 'app/helpers/gera/currency_rate_modes_helper.rb', line 58 def crms_status_label(status) content_tag :span, status, class: "label #{STATUS_CLASS[status]}" end |
#currencies_enum ⇒ Object
70 71 72 |
# File 'app/helpers/gera/currency_rate_modes_helper.rb', line 70 def currencies_enum Money::Currency.all.map(&:to_s) end |
#currency_rate_mode_build_result_details(build_result) ⇒ Object
33 34 35 36 37 |
# File 'app/helpers/gera/currency_rate_modes_helper.rb', line 33 def currency_rate_mode_build_result_details(build_result) return build_result.error. if build_result.error? raw t('.calculation_method', rate: currency_rate_mode_detailed(build_result.currency_rate)) end |
#currency_rate_mode_detailed(currency_rate, level = 0) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/helpers/gera/currency_rate_modes_helper.rb', line 16 def currency_rate_mode_detailed(currency_rate, level = 0) buffer = [] if currency_rate.mode_cross? currency_rate.external_rates.each do |er| buffer << "#{er.currency_pair}(#{er.source})<sup>#{humanized_rate er.rate_value}</sup>" end elsif currency_rate.mode_same? buffer << t('.same_currency') else buffer << "#{currency_rate.currency_pair}(#{currency_rate.rate_source})" end buffer = buffer.join(' × ') buffer << " = #{humanized_rate currency_rate.rate_value} #{currency_rate.currency_pair.last}" if level == 0 buffer.html_safe end |
#currency_rate_mode_snapshot_icon(crms) ⇒ Object
62 63 64 |
# File 'app/helpers/gera/currency_rate_modes_helper.rb', line 62 def currency_rate_mode_snapshot_icon(crms) ion_icon ICON_CLASS[crms.status] end |
#currency_rate_modes_enum ⇒ Object
66 67 68 |
# File 'app/helpers/gera/currency_rate_modes_helper.rb', line 66 def currency_rate_modes_enum Gera::CurrencyRateMode.modes.keys end |