diff --git a/app/controllers/admin/education/diplomas_controller.rb b/app/controllers/admin/education/diplomas_controller.rb index e4391fc9d..c1a17065a 100644 --- a/app/controllers/admin/education/diplomas_controller.rb +++ b/app/controllers/admin/education/diplomas_controller.rb @@ -67,6 +67,9 @@ def diploma_params :level, :ects, :certification, localizations_attributes: [ :id, :name, :slug, :short_name, :summary, :duration, + :pedagogy, :evaluation, :prerequisites, :registration, :other, + :pricing, :pricing_initial, :pricing_continuing, :pricing_apprenticeship, + :accessibility, :contacts, :language_id ] ) diff --git a/app/models/concerns/with_inheritance.rb b/app/models/concerns/with_inheritance.rb deleted file mode 100644 index 9df918ddd..000000000 --- a/app/models/concerns/with_inheritance.rb +++ /dev/null @@ -1,35 +0,0 @@ -module WithInheritance - extend ActiveSupport::Concern - - included do - def self.rich_text_areas_with_inheritance(*properties) - properties.each do |property| - has_summernote property - - class_eval <<-CODE, __FILE__, __LINE__ + 1 - def best_#{property} - best("#{property}") - end - - def best_#{property}_source - best_source("#{property}") - end - CODE - end - end - end - - protected - - def best(property) - value = send(property) - html = value.to_s - Static.blank?(html) ? parent&.send("best_#{property}") : value - end - - def best_source(property, is_ancestor: false) - value = send(property) - return (is_ancestor ? self : nil) if Static.has_content?(value.to_s) - parent&.send(:best_source, property, is_ancestor: true) - end -end diff --git a/app/models/education/diploma/localization.rb b/app/models/education/diploma/localization.rb index 8fd599c8c..3a67b5495 100644 --- a/app/models/education/diploma/localization.rb +++ b/app/models/education/diploma/localization.rb @@ -2,19 +2,30 @@ # # Table name: education_diploma_localizations # -# id :uuid not null, primary key -# duration :text -# name :string -# published :boolean default(FALSE) -# published_at :datetime -# short_name :string -# slug :string -# summary :text -# created_at :datetime not null -# updated_at :datetime not null -# about_id :uuid indexed -# language_id :uuid indexed -# university_id :uuid indexed +# id :uuid not null, primary key +# accessibility :text +# contacts :text +# duration :text +# evaluation :text +# name :string +# other :text +# pedagogy :text +# prerequisites :text +# pricing :text +# pricing_apprenticeship :text +# pricing_continuing :text +# pricing_initial :text +# published :boolean default(FALSE) +# published_at :datetime +# registration :text +# short_name :string +# slug :string +# summary :text +# created_at :datetime not null +# updated_at :datetime not null +# about_id :uuid indexed +# language_id :uuid indexed +# university_id :uuid indexed # # Indexes # diff --git a/app/models/education/program/localization/with_inheritance.rb b/app/models/education/program/localization/with_inheritance.rb new file mode 100644 index 000000000..c421f09ae --- /dev/null +++ b/app/models/education/program/localization/with_inheritance.rb @@ -0,0 +1,64 @@ +module Education::Program::Localization::WithInheritance + extend ActiveSupport::Concern + + included do + def self.rich_text_areas_with_inheritance(*properties) + properties.each do |property| + has_summernote property + + class_eval <<-CODE, __FILE__, __LINE__ + 1 + def best_#{property} + best("#{property}") + end + + def best_#{property}_source + best_source("#{property}") + end + CODE + end + end + end + + protected + + def best(property) + value = public_send(property) + Static.blank?(value.to_s) ? search_above(property) : value + end + + def search_above(property) + if parent.present? + parent.public_send("best_#{property}") + elsif diploma.present? && diploma.respond_to?(property) + diploma.public_send(property) + end + end + + def best_source(property, is_ancestor: false) + value = public_send(property) + if Static.has_content?(value.to_s) + # Le contenu vient de cette formation + # Si c'est un ancêtre (via appel récursif), c'est bien la meilleure source + # Si ce n'est pas un ancêtre, c'est que la formation a sa propre donnée, et il n'y a pas de meilleure source + is_ancestor ? self : nil + else + search_source_above(property) + end + end + + def search_source_above(property) + if parent.present? + # Appel récursif, on n'a pas trouvé, on remonte la parentèle + parent&.send(:best_source, property, is_ancestor: true) + elsif is_diploma_source?(property) + diploma + end + end + + def is_diploma_source?(property) + return false if diploma.nil? + return false unless diploma.respond_to?(property) + value = diploma.public_send(property) + Static.has_content?(value.to_s) + end +end diff --git a/app/views/admin/application/property/_text.html.erb b/app/views/admin/application/property/_text.html.erb index 3123d4350..98f9ceb35 100644 --- a/app/views/admin/application/property/_text.html.erb +++ b/app/views/admin/application/property/_text.html.erb @@ -7,23 +7,25 @@ end is_blank = Static.blank?(value) hide_blank ||= false title = object.class.human_attribute_name(property) -if source - # source is a l10n - source_about = source.about - language = source.language - title += ' ' - title += t 'admin.inheritance.sentence_html', link: link_to(source, [:admin, source_about, { lang: language }]) - title += '' -end %> <% unless hide_blank && is_blank %> <%= osuny_label title %> -

