From baea81b1147141276ecefc69696bae5c3bba9af5 Mon Sep 17 00:00:00 2001 From: guillaume imary Date: Fri, 15 Nov 2024 11:25:38 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20Remplace=20les=20cha?= =?UTF-8?q?=C3=AEnes=20de=20caract=C3=A8res=20par=20des=20constantes=20de?= =?UTF-8?q?=20type=20pour=20les=20questions=20dans=20l'administration=20et?= =?UTF-8?q?=20l'import/export?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/questions.rb | 12 ++++++------ app/admin/questions_clic_dans_image.rb | 2 +- app/admin/questions_clic_dans_texte.rb | 2 +- app/admin/questions_glisser_deposer.rb | 2 +- app/admin/questions_qcm.rb | 2 +- app/admin/questions_saisie.rb | 2 +- app/admin/questions_sous_consigne.rb | 3 ++- app/models/import_export/questions/export.rb | 10 +++++----- app/models/import_export/questions/import.rb | 10 +++++----- .../questions/import_export_donnees.rb | 12 ++++++------ app/models/question.rb | 18 +++++++++--------- app/models/question_clic_dans_image.rb | 1 + app/models/question_clic_dans_texte.rb | 2 +- app/models/question_glisser_deposer.rb | 1 + app/models/question_qcm.rb | 1 + app/models/question_saisie.rb | 2 ++ app/models/question_sous_consigne.rb | 2 ++ app/models/restitution/questions_reponses.rb | 4 ++-- 18 files changed, 48 insertions(+), 40 deletions(-) diff --git a/app/admin/questions.rb b/app/admin/questions.rb index ec9415f41..8ebf3008f 100644 --- a/app/admin/questions.rb +++ b/app/admin/questions.rb @@ -42,12 +42,12 @@ def erreur_import(error) def redirection_apres_import redirection_paths = { - 'QuestionClicDansImage' => admin_questions_clic_dans_image_path, - 'QuestionGlisserDeposer' => admin_questions_glisser_deposer_path, - 'QuestionQcm' => admin_question_qcms_path, - 'QuestionSaisie' => admin_questions_saisies_path, - 'QuestionSousConsigne' => admin_question_sous_consignes_path, - 'QuestionClicDansTexte' => admin_questions_clic_dans_texte_path + QuestionClicDansImage.QUESTION_TYPE => admin_questions_clic_dans_image_path, + QuestionGlisserDeposer.QUESTION_TYPE => admin_questions_glisser_deposer_path, + QuestionQcm.QUESTION_TYPE => admin_question_qcms_path, + QuestionSaisie.QUESTION_TYPE => admin_questions_saisies_path, + QuestionSousConsigne.QUESTION_TYPE => admin_question_sous_consignes_path, + QuestionClicDansTexte.QUESTION_TYPE => admin_questions_clic_dans_texte_path } redirection_paths[params[:type]] || admin_questions_path diff --git a/app/admin/questions_clic_dans_image.rb b/app/admin/questions_clic_dans_image.rb index 805a78f11..b8dd965f1 100644 --- a/app/admin/questions_clic_dans_image.rb +++ b/app/admin/questions_clic_dans_image.rb @@ -35,7 +35,7 @@ action_item :importer_question, only: :index do link_to 'Importer questions clic dans image', - admin_import_xls_path(type: 'QuestionClicDansImage') + admin_import_xls_path(type: QuestionClicDansImage.QUESTION_TYPE) end action_item :exporter_question, only: :show do diff --git a/app/admin/questions_clic_dans_texte.rb b/app/admin/questions_clic_dans_texte.rb index f5f399265..091c64fd2 100644 --- a/app/admin/questions_clic_dans_texte.rb +++ b/app/admin/questions_clic_dans_texte.rb @@ -16,7 +16,7 @@ action_item :importer_question, only: :index do link_to 'Importer questions Clic dans texte', - admin_import_xls_path(type: 'QuestionClicDansTexte') + admin_import_xls_path(type: QuestionClicDansTexte.QUESTION_TYPE) end action_item :exporter_question, only: :show do diff --git a/app/admin/questions_glisser_deposer.rb b/app/admin/questions_glisser_deposer.rb index 426cd9872..088861242 100644 --- a/app/admin/questions_glisser_deposer.rb +++ b/app/admin/questions_glisser_deposer.rb @@ -19,7 +19,7 @@ action_item :importer_question, only: :index do link_to 'Importer questions glisser déposer', - admin_import_xls_path(type: 'QuestionGlisserDeposer') + admin_import_xls_path(type: QuestionGlisserDeposer.QUESTION_TYPE) end action_item :exporter_question, only: :show do diff --git a/app/admin/questions_qcm.rb b/app/admin/questions_qcm.rb index 3b00c107a..f713d984f 100644 --- a/app/admin/questions_qcm.rb +++ b/app/admin/questions_qcm.rb @@ -18,7 +18,7 @@ form partial: 'form' action_item :importer_question, only: :index do - link_to 'Importer questions QCM', admin_import_xls_path(type: 'QuestionQcm') + link_to 'Importer questions QCM', admin_import_xls_path(type: QuestionQcm.QUESTION_TYPE) end action_item :exporter_question, only: :show do diff --git a/app/admin/questions_saisie.rb b/app/admin/questions_saisie.rb index efdf9cd8b..011477087 100644 --- a/app/admin/questions_saisie.rb +++ b/app/admin/questions_saisie.rb @@ -16,7 +16,7 @@ filter :nom_technique action_item :importer_question, only: :index do - link_to 'Importer questions saisies', admin_import_xls_path(type: 'QuestionSaisie') + link_to 'Importer questions saisies', admin_import_xls_path(type: QuestionSaisie.QUESTION_TYPE) end action_item :exporter_question, only: :show do diff --git a/app/admin/questions_sous_consigne.rb b/app/admin/questions_sous_consigne.rb index c7415855a..d5f038dff 100644 --- a/app/admin/questions_sous_consigne.rb +++ b/app/admin/questions_sous_consigne.rb @@ -11,7 +11,8 @@ filter :nom_technique action_item :importer_question, only: :index do - link_to 'Importer questions sous consigne', admin_import_xls_path(type: 'QuestionSousConsigne') + link_to 'Importer questions sous consigne', + admin_import_xls_path(type: QuestionSousConsigne.QUESTION_TYPE) end action_item :exporter_question, only: :show do diff --git a/app/models/import_export/questions/export.rb b/app/models/import_export/questions/export.rb index 11e601460..938b0a340 100644 --- a/app/models/import_export/questions/export.rb +++ b/app/models/import_export/questions/export.rb @@ -50,11 +50,11 @@ def remplis_champs_additionnels def remplis_champs_specifiques case @question.type - when 'QuestionClicDansImage' then remplis_champs_clic_dans_image - 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 + when QuestionClicDansImage.QUESTION_TYPE then remplis_champs_clic_dans_image + when QuestionGlisserDeposer.QUESTION_TYPE then remplis_champs_glisser_deposer + when QuestionQcm.QUESTION_TYPE then remplis_champs_qcm + when QuestionSaisie.QUESTION_TYPE then remplis_champs_saisie + when QuestionClicDansTexte.QUESTION_TYPE then remplis_champs_clic_dans_texte end end diff --git a/app/models/import_export/questions/import.rb b/app/models/import_export/questions/import.rb index b090a82fa..de92338c7 100644 --- a/app/models/import_export/questions/import.rb +++ b/app/models/import_export/questions/import.rb @@ -55,11 +55,11 @@ def cree_transcription(categorie, audio_url, ecrit) def update_champs_specifiques updates = { - 'QuestionClicDansImage' => :update_clic_dans_image, - 'QuestionGlisserDeposer' => :update_glisser_deposer, - 'QuestionQcm' => :update_qcm, - 'QuestionSaisie' => :update_saisie, - 'QuestionClicDansTexte' => :update_clic_dans_texte + QuestionClicDansImage.QUESTION_TYPE => :update_clic_dans_image, + QuestionGlisserDeposer.QUESTION_TYPE => :update_glisser_deposer, + QuestionQcm.QUESTION_TYPE => :update_qcm, + QuestionSaisie.QUESTION_TYPE => :update_saisie, + QuestionClicDansTexte.QUESTION_TYPE => :update_clic_dans_texte } send(updates[@type]) if updates.key?(@type) end diff --git a/app/models/import_export/questions/import_export_donnees.rb b/app/models/import_export/questions/import_export_donnees.rb index 44f1a1fca..54ef26825 100644 --- a/app/models/import_export/questions/import_export_donnees.rb +++ b/app/models/import_export/questions/import_export_donnees.rb @@ -13,12 +13,12 @@ class ImportExportDonnees intitule_audio].freeze 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, - 'QuestionSousConsigne' => HEADERS_SOUS_CONSIGNE }.freeze + HEADERS_ATTENDUS = { QuestionClicDansImage.QUESTION_TYPE => HEADERS_COMMUN + HEADERS_CLIC_DANS_IMAGE, + QuestionClicDansTexte.QUESTION_TYPE => HEADERS_COMMUN + HEADERS_CLIC_DANS_TEXTE, + QuestionGlisserDeposer.QUESTION_TYPE => HEADERS_COMMUN + HEADERS_GLISSER_DEPOSER, + QuestionQcm.QUESTION_TYPE => HEADERS_COMMUN + HEADERS_QCM, + QuestionSaisie.QUESTION_TYPE => HEADERS_COMMUN + HEADERS_SAISIE, + QuestionSousConsigne.QUESTION_TYPE => HEADERS_SOUS_CONSIGNE }.freeze def initialize(questions: nil, type: nil) @questions = questions diff --git a/app/models/question.rb b/app/models/question.rb index 63b75113e..4f2ef1f8c 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -28,12 +28,12 @@ class Question < ApplicationRecord CATEGORIE = %i[situation scolarite sante appareils].freeze AUDIO_TYPES = %i[intitule modalite_reponse consigne].freeze INTERACTION_TYPES = { - 'QuestionQcm' => 'qcm', - 'QuestionClicDansImage' => 'clic dans image', - 'QuestionGlisserDeposer' => 'glisser deposer', - 'QuestionSousConsigne' => 'sous consigne', - 'QuestionSaisie' => 'saisie', - 'QuestionClicDansTexte' => 'clic dans texte' + QuestionQcm.QUESTION_TYPE => 'qcm', + QuestionClicDansImage.QUESTION_TYPE => 'clic dans image', + QuestionGlisserDeposer.QUESTION_TYPE => 'glisser deposer', + QuestionSousConsigne.QUESTION_TYPE => 'sous consigne', + QuestionSaisie.QUESTION_TYPE => 'saisie', + QuestionClicDansTexte.QUESTION_TYPE => 'clic dans texte' }.freeze enum :categorie, CATEGORIE.zip(CATEGORIE.map(&:to_s)).to_h, prefix: true @@ -84,15 +84,15 @@ def interaction end def saisie? - type == 'QuestionSaisie' + type == QuestionSaisie.QUESTION_TYPE end def qcm? - type == 'QuestionQcm' + type == QuestionQcm.QUESTION_TYPE end def sous_consigne? - type == 'QuestionSousConsigne' + type == QuestionSousConsigne.QUESTION_TYPE end private diff --git a/app/models/question_clic_dans_image.rb b/app/models/question_clic_dans_image.rb index 5822bacff..529a0121a 100644 --- a/app/models/question_clic_dans_image.rb +++ b/app/models/question_clic_dans_image.rb @@ -2,6 +2,7 @@ class QuestionClicDansImage < Question CLASS_BONNE_REPONSE = 'bonne-reponse' + QUESTION_TYPE = 'QuestionClicDansImage' has_one_attached :zone_cliquable has_one_attached :image_au_clic diff --git a/app/models/question_clic_dans_texte.rb b/app/models/question_clic_dans_texte.rb index ee1af5e73..b4db85b46 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 + QUESTION_TYPE = 'QuestionClicDansTexte' def as_json(_options = nil) base_json diff --git a/app/models/question_glisser_deposer.rb b/app/models/question_glisser_deposer.rb index 3c73487b6..2ea34a0c5 100644 --- a/app/models/question_glisser_deposer.rb +++ b/app/models/question_glisser_deposer.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class QuestionGlisserDeposer < Question + QUESTION_TYPE = 'QuestionGlisserDeposer' has_many :reponses, -> { order(position: :asc) }, foreign_key: :question_id, class_name: 'Choix', diff --git a/app/models/question_qcm.rb b/app/models/question_qcm.rb index fd21f6bcb..de92a9031 100644 --- a/app/models/question_qcm.rb +++ b/app/models/question_qcm.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class QuestionQcm < Question + QUESTION_TYPE = 'QuestionQcm' enum :metacompetence, { numeratie: 0, ccf: 1, 'syntaxe-orthographe': 2 } enum :type_qcm, { standard: 0, jauge: 1 } has_many :choix, lambda { diff --git a/app/models/question_saisie.rb b/app/models/question_saisie.rb index 058963794..a5a742b91 100644 --- a/app/models/question_saisie.rb +++ b/app/models/question_saisie.rb @@ -2,6 +2,8 @@ class QuestionSaisie < Question QUESTION_REDACTION = 'redaction_note' + QUESTION_TYPE = 'QuestionSaisie' + enum :type_saisie, { redaction: 0, numerique: 1 } has_one :bonne_reponse, class_name: 'Choix', foreign_key: :question_id, dependent: :destroy diff --git a/app/models/question_sous_consigne.rb b/app/models/question_sous_consigne.rb index 43587a75e..b744a72f7 100644 --- a/app/models/question_sous_consigne.rb +++ b/app/models/question_sous_consigne.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class QuestionSousConsigne < Question + QUESTION_TYPE = 'QuestionSousConsigne' + def as_json(_options = nil) json = slice(:id, :nom_technique) json['type'] = 'sous-consigne' diff --git a/app/models/restitution/questions_reponses.rb b/app/models/restitution/questions_reponses.rb index 00f51618e..13e7499f9 100644 --- a/app/models/restitution/questions_reponses.rb +++ b/app/models/restitution/questions_reponses.rb @@ -32,8 +32,8 @@ def choix_repondu(question, evenement_reponse) def questions_repondues questions_ids = reponses.collect { |r| r.donnees['question'] } - Question.where(id: questions_ids, type: 'QuestionQcm').includes(:choix) + - Question.where(id: questions_ids).where.not(type: 'QuestionQcm') + Question.where(id: questions_ids, type: QuestionQcm.QUESTION_TYPE).includes(:choix) + + Question.where(id: questions_ids).where.not(type: QuestionQcm.QUESTION_TYPE) end end end