diff --git a/app/components/procedure/groupes_ajout_component/groupes_ajout_component.html.haml b/app/components/procedure/groupes_ajout_component/groupes_ajout_component.html.haml index 84804dc43..853158898 100644 --- a/app/components/procedure/groupes_ajout_component/groupes_ajout_component.html.haml +++ b/app/components/procedure/groupes_ajout_component/groupes_ajout_component.html.haml @@ -1,9 +1,6 @@ - content_for(:title, 'Ajout de groupes') %h1 Ajout de groupes d'instructeurs -= render partial: 'administrateurs/groupe_instructeurs/import', - locals: { procedure: @procedure } - %section = form_for :groupe_instructeur, method: :post do |f| diff --git a/app/components/procedure/import_component.rb b/app/components/procedure/import_component.rb new file mode 100644 index 000000000..f8917e1a1 --- /dev/null +++ b/app/components/procedure/import_component.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +class Procedure::ImportComponent < ApplicationComponent + def initialize(procedure:) + @procedure = procedure + end + + def scope + @procedure.routing_enabled? ? 'groupes' : 'instructeurs' + end + + def template_url + 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 + if @procedure.routing_enabled? + Rails.public_path.join('csv/import-groupe-test.csv') + else + Rails.public_path.join('csv/import-instructeurs-test.csv') + end + end +end diff --git a/app/components/procedure/import_component/import_component.en.yml b/app/components/procedure/import_component/import_component.en.yml new file mode 100644 index 000000000..3958a266b --- /dev/null +++ b/app/components/procedure/import_component/import_component.en.yml @@ -0,0 +1,14 @@ +en: + csv_import: + import_file: Import file + import_file_alert: All instructors added to the procedure will be notified by email. Do you want to continue? + file_to_import: File to import + file_size_limit: "File size limit : %{max_file_size}." + groupes: + title: Bulk Import / Export + notice_1_html: For the import, your csv file must have 2 columns (Group, Email) (see file model below). The file size must be less than %{csv_max_size}. + notice_2_html: The import does not overwrite existing groups and instructors. It only allows you to add them. + instructeurs: + title: Adding instructors with file import + notice_1_html: For the import, your csv file must have 1 column (Email) listing the email addresses of the instructors (see file model below). The file size must be less than %{csv_max_size}. + notice_2_html: The import does not overwrite existing instructors. It only allows you to add them. diff --git a/app/components/procedure/import_component/import_component.fr.yml b/app/components/procedure/import_component/import_component.fr.yml new file mode 100644 index 000000000..7773c6bae --- /dev/null +++ b/app/components/procedure/import_component/import_component.fr.yml @@ -0,0 +1,15 @@ +fr: + csv_import: + import_file: Importer le fichier + import_file_alert: Tous les instructeurs ajoutés à la procédure vont être notifiés par email. Voulez-vous continuer ? + file_to_import: Fichier à importer + download_template: Modèle à télécharger + file_size_limit: "Taille maximale : %{max_file_size}." + groupes: + title: Ajout de groupes / instructeurs avec import de fichier + notice_1_html: Pour l’import, votre fichier csv doit comporter 2 colonnes (Groupe, Email) (voir modèle de fichier ci-dessous). Le poids du fichier doit être inférieur à %{csv_max_size}. + notice_2_html: L’import n’écrase pas les groupes et instructeurs existants. Il permet uniquement d’en ajouter. + instructeurs: + title: Ajout d’instructeurs avec import de fichier + notice_1_html: Pour l’import, votre fichier csv doit comporter 1 seule colonne (Email) listant les adresses emails des instructeurs (voir modèle de fichier ci-dessous). Le poids du fichier doit être inférieur à %{csv_max_size}. + notice_2_html: L’import n’écrase pas les instructeurs existants. Il permet uniquement d’en ajouter. diff --git a/app/views/administrateurs/groupe_instructeurs/_import.html.haml b/app/components/procedure/import_component/import_component.html.haml similarity index 63% rename from app/views/administrateurs/groupe_instructeurs/_import.html.haml rename to app/components/procedure/import_component/import_component.html.haml index 344b721c4..cbf8bad57 100644 --- a/app/views/administrateurs/groupe_instructeurs/_import.html.haml +++ b/app/components/procedure/import_component/import_component.html.haml @@ -1,16 +1,14 @@ -- key = procedure.groupe_instructeurs.one? ? 'instructeurs' : 'groupes' %section.fr-accordion.fr-mb-3w %h3.fr-accordion__title %button.fr-accordion__btn{ "aria-controls" => "accordion-106", "aria-expanded" => "false" } - = t(".csv_import.#{key}.title") + = t(".csv_import.#{scope}.title") .fr-collapse#accordion-106 - - csv_max_size = Administrateurs::GroupeInstructeursController::CSV_MAX_SIZE .notice.fr-mb-1w - = t(".csv_import.#{key}.notice_1_html", csv_max_size: number_to_human_size(csv_max_size)) + = t(".csv_import.#{scope}.notice_1_html", csv_max_size: number_to_human_size(csv_max_size)) .notice - = t(".csv_import.#{key}.notice_2_html") + = t(".csv_import.#{scope}.notice_2_html") - = form_tag import_admin_procedure_groupe_instructeurs_path(procedure), method: :post, multipart: true, class: "mt-4 column" do + = form_tag import_admin_procedure_groupe_instructeurs_path(@procedure), method: :post, multipart: true, class: "mt-4 column" do %label.fr-label.font-weight-bold = t('.csv_import.file_to_import') .fr-download @@ -18,6 +16,8 @@ = t('.csv_import.download_template') %span.fr-download__detail = template_detail + .fr-hint-text.fr-mb-1w + = t('.csv_import.file_size_limit', max_file_size: number_to_human_size(csv_max_size)) .flex.column = file_field_tag :csv_file, required: true, accept: 'text/csv', size: "1", class: 'fr-mb-2w' = submit_tag t('.csv_import.import_file'), class: 'fr-btn fr-btn--tertiary', data: { disable_with: "Envoi...", confirm: t('.csv_import.import_file_alert') } diff --git a/app/components/procedure/instructeurs_management_component.rb b/app/components/procedure/instructeurs_management_component.rb index 4b30aa376..919a2ebad 100644 --- a/app/components/procedure/instructeurs_management_component.rb +++ b/app/components/procedure/instructeurs_management_component.rb @@ -8,20 +8,4 @@ class Procedure::InstructeursManagementComponent < ApplicationComponent @available_instructeur_emails = available_instructeur_emails @disabled_as_super_admin = disabled_as_super_admin end - - def csv_template - template_path.open - end - - def template_path - Rails.public_path.join('csv/import-instructeurs-test.csv') - end - - def template_url - template_path.to_s - end - - def template_detail - "#{File.extname(csv_template.to_path).upcase.delete_prefix('.')} – #{number_to_human_size(csv_template.size)}" - end end diff --git a/app/components/procedure/instructeurs_management_component/instructeurs_management_component.html.haml b/app/components/procedure/instructeurs_management_component/instructeurs_management_component.html.haml index a0b6d0b7f..0ab12c41b 100644 --- a/app/components/procedure/instructeurs_management_component/instructeurs_management_component.html.haml +++ b/app/components/procedure/instructeurs_management_component/instructeurs_management_component.html.haml @@ -2,8 +2,8 @@ %h1.fr-h2= t('.title') .fr-icon-mail-line.fr-alert.fr-mb-3w %p= t('.notification_alert') -= render partial: 'administrateurs/groupe_instructeurs/import', - locals: { procedure: @procedure, template_url:, template_detail: } + += render Procedure::ImportComponent.new(procedure: @procedure) = render partial: 'administrateurs/groupe_instructeurs/instructeurs', locals: { procedure: @procedure, diff --git a/app/components/procedure/one_groupe_management_component.rb b/app/components/procedure/one_groupe_management_component.rb index c01b2ce61..abf6da24e 100644 --- a/app/components/procedure/one_groupe_management_component.rb +++ b/app/components/procedure/one_groupe_management_component.rb @@ -8,20 +8,4 @@ class Procedure::OneGroupeManagementComponent < ApplicationComponent @groupe_instructeur = groupe_instructeur @procedure = revision.procedure end - - def csv_template - template_path.open - end - - def template_path - Rails.public_path.join('csv/import-instructeurs-test.csv') - end - - def template_url - template_path.to_s - end - - def template_detail - "#{File.extname(csv_template.to_path).upcase.delete_prefix('.')} – #{number_to_human_size(csv_template.size)}" - end end diff --git a/app/components/procedure/one_groupe_management_component/one_groupe_management_component.html.haml b/app/components/procedure/one_groupe_management_component/one_groupe_management_component.html.haml index 2c2202529..6356b579e 100644 --- a/app/components/procedure/one_groupe_management_component/one_groupe_management_component.html.haml +++ b/app/components/procedure/one_groupe_management_component/one_groupe_management_component.html.haml @@ -1,8 +1,7 @@ %div{ id: dom_id(@groupe_instructeur, :routing) } %h1 Paramètres du groupe - = render partial: 'administrateurs/groupe_instructeurs/import', - locals: { procedure: @procedure, template_url:, template_detail: } + = render Procedure::ImportComponent.new(procedure: @procedure) = form_for @groupe_instructeur, url: admin_procedure_groupe_instructeur_path(@procedure, @groupe_instructeur), diff --git a/config/locales/views/administrateurs/groupe_instructeurs/en.yml b/config/locales/views/administrateurs/groupe_instructeurs/en.yml index ec58bcdf8..790906ba2 100644 --- a/config/locales/views/administrateurs/groupe_instructeurs/en.yml +++ b/config/locales/views/administrateurs/groupe_instructeurs/en.yml @@ -30,19 +30,3 @@ en: instructeur_emails: Email addresses of the instructors you want to assign to this procedure copy_paste_hint: "You can enter addresses individually, or copy-paste a list of addresses separated by semicolons into the field below (example: adress1@mail.com; adress2@mail.com; adress3@mail.com)." actions: Remove - import: - csv_import: - import_file: Import file - import_file_alert: All instructors added to the procedure will be notified by email. Do you want to continue? - file_to_import: File to import - groupes: - title: Bulk Import / Export - notice_1_html: For the import, your csv file must have 2 columns (Group, Email) (see file model below). The file size must be less than %{csv_max_size}. - notice_2_html: The import does not overwrite existing groups and instructors. It only allows you to add them. - instructeurs: - title: Adding instructors with file import - notice_1_html: For the import, your csv file must have 1 column (Email) listing the email addresses of the instructors (see file model below). The file size must be less than %{csv_max_size}. - notice_2_html: The import does not overwrite existing instructors. It only allows you to add them. - existing_groupe: - one: "%{count} groupe existe" - other: "%{count} groupes existent" diff --git a/config/locales/views/administrateurs/groupe_instructeurs/fr.yml b/config/locales/views/administrateurs/groupe_instructeurs/fr.yml index e28d9b16b..0594811e3 100644 --- a/config/locales/views/administrateurs/groupe_instructeurs/fr.yml +++ b/config/locales/views/administrateurs/groupe_instructeurs/fr.yml @@ -38,22 +38,6 @@ fr: copy_paste_hint: "Vous pouvez saisir les adresses individuellement, ou bien copier-coller dans le champ ci-dessous une liste d’adresses séparées par des points-virgules (exemple : adresse1@mail.com; adresse2@mail.com; adresse3@mail.com)." actions: Retirer import: - csv_import: - import_file: Importer le fichier - import_file_alert: Tous les instructeurs ajoutés à la procédure vont être notifiés par email. Voulez-vous continuer ? - file_to_import: Fichier à importer - download_template: Modèle à télécharger - groupes: - title: Import / Export en masse - notice_1_html: Pour l’import, votre fichier csv doit comporter 2 colonnes (Groupe, Email) (voir modèle de fichier ci-dessous). Le poids du fichier doit être inférieur à %{csv_max_size}. - notice_2_html: L’import n’écrase pas les groupes et instructeurs existants. Il permet uniquement d’en ajouter. - instructeurs: - title: Ajout d’instructeurs avec import de fichier - notice_1_html: Pour l’import, votre fichier csv doit comporter 1 seule colonne (Email) listant les adresses emails des instructeurs (voir modèle de fichier ci-dessous). Le poids du fichier doit être inférieur à %{csv_max_size}. - notice_2_html: L’import n’écrase pas les instructeurs existants. Il permet uniquement d’en ajouter. - existing_groupe: - one: "%{count} groupe existe" - other: "%{count} groupes existent" groupe: one: "%{count} groupe" other: "%{count} groupes" diff --git a/public/csv/en/import-groupe-test.csv b/public/csv/en/import-groupe-test.csv deleted file mode 100644 index 1045de444..000000000 --- a/public/csv/en/import-groupe-test.csv +++ /dev/null @@ -1,5 +0,0 @@ -Email,Groupe -camilia@gouv.fr,Nord -kara@gouv.fr,Finistère -simon@gouv.fr,Isère -pauline@gouv.fr,Bouches-du-Rhône \ No newline at end of file diff --git a/public/csv/fr/import-groupe-test.csv b/public/csv/import-groupe-test.csv similarity index 100% rename from public/csv/fr/import-groupe-test.csv rename to public/csv/import-groupe-test.csv