From 8c60943a38a1bd8ff0b833e14f857dfee751130c Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Fri, 22 Jul 2022 13:14:31 +0200 Subject: [PATCH] full width --- .../websites/pages_controller.rb | 2 +- app/models/communication/website/page.rb | 6 ++ .../admin/communication/blocks/_list.html.erb | 64 +++++++++++-------- .../websites/pages/_form.html.erb | 1 + .../websites/pages/show.html.erb | 3 + .../websites/pages/static.html.erb | 1 + config/locales/communication/en.yml | 2 + config/locales/communication/fr.yml | 2 + ...ull_width_to_communication_website_page.rb | 5 ++ db/schema.rb | 3 +- 10 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 db/migrate/20220722103657_add_full_width_to_communication_website_page.rb diff --git a/app/controllers/admin/communication/websites/pages_controller.rb b/app/controllers/admin/communication/websites/pages_controller.rb index b7c8e6a92..203ff4d27 100644 --- a/app/controllers/admin/communication/websites/pages_controller.rb +++ b/app/controllers/admin/communication/websites/pages_controller.rb @@ -98,7 +98,7 @@ class Admin::Communication::Websites::PagesController < Admin::Communication::We params.require(:communication_website_page) .permit( :communication_website_id, :title, :breadcrumb_title, :bodyclass, - :description, :description_short, :header_text, :text, :slug, :published, + :description, :description_short, :header_text, :text, :slug, :published, :full_width, :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit, :parent_id, :language_id ) diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 85c2006d5..f819101e0 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -9,6 +9,7 @@ # description_short :text # featured_image_alt :string # featured_image_credit :text +# full_width :boolean default(FALSE) # github_path :text # header_text :text # kind :integer @@ -157,6 +158,11 @@ class Communication::Website::Page < ApplicationRecord page end + def full_width + kind_home? ? true + : attributes['full_width'] + end + def to_s "#{title}" end diff --git a/app/views/admin/communication/blocks/_list.html.erb b/app/views/admin/communication/blocks/_list.html.erb index 4f407759b..41505a23d 100644 --- a/app/views/admin/communication/blocks/_list.html.erb +++ b/app/views/admin/communication/blocks/_list.html.erb @@ -10,36 +10,44 @@ </h2> </div> <% if about.blocks.any? %> - <table class="<%= table_classes %>"> - <thead> - <tr> - <% if can? :reorder, Communication::Block %> - <th width="20" class="ps-0"> </th> - <% end %> - <th><%= Communication::Block.human_attribute_name('title') %></th> - <th><%= Communication::Block.human_attribute_name('template') %></th> - <th><%= t 'accessibility.label' %></th> - <th></th> - </tr> - </thead> - <tbody data-sortable data-sort-url="<%= reorder_admin_communication_blocks_path %>"> - <% about.blocks.ordered.each do |block| %> - <tr data-id="<%= block.id %>" class="<%= 'draft' unless block.published? %>"> + <div class="table-responsive"> + <table class="<%= table_classes %>"> + <thead> + <tr> <% if can? :reorder, Communication::Block %> - <td><i class="fa fa-bars handle"></i></td> + <th width="20" class="ps-0"> </th> <% end %> - <td><%= block.to_s.truncate(50) %></td> - <td><%= block.template_kind_i18n %></td> - <td><%= render 'admin/application/a11y/status', about: block %></td> - <td class="text-end"> - <div class="btn-group"> - <%= duplicate_link block %> - <%= edit_link block %> - </div> - </td> + <th><%= Communication::Block.model_name.human %></th> + <th></th> + <th><%= t 'accessibility.label' %></th> + <th></th> </tr> - <% end %> - </tbody> - </table> + </thead> + <tbody data-sortable data-sort-url="<%= reorder_admin_communication_blocks_path %>"> + <% about.blocks.ordered.each do |block| %> + <tr data-id="<%= block.id %>" class="<%= 'draft' unless block.published? %>"> + <% if can? :reorder, Communication::Block %> + <td><i class="fa fa-bars handle"></i></td> + <% end %> + <td> + <%= block.to_s.truncate(50) %><br> + <span class="small"><%= block.template_kind_i18n %></span> + </td> + <td class="p-0"> + <%= image_tag "communication/blocks/templates/#{block.template_kind}.jpg", + height: "100px", alt: '', style:"max-height: 50px" %> + </td> + <td><%= render 'admin/application/a11y/status', about: block %></td> + <td class="text-end"> + <div class="btn-group"> + <%= duplicate_link block %> + <%= edit_link block %> + </div> + </td> + </tr> + <% end %> + </tbody> + </table> + </div> <% end %> </div> diff --git a/app/views/admin/communication/websites/pages/_form.html.erb b/app/views/admin/communication/websites/pages/_form.html.erb index 51d19dd14..129062b21 100644 --- a/app/views/admin/communication/websites/pages/_form.html.erb +++ b/app/views/admin/communication/websites/pages/_form.html.erb @@ -51,6 +51,7 @@ label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } unless page.kind_home? %> <%= f.input :bodyclass if can?(:edit, @website) %> + <%= f.input :full_width %> </div> </div> <% else %> diff --git a/app/views/admin/communication/websites/pages/show.html.erb b/app/views/admin/communication/websites/pages/show.html.erb index 641abd9c4..52d79983c 100644 --- a/app/views/admin/communication/websites/pages/show.html.erb +++ b/app/views/admin/communication/websites/pages/show.html.erb @@ -79,6 +79,9 @@ </p> <% end %> + <h3 class="h5"><%= Communication::Website::Page.human_attribute_name('full_width') %></h3> + <p><%= t @page.full_width %></p> + <% if @page.children.any? %> <h3 class="h5"><%= Communication::Website::Page.human_attribute_name('children') %></h3> <ul class="list-unstyled mb-0"> diff --git a/app/views/admin/communication/websites/pages/static.html.erb b/app/views/admin/communication/websites/pages/static.html.erb index 8812dd9cf..bfc2c8103 100644 --- a/app/views/admin/communication/websites/pages/static.html.erb +++ b/app/views/admin/communication/websites/pages/static.html.erb @@ -4,6 +4,7 @@ title: > breadcrumb_title: "<%= @about.breadcrumb_title.blank? ? @about.title : @about.breadcrumb_title %>" url: "<%= @about.path %>" position: <%= @about.position %> +full_width: <%= @about.full_width %> bodyclass: <%= @about.best_bodyclass %> <%= render 'admin/communication/unsplash/static' %> <% if @about.children.published.any? %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index b5e6644ce..bab76259a 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -97,6 +97,7 @@ en: description_short: Lead text featured_image: Featured image featured_image_alt: Alt text + full_width: Full width header_text: Title displayed in header parent: Parent page published: Published? @@ -592,5 +593,6 @@ en: communication_website_page: breadcrumb_title: If the field is empty, page title will be used in breadcrumbs. description: If this field is empty, the "lead text" field will be used. If also emty the main text's begining will be used. + full_width: On large screens, a full width page uses all available space for the content. This is good for landing pages, or to make them spectacular. If the page is not full width, the content column will be smaller to make reading easier. The unused space might be used for a table of contents. communication_website_post: description: If this field is empty, the "lead text" field will be used. If also emty the main text's begining will be used. diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 336003335..d8f817729 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -97,6 +97,7 @@ fr: description_short: Chapô featured_image: Image à la une featured_image_alt: Texte alternatif + full_width: Pleine largeur header_text: Titre affiché dans le header parent: Page parente published: Publié ? @@ -596,5 +597,6 @@ fr: communication_website_page: breadcrumb_title: Si ce champ est vide le titre de la page sera utilisé dans le fil d'Ariane. description: Si ce champ est vide le "chapô" sera utilisé. Si il est également vide le début du texte principal sera utilisé. + full_width: Sur de grands écrans, la page en pleine largeur utilisera tout l'espace disponible, ce qui est pertinent pour événementialiser une page. Si la page n'est pas en pleine largeur, l'espace dédié au contenu sera réduit pour faciliter la lecture, et l'espace libre pourra être utilisé pour une table des matières facilitant la navigation. communication_website_post: description: Si ce champ est vide le "chapô" sera utilisé. Si il est également vide le début du texte principal sera utilisé. diff --git a/db/migrate/20220722103657_add_full_width_to_communication_website_page.rb b/db/migrate/20220722103657_add_full_width_to_communication_website_page.rb new file mode 100644 index 000000000..fe39e1f41 --- /dev/null +++ b/db/migrate/20220722103657_add_full_width_to_communication_website_page.rb @@ -0,0 +1,5 @@ +class AddFullWidthToCommunicationWebsitePage < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_pages, :full_width, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 8ef9ad8eb..5bf914598 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_07_04_164321) do +ActiveRecord::Schema.define(version: 2022_07_22_103657) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -310,6 +310,7 @@ ActiveRecord::Schema.define(version: 2022_07_04_164321) do t.string "bodyclass" t.uuid "language_id" t.text "featured_image_credit" + t.boolean "full_width", default: false t.index ["communication_website_id"], name: "index_communication_website_pages_on_communication_website_id" t.index ["language_id"], name: "index_communication_website_pages_on_language_id" t.index ["parent_id"], name: "index_communication_website_pages_on_parent_id" -- GitLab