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.

49 lines
1.2 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. AnnouncementFilter::KEYS,
  12. Admin::ActionLogFilter::KEYS,
  13. ].flatten.freeze
  14. def filter_link_to(text, link_to_params, link_class_params = link_to_params)
  15. new_url = filtered_url_for(link_to_params)
  16. new_class = filtered_url_for(link_class_params)
  17. link_to text, new_url, class: filter_link_class(new_class)
  18. end
  19. def table_link_to(icon, text, path, **options)
  20. link_to safe_join([fa_icon(icon), text]), path, options.merge(class: 'table-action-link')
  21. end
  22. def selected?(more_params)
  23. new_url = filtered_url_for(more_params)
  24. filter_link_class(new_url) == 'selected'
  25. end
  26. private
  27. def filter_params(more_params)
  28. controller_request_params.merge(more_params)
  29. end
  30. def filter_link_class(new_url)
  31. filtered_url_for(controller_request_params) == new_url ? 'selected' : ''
  32. end
  33. def filtered_url_for(url_params)
  34. url_for filter_params(url_params)
  35. end
  36. def controller_request_params
  37. params.permit(FILTERS)
  38. end
  39. end