The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

46 lines
1.4 KiB

  1. # frozen_string_literal: true
  2. module Admin::FilterHelper
  3. ACCOUNT_FILTERS = %i(local remote by_domain active silenced suspended username display_name email ip staff).freeze
  4. REPORT_FILTERS = %i(resolved account_id target_account_id).freeze
  5. INVITE_FILTER = %i(available expired).freeze
  6. CUSTOM_EMOJI_FILTERS = %i(local remote by_domain shortcode).freeze
  7. TAGS_FILTERS = %i(hidden).freeze
  8. INSTANCES_FILTERS = %i(limited).freeze
  9. FILTERS = ACCOUNT_FILTERS + REPORT_FILTERS + INVITE_FILTER + CUSTOM_EMOJI_FILTERS + TAGS_FILTERS + INSTANCES_FILTERS
  10. def filter_link_to(text, link_to_params, link_class_params = link_to_params)
  11. new_url = filtered_url_for(link_to_params)
  12. new_class = filtered_url_for(link_class_params)
  13. link_to text, new_url, class: filter_link_class(new_class)
  14. end
  15. def table_link_to(icon, text, path, **options)
  16. link_to safe_join([fa_icon(icon), text]), path, options.merge(class: 'table-action-link')
  17. end
  18. def selected?(more_params)
  19. new_url = filtered_url_for(more_params)
  20. filter_link_class(new_url) == 'selected'
  21. end
  22. private
  23. def filter_params(more_params)
  24. controller_request_params.merge(more_params)
  25. end
  26. def filter_link_class(new_url)
  27. filtered_url_for(controller_request_params) == new_url ? 'selected' : ''
  28. end
  29. def filtered_url_for(url_params)
  30. url_for filter_params(url_params)
  31. end
  32. def controller_request_params
  33. params.permit(FILTERS)
  34. end
  35. end