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.

52 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. class Filters::StatusesController < ApplicationController
  3. layout 'admin'
  4. before_action :authenticate_user!
  5. before_action :set_filter
  6. before_action :set_status_filters
  7. before_action :set_pack
  8. before_action :set_body_classes
  9. PER_PAGE = 20
  10. def index
  11. @status_filter_batch_action = Form::StatusFilterBatchAction.new
  12. end
  13. def batch
  14. @status_filter_batch_action = Form::StatusFilterBatchAction.new(status_filter_batch_action_params.merge(current_account: current_account, filter_id: params[:filter_id], type: action_from_button))
  15. @status_filter_batch_action.save!
  16. rescue ActionController::ParameterMissing
  17. flash[:alert] = I18n.t('admin.statuses.no_status_selected')
  18. ensure
  19. redirect_to edit_filter_path(@filter)
  20. end
  21. private
  22. def set_pack
  23. use_pack 'admin'
  24. end
  25. def set_filter
  26. @filter = current_account.custom_filters.find(params[:filter_id])
  27. end
  28. def set_status_filters
  29. @status_filters = @filter.statuses.preload(:status).page(params[:page]).per(PER_PAGE)
  30. end
  31. def status_filter_batch_action_params
  32. params.require(:form_status_filter_batch_action).permit(status_filter_ids: [])
  33. end
  34. def action_from_button
  35. 'remove' if params[:remove]
  36. end
  37. def set_body_classes
  38. @body_classes = 'admin'
  39. end
  40. end