Skip to content

Commit

Permalink
✨ Gère l'import et l'export des questions clic dans texte
Browse files Browse the repository at this point in the history
  • Loading branch information
Guitguitou authored and cprodhomme committed Nov 15, 2024
1 parent f59fee4 commit 786e641
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion app/admin/questions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions app/models/import_export/questions/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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|
Expand Down
10 changes: 7 additions & 3 deletions app/models/import_export/questions/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions app/models/import_export/questions/import_export_donnees.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/models/question_clic_dans_texte.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion config/locales/models/question.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions spec/models/question_clic_dans_texte_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 786e641

Please sign in to comment.