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

Le superadmin peut paramétrer l’illustration d’une question numératie #1618

Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion .buildpacks
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
https://github.com/Scalingo/apt-buildpack.git
https://github.com/Scalingo/ffmpeg-buildpack.git
https://github.com/Scalingo/ruby-buildpack.git
https://github.com/Scalingo/ruby-buildpack.git
2 changes: 2 additions & 0 deletions Aptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Pour la manipulation d'image
libvips-dev
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gem 'activeadmin_addons'
gem 'activeadmin_reorderable'
gem 'activeadmin-xls', git: 'https://github.com/shanser/activeadmin-xls',
branch: 'autoload'
gem 'activestorage-validator', '~> 0.4.0'
gem 'acts_as_list'
gem 'addressable'
gem 'ancestry', '~> 4.3'
Expand All @@ -35,6 +36,7 @@ gem 'font-awesome-sass', '~> 6.5.1'
gem 'geocoder'
gem 'groupdate'
gem 'i18n-js', '~> 3.9.0'
gem 'image_processing', '~> 1.12.2'
gem 'inline_svg'
gem 'jbuilder'
gem 'jquery-rails'
Expand Down
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ GEM
activesupport (= 7.0.8.4)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activestorage-validator (0.4.0)
rails (>= 6.1.0)
activesupport (7.0.8.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
Expand Down Expand Up @@ -250,6 +252,9 @@ GEM
concurrent-ruby (~> 1.0)
i18n-js (3.9.2)
i18n (>= 0.6.6)
image_processing (1.12.2)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
inherited_resources (1.14.0)
actionpack (>= 6.0)
has_scope (>= 0.6)
Expand Down Expand Up @@ -295,6 +300,7 @@ GEM
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.0)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand All @@ -315,6 +321,7 @@ GEM
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0604)
mini_magick (4.13.2)
mini_mime (1.1.5)
mini_portile2 (2.8.7)
minitest (5.24.0)
Expand Down Expand Up @@ -481,6 +488,9 @@ GEM
ruby-ole (1.2.13.1)
ruby-progressbar (1.13.0)
ruby-rc4 (0.1.5)
ruby-vips (2.2.2)
ffi (~> 1.12)
logger
ruby2_keywords (0.0.5)
rufus-scheduler (3.9.1)
fugit (~> 1.1, >= 1.1.6)
Expand Down Expand Up @@ -572,6 +582,7 @@ DEPENDENCIES
activeadmin-xls!
activeadmin_addons
activeadmin_reorderable
activestorage-validator (~> 0.4.0)
acts_as_list
addressable
ancestry (~> 4.3)
Expand All @@ -598,6 +609,7 @@ DEPENDENCIES
guard-rspec
guard-rubocop
i18n-js (~> 3.9.0)
image_processing (~> 1.12.2)
inline_svg
jbuilder
jquery-rails
Expand Down
2 changes: 1 addition & 1 deletion app/admin/questions_qcm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
menu parent: 'Parcours', if: proc { can? :manage, Compte }

permit_params :categorie, :libelle, :nom_technique, :description,
:metacompetence, :type_qcm,
:metacompetence, :type_qcm, :illustration,
choix_attributes: %i[id intitule audio type_choix _destroy nom_technique],
transcriptions_attributes: %i[id categorie ecrit audio _destroy]

Expand Down
9 changes: 9 additions & 0 deletions app/models/question.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# frozen_string_literal: true

class Question < ApplicationRecord
has_one_attached :illustration do |attachable|
attachable.variant :thumb,
resize_to_limit: [1008, 566],
preprocessed: true
end

validates :illustration,
blob: { content_type: ['image/png', 'image/jpeg', 'image/webp'] }

validates :libelle, :nom_technique, presence: true
has_many :transcriptions, dependent: :destroy

Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/question_qcms/_form.html.arb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ active_admin_form_for [:admin, resource] do |f|
f.input :metacompetence
f.input :type_qcm
f.input :description
f.input :illustration, as: :file,
input_html: { accept: 'image/png,image/jpg,image/jpeg' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu n'accepte pas le webp ici, c'est normal ?
Tu duplique d'ailleurs du texte du model Question.

J'aurais tendance dans le model Question à faire :

class Question < ApplicationRecord
  ...

  ILLUSTRATION_CONTENT_TYPES = ['image/png', 'image/jpeg', 'image/webp']
  validates :illustration,
            blob: { content_type: ILLUSTRATION_CONTENT_TYPES }
Suggested change
input_html: { accept: 'image/png,image/jpg,image/jpeg' },
input_html: { accept: Question::ILLUSTRATION_CONTENT_TYPES.join(',') },

hint: 'La taille de l’image rendue est de 1008x566.'
end

f.inputs do
Expand Down
6 changes: 6 additions & 0 deletions app/views/admin/question_qcms/_show.html.arb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ panel 'Détails de la question' do
row :categorie
row :nom_technique
row :description
row :illustration do
if resource.illustration.attached?
link_to("Voir l'image du jeu", url_for(resource.illustration), target: '_blank',
rel: 'noopener')
end
end
intitule = question_qcm.transcription_pour(:intitule)
row :intitule do
div intitule.ecrit if intitule&.ecrit
Expand Down
3 changes: 2 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Application < Rails::Application
config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore
config.exceptions_app = CustomExceptionsAppWrapper.new(exceptions_app: routes)

config.generators do |g|
g.orm :active_record, primary_key_type: :uuid
g.orm :active_record, foreign_key_type: :uuid
Expand All @@ -53,6 +53,7 @@ class Application < Rails::Application
}

