Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Permet à l'admin d'ajouter une illustration et un intitulé audio à … #1681

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions app/admin/questions_sous_consigne.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
ActiveAdmin.register QuestionSousConsigne do
menu parent: 'Parcours', if: proc { current_compte.superadmin? }

permit_params :libelle, :nom_technique,
permit_params :libelle, :nom_technique, :illustration, :supprimer_illustration,
:supprimer_audio_intitule,
transcriptions_attributes: %i[id categorie ecrit audio _destroy]

filter :libelle
Expand All @@ -14,10 +15,16 @@
f.inputs do
f.input :libelle
f.input :nom_technique
render partial: 'admin/questions/input_illustration', locals: { f: f }

f.object.transcriptions.build(categorie: :intitule) if f.object.transcription_intitule.nil?

f.has_many :transcriptions, allow_destroy: false, new_record: false, heading: false do |t|
t.input :ecrit, label: t('.label.intitule')
render partial: 'admin/transcriptions/input_ecrit_audio',
locals: { f: f, transcription_categorie: :intitule }

if f.object.transcription_intitule&.audio&.attached?
f.input :supprimer_audio_intitule, as: :boolean,
hint: tag_audio(f.object.transcription_intitule)
end
end
f.actions do
Expand Down
6 changes: 3 additions & 3 deletions app/assets/stylesheets/admin/pages/_question.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ form.question_saisie .choix {
vertical-align: middle;
border-bottom: 1px solid $eva_bluegrey;
}
.image-preview {
width: 100px;
}
}
}
.show .image-preview {
width: 100px;
}
.show.admin_questions_clic_dans_image {
svg {
stroke: $eva_bluegrey;
Expand Down
2 changes: 2 additions & 0 deletions app/models/question_sous_consigne.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ def as_json(_options = nil)
json = slice(:id, :nom_technique)
json['type'] = 'sous-consigne'
json['intitule'] = transcription_intitule&.ecrit
json['illustration'] = cdn_for(illustration)
json['audio_url'] = transcription_intitule&.audio_url
json
end
end
15 changes: 14 additions & 1 deletion app/views/admin/question_sous_consignes/_show.html.arb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ panel 'Détails de la question' do
row :id
row :libelle
row :nom_technique
row(:transcription_intitule) { md(question_sous_consigne.transcription_intitule&.ecrit) }
row :illustration do
if resource.illustration.attached?
link_to(cdn_for(resource.illustration), target: '_blank', rel: 'noopener') do
image_tag cdn_for(resource.illustration), class: 'image-preview'
end
end
end
intitule = question_sous_consigne.transcription_intitule
row :intitule do
div intitule.ecrit if intitule&.ecrit
end
row :audio_intitule do
tag_audio(intitule)
end
row :created_at
end
end
26 changes: 26 additions & 0 deletions spec/models/question_sous_consigne_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require 'rails_helper'

describe QuestionSousConsigne, type: :model do
describe '#as_json' do
let(:question_sous_consigne) do
create(:question_sous_consigne,
illustration: Rack::Test::UploadedFile.new(
Rails.root.join('spec/support/programme_tele.png')
))
end
let(:json) { question_sous_consigne.as_json }

it 'serialise les champs' do
expect(json.keys).to match_array(%w[id intitule audio_url nom_technique illustration type])
expect(json['type']).to eql('sous-consigne')
end

it "retourne l'illustration" do
expect(json['illustration']).to eql(Rails.application.routes.url_helpers.url_for(
question_sous_consigne.illustration
))
end
end
end