diff --git a/app/admin/questions.rb b/app/admin/questions.rb deleted file mode 100644 index c651b8c65..000000000 --- a/app/admin/questions.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -ActiveAdmin.register Question do - menu parent: 'Parcours', if: proc { current_compte.superadmin? } - - permit_params :libelle, :nom_technique, :intitule, :type, :modalite_reponse, - choix_attributes: %i[id intitule type_choix _destroy nom_technique] - - filter :libelle - - form partial: 'form' - - index do - column :libelle - column :created_at - column :type - actions - end - - show do - render partial: 'show' - end -end diff --git a/app/assets/javascripts/active_admin.js b/app/assets/javascripts/active_admin.js index 278163105..17b870914 100644 --- a/app/assets/javascripts/active_admin.js +++ b/app/assets/javascripts/active_admin.js @@ -13,7 +13,6 @@ //= require clipboard //= require evaluation //= require cgu -//=require form_question_script //= require chartkick //= require Chart.bundle diff --git a/app/assets/javascripts/form_question_script.js b/app/assets/javascripts/form_question_script.js deleted file mode 100644 index 9f319caee..000000000 --- a/app/assets/javascripts/form_question_script.js +++ /dev/null @@ -1,30 +0,0 @@ -function initialize() { - const inputType = document.getElementById("question_qcm_type"); - inputType && inputType.value === 'QuestionQcm' ? $('.choix').show() : $('.choix').hide(); -} - -function displayInputChoixOnCreate() { - $('#question_type_input').on('change', function(event) { - event.target.value === 'QuestionQcm' ? $('.choix').show() : $('.choix').hide(); - }); -} - -function displayInputChoixOnEdit() { - $('#question_saisie_type_input').on('change', function(event) { - event.target.value === 'QuestionQcm' ? $('.choix').show() : $('.choix').hide(); - }); - $('#question_qcm_type_input').on('change', function(event) { - event.target.value === 'QuestionQcm' ? $('.choix').show() : $('.choix').hide(); - }); -} - - -document.addEventListener('DOMContentLoaded', () => { - const form = document.querySelector(".form-question"); - - if(form) { - initialize(); - displayInputChoixOnCreate(); - displayInputChoixOnEdit(); - } -}); diff --git a/app/models/question.rb b/app/models/question.rb index 5b54d5895..b736545b5 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -1,20 +1,11 @@ # frozen_string_literal: true class Question < ApplicationRecord - validates :libelle, :nom_technique, :type, presence: true + validates :intitule, :libelle, :nom_technique, presence: true CATEGORIE = %i[situation scolarite sante appareils].freeze - TYPES = %i[QuestionQcm QuestionSaisie QuestionSousConsigne].freeze - enum :type, TYPES.zip(TYPES.map(&:to_s)).to_h enum :categorie, CATEGORIE.zip(CATEGORIE.map(&:to_s)).to_h, prefix: true - has_many :choix, lambda { - order(position: :asc) - }, foreign_key: :question_id, - dependent: :destroy - - accepts_nested_attributes_for :choix, allow_destroy: true - acts_as_paranoid def display_name diff --git a/app/views/admin/questions/_form.html.arb b/app/views/admin/questions/_form.html.arb deleted file mode 100644 index 09b81e2b6..000000000 --- a/app/views/admin/questions/_form.html.arb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -active_admin_form_for [:admin, resource], html: { class: 'form-question' } do |f| - f.inputs do - f.input :libelle - f.input :nom_technique, placeholder: 'N1Prn1' - f.input :modalite_reponse - f.input :intitule, label: t('.label_intitule') - f.input :type, as: :select, label: t('.label_type'), collection: ['QuestionQcm'] - f.has_many :choix, allow_destroy: ->(choix) { can? :destroy, choix } do |c| - c.input :id, as: :hidden - c.input :intitule - c.input :nom_technique - c.input :type_choix - end - end - f.actions do - f.action :submit - annulation_formulaire(f) - end -end diff --git a/app/views/admin/questions/_show.html.arb b/app/views/admin/questions/_show.html.arb deleted file mode 100644 index c927835c0..000000000 --- a/app/views/admin/questions/_show.html.arb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -panel 'Détails de la question' do - attributes_table_for question do - row :id - row :libelle - row :nom_technique - row :intitule - row t('.label_type'), &:type - row :modalite_reponse - row :created_at - end -end - -if question.QuestionQcm? - panel 'Choix' do - reorderable_table_for question.choix do - column :intitule - column :type_choix - end - end -end diff --git a/config/locales/views/questions.yml b/config/locales/views/questions.yml deleted file mode 100644 index cade9d1f5..000000000 --- a/config/locales/views/questions.yml +++ /dev/null @@ -1,10 +0,0 @@ -fr: - admin: - questions: - form: - label_intitule: | - Intitulé de la question - (telle qu’elle sera écrite dans le jeu) - label_type: Interaction - show: - label_type: Interaction diff --git a/spec/factories/question.rb b/spec/factories/question.rb index b2bb6f269..703c1efe8 100644 --- a/spec/factories/question.rb +++ b/spec/factories/question.rb @@ -5,7 +5,6 @@ libelle { 'Question' } nom_technique { 'question' } intitule { 'Ma Question' } - type { 'QuestionQcm' } end factory :question_qcm do diff --git a/spec/models/question_spec.rb b/spec/models/question_spec.rb index 7c0fec9e8..4321c68b5 100644 --- a/spec/models/question_spec.rb +++ b/spec/models/question_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe Question, type: :model do - it { is_expected.to validate_presence_of :type } + it { is_expected.to validate_presence_of :intitule } it { is_expected.to validate_presence_of :libelle } it { is_expected.to validate_presence_of :nom_technique } end