demarches-normaliennes/app/components/procedure/import_component.rb
2024-10-14 15:14:06 +02:00

37 lines
774 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
class Procedure::ImportComponent < ApplicationComponent
def initialize(procedure:)
@procedure = procedure
end
def scope
@procedure.routing_enabled? ? 'groupes' : 'instructeurs'
end
def template_file
if @procedure.routing_enabled?
'/csv/import-groupe-test.csv'
else
'/csv/import-instructeurs-test.csv'
end
end
def template_detail
"#{File.extname(csv_template.to_path).upcase.delete_prefix('.')} #{number_to_human_size(csv_template.size)}"
end
def csv_max_size
Administrateurs::GroupeInstructeursController::CSV_MAX_SIZE
end
private
def csv_template
template_path.open
end
def template_path
Rails.public_path.join(template_file.delete_prefix('/'))
end
end