From 0d744906379f900a26a947bb68f9b25fa49bf881 Mon Sep 17 00:00:00 2001 From: pabois <pierreandre.boissinot@noesya.coop> Date: Tue, 19 Apr 2022 17:27:23 +0200 Subject: [PATCH] wip #321 --- .../communication/website/pages_controller.rb | 2 +- app/models/communication/website/page.rb | 15 ++++++++---- .../website/pages/_form.html.erb | 1 + .../communication/website/pages/show.html.erb | 23 +++++++++++++++++-- .../website/pages/static.html.erb | 3 ++- config/locales/communication/en.yml | 1 + config/locales/communication/fr.yml | 1 + config/locales/en.yml | 1 + config/locales/fr.yml | 1 + ...bodyclass_to_communication_website_page.rb | 5 ++++ db/schema.rb | 3 ++- 11 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20220419144340_add_bodyclass_to_communication_website_page.rb diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb index 341160093..65f47b994 100644 --- a/app/controllers/admin/communication/website/pages_controller.rb +++ b/app/controllers/admin/communication/website/pages_controller.rb @@ -84,7 +84,7 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web def page_params params.require(:communication_website_page) - .permit(:communication_website_id, :title, :breadcrumb_title, + .permit(:communication_website_id, :title, :breadcrumb_title, :bodyclass, :description, :description_short, :header_text, :text, :slug, :published, :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :parent_id, :related_category_id) diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 03276e1d4..b0b9c44e0 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -3,6 +3,7 @@ # Table name: communication_website_pages # # id :uuid not null, primary key +# bodyclass :string # breadcrumb_title :string # description :text # description_short :text @@ -121,11 +122,15 @@ class Communication::Website::Page < ApplicationRecord "#{title}" end - def best_featured_image(fallback: true) - return featured_image if featured_image.attached? - best_image = parent&.best_featured_image(fallback: false) - best_image ||= featured_image if fallback - best_image + def best_featured_image + # we don't want to fallback on homepage featured_image + return featured_image if featured_image.attached? || parent.kind_home? + parent&.best_featured_image + end + + def best_bodyclass + return bodyclass if bodyclass.present? + parent&.best_bodyclass unless parent.kind_home? end def update_children_paths diff --git a/app/views/admin/communication/website/pages/_form.html.erb b/app/views/admin/communication/website/pages/_form.html.erb index 7846ec1ef..6291c5fb5 100644 --- a/app/views/admin/communication/website/pages/_form.html.erb +++ b/app/views/admin/communication/website/pages/_form.html.erb @@ -42,6 +42,7 @@ include_blank: false, label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } unless page.kind_home? %> + <%= f.input :bodyclass if can?(:edit, @website) %> </div> </div> <% end %> diff --git a/app/views/admin/communication/website/pages/show.html.erb b/app/views/admin/communication/website/pages/show.html.erb index d4cf76214..c29dbc0f4 100644 --- a/app/views/admin/communication/website/pages/show.html.erb +++ b/app/views/admin/communication/website/pages/show.html.erb @@ -47,6 +47,20 @@ ), class: "#{'opacity-50' unless @page.parent.published?}" %></p> <% end %> + + <% if can?(:edit, @website) && @page.best_bodyclass %> + <h3 class="h5"><%= Communication::Website::Page.human_attribute_name('bodyclass') %></h3> + <p> + <%= @page.best_bodyclass %> + <% if @page.bodyclass.blank? %> + <br> + <span class="small text-muted"> + <%= t 'admin.inheritance.sentence_without_link' %> + </span> + <% end %> + </p> + <% end %> + <% if @page.related_category %> <h3 class="h5"><%= Communication::Website::Page.human_attribute_name('related_category') %></h3> <p><%= link_to_if can?(:read, @page.related_category), @@ -71,13 +85,18 @@ <% end %> </div> </div> - <% if @page.featured_image.attached? && @page.featured_image.variable? %> + <% if @page.best_featured_image && @page.best_featured_image.attached? && @page.best_featured_image.variable? %> <div class="card flex-fill w-100"> <div class="card-header"> <h5 class="card-title mb-0"><%= t('activerecord.attributes.communication/website/page.featured_image') %></h5> </div> <div class="card-body"> - <%= image_tag @page.featured_image.variant(resize: '600'), class: 'img-fluid mb-3' %><br> + <%= image_tag @page.best_featured_image.variant(resize: '600'), class: 'img-fluid mb-3' %><br> + <% unless @page.featured_image.attached? %> + <span class="small text-muted"> + <%= t 'admin.inheritance.sentence_without_link' %> + </span> + <% end %> </div> </div> <% end %> diff --git a/app/views/admin/communication/website/pages/static.html.erb b/app/views/admin/communication/website/pages/static.html.erb index 159cccbde..03b8546f5 100644 --- a/app/views/admin/communication/website/pages/static.html.erb +++ b/app/views/admin/communication/website/pages/static.html.erb @@ -4,7 +4,8 @@ title: > breadcrumb_title: "<%= @about.breadcrumb_title.blank? ? @about.title : @about.breadcrumb_title %>" url: "<%= @about.path unless @about.kind_home? %>/" position: <%= @about.position %> -<% if @about.best_featured_image.attached? %> +bodyclass: <%= @about.best_bodyclass %> +<% if @about.best_featured_image && @about.best_featured_image.attached? %> image: "<%= @about.best_featured_image.blob.id %>" image_alt: "<%= @about.featured_image_alt %>" <% end %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 38739009e..9aa4e9313 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -83,6 +83,7 @@ en: title: Title url: URL communication/website/page: + bodyclass: Specific CSS class breadcrumb_title: Title in breadcrumbs children: Children pages description: Meta Description diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 7361ca16d..08d1fec8c 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -83,6 +83,7 @@ fr: title: Titre url: URL communication/website/page: + bodyclass: Classe CSS spécifique breadcrumb_title: Nom affiché dans le fil d'ariane children: Pages enfants description: Meta Description diff --git a/config/locales/en.yml b/config/locales/en.yml index d8c2241b8..a07167520 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -40,6 +40,7 @@ en: dashboard: Dashboard infos: Informations inheritance: + sentence_without_link: Value inherited sentence_html: Value inherited from %{link} status: Inherited value password_hint: Leave blank if you do not wish to change the password. diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 9c50eb42a..cfb4f9c6e 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -40,6 +40,7 @@ fr: dashboard: Tableau de bord infos: Informations inheritance: + sentence_without_link: Valeur héritée sentence_html: Valeur héritée de %{link} status: Valeur héritée password_hint: Laissez vide si vous ne souhaitez pas modifier le mot de passe. diff --git a/db/migrate/20220419144340_add_bodyclass_to_communication_website_page.rb b/db/migrate/20220419144340_add_bodyclass_to_communication_website_page.rb new file mode 100644 index 000000000..2601f3512 --- /dev/null +++ b/db/migrate/20220419144340_add_bodyclass_to_communication_website_page.rb @@ -0,0 +1,5 @@ +class AddBodyclassToCommunicationWebsitePage < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_pages, :bodyclass, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 507e9bcab..583c931e5 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.define(version: 2022_04_13_203256) do +ActiveRecord::Schema.define(version: 2022_04_19_144340) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -323,6 +323,7 @@ ActiveRecord::Schema.define(version: 2022_04_13_203256) do t.text "header_text" t.integer "kind" t.text "description_short" + t.string "bodyclass" t.index ["communication_website_id"], name: "index_communication_website_pages_on_communication_website_id" t.index ["parent_id"], name: "index_communication_website_pages_on_parent_id" t.index ["related_category_id"], name: "index_communication_website_pages_on_related_category_id" -- GitLab