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.

44 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. FILTERS = ACCOUNT_FILTERS + REPORT_FILTERS + INVITE_FILTER + CUSTOM_EMOJI_FILTERS + TAGS_FILTERS
  9. def filter_link_to(text, link_to_params, link_class_params = link_to_params)
  10. new_url = filtered_url_for(link_to_params)
  11. new_class = filtered_url_for(link_class_params)
  12. link_to text, new_url, class: filter_link_class(new_class)
  13. end
  14. def table_link_to(icon, text, path, **options)
  15. link_to safe_join([fa_icon(icon), text]), path, options.merge(class: 'table-action-link')
  16. end
  17. def selected?(more_params)
  18. new_url = filtered_url_for(more_params)
  19. filter_link_class(new_url) == 'selected'
  20. end
  21. private
  22. def filter_params(more_params)
  23. controller_request_params.merge(more_params)
  24. end
  25. def filter_link_class(new_url)
  26. filtered_url_for(controller_request_params) == new_url ? 'selected' : ''
  27. end
  28. def filtered_url_for(url_params)
  29. url_for filter_params(url_params)
  30. end
  31. def controller_request_params
  32. params.permit(FILTERS)
  33. end
  34. end