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.

42 lines
1.2 KiB

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