config.active_job.queue_adapter = :sidekiq
config.active_storage.track_variants = false

config.middleware.insert_before 0, Rack::Cors do
allow do
Expand Down
1 change: 1 addition & 0 deletions config/locales/models/question.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fr:
libelle: Libellé
nom_technique: Nom technique
metacompetence: Méta-compétence
illustration: Image du jeu
type_qcm: Type QCM
question_saisie:
suffix_reponse: Suffix réponse
Expand Down
5 changes: 5 additions & 0 deletions config/sidekiq.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
:queues:
- active_storage_transform
- active_storage_analysis
- active_storage_purge

:scheduler:
:schedule:
anonymisations_evaluations_job:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!-- 📄 Standard : https://www.notion.so/captive/Le-cadrage-technique-dbb611e45f114737a6b14745caa584e9?pvs=4 -->
# Le superadmin peut paramétrer l’illustration d’une question numératie

[Lien du ticket](https://captive-team.atlassian.net/browse/EVA-170?atlOrigin=eyJpIjoiODVkNzRlZjE3ZmU1NDNlMjkwZTVkN2IzYmYwNzE3ZjkiLCJwIjoiaiJ9)


## 1 - Ajout d'un nouveau champs.

Ajouter dans le model `Question` : `has_one_attached :image`

## 2 - Ajouter une validation sur le type de fichier coté back

On souhaite authoriser uniquement les fichier JPG, PNG et WebP. Donc ajouter dans le model `Question`

```ruby
validates :image,
blob: { content_type: ["image/png", "image/jpeg", "image/webp"] }
```

## 3 - Redimensionner l'image

Il va falloir redimensionner les images `1008x566`
Pour ce faire il y a plusieurs etapes :

- Ajouter la gem image_processing
- Dans le .buildpack ajouter `https://github.com/Scalingo/apt-buildpack.git`
- Creer un fichier Aptfile dans lequel on ajoutera `libvips-dev`

Modifier le model :

```ruby
has_one_attached :photo do |attachable|
attachable.variant :thumb,
resize_to_limit: [1008, 566],
preprocessed: true
end
```

## 4 - Ajouter le champs dans le formulaire

Dans le formulaire `question_qcms/_form.html.arb` ajouter:

`f.input :image, as: :file, input_html: { accept: 'image/png,image/jpg,image/jpeg' }`

Ne pas oublier de le preciser dans les permit_params

Ajouter egalement un hint sur ce champs :
`La taille de l’image rendu est 1008x566`

## 5 - Ajouter la traduction du champs.

Ceci se passe dans le fichier `question_qcms.yml` en ajoutant la traduction suivante : `Image du jeu`

## 6 - Niveau des droits

Seul le super admin peut ajouter une image. Les droits pour ajouter des questions sont deja destiné uniquement aux superadmin. Donc rien a faire de ce coté.
13 changes: 13 additions & 0 deletions spec/features/admin/question_qcm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@
expect(Question.first.transcription_ecrite_pour(:modalite_reponse)).to eq 'Consigne'
end
end

context 'quand une illustration est ajoutée' do
before do
fill_in :question_qcm_libelle, with: 'Question'
fill_in :question_qcm_nom_technique, with: 'question'
attach_file(:question_qcm_illustration, Rails.root.join('spec/support/programme_tele.png'))
click_on 'Créer'
end

it do
expect(Question.first.illustration.attached?).to eq true
end
end
end

describe 'modification' do
Expand Down
1 change: 1 addition & 0 deletions spec/models/question_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
it { is_expected.to validate_presence_of :nom_technique }
it { is_expected.to have_many(:transcriptions).dependent(:destroy) }
it { is_expected.to accept_nested_attributes_for(:transcriptions).allow_destroy(true) }
it { is_expected.to have_one_attached(:illustration) }
end
Binary file added spec/support/programme_tele.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.