From 786e641d4eae5c51ff8b4fedae425b9f27125c40 Mon Sep 17 00:00:00 2001 From: guillaume imary Date: Fri, 15 Nov 2024 10:43:24 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20G=C3=A8re=20l'import=20et=20l'expor?= =?UTF-8?q?t=20des=20questions=20clic=20dans=20texte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/questions.rb | 3 ++- app/models/import_export/questions/export.rb | 9 +++++++-- app/models/import_export/questions/import.rb | 10 +++++++--- .../import_export/questions/import_export_donnees.rb | 2 ++ app/models/question_clic_dans_texte.rb | 2 +- config/locales/models/question.yml | 5 ++++- spec/models/question_clic_dans_texte_spec.rb | 2 -- 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/admin/questions.rb b/app/admin/questions.rb index 09a65b702..ec9415f41 100644 --- a/app/admin/questions.rb +++ b/app/admin/questions.rb @@ -46,7 +46,8 @@ def redirection_apres_import 'QuestionGlisserDeposer' => admin_questions_glisser_deposer_path, 'QuestionQcm' => admin_question_qcms_path, 'QuestionSaisie' => admin_questions_saisies_path, - 'QuestionSousConsigne' => admin_question_sous_consignes_path + 'QuestionSousConsigne' => admin_question_sous_consignes_path, + 'QuestionClicDansTexte' => admin_questions_clic_dans_texte_path } redirection_paths[params[:type]] || admin_questions_path diff --git a/app/models/import_export/questions/export.rb b/app/models/import_export/questions/export.rb index 80c775553..11e601460 100644 --- a/app/models/import_export/questions/export.rb +++ b/app/models/import_export/questions/export.rb @@ -12,7 +12,7 @@ def initialize(questions, headers) def to_xls entetes = @headers.map { |header| { titre: header.to_s.humanize, taille: 20 } } @sheet = ::ImportExport::ExportXls.new(entetes: entetes).sheet - remplie_la_feuille + remplis_la_feuille retourne_le_contenu_du_xls end @@ -22,7 +22,7 @@ def nom_du_fichier(type) private - def remplie_la_feuille + def remplis_la_feuille @questions.each_with_index do |question, index| @question = question @ligne = index + 1 @@ -54,6 +54,7 @@ def remplis_champs_specifiques when 'QuestionGlisserDeposer' then remplis_champs_glisser_deposer when 'QuestionQcm' then remplis_champs_qcm when 'QuestionSaisie' then remplis_champs_saisie + when 'QuestionClicDansTexte' then remplis_champs_clic_dans_texte end end @@ -82,6 +83,10 @@ def remplis_champs_qcm @question.choix.each_with_index { |choix, index| ajoute_choix(choix, index) } end + def remplis_champs_clic_dans_texte + @sheet[@ligne, 8] = @question.texte_sur_illustration + end + def ajoute_choix(choix, index) columns = %w[intitule nom_technique type_choix audio] columns.each_with_index do |col, i| diff --git a/app/models/import_export/questions/import.rb b/app/models/import_export/questions/import.rb index 8975a3320..b090a82fa 100644 --- a/app/models/import_export/questions/import.rb +++ b/app/models/import_export/questions/import.rb @@ -43,8 +43,7 @@ def cree_question def intialise_question @question = Question.new(type: @type) # On crée une nouvelle instance pour chaque ligne - @question.assign_attributes(libelle: @row[0], nom_technique: @row[1], - description: @row[7]) + @question.assign_attributes(libelle: @row[0], nom_technique: @row[1], description: @row[7]) attache_fichier(@question.illustration, @row[2]) @question.save! end @@ -59,7 +58,8 @@ def update_champs_specifiques 'QuestionClicDansImage' => :update_clic_dans_image, 'QuestionGlisserDeposer' => :update_glisser_deposer, 'QuestionQcm' => :update_qcm, - 'QuestionSaisie' => :update_saisie + 'QuestionSaisie' => :update_saisie, + 'QuestionClicDansTexte' => :update_clic_dans_texte } send(updates[@type]) if updates.key?(@type) end @@ -85,6 +85,10 @@ def update_saisie cree_reponse_generique(@row[11], @row[12], 'bon') end + def update_clic_dans_texte + @question.update!(texte_sur_illustration: @row[8]) + end + def cree_reponses(type, creation_method) extrait_colonnes_reponses(type).each_value do |data| creation_method.call(data) diff --git a/app/models/import_export/questions/import_export_donnees.rb b/app/models/import_export/questions/import_export_donnees.rb index 03c3ee1e1..44f1a1fca 100644 --- a/app/models/import_export/questions/import_export_donnees.rb +++ b/app/models/import_export/questions/import_export_donnees.rb @@ -4,6 +4,7 @@ module ImportExport module Questions class ImportExportDonnees HEADERS_CLIC_DANS_IMAGE = %i[zone_cliquable image_au_clic].freeze + HEADERS_CLIC_DANS_TEXTE = %i[texte_sur_illustration].freeze HEADERS_GLISSER_DEPOSER = %i[zone_depot].freeze HEADERS_QCM = %i[type_qcm].freeze HEADERS_SAISIE = %i[suffix_reponse reponse_placeholder type_saisie bonne_reponse_intitule @@ -13,6 +14,7 @@ class ImportExportDonnees HEADERS_COMMUN = %i[libelle nom_technique illustration intitule_ecrit intitule_audio consigne_ecrit consigne_audio description].freeze HEADERS_ATTENDUS = { 'QuestionClicDansImage' => HEADERS_COMMUN + HEADERS_CLIC_DANS_IMAGE, + 'QuestionClicDansTexte' => HEADERS_COMMUN + HEADERS_CLIC_DANS_TEXTE, 'QuestionGlisserDeposer' => HEADERS_COMMUN + HEADERS_GLISSER_DEPOSER, 'QuestionQcm' => HEADERS_COMMUN + HEADERS_QCM, 'QuestionSaisie' => HEADERS_COMMUN + HEADERS_SAISIE, diff --git a/app/models/question_clic_dans_texte.rb b/app/models/question_clic_dans_texte.rb index 66f7a3590..ee1af5e73 100644 --- a/app/models/question_clic_dans_texte.rb +++ b/app/models/question_clic_dans_texte.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class QuestionClicDansTexte < Question - validates :texte_sur_illustration, presence: true + # validates :texte_sur_illustration, presence: true def as_json(_options = nil) base_json diff --git a/config/locales/models/question.yml b/config/locales/models/question.yml index ccec251c8..82f4e8cba 100644 --- a/config/locales/models/question.yml +++ b/config/locales/models/question.yml @@ -12,7 +12,10 @@ fr: other: Questions sous consigne question_clic_dans_image: one: Question clic dans image - other: Questions clic dans image + other: Questions clic dans image + question_clic_dans_texte: + one: Question clic dans texte + other: Questions clic dans texte question_glisser_deposer: one: Question glisser déposer other: Questions glisser déposer diff --git a/spec/models/question_clic_dans_texte_spec.rb b/spec/models/question_clic_dans_texte_spec.rb index 830279893..63b3f6b96 100644 --- a/spec/models/question_clic_dans_texte_spec.rb +++ b/spec/models/question_clic_dans_texte_spec.rb @@ -3,8 +3,6 @@ require 'rails_helper' describe QuestionClicDansTexte, type: :model do - it { is_expected.to validate_presence_of(:texte_sur_illustration) } - describe '#as_json' do let(:contenu) { 'Mon Intitulé [mot1](#bonne-reponse) [mot2](#bonne-reponse) [mot3]()' } let(:question_clic_dans_texte) do