+

+ <% + if source + # source is a l10n + source_about = source.about + language = source.language + %> +

+ <%= t 'admin.inheritance.sentence_html', link: link_to(source, [:admin, source_about, { lang: language }]) %> +

+ <% end %> <% if is_blank %> <%= t 'properties.text.missing' %> <% else %> <%= sanitize value %> <% end %> -

+
<% end %> \ No newline at end of file diff --git a/app/views/admin/education/diplomas/_form.html.erb b/app/views/admin/education/diplomas/_form.html.erb index 4f33d6ac1..471ba2e52 100644 --- a/app/views/admin/education/diplomas/_form.html.erb +++ b/app/views/admin/education/diplomas/_form.html.erb @@ -28,6 +28,35 @@ source: '#education_diploma_localizations_attributes_0_name' %> + + <%= osuny_separator %> + + <%= osuny_label t('admin.education.diplomas.fields_for_programs') %> +
+ <% + [ + :pedagogy, + :evaluation, + :prerequisites, + :registration, + :other, + :pricing, + :pricing_initial, + :pricing_continuing, + :pricing_apprenticeship, + :accessibility, + :contacts + ].each do |property| %> +
+ <%= lf.input property, + as: :summernote, + input_html: { + data: { 'summernote-config' => 'mini' } + } %> +
+ <% end %> +
+ <%= f.input :certification, as: :radio_buttons, collection: Education::Diploma.certifications << '', diff --git a/app/views/admin/education/diplomas/show.html.erb b/app/views/admin/education/diplomas/show.html.erb index 03539a9a0..7e6687d30 100644 --- a/app/views/admin/education/diplomas/show.html.erb +++ b/app/views/admin/education/diplomas/show.html.erb @@ -46,7 +46,38 @@ <%= render 'admin/communication/contents/editor', about: @l10n %> -

<%= Education::Program.model_name.human(count: 2) %>

+<%= osuny_separator %> + +<%= osuny_label t('admin.education.diplomas.fields_for_programs') %> +
+ <% + [ + :pedagogy, + :evaluation, + :prerequisites, + :registration, + :other, + :pricing, + :pricing_initial, + :pricing_continuing, + :pricing_apprenticeship, + :accessibility, + :contacts + ].each do |property| + value = @l10n.send property + %> +
+ <%= osuny_label Education::Diploma::Localization.human_attribute_name(property) %> + <% if value.blank? %> +

-

+ <% else %> + <%= sanitize value %> + <% end %> +
+ <% end %> +
+ +

