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 %> -
+
+ <%= 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 %> - +-
+ <% else %> + <%= sanitize value %> + <% end %> +
<%= 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 %>
+
<%= t('education.program.parts.admission.hint') %>
<%= link_to @l10n.registration_url, @l10n.registration_url, target: :_blank %>
<% end %><%= t('education.program.parts.pedagogy.hint') %>