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.

47 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. module Admin::FilterHelper
  3. FILTERS = [
  4. AccountFilter::KEYS,
  5. CustomEmojiFilter::KEYS,
  6. ReportFilter::KEYS,
  7. TagFilter::KEYS,
  8. InstanceFilter::KEYS,
  9. InviteFilter::KEYS,
  10. RelationshipFilter::KEYS,
  11. ].flatten.freeze
  12. def filter_link_to(text, link_to_params, link_class_params = link_to_params)
  13. new_url = filtered_url_for(link_to_params)
  14. new_class = filtered_url_for(link_class_params)
  15. link_to text, new_url, class: filter_link_class(new_class)
  16. end
  17. def table_link_to(icon, text, path, **options)
  18. link_to safe_join([fa_icon(icon), text]), path, options.merge(class: 'table-action-link')
  19. end
  20. def selected?(more_params)
  21. new_url = filtered_url_for(more_params)
  22. filter_link_class(new_url) == 'selected'
  23. end
  24. private
  25. def filter_params(more_params)
  26. controller_request_params.merge(more_params)
  27. end
  28. def filter_link_class(new_url)
  29. filtered_url_for(controller_request_params) == new_url ? 'selected' : ''
  30. end
  31. def filtered_url_for(url_params)
  32. url_for filter_params(url_params)
  33. end
  34. def controller_request_params
  35. params.permit(FILTERS)
  36. end
  37. end