<%= Education::Program.model_name.human(count: 2) %>

<%= render 'admin/education/programs/list', programs: @programs, hide_diploma: true %> <% content_for :action_bar_left do %> diff --git a/app/views/admin/education/programs/_form.html.erb b/app/views/admin/education/programs/_form.html.erb index e4474750b..fd948e569 100644 --- a/app/views/admin/education/programs/_form.html.erb +++ b/app/views/admin/education/programs/_form.html.erb @@ -60,24 +60,22 @@
- <%= render 'admin/education/programs/forms/part', part: :technical do %> - <%= lf.input :published %> - <%= render "admin/application/slug/form", - f: lf, - source: '#education_program_localizations_attributes_0_name' %> - <%= f.association :parent, - collection: osuny_collection_tree( - current_university.education_programs.root, - localized: true, - except: program - ) %> - <%= f.input :bodyclass %> - <%= lf.input :logo, - as: :single_deletable_file, - hint: images_formats_accepted_hint, - input_html: { accept: default_images_formats_accepted } - %> - <% end %> + <%= lf.input :published %> + <%= render "admin/application/slug/form", + f: lf, + source: '#education_program_localizations_attributes_0_name' %> + <%= f.association :parent, + collection: osuny_collection_tree( + current_university.education_programs.root, + localized: true, + except: program + ) %> + <%= f.input :bodyclass %> + <%= lf.input :logo, + as: :single_deletable_file, + hint: images_formats_accepted_hint, + input_html: { accept: default_images_formats_accepted } + %> <%= render 'admin/application/featured_image/edit', f: lf, about: l10n %>
diff --git a/app/views/admin/education/programs/forms/_input_with_inheritance.html.erb b/app/views/admin/education/programs/forms/_input_with_inheritance.html.erb index 0746768dd..182350902 100644 --- a/app/views/admin/education/programs/forms/_input_with_inheritance.html.erb +++ b/app/views/admin/education/programs/forms/_input_with_inheritance.html.erb @@ -30,15 +30,15 @@ id = "#{property}Collapse" } %>
- +

<%= t 'admin.inheritance.sentence_html', link: link_to( best_prop_source, [:admin, best_prop_source_about, { lang: best_prop_source_language }], target: :_blank ) %> -
- <%= best_prop_value %> +

+ <%= sanitize best_prop_value %>
diff --git a/app/views/admin/education/programs/parts/admission.html.erb b/app/views/admin/education/programs/parts/admission.html.erb index 17a7f71bc..9ea780369 100644 --- a/app/views/admin/education/programs/parts/admission.html.erb +++ b/app/views/admin/education/programs/parts/admission.html.erb @@ -3,36 +3,25 @@

<%= t('education.program.parts.admission.hint') %>

-
- <%= render 'admin/application/property/text', object: @l10n, property: :prerequisites %> -
-
- <%= render 'admin/application/property/text', object: @l10n, property: :registration %> -
-
- <%= render 'admin/application/property/text', object: @l10n, property: :other %> -
-
- <%= render 'admin/application/property/text', object: @l10n, property: :pricing %> -
-
- <%= render 'admin/application/property/text', object: @l10n, property: :pricing_initial %> -
-
- <%= render 'admin/application/property/text', object: @l10n, property: :pricing_continuing %> -
-
- <%= render 'admin/application/property/text', object: @l10n, property: :pricing_apprenticeship %> -
-
- <%= render 'admin/application/property/text', object: @l10n, property: :accessibility %> -
-
- <%= render 'admin/application/property/text', object: @l10n, property: :contacts %> -
+ <% + [ + :prerequisites, + :registration, + :other, + :pricing, + :pricing_initial, + :pricing_continuing, + :pricing_apprenticeship, + :accessibility, + :contacts + ].each do |property| %> +
+ <%= render 'admin/application/property/text', object: @l10n, property: property %> +
+ <% end %>
<% if @l10n.registration_url.present? %> - <%= osuny_label Education::Program.human_attribute_name(:registration_url) %> + <%= osuny_label Education::Program::Localization.human_attribute_name(:registration_url) %>

