mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Rubocop was complaining about too many arguments. But `ApplicationJob#perform` needs all arguments handled in one call. While we could allow the `perform` method generally to have more arguments, there could be other methods called `perform` which should still be scrutinised. Instead, it seems acceptable to me to have more arguments as long as they are clearly named as keyword arguments. Rails uses this a lot to document all options including their default values, for example in Active Storage. It's better then bundling several arguments in an undocumented hash just to reduce the number of given arguments. And once we upgraded to Ruby 3.1, we can clean the method calls up as well. `call(user: user)` becomes `call(user:)` without repetition.
83 lines
2.0 KiB
Ruby
83 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Admin
|
|
class ReportsController < Spree::Admin::BaseController
|
|
include ActiveStorage::SetCurrent
|
|
include ReportsActions
|
|
helper ReportsHelper
|
|
|
|
before_action :authorize_report, only: [:show]
|
|
|
|
# Define model class for Can? permissions
|
|
def model_class
|
|
Admin::ReportsController
|
|
end
|
|
|
|
def index
|
|
@reports = reports.select do |report_type, _description|
|
|
can? report_type, :report
|
|
end
|
|
end
|
|
|
|
def show
|
|
@report = report_class.new(spree_current_user, params, render: render_data?)
|
|
|
|
@background_reports = OpenFoodNetwork::FeatureToggle
|
|
.enabled?(:background_reports, spree_current_user)
|
|
|
|
if @background_reports && request.post?
|
|
return background(report_format)
|
|
end
|
|
|
|
if params[:report_format].present?
|
|
export_report
|
|
else
|
|
show_report
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def export_report
|
|
send_data @report.render_as(report_format), filename: report_filename
|
|
end
|
|
|
|
def show_report
|
|
assign_view_data
|
|
@table = @report.render_as(:html) if render_data?
|
|
render "show"
|
|
end
|
|
|
|
def assign_view_data
|
|
@report_type = report_type
|
|
@report_subtypes = report_subtypes
|
|
@report_subtype = report_subtype
|
|
@report_title = report_title
|
|
@rendering_options = rendering_options
|
|
@data = Reporting::FrontendData.new(spree_current_user)
|
|
end
|
|
|
|
def render_data?
|
|
request.post?
|
|
end
|
|
|
|
def background(format)
|
|
blob = ReportBlob.create_for_upload_later!(report_filename)
|
|
|
|
ReportJob.perform_later(
|
|
report_class: report_class, user: spree_current_user, params: params,
|
|
format: format, blob: blob, channel: ScopedChannel.for_id(params[:uuid]),
|
|
)
|
|
|
|
render cable_ready: cable_car.
|
|
inner_html(
|
|
selector: "#report-table",
|
|
html: render_to_string(partial: "admin/reports/loading")
|
|
).scroll_into_view(
|
|
selector: "#report-table",
|
|
block: "start"
|
|
)
|
|
end
|
|
end
|
|
end
|