Module: SnitchReporting::ParamsHelper
- Included in:
- SnitchReportsController
- Defined in:
- app/helpers/snitch_reporting/params_helper.rb
Instance Method Summary collapse
- #sort_order ⇒ Object
- #sortable(link_text, param_string, options = {}) ⇒ Object
- #svg(img, opts = {}) ⇒ Object
- #toggled_sort_order ⇒ Object
- #true_param?(*param_keys) ⇒ Boolean
- #truthy?(val) ⇒ Boolean
Instance Method Details
#sort_order ⇒ Object
2 3 4 |
# File 'app/helpers/snitch_reporting/params_helper.rb', line 2 def sort_order params[:order] == "desc" ? "desc" : "asc" end |
#sortable(link_text, param_string, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/snitch_reporting/params_helper.rb', line 22 def sortable(link_text, param_string, ={}) if param_string.nil? return link_to link_text.html_safe, [:additional_params] || {}, class: "sortable #{[:class]}" # rubocop:disable Rails/OutputSafety - We're certain this is safe because we're in control of all of the elements. end if params[:sort] == param_string sorted_class = "sorted sortable-#{toggled_sort_order}" default_order = toggled_sort_order end additional_params = [:additional_params] || {} additional_params = additional_params.permit!.to_h if additional_params.is_a?(ActionController::Parameters) # rubocop:disable Rails/OutputSafety - We're certain this is safe because we're in control of all of the elements. link_html = "#{link_text}<div class=\"sortable-arrows\">#{svg('icons/UpChevron.svg', class: 'desc')}#{svg('icons/DownChevron.svg', class: 'asc')}</div>".html_safe # rubocop:enable Rails/OutputSafety link_to link_html, { sort: param_string, order: default_order || "desc" }.reverse_merge(additional_params), class: "sortable #{sorted_class} #{[:class]}" end |
#svg(img, opts = {}) ⇒ Object
18 19 20 |
# File 'app/helpers/snitch_reporting/params_helper.rb', line 18 def svg(img, opts={}) "" end |
#toggled_sort_order ⇒ Object
6 7 8 |
# File 'app/helpers/snitch_reporting/params_helper.rb', line 6 def toggled_sort_order params[:order] == "desc" ? "asc" : "desc" end |
#true_param?(*param_keys) ⇒ Boolean
14 15 16 |
# File 'app/helpers/snitch_reporting/params_helper.rb', line 14 def true_param?(*param_keys) truthy?(params&.dig(*param_keys)) end |
#truthy?(val) ⇒ Boolean
10 11 12 |
# File 'app/helpers/snitch_reporting/params_helper.rb', line 10 def truthy?(val) val.to_s.downcase.in?(["true", "t", "1"]) end |