Skip to content
Snippets Groups Projects
Unverified Commit 5d78083c authored by Sébastien Gaya's avatar Sébastien Gaya Committed by GitHub
Browse files

Merge pull request #724 from noesya/clean/issue-710

Nettoyage de données (featured image, summary, journal)
parents 6aa9a79e b34d36c1
No related branches found
No related tags found
No related merge requests found
Showing
with 64 additions and 37 deletions
...@@ -58,7 +58,7 @@ class Admin::Research::Journals::VolumesController < Admin::Research::Journals:: ...@@ -58,7 +58,7 @@ class Admin::Research::Journals::VolumesController < Admin::Research::Journals::
def volume_params def volume_params
params.require(:research_journal_volume) params.require(:research_journal_volume)
.permit( .permit(
:title, :slug, :number, :keywords, :published, :published_at, :meta_description, :text, :title, :slug, :number, :keywords, :published, :published_at, :meta_description, :summary, :text,
:featured_image, :featured_image_infos, :featured_image_delete, :featured_image_alt, :featured_image_credit :featured_image, :featured_image_infos, :featured_image_delete, :featured_image_alt, :featured_image_credit
) )
.merge(university_id: current_university.id) .merge(university_id: current_university.id)
......
...@@ -53,7 +53,7 @@ class Admin::Research::JournalsController < Admin::Research::ApplicationControll ...@@ -53,7 +53,7 @@ class Admin::Research::JournalsController < Admin::Research::ApplicationControll
def journal_params def journal_params
params.require(:research_journal) params.require(:research_journal)
.permit(:title, :meta_description, :issn, :access_token, :repository) .permit(:title, :meta_description, :summary, :issn)
.merge(university_id: current_university.id) .merge(university_id: current_university.id)
end end
end end
...@@ -111,6 +111,13 @@ class Communication::Website::Category < ApplicationRecord ...@@ -111,6 +111,13 @@ class Communication::Website::Category < ApplicationRecord
(ancestors.map(&:slug) << slug).join('-') (ancestors.map(&:slug) << slug).join('-')
end end
def best_featured_image_source(fallback: true)
return self if featured_image.attached?
best_source = parent&.best_featured_image_source(fallback: false)
best_source ||= self if fallback
best_source
end
protected protected
def last_ordered_element def last_ordered_element
......
...@@ -116,10 +116,10 @@ class Communication::Website::Page < ApplicationRecord ...@@ -116,10 +116,10 @@ class Communication::Website::Page < ApplicationRecord
"#{title}" "#{title}"
end end
def best_featured_image def best_featured_image_source(fallback: true)
# we don't want to fallback on homepage featured_image # we don't want to fallback on homepage featured_image
return featured_image if featured_image.attached? || is_home? || parent&.is_home? return self if featured_image.attached? || is_home? || parent&.is_home?
parent&.best_featured_image parent&.best_featured_image_source
end end
def best_bodyclass def best_bodyclass
......
...@@ -8,8 +8,20 @@ module WithFeaturedImage ...@@ -8,8 +8,20 @@ module WithFeaturedImage
end end
# Can be overwrite to get featured_image from associated objects (ex: parents) # Can be overwrite to get featured_image from associated objects (ex: parents)
def best_featured_image(fallback: true) def best_featured_image_source(fallback: true)
featured_image self
end
def best_featured_image
best_featured_image_source.featured_image
end
def best_featured_image_alt
best_featured_image_source.featured_image_alt
end
def best_featured_image_credit
best_featured_image_source.featured_image_credit
end end
def add_unsplash_image(id) def add_unsplash_image(id)
......
...@@ -126,11 +126,11 @@ class Education::Program < ApplicationRecord ...@@ -126,11 +126,11 @@ class Education::Program < ApplicationRecord
"#{name}" "#{name}"
end end
def best_featured_image(fallback: true) def best_featured_image_source(fallback: true)
return featured_image if featured_image.attached? return self if featured_image.attached?
best_image = parent&.best_featured_image(fallback: false) best_source = parent&.best_featured_image_source(fallback: false)
best_image ||= featured_image if fallback best_source ||= self if fallback
best_image best_source
end end
def git_path(website) def git_path(website)
......
...@@ -3,10 +3,9 @@ ...@@ -3,10 +3,9 @@
# Table name: research_journals # Table name: research_journals
# #
# id :uuid not null, primary key # id :uuid not null, primary key
# access_token :string
# issn :string # issn :string
# meta_description :text # meta_description :text
# repository :string # summary :text
# title :string # title :string
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
# published :boolean default(FALSE) # published :boolean default(FALSE)
# published_at :datetime # published_at :datetime
# slug :string # slug :string
# summary :text
# text :text # text :text
# title :string # title :string
# created_at :datetime not null # created_at :datetime not null
......
<% if about.featured_image.attached? %> <% if about.best_featured_image.attached? %>
<div class="card flex-fill w-100"> <div class="card flex-fill w-100">
<div class="card-header"> <div class="card-header">
<h2 class="card-title mb-0 h5"> <h2 class="card-title mb-0 h5">
<%= about.class.human_attribute_name :featured_image %> <%= about.class.human_attribute_name :featured_image %>
<% unless about.featured_image.attached? %>
(<%= t('admin.inheritance.sentence_without_link').downcase %>)
<% end %>
</h2> </h2>
</div> </div>
<div class="card-body"> <div class="card-body">
<% image = about.featured_image.variable? ? about.featured_image.variant(resize: '600') <% image = about.best_featured_image.variable? ? about.best_featured_image.variant(resize: '600')
: about.featured_image %> : about.best_featured_image %>
<%= image_tag image, class: 'img-fluid mb-2' %> <%= image_tag image, class: 'img-fluid mb-2' %>
<% if about.featured_image_credit %> <% if about.best_featured_image_alt %>
<p class="mb-0"> <p class="mb-0">
<%= about.featured_image_alt %> <%= about.best_featured_image_alt %>
</p> </p>
<% end %> <% end %>
<% if about.featured_image_credit %> <% if about.best_featured_image_credit %>
<p class="small mb-0"> <div class="small mb-0">
<%= about.featured_image_credit.html_safe %> <%= sanitize about.best_featured_image_credit %>
</p> </div>
<% end %> <% end %>
</div> </div>
</div> </div>
......
<%
best_featured_image = @about.best_featured_image
if best_featured_image&.attached?
%>
image:
id: "<%= best_featured_image.blob.id %>"
alt: "<%= @about.best_featured_image_alt %>"
credit: >
<%= prepare_html_for_static @about.best_featured_image_credit, @about.university %>
<% end %>
<%
featured_image = @about&.best_featured_image || @about.featured_image
if featured_image.attached?
%>
image:
id: "<%= featured_image.blob.id %>"
alt: "<%= @about.featured_image_alt %>"
credit: >
<%= prepare_html_for_static @about.featured_image_credit, @about.university %>
<% end %>
...@@ -12,7 +12,7 @@ children: ...@@ -12,7 +12,7 @@ children:
<% end %> <% end %>
<% end %> <% end %>
position: <%= @about.position %> position: <%= @about.position %>
<%= render 'admin/communication/unsplash/static' %> <%= render 'admin/application/featured_image/static' %>
<%= render 'admin/application/meta_description/static' %> <%= render 'admin/application/meta_description/static' %>
<%= render 'admin/application/summary/static' %> <%= render 'admin/application/summary/static' %>
<%= render 'admin/communication/blocks/static', about: @about %> <%= render 'admin/communication/blocks/static', about: @about %>
......
...@@ -13,7 +13,7 @@ has: ...@@ -13,7 +13,7 @@ has:
<% end %> <% end %>
position: <%= @about.position %> position: <%= @about.position %>
bodyclass: <%= @about.best_bodyclass %> bodyclass: <%= @about.best_bodyclass %>
<%= render 'admin/communication/unsplash/static' %> <%= render 'admin/application/featured_image/static' %>
<% if @about.children.published.any? %> <% if @about.children.published.any? %>
children: children:
<% @about.children.published.ordered.each do |child| %> <% @about.children.published.ordered.each do |child| %>
......
...@@ -16,7 +16,7 @@ categories: ...@@ -16,7 +16,7 @@ categories:
- "<%= category.slug_with_ancestors_slugs %>" - "<%= category.slug_with_ancestors_slugs %>"
<% end %> <% end %>
<% end %> <% end %>
<%= render 'admin/communication/unsplash/static' %> <%= render 'admin/application/featured_image/static' %>
<%= render 'admin/application/meta_description/static' %> <%= render 'admin/application/meta_description/static' %>
<%= render 'admin/application/summary/static' %> <%= render 'admin/application/summary/static' %>
<%= render 'admin/communication/blocks/static', about: @about %> <%= render 'admin/communication/blocks/static', about: @about %>
......
...@@ -27,7 +27,7 @@ parent: ...@@ -27,7 +27,7 @@ parent:
<%= @about.parent.name %> <%= @about.parent.name %>
url: <%= @about.parent.current_permalink_in_website(@website)&.path %> url: <%= @about.parent.current_permalink_in_website(@website)&.path %>
<% end %> <% end %>
<%= render 'admin/communication/unsplash/static' %> <%= render 'admin/application/featured_image/static' %>
related_category: "<%= @website.categories.find_by(program_id: @about.id)&.slug_with_ancestors_slugs %>" related_category: "<%= @website.categories.find_by(program_id: @about.id)&.slug_with_ancestors_slugs %>"
diplomas: "<%= @about.diploma&.slug %>" diplomas: "<%= @about.diploma&.slug %>"
teachers: teachers:
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<div class="card flex-fill w-100"> <div class="card flex-fill w-100">
<div class="card-body"> <div class="card-body">
<%= f.input :title %> <%= f.input :title %>
<%= render 'admin/application/summary/form', f: f, about: journal %>
<%= f.input :issn %> <%= f.input :issn %>
</div> </div>
</div> </div>
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<% if @journal.issn %><%= Research::Journal.human_attribute_name('issn') %> <%= @journal.issn %><% end %> <% if @journal.issn %><%= Research::Journal.human_attribute_name('issn') %> <%= @journal.issn %><% end %>
<% end %> <% end %>
<%= render 'admin/application/summary/show', about: @journal %>
<div class="card mt-5"> <div class="card mt-5">
<div class="card-header"> <div class="card-header">
<div class="float-end"> <div class="float-end">
......
...@@ -4,4 +4,5 @@ title: > ...@@ -4,4 +4,5 @@ title: >
issn: > issn: >
<%= @about.issn %> <%= @about.issn %>
<%= render 'admin/application/meta_description/static' %> <%= render 'admin/application/meta_description/static' %>
<%= render 'admin/application/summary/static' %>
--- ---
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
</div> </div>
<div class="card-body"> <div class="card-body">
<%= f.input :title %> <%= f.input :title %>
<%= render 'admin/application/summary/form', f: f, about: volume %>
<%= f.input :text, as: :summernote %> <%= f.input :text, as: :summernote %>
</div> </div>
</div> </div>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<div class="row"> <div class="row">
<div class="col-md-9"> <div class="col-md-9">
<%= render 'admin/application/summary/show', about: @volume %>
<div class="card flex-fill w-100"> <div class="card flex-fill w-100">
<div class="card-header"> <div class="card-header">
<h2 class="card-title mb-0 h5"><%= t('content') %></h2> <h2 class="card-title mb-0 h5"><%= t('content') %></h2>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment