2022-05-11 16:30:41 +02:00
|
|
|
class Dossiers::ExportComponent < ApplicationComponent
|
2023-01-13 15:36:13 +01:00
|
|
|
def initialize(procedure:, exports:, statut: nil, count: nil, class_btn: nil, export_url: nil)
|
2022-05-11 16:30:41 +02:00
|
|
|
@procedure = procedure
|
|
|
|
@exports = exports
|
|
|
|
@statut = statut
|
|
|
|
@count = count
|
2023-01-13 15:36:13 +01:00
|
|
|
@class_btn = class_btn
|
2022-07-04 16:13:15 +02:00
|
|
|
@export_url = export_url
|
2022-05-11 16:30:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def exports
|
2022-11-16 11:50:19 +01:00
|
|
|
if @statut
|
|
|
|
Export::FORMATS.filter(&method(:allowed_format?)).map do |item|
|
|
|
|
export = @exports
|
|
|
|
.fetch(item.fetch(:format))
|
|
|
|
.fetch(:statut)
|
|
|
|
.fetch(@statut, nil)
|
|
|
|
item.merge(export: export)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Export::FORMATS_WITH_TIME_SPAN.map do |item|
|
|
|
|
export = @exports
|
|
|
|
.fetch(item.fetch(:format))
|
|
|
|
.fetch(:time_span_type)
|
|
|
|
.fetch(item.fetch(:time_span_type), nil)
|
|
|
|
item.merge(export: export)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def allowed_format?(item)
|
|
|
|
item.fetch(:format) != :json || @procedure.active_revision.carte?
|
2022-05-11 16:30:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def download_export_path(export_format:, force_export: false, no_progress_notification: nil)
|
2022-07-04 16:13:15 +02:00
|
|
|
@export_url.call(@procedure,
|
2022-05-11 16:30:41 +02:00
|
|
|
export_format: export_format,
|
|
|
|
statut: @statut,
|
|
|
|
force_export: force_export,
|
|
|
|
no_progress_notification: no_progress_notification)
|
|
|
|
end
|
|
|
|
|
|
|
|
def refresh_button_options(export)
|
|
|
|
{
|
|
|
|
title: t(".everything_short", export_format: ".#{export.format}"),
|
|
|
|
class: "button small",
|
|
|
|
style: "padding-right: 2px"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def ready_link_label(export)
|
|
|
|
t(".everything_ready_html",
|
|
|
|
export_time: helpers.time_ago_in_words(export.updated_at),
|
|
|
|
export_format: ".#{export.format}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def pending_label(export)
|
|
|
|
t(".everything_pending_html",
|
|
|
|
export_time: time_ago_in_words(export.created_at),
|
|
|
|
export_format: ".#{export.format}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def poll_controller_options(export)
|
|
|
|
{
|
|
|
|
controller: 'turbo-poll',
|
|
|
|
turbo_poll_url_value: download_export_path(export_format: export.format, no_progress_notification: true),
|
|
|
|
turbo_poll_interval_value: 6000,
|
|
|
|
turbo_poll_max_checks_value: 10
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|