diff --git a/app/controllers/admin/communication/blocks_controller.rb b/app/controllers/admin/communication/blocks_controller.rb index 511a159e2b81d0ba7a06c267122e0214db04d824..3356a1afce19e2b4963a7407d7f2123dfe13f6d4 100644 --- a/app/controllers/admin/communication/blocks_controller.rb +++ b/app/controllers/admin/communication/blocks_controller.rb @@ -42,6 +42,8 @@ class Admin::Communication::BlocksController < Admin::Communication::Application def create @block.university = current_university + headings = @block.about.headings + @block.heading = headings.last if headings.any? if @block.save # No need to sync as content is empty redirect_to [:edit, :admin, @block], diff --git a/app/models/communication/block.rb b/app/models/communication/block.rb index 04ab7f2dbc2c195e5c817cc70b57fc204c5de177..8711957ea97c66254a3258d05443d217c092d097 100644 --- a/app/models/communication/block.rb +++ b/app/models/communication/block.rb @@ -27,8 +27,8 @@ # fk_rails_90ac986fab (heading_id => communication_block_headings.id) # class Communication::Block < ApplicationRecord - include Accessible include Sanitizable + include WithAccessibility include WithUniversity include WithPosition diff --git a/app/models/communication/block/component/base.rb b/app/models/communication/block/component/base.rb index b0e3accc8fd9b0ca49593b863d10e67669a60350..ebb20af14abb77b9f253d79a80ca284ac4ba4ce8 100644 --- a/app/models/communication/block/component/base.rb +++ b/app/models/communication/block/component/base.rb @@ -1,5 +1,5 @@ class Communication::Block::Component::Base - include Accessible + include WithAccessibility attr_reader :property, :template diff --git a/app/models/communication/block/heading.rb b/app/models/communication/block/heading.rb index b15589e15cf0b0e61106acf611fcb08e43d149a7..90d5e37b409ddff68659504368429feae3181396 100644 --- a/app/models/communication/block/heading.rb +++ b/app/models/communication/block/heading.rb @@ -41,7 +41,8 @@ class Communication::Block::Heading < ApplicationRecord DEFAULT_LEVEL = 2 scope :root, -> { where(level: DEFAULT_LEVEL) } - default_scope { order(:position) } + scope :ordered, -> { order(:position) } + default_scope { ordered } before_validation :compute_level diff --git a/app/models/communication/block/template/base.rb b/app/models/communication/block/template/base.rb index fbc8a7f2a6881f24ef3aba3f527b71c44dab4f01..3901275733afc39b82db08edfa4168db09d82f17 100644 --- a/app/models/communication/block/template/base.rb +++ b/app/models/communication/block/template/base.rb @@ -1,5 +1,5 @@ class Communication::Block::Template::Base - include Accessible + include WithAccessibility class_attribute :components_descriptions, :layouts, diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index da268152d78e2cfc5c7c1402bcb2bb7111947ef4..c2a1c3d5015cead14d852a67f297aeccae2a8fe0 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -46,8 +46,8 @@ class Communication::Website::Page < ApplicationRecord self.ignored_columns = %w(path) - include Accessible include Sanitizable + include WithAccessibility include WithBlobs include WithBlocks include WithDuplication diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 5264c87a58e5cc09dc1be2f23935b5bc17d7235e..e4c7fafeac32d8344f543c91b0ff831b31d52b6a 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -39,6 +39,7 @@ # class Communication::Website::Post < ApplicationRecord include Sanitizable + include WithAccessibility include WithBlobs include WithBlocks include WithDuplication @@ -156,6 +157,10 @@ class Communication::Website::Post < ApplicationRecord protected + def check_accessibility + accessibility_merge_array blocks + end + def slug_unavailable?(slug) self.class.unscoped .where(communication_website_id: self.communication_website_id, language_id: language_id, slug: slug) diff --git a/app/models/concerns/accessible.rb b/app/models/concerns/with_accessibility.rb similarity index 97% rename from app/models/concerns/accessible.rb rename to app/models/concerns/with_accessibility.rb index de07704aae309895afbb9bf5ea3a27752774902f..0e24f40f390aea2ab2b7dd59b3cf571295ce3921 100644 --- a/app/models/concerns/accessible.rb +++ b/app/models/concerns/with_accessibility.rb @@ -1,4 +1,4 @@ -module Accessible +module WithAccessibility extend ActiveSupport::Concern def accessible? diff --git a/app/views/admin/application/a11y/_widget.html.erb b/app/views/admin/application/a11y/_widget.html.erb index b023bd180d17046d3398e3c191160293ef52fd0d..9291b09109efce026800ff3eb6373def20fd6c25 100644 --- a/app/views/admin/application/a11y/_widget.html.erb +++ b/app/views/admin/application/a11y/_widget.html.erb @@ -1,14 +1,15 @@ <% horizontal ||= false -color = about.accessible? ? 'text-success' : 'text-danger' -action = "<i class=\"#{ Icon::A11Y } fa-2x float-end #{ color}\"></i>" %> -<%= osuny_panel t('accessibility.label'), action: action do %> +<%= osuny_panel t('accessibility.label') do %> <% if horizontal %> - <div class="row"><div class="offset-lg-4 col-lg-8"> + <div class="row"><div class="offset-lg-4 col-lg-8 pt-n4"> <% end %> <% if about.accessibility_errors.any? %> - <%= osuny_label t('accessibility.errors', count: about.accessibility_errors.count), classes: 'text-danger' %> + <p class="text-danger"> + <i class="<%= Icon::A11Y %>"></i> + <%= t('accessibility.errors', count: about.accessibility_errors.count) %> + </p> <ol class="list-unstyled"> <% about.accessibility_errors.each do |key| %> <li> @@ -18,7 +19,10 @@ action = "<i class=\"#{ Icon::A11Y } fa-2x float-end #{ color}\"></i>" <% end %> </ol> <% else %> - <p><%= t 'accessibility.errors', count: 0 %></p> + <p> + <i class="<%= Icon::A11Y %> text-success"></i> + <%= t 'accessibility.errors', count: 0 %> + </p> <% end %> <% if about.accessibility_warnings.any? %> <%= osuny_label t('accessibility.warnings', count: about.accessibility_warnings.count) %> diff --git a/app/views/admin/communication/blocks/_block.html.erb b/app/views/admin/communication/blocks/_block.html.erb index ba4c34b9d0966d72bca56bc91f602c8a22d0ca67..978b3f30313553823e8c2f63df5a4a9d0e22f11b 100644 --- a/app/views/admin/communication/blocks/_block.html.erb +++ b/app/views/admin/communication/blocks/_block.html.erb @@ -1,4 +1,4 @@ -<div class="row" data-id="block_<%= block.id %>"> +<div data-id="block_<%= block.id %>" class="row"> <div class="offset-lg-4 col-lg-8"> <article class="blocks__list__element mt-5 <%= 'draft' unless block.published? %>"> <div class="mb-1"> diff --git a/app/views/admin/communication/blocks/_index_edit.html.erb b/app/views/admin/communication/blocks/_index_edit.html.erb index 1ff42a3dd36848f5276f02a79348c8ef47ef3b29..73a81938a5d17487d3bdb541eb5d551ce5c410df 100644 --- a/app/views/admin/communication/blocks/_index_edit.html.erb +++ b/app/views/admin/communication/blocks/_index_edit.html.erb @@ -1,22 +1,20 @@ -<%= osuny_panel Communication::Block.model_name.human(count: 2) do %> - <div class="blocks" data-sortable data-sort-url="<%= reorder_admin_communication_blocks_path %>"> - <% about.blocks.with_no_heading.ordered.each do |block| %> - <%= render 'admin/communication/blocks/block', block: block %> - <% end %> - <% about.headings.root.each do |heading| %> - <%= render 'admin/communication/blocks/headings/heading', heading: heading %> - <% end %> +<div class="blocks" data-sortable data-sort-url="<%= reorder_admin_communication_blocks_path %>"> + <% about.blocks.with_no_heading.ordered.each do |block| %> + <%= render 'admin/communication/blocks/block', block: block %> + <% end %> + <% about.headings.root.each do |heading| %> + <%= render 'admin/communication/blocks/headings/heading', heading: heading %> + <% end %> +</div> +<div class="row mt-5"> + <div class="col-lg-4"> + <%= link_to t('admin.communication.blocks.headings.add'), + new_admin_communication_heading_path(about_id: about.id, about_type: about.class.name), + class: 'py-5 px-2 d-block bg-light text-center h4' if can? :create, Communication::Block::Heading%> </div> - <div class="row mt-5"> - <div class="col-lg-4"> - <%= link_to t('admin.communication.blocks.headings.add'), - new_admin_communication_heading_path(about_id: about.id, about_type: about.class.name), - class: 'py-5 px-2 d-block bg-light text-center h4' if can? :create, Communication::Block::Heading%> - </div> - <div class="col-lg-8"> - <%= link_to t('admin.communication.blocks.add'), - new_admin_communication_block_path(about_id: about.id, about_type: about.class.name), - class: 'py-5 px-2 d-block bg-light text-center h4' if can? :create, Communication::Block%> - </div> + <div class="col-lg-8"> + <%= link_to t('admin.communication.blocks.add'), + new_admin_communication_block_path(about_id: about.id, about_type: about.class.name), + class: 'py-5 px-2 d-block bg-light text-center h4' if can? :create, Communication::Block%> </div> -<% end %> +</div> diff --git a/app/views/admin/communication/blocks/headings/_form.html.erb b/app/views/admin/communication/blocks/headings/_form.html.erb index 1af6668bea2e52e4baa33a5ea29609a2e7cf25b4..b3838a45a6bc07c0e93a1ca867ce8af538c990e4 100644 --- a/app/views/admin/communication/blocks/headings/_form.html.erb +++ b/app/views/admin/communication/blocks/headings/_form.html.erb @@ -8,12 +8,14 @@ url = heading.persisted? ? admin_communication_heading_path(heading) <%= f.input :title %> <%= f.input :about_type, as: :hidden %> <%= f.input :about_id, as: :hidden %> - <% content_for :action_bar_left do %> - <%= link_to t('delete'), - admin_communication_heading_path(heading), - method: :delete, - data: { confirm: t('please_confirm') }, - class: button_classes_danger if can? :destroy, heading %> + <% if heading.persisted?%> + <% content_for :action_bar_left do %> + <%= link_to t('delete'), + admin_communication_heading_path(heading), + method: :delete, + data: { confirm: t('please_confirm') }, + class: button_classes_danger if can? :destroy, heading %> + <% end %> <% end %> <% content_for :action_bar_right do %> <%= submit f %> diff --git a/app/views/admin/communication/blocks/headings/_heading_static.html.erb b/app/views/admin/communication/blocks/headings/_heading_static.html.erb index 676e103138c90e352c60022bb63522f17cf7356e..a03e792a2b574ab03f7e3e243263f4166bc70b5a 100644 --- a/app/views/admin/communication/blocks/headings/_heading_static.html.erb +++ b/app/views/admin/communication/blocks/headings/_heading_static.html.erb @@ -6,3 +6,7 @@ <% @heading.blocks.published.ordered.each do |block| @block = block %> <%= render 'admin/communication/blocks/block_static' %> <% end %> +<% children = @heading.children %> +<% children.ordered.each do |heading| @heading = heading %> +<%= render 'admin/communication/blocks/headings/heading_static' %> +<% end %> diff --git a/app/views/admin/communication/websites/menus/show.html.erb b/app/views/admin/communication/websites/menus/show.html.erb index dc23ad95368cab901ab517bfbbd3bcee43c2bb9e..249e1ec2a0b7aa7e7e330db6a294f4028f32be3c 100644 --- a/app/views/admin/communication/websites/menus/show.html.erb +++ b/app/views/admin/communication/websites/menus/show.html.erb @@ -1,23 +1,14 @@ <% content_for :title, @menu %> <%= render 'admin/communication/websites/sidebar' do %> - <div class="row"> - <div class="col-md-8"> - <h2 class="h3"> - <%= "#{Communication::Website::Menu::Item.model_name.human(count: 2)} (#{@root_items.size})" %> - </h2> + <% + action = '' + action += link_to t('create'), + new_admin_communication_website_menu_item_path(website_id: @website, menu_id: @menu.id), + class: button_classes if can?(:create, Communication::Website::Menu::Item) %> + <%= osuny_panel Communication::Website::Menu::Item.model_name.human(count: 2), action: action do %> <%= render 'admin/communication/websites/menus/items/list', items: @root_items if @items.any? %> - <%= link_to t('create'), - new_admin_communication_website_menu_item_path(website_id: @website, menu_id: @menu.id), - class: button_classes if can?(:create, Communication::Website::Menu::Item) %> - </div> - <div class="col-md-4"> - <%= render 'admin/application/i18n/widget', about: @menu %> - <%= osuny_panel t('metadata') do %> - <%= osuny_label Communication::Website::Menu.human_attribute_name('identifier') %> - <p><%= @menu.identifier %></p> - <% end %> - </div> + <% end %> <% end %> <% content_for :action_bar_left do %> diff --git a/app/views/admin/communication/websites/posts/show.html.erb b/app/views/admin/communication/websites/posts/show.html.erb index c560d5e920b0c1234aa262c5b3f78e5667d30389..619fa1dfb53f3e1003cd0ff204ee2f6a884d78f6 100644 --- a/app/views/admin/communication/websites/posts/show.html.erb +++ b/app/views/admin/communication/websites/posts/show.html.erb @@ -2,53 +2,29 @@ <%= render 'admin/communication/websites/sidebar' do %> <div class="row"> - <div class="col-xl-8"> - <%= render 'admin/application/summary/show', about: @post %> - <%= render 'admin/communication/blocks/index_edit', about: @post %> - </div> - <div class="col-xl-4"> - <%= render 'admin/application/i18n/widget', about: @post %> - <% - action = '' - action += link_to t('open'), - @post.url, - target: :_blank, - class: 'btn btn-light btn-xs' if @post.url - %> - <%= osuny_panel t('metadata'), action: action do %> - <div class="row pure__row--small"> - <div class="col-6"> - <%= osuny_label Communication::Website::Post.human_attribute_name('published') %> - <p> - <%= t @post.published %><% if @post.published & @post.published_at %>, - <%= l @post.published_at.to_date, format: :long if @post.published_at %> - <% end %> - </p> - </div> - <div class="col-6"> - <%= osuny_label Communication::Website::Post.human_attribute_name('pinned') %> - <p><%= t @post.pinned %></p> - </div> - </div> - <% if @post.author %> - <%= osuny_label Communication::Website::Post.human_attribute_name('author') %> - <p><%= link_to_if can?(:read, @post.author), @post.author, admin_communication_website_author_path(@post.author) %></p> - <% end %> - <% if @post.categories.any? %> - <%= osuny_label Communication::Website::Post.human_attribute_name('categories') %> - <ul class="list-unstyled"> - <% @post.categories.each do |category| %> - <li><%= link_to_if can?(:read, category), category, [:admin, category] %></li> - <% end %> - </ul> - <% end %> - <%= osuny_label Communication::Website::Post.human_attribute_name('slug') %> - <p><%= @post.slug %></p> + <div class="col-lg-7"> + <%= osuny_panel Communication::Website::Post.human_attribute_name(:title) do %> + <p class="lead"><%= @post.title %></p> <% end %> + </div> + <div class="offset-lg-1 col-lg-4"> <%= render 'admin/application/featured_image/show', about: @post %> + </div> + </div> + <hr class="my-5"> + <%= render 'admin/application/a11y/widget', about: @post, horizontal: true %> + <hr class="my-5"> + <div class="row"> + <div class="col-lg-4"> + <%= render 'admin/communication/websites/posts/show/metadata' %> + <%= render 'admin/application/i18n/widget', about: @post %> + </div> + <div class="col-lg-8"> + <%= render 'admin/application/summary/show', about: @post %> <%= render 'admin/application/meta_description/show', about: @post %> </div> </div> + <%= render 'admin/communication/blocks/index_edit', about: @post %> <% end %> <% content_for :action_bar_left do %> @@ -58,6 +34,10 @@ <% end %> <% content_for :action_bar_right do %> + <%= link_to t('open'), + @post.url, + target: :_blank, + class: 'btn btn-light btn-xs' if @post.url %> <%= preview_link %> <%= edit_link @post %> <% end %> diff --git a/app/views/admin/communication/websites/posts/show/_metadata.html.erb b/app/views/admin/communication/websites/posts/show/_metadata.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..6e13f96c9d59e0586c980ba0878fe9363f124b14 --- /dev/null +++ b/app/views/admin/communication/websites/posts/show/_metadata.html.erb @@ -0,0 +1,15 @@ +<%= osuny_label t('metadata') %><br> +<% if @post.published %> + Publié le <%= l @post.published_at.to_date %> + <% if @post.pinned %> + et mis en avant + <% end %> +<% else %> + Brouillon +<% end %> +<% if @post.author %> + <br>par <%= @post.author %> +<% end %> +<% if @post.categories.any? %> + <br>dans <%= @post.categories.collect(&:to_s).join(', ') %> +<% end %>