Skip to content

Commit

Permalink
Merge pull request #11329 from demarches-simplifiees/improve-combobox…
Browse files Browse the repository at this point in the history
…-usability-for-dropdown-with-many-items-ldu

ETQ instructeur je veux pouvoir uploader un referentiel csv de 5 000 lignes (au lieu de 1000 max)
  • Loading branch information
lisa-durand authored Feb 19, 2025
2 parents 811e28a + 0f0ee73 commit a3883cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
%span.fr-download__detail
= template_detail
.fr-hint-text.fr-mb-1w
Votre fichier doit peser maximum #{number_to_human_size(referentiel_max_size)} et ne doit pas contenir plus de #{referentiel_max_lines} lignes.
Votre fichier doit peser maximum #{number_to_human_size(referentiel_max_size)} et ne doit pas contenir plus de #{number_with_delimiter(referentiel_max_lines)} lignes.
.flex.column
= file_field_tag :referentiel_file, required: true, accept: 'text/csv', size: "1", class: 'fr-mb-2w', id: dom_id(type_de_champ, :import_referentiel)

Expand Down
10 changes: 7 additions & 3 deletions app/controllers/administrateurs/types_de_champ_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TypesDeChampController < AdministrateurController
before_action :reload_procedure_with_includes, only: [:destroy]

CSV_MAX_SIZE = 1.megabyte
CSV_MAX_LINES = 1000
CSV_MAX_LINES = 5_000
CSV_ACCEPTED_CONTENT_TYPES = [
"text/csv",
"application/vnd.ms-excel"
Expand Down Expand Up @@ -153,9 +153,13 @@ def import_referentiel

type_de_champ = draft.find_and_ensure_exclusive_use(params[:stable_id])

csv_to_code = ACSV::CSV.new_for_ruby3(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true).map(&:to_h)
begin
csv_to_code = ACSV::CSV.new_for_ruby3(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true).map(&:to_h)
rescue CSV::MalformedCSVError
return flash[:alert] = "Importation impossible : le fichier est mal formaté"
end

return flash[:alert] = "Importation impossible : votre fichier CSV fait plus de 1000 lignes" if csv_to_code.size > 1000
return flash[:alert] = "Importation impossible : votre fichier CSV fait plus de #{helpers.number_with_delimiter(CSV_MAX_LINES)} lignes" if csv_to_code.size > CSV_MAX_LINES

headers = csv_to_code.first.keys

Expand Down

0 comments on commit a3883cf

Please sign in to comment.