demarches-normaliennes/app/components/dossiers/export_dropdown_component.rb

31 lines
814 B
Ruby
Raw Normal View History

class Dossiers::ExportDropdownComponent < ApplicationComponent
include ApplicationHelper
def initialize(procedure:, statut: nil, count: nil, class_btn: nil, export_url: nil)
@procedure = procedure
@statut = statut
@count = count
@class_btn = class_btn
2022-07-04 16:13:15 +02:00
@export_url = export_url
end
def formats
2022-11-16 11:50:19 +01:00
if @statut
Export::FORMATS.filter(&method(:allowed_format?))
2022-11-16 11:50:19 +01:00
else
Export::FORMATS_WITH_TIME_SPAN
end.map { _1[:format] }
2022-11-16 11:50:19 +01:00
end
def allowed_format?(item)
item.fetch(:format) != :json || @procedure.active_revision.carte?
end
def download_export_path(export_format:, no_progress_notification: nil)
2022-07-04 16:13:15 +02:00
@export_url.call(@procedure,
export_format: export_format,
statut: @statut,
no_progress_notification: no_progress_notification)
end
end