links_controller.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. class Admin::Trends::LinksController < Admin::BaseController
  3. def index
  4. authorize :preview_card, :review?
  5. @locales = PreviewCardTrend.pluck('distinct language')
  6. @preview_cards = filtered_preview_cards.page(params[:page])
  7. @form = Trends::PreviewCardBatch.new
  8. end
  9. def batch
  10. authorize :preview_card, :review?
  11. @form = Trends::PreviewCardBatch.new(trends_preview_card_batch_params.merge(current_account: current_account, action: action_from_button))
  12. @form.save
  13. rescue ActionController::ParameterMissing
  14. flash[:alert] = I18n.t('admin.trends.links.no_link_selected')
  15. ensure
  16. redirect_to admin_trends_links_path(filter_params)
  17. end
  18. private
  19. def filtered_preview_cards
  20. Trends::PreviewCardFilter.new(filter_params.with_defaults(trending: 'all')).results
  21. end
  22. def filter_params
  23. params.slice(:page, *Trends::PreviewCardFilter::KEYS).permit(:page, *Trends::PreviewCardFilter::KEYS)
  24. end
  25. def trends_preview_card_batch_params
  26. params.require(:trends_preview_card_batch).permit(:action, preview_card_ids: [])
  27. end
  28. def action_from_button
  29. if params[:approve]
  30. 'approve'
  31. elsif params[:approve_providers]
  32. 'approve_providers'
  33. elsif params[:reject]
  34. 'reject'
  35. elsif params[:reject_providers]
  36. 'reject_providers'
  37. end
  38. end
  39. end