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.
 
 
 
 

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