11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/activeadmin/batched_export/controller_methods.rb', line 11
def batched_export
authorize! ActiveAdmin::Authorization::READ, active_admin_config.resource_class
export_format = normalized_export_format
return if export_format.nil?
if request.format.json? && params[:export_meta].present?
ensure_batch_download_format_allowed!(export_format)
return render(json: batched_export_meta(export_format))
end
batch_page = params[:batch_page].to_i
if batch_page.positive?
if request.format.symbol != export_format
head :not_acceptable
return
end
ensure_batch_download_format_allowed!(export_format)
page = page_relation(batch_page)
if page.out_of_range?
head :not_found
return
end
begin
body = batched_export_batch_body(export_format, batch_page, page: page)
rescue ExportMacroCatalog::UnknownMacroError
return render(
plain: I18n.t("active_admin.batched_export_page.unknown_macro"),
status: :unprocessable_content
)
end
return render(plain: body, content_type: batch_content_type(export_format))
end
ensure_batch_download_format_allowed!(export_format)
@batched_export_format = export_format
@batched_export_meta_url = batched_export_url_for(
request_format: :json,
extra_params: {"export_meta" => "1", "export_format" => export_format.to_s}
)
@batched_export_batch_base_url = batched_export_url_for(
request_format: export_format,
extra_params: {"export_format" => export_format.to_s}
)
@batched_export_styles = BatchedExport.styles
@batched_export_stimulus_controller = BatchedExport.config.stimulus_controller
(export_format)
render "active_admin/batched_export/workspace", layout: "active_admin"
end
|