<%= link_to @l10n.registration_url, @l10n.registration_url, target: :_blank %>

<% end %>
diff --git a/app/views/admin/education/programs/parts/admission_edit.html.erb b/app/views/admin/education/programs/parts/admission_edit.html.erb index bb42be366..c9eee35d8 100644 --- a/app/views/admin/education/programs/parts/admission_edit.html.erb +++ b/app/views/admin/education/programs/parts/admission_edit.html.erb @@ -7,33 +7,22 @@ <%= f.hidden_field :part, value: 'admission' %>
-
- <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: :prerequisites %> -
-
- <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: :registration %> -
-
- <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: :other %> -
-
- <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: :pricing %> -
-
- <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: :pricing_initial %> -
-
- <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: :pricing_continuing %> -
-
- <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: :pricing_apprenticeship %> -
-
- <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: :accessibility %> -
-
- <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: :contacts %> -
+ <% + [ + :prerequisites, + :registration, + :other, + :pricing, + :pricing_initial, + :pricing_continuing, + :pricing_apprenticeship, + :accessibility, + :contacts + ].each do |property| %> +
+ <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: property %> +
+ <% end %>
<%= lf.input :registration_url %>
diff --git a/app/views/admin/education/programs/parts/pedagogy.html.erb b/app/views/admin/education/programs/parts/pedagogy.html.erb index 836f1cbee..0e2b03ac8 100644 --- a/app/views/admin/education/programs/parts/pedagogy.html.erb +++ b/app/views/admin/education/programs/parts/pedagogy.html.erb @@ -3,21 +3,18 @@

<%= t('education.program.parts.pedagogy.hint') %>

