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.
 
 
 
 

48 lines
1.6 KiB

  1. # frozen_string_literal: true
  2. module Admin::FilterHelper
  3. ACCOUNT_FILTERS = %i(local remote by_domain active pending 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(context review).freeze
  8. INSTANCES_FILTERS = %i(limited by_domain).freeze
  9. FOLLOWERS_FILTERS = %i(relationship status by_domain activity order).freeze
  10. FILTERS = ACCOUNT_FILTERS + REPORT_FILTERS + INVITE_FILTER + CUSTOM_EMOJI_FILTERS + TAGS_FILTERS + INSTANCES_FILTERS + FOLLOWERS_FILTERS
  11. def filter_link_to(text, link_to_params, link_class_params = link_to_params)
  12. new_url = filtered_url_for(link_to_params)
  13. new_class = filtered_url_for(link_class_params)
  14. link_to text, new_url, class: filter_link_class(new_class)
  15. end
  16. def table_link_to(icon, text, path, **options)
  17. link_to safe_join([fa_icon(icon), text]), path, options.merge(class: 'table-action-link')
  18. end
  19. def selected?(more_params)
  20. new_url = filtered_url_for(more_params)
  21. filter_link_class(new_url) == 'selected'
  22. end
  23. private
  24. def filter_params(more_params)
  25. controller_request_params.merge(more_params)
  26. end
  27. def filter_link_class(new_url)
  28. filtered_url_for(controller_request_params) == new_url ? 'selected' : ''
  29. end
  30. def filtered_url_for(url_params)
  31. url_for filter_params(url_params)
  32. end
  33. def controller_request_params
  34. params.permit(FILTERS)
  35. end
  36. end