preview_card_providers_controller.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # frozen_string_literal: true
  2. class Admin::Trends::Links::PreviewCardProvidersController < Admin::BaseController
  3. def index
  4. authorize :preview_card_provider, :review?
  5. @preview_card_providers = filtered_preview_card_providers.page(params[:page])
  6. @form = Trends::PreviewCardProviderBatch.new
  7. end
  8. def batch
  9. authorize :preview_card_provider, :review?
  10. @form = Trends::PreviewCardProviderBatch.new(trends_preview_card_provider_batch_params.merge(current_account: current_account, action: action_from_button))
  11. @form.save
  12. rescue ActionController::ParameterMissing
  13. flash[:alert] = I18n.t('admin.trends.links.publishers.no_publisher_selected')
  14. ensure
  15. redirect_to admin_trends_links_preview_card_providers_path(filter_params)
  16. end
  17. private
  18. def filtered_preview_card_providers
  19. Trends::PreviewCardProviderFilter.new(filter_params).results
  20. end
  21. def filter_params
  22. params.slice(:page, *Trends::PreviewCardProviderFilter::KEYS).permit(:page, *Trends::PreviewCardProviderFilter::KEYS)
  23. end
  24. def trends_preview_card_provider_batch_params
  25. params.require(:trends_preview_card_provider_batch).permit(:action, preview_card_provider_ids: [])
  26. end
  27. def action_from_button
  28. if params[:approve]
  29. 'approve'
  30. elsif params[:reject]
  31. 'reject'
  32. end
  33. end
  34. end