Skip to content

Commit

Permalink
Les formations héritent certains champs des diplômes (#2346)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudlevy authored Oct 19, 2024
1 parent e3d7c4e commit e3aad9c
Show file tree
Hide file tree
Showing 17 changed files with 295 additions and 168 deletions.
3 changes: 3 additions & 0 deletions app/controllers/admin/education/diplomas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
)
Expand Down
35 changes: 0 additions & 35 deletions app/models/concerns/with_inheritance.rb

This file was deleted.

37 changes: 24 additions & 13 deletions app/models/education/diploma/localization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
64 changes: 64 additions & 0 deletions app/models/education/program/localization/with_inheritance.rb
Original file line number Diff line number Diff line change
@@ -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
22 changes: 12 additions & 10 deletions app/views/admin/application/property/_text.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 += ' <span class="small">'
title += t 'admin.inheritance.sentence_html', link: link_to(source, [:admin, source_about, { lang: language }])
title += '</span>'
end
%>
<% unless hide_blank && is_blank %>
<%= osuny_label title %>
<p>
<div>
<%
if source
# source is a l10n
source_about = source.about
language = source.language
%>
<p class="badge bg-light text-black small">
<%= t 'admin.inheritance.sentence_html', link: link_to(source, [:admin, source_about, { lang: language }]) %>
</p>
<% end %>
<% if is_blank %>
<i class="<%= Icon::WARNING %> text-danger"></i>
<%= t 'properties.text.missing' %>
<% else %>
<%= sanitize value %>
<% end %>
</p>
</div>
<% end %>
29 changes: 29 additions & 0 deletions app/views/admin/education/diplomas/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,35 @@
source: '#education_diploma_localizations_attributes_0_name' %>
</div>
</div>

<%= osuny_separator %>

<%= osuny_label t('admin.education.diplomas.fields_for_programs') %>
<div class="row">
<%
[
:pedagogy,
:evaluation,
:prerequisites,
:registration,
:other,
:pricing,
:pricing_initial,
:pricing_continuing,
:pricing_apprenticeship,
:accessibility,
:contacts
].each do |property| %>
<div class="col-xxl-4 col-md-6 mb-4">
<%= lf.input property,
as: :summernote,
input_html: {
data: { 'summernote-config' => 'mini' }
} %>
</div>
<% end %>
</div>

<%= f.input :certification,
as: :radio_buttons,
collection: Education::Diploma.certifications << '',
Expand Down
33 changes: 32 additions & 1 deletion app/views/admin/education/diplomas/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,38 @@

<%= render 'admin/communication/contents/editor', about: @l10n %>

<h2 class="h4"><%= Education::Program.model_name.human(count: 2) %></h2>
<%= osuny_separator %>

<%= osuny_label t('admin.education.diplomas.fields_for_programs') %>
<div class="row">
<%
[
:pedagogy,
:evaluation,
:prerequisites,
:registration,
:other,
:pricing,
:pricing_initial,
:pricing_continuing,
:pricing_apprenticeship,
:accessibility,
:contacts
].each do |property|
value = @l10n.send property
%>
<div class="col-xxl-4 col-md-6 mb-4">
<%= osuny_label Education::Diploma::Localization.human_attribute_name(property) %>
<% if value.blank? %>
<p>-</p>
<% else %>
<%= sanitize value %>
<% end %>
</div>
<% end %>
</div>

<h2 class="h4 mt-5"><%= Education::Program.model_name.human(count: 2) %></h2>
<%= render 'admin/education/programs/list', programs: @programs, hide_diploma: true %>

<% content_for :action_bar_left do %>
Expand Down
34 changes: 16 additions & 18 deletions app/views/admin/education/programs/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,22 @@
</div>
</div>
<div class="col-lg-4 col-xxl-3">
<%= 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 %>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ id = "#{property}Collapse"
}
%>
<div class="bg-light p-2 mt-n2">
<b>
<p class="small text-muted mt-2 mb-0">
<%= t 'admin.inheritance.sentence_html',
link: link_to(
best_prop_source,
[:admin, best_prop_source_about, { lang: best_prop_source_language }],
target: :_blank
) %>
</b><br>
<%= best_prop_value %>
</p>
<%= sanitize best_prop_value %>
</div>
</div>
</div>
Expand Down
45 changes: 17 additions & 28 deletions app/views/admin/education/programs/parts/admission.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,25 @@
<p class="lead mb-5"><%= t('education.program.parts.admission.hint') %>

<div class="row">
<div class="col-xxl-4 col-md-6 mb-4">
<%= render 'admin/application/property/text', object: @l10n, property: :prerequisites %>
</div>
<div class="col-xxl-4 col-md-6 mb-4">
<%= render 'admin/application/property/text', object: @l10n, property: :registration %>
</div>
<div class="col-xxl-4 col-md-6 mb-4">
<%= render 'admin/application/property/text', object: @l10n, property: :other %>
</div>
<div class="col-xxl-4 col-md-6 mb-4">
<%= render 'admin/application/property/text', object: @l10n, property: :pricing %>
</div>
<div class="col-xxl-4 col-md-6 mb-4">
<%= render 'admin/application/property/text', object: @l10n, property: :pricing_initial %>
</div>
<div class="col-xxl-4 col-md-6 mb-4">
<%= render 'admin/application/property/text', object: @l10n, property: :pricing_continuing %>
</div>
<div class="col-xxl-4 col-md-6 mb-4">
<%= render 'admin/application/property/text', object: @l10n, property: :pricing_apprenticeship %>
</div>
<div class="col-xxl-4 col-md-6 mb-4">
<%= render 'admin/application/property/text', object: @l10n, property: :accessibility %>
</div>
<div class="col-xxl-4 col-md-6 mb-4">
<%= render 'admin/application/property/text', object: @l10n, property: :contacts %>
</div>
<%
[
:prerequisites,
:registration,
:other,
:pricing,
:pricing_initial,
:pricing_continuing,
:pricing_apprenticeship,
:accessibility,
:contacts
].each do |property| %>
<div class="col-xxl-4 col-md-6 mb-4">
<%= render 'admin/application/property/text', object: @l10n, property: property %>
</div>
<% end %>
<div class="col-xxl-4 col-md-6 mb-4">
<% if @l10n.registration_url.present? %>
<%= osuny_label Education::Program.human_attribute_name(:registration_url) %>
<%= osuny_label Education::Program::Localization.human_attribute_name(:registration_url) %>
<p><%= link_to @l10n.registration_url, @l10n.registration_url, target: :_blank %></p>
<% end %>
</div>
Expand Down
Loading

0 comments on commit e3aad9c

Please sign in to comment.