-
- <%= render 'admin/application/property/text', object: @l10n, property: :content %> -
-
- <%= render 'admin/application/property/text', object: @l10n, property: :pedagogy %> -
-
- <%= render 'admin/application/property/text', object: @l10n, property: :evaluation %> -
-
- <%= render 'admin/application/property/text', object: @l10n, property: :opportunities %> -
-
- <%= render 'admin/application/property/text', object: @l10n, property: :results %> -
+ <% + [ + :content, + :pedagogy, + :evaluation, + :opportunities, + :results + ].each do |property| %> +
+ <%= render 'admin/application/property/text', object: @l10n, property: property %> +
+ <% end %>
<%= osuny_label t('education.teachings') %> diff --git a/app/views/admin/education/programs/parts/pedagogy_edit.html.erb b/app/views/admin/education/programs/parts/pedagogy_edit.html.erb index d3752f833..25ccb41c3 100644 --- a/app/views/admin/education/programs/parts/pedagogy_edit.html.erb +++ b/app/views/admin/education/programs/parts/pedagogy_edit.html.erb @@ -7,21 +7,18 @@ <%= f.hidden_field :part, value: 'pedagogy' %>
-
- <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: :content %> -
-
- <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: :pedagogy %> -
-
- <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: :evaluation %> -
-
- <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: :opportunities %> -
-
- <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: :results %> -
+ <% + [ + :content, + :pedagogy, + :evaluation, + :opportunities, + :results + ].each do |property| %> +
+ <%= render 'admin/education/programs/forms/input_with_inheritance', f: lf, property: property %> +
+ <% end %>
<%= osuny_panel t('education.teachings'), small: true do %> diff --git a/config/locales/education/en.yml b/config/locales/education/en.yml index c87ca8ffe..cb0327641 100644 --- a/config/locales/education/en.yml +++ b/config/locales/education/en.yml @@ -39,8 +39,20 @@ en: level: Level programs: Programs education/diploma/localization: + accessibility: Accessibilité + contacts: Contacts duration: Duration + evaluation: Evaluation method name: Name + other: Other + pedagogy: Méthodes mobilisées + prerequisites: Prérequis + pricing: Costs + pricing_initial: Costs for initial training + pricing_continuing: Costs for continuous training + pricing_apprenticeship: Costs for apprenticeship + registration: Registration procedure and delays + results: Results' indicator short_name: Short name slug: Slug education/program: @@ -63,7 +75,7 @@ en: content: Program's content duration: Duration downloadable_summary: Downloadable summary - evaluation: Modalités d’évaluation + evaluation: Evaluation method featured_image: Featured image featured_image_alt: Alt text is_published: Published @@ -83,7 +95,7 @@ en: pricing_apprenticeship: Costs for apprenticeship published: Published? qualiopi_text: Certification details - registration: Modalités et délais d’accès + registration: Registration procedure and delays registration_url: Registration link (URL) results: Results' indicator short_name: Short name @@ -113,6 +125,7 @@ en: admin: education: diplomas: + fields_for_programs: The fields below are used as basic values for programs certification: none: No certification programs: diff --git a/config/locales/education/fr.yml b/config/locales/education/fr.yml index 399db6955..b90b4dd7f 100644 --- a/config/locales/education/fr.yml +++ b/config/locales/education/fr.yml @@ -39,8 +39,20 @@ fr: level: Niveau programs: Formations education/diploma/localization: + accessibility: Accessibilité + contacts: Contacts duration: Durée + evaluation: Modalités d’évaluation name: Nom + other: Autre + pedagogy: Méthodes mobilisées + prerequisites: Prérequis + pricing: Coûts + pricing_initial: Coûts de la formation initiale + pricing_continuing: Coûts de la formation continue + pricing_apprenticeship: Coûts de l'apprentissage + registration: Modalités et délais d’accès + results: Indicateurs de résultats short_name: Nom abrégé slug: Identifiant education/program: @@ -113,6 +125,7 @@ fr: admin: education: diplomas: + fields_for_programs: Les champs ci-dessous servent de valeur de base aux formations certification: none: Pas de certification programs: diff --git a/db/migrate/20241018144920_add_program_fields_to_education_diplomas.rb b/db/migrate/20241018144920_add_program_fields_to_education_diplomas.rb new file mode 100644 index 000000000..c2525adc0 --- /dev/null +++ b/db/migrate/20241018144920_add_program_fields_to_education_diplomas.rb @@ -0,0 +1,15 @@ +class AddProgramFieldsToEducationDiplomas < ActiveRecord::Migration[7.1] + def change + add_column :education_diploma_localizations, :pedagogy, :text + add_column :education_diploma_localizations, :evaluation, :text + add_column :education_diploma_localizations, :registration, :text + add_column :education_diploma_localizations, :prerequisites, :text + add_column :education_diploma_localizations, :other, :text + add_column :education_diploma_localizations, :pricing, :text + add_column :education_diploma_localizations, :pricing_initial, :text + add_column :education_diploma_localizations, :pricing_continuing, :text + add_column :education_diploma_localizations, :pricing_apprenticeship, :text + add_column :education_diploma_localizations, :accessibility, :text + add_column :education_diploma_localizations, :contacts, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index b174304b5..db3cefbb6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_10_16_094257) do +ActiveRecord::Schema[7.1].define(version: 2024_10_18_144920) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" enable_extension "pgcrypto" @@ -901,6 +901,17 @@ t.uuid "university_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.text "pedagogy" + t.text "evaluation" + t.text "registration" + t.text "prerequisites" + t.text "other" + t.text "pricing" + t.text "pricing_initial" + t.text "pricing_continuing" + t.text "pricing_apprenticeship" + t.text "accessibility" + t.text "contacts" t.index ["about_id"], name: "index_education_diploma_localizations_on_about_id" t.index ["language_id"], name: "index_education_diploma_localizations_on_language_id" t.index ["university_id"], name: "index_education_diploma_localizations_on_university_id"