diff --git a/app/models/communication/block/component/page.rb b/app/models/communication/block/component/page.rb new file mode 100644 index 0000000000000000000000000000000000000000..61978e9b802ee00a09dd41c9f34380ec510defa1 --- /dev/null +++ b/app/models/communication/block/component/page.rb @@ -0,0 +1,8 @@ +class Communication::Block::Component::Page < Communication::Block::Component::Base + + def page + return unless website + website.pages.published.find_by(id: data) + end + +end diff --git a/app/models/communication/block/template/base.rb b/app/models/communication/block/template/base.rb index 1cd430c1defafc2c16f5a97fbf3e1bcbb144e044..0f8aa7b41d60682e8c416b6b6b0650e8c07a2d88 100644 --- a/app/models/communication/block/template/base.rb +++ b/app/models/communication/block/template/base.rb @@ -7,7 +7,8 @@ class Communication::Block::Template::Base attr_reader :block - def self.has_elements(element_class) + def self.has_elements(element_class = nil) + element_class = "#{self}::Element".constantize if element_class.nil? self.element_class = element_class end diff --git a/app/models/communication/block/template/page.rb b/app/models/communication/block/template/page.rb index 578ad8a652731b0ff14a5264e0042b234b5e2de0..c24a2757b72573bd4e2d7c38a7220dad98118b4d 100644 --- a/app/models/communication/block/template/page.rb +++ b/app/models/communication/block/template/page.rb @@ -1,51 +1,31 @@ class Communication::Block::Template::Page < Communication::Block::Template::Base + has_elements has_layouts [:grid, :list, :cards] - has_elements Communication::Block::Template::Page::Element has_component :mode, :option, options: [:selection, :children] has_component :text, :rich_text + has_component :page_id, :page + has_component :show_main_description, :boolean + has_component :show_description, :boolean + has_component :show_image, :boolean - def selected_pages - @selected_pages ||= send "selected_pages_#{mode}" - end - - def main_page - @main_page ||= page(data['page_id']) - end - - def show_main_description - data['show_main_description'] || false + def page + page_id_component.page end - def show_description - data['show_description'] || false - end - - def show_image - data['show_image'] || false + def selected_pages + @selected_pages ||= send "selected_pages_#{mode}" end protected def selected_pages_selection - return [] - elements.map { |element| - element.page - }.compact + elements.map { |element| element.page }.compact end def selected_pages_children return [] unless main_page - main_page.children - .published - .ordered + main_page.children.published.ordered end - def page(id) - return if id.blank? - page = block.about&.website - .pages - .published - .find_by(id: id) - end end diff --git a/app/models/communication/block/template/page/element.rb b/app/models/communication/block/template/page/element.rb index c785d9d93c61a10e59c7ef4ae04c7194bf0d0885..fa6fc0cf5a810a1da2c3f8618fbca4628941500c 100644 --- a/app/models/communication/block/template/page/element.rb +++ b/app/models/communication/block/template/page/element.rb @@ -1,3 +1,8 @@ class Communication::Block::Template::Page::Element < Communication::Block::Template::Base + has_component :id, :page + + def page + id_component.page + end end diff --git a/app/views/admin/communication/blocks/components/_edit.html.erb b/app/views/admin/communication/blocks/components/_edit.html.erb index cb88da9dbf5efa5dfce2557ef1fdfd24d5333c95..e65d331efe11a0827686799d6ff4c41ed5690b82 100644 --- a/app/views/admin/communication/blocks/components/_edit.html.erb +++ b/app/views/admin/communication/blocks/components/_edit.html.erb @@ -14,16 +14,20 @@ else dom_id = "'element-' + index + '-#{property}'" i18n_component = "#{i18n}.element.#{property}" end -label ||= t "#{i18n_component}.label" -placeholder ||= t "#{i18n_component}.placeholder" +label ||= t "#{i18n_component}.label", default: '' +placeholder ||= t "#{i18n_component}.placeholder", default: '' +hint ||= t "#{i18n_component}.hint", default: '' +none ||= t "#{i18n_component}.none", default: '' partial = "admin/communication/blocks/components/#{component.kind}/edit" local_assigns[:template] = template local_assigns[:component] = component local_assigns[:model] = model local_assigns[:dom_id] = dom_id +local_assigns[:i18n_component] = i18n_component local_assigns[:label] = label local_assigns[:placeholder] = placeholder -local_assigns[:i18n_component] = i18n_component +local_assigns[:hint] = hint +local_assigns[:none] ||= t "#{i18n_component}.none", default: '' %> <%= render partial, **local_assigns %> diff --git a/app/views/admin/communication/blocks/components/page/_edit.html.erb b/app/views/admin/communication/blocks/components/page/_edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..3f922d8f45ae918c776f8142d5accd98e7945aff --- /dev/null +++ b/app/views/admin/communication/blocks/components/page/_edit.html.erb @@ -0,0 +1,26 @@ +<% +pages = collection_tree(@block.about&.website.pages) +%> +<% unless label.blank? %> + <label class="form-label" + :for="<%= dom_id.html_safe %>"> + <%= label %> + </label> +<% end %> +<select :id="<%= dom_id.html_safe %>" + class="form-select select mb-3" + v-model="<%= model %>.<%= property %>"> + <% unless none.blank? %> + <option value="" :selected="true"><%= none %></option> + <% end %> + <% pages.each do |page| %> + <option value="<%= page[:id] %>"> + <%= page[:label].html_safe %> + </option> + <% end %> +</select> +<% unless hint.blank? %> + <div class="form-text"> + <%= hint %> + </div> +<% end %> diff --git a/app/views/admin/communication/blocks/components/page/_preview.html.erb b/app/views/admin/communication/blocks/components/page/_preview.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/views/admin/communication/blocks/components/page/_static.html.erb b/app/views/admin/communication/blocks/components/page/_static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..e7e1732f246c835efd046479044043da7fdd97d9 --- /dev/null +++ b/app/views/admin/communication/blocks/components/page/_static.html.erb @@ -0,0 +1 @@ +<%= indentation %><%= property %>: <%= value %> diff --git a/app/views/admin/communication/blocks/templates/pages/_edit.html.erb b/app/views/admin/communication/blocks/templates/pages/_edit.html.erb index efde9f5080ea76524b1a712c16567ccb266818d9..710e18d7c02e0bd05c066f317bcb5b3e0128f062 100644 --- a/app/views/admin/communication/blocks/templates/pages/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/pages/_edit.html.erb @@ -2,72 +2,28 @@ <div class="row mb-4"> <div class="col-lg-6"> - <div class="mb-4"> - <h2 class="h3"><%= t '.kind.title' %></h2> - <div class="form-check form-check-inline mb-3"> - <input class="form-check-input" - type="radio" - name="kind" - v-model="data.kind" - value="children" - id="kind-children"> - <label class="form-check-label" for="kind-children"> - <%= t '.kind.children' %> - </label> - </div> - <div class="form-check form-check-inline"> - <input class="form-check-input" - type="radio" - name="kind" - v-model="data.kind" - value="selection" - id="kind-selection"> - <label class="form-check-label" for="kind-selection"> - <%= t '.kind.selection' %> - </label> - </div> + <div class="mb-5"> + <%= block_component_edit :mode %> </div> - <div class="mb-4"> + <div class="mb-5"> <h2 class="h3"><%= t '.main_page.title' %></h2> - <label class="form-label" - for="page_id"><%= t '.main_page.label' %></label> - <select id="page_id" - class="form-select select" - v-model="data.page_id"> - <option value=""><%= t '.main_page.none' %></option> - <% pages.each_with_index do |page, index| %> - <option value="<%= page[:id] %>"><%= page[:label].html_safe %></option> - <% end %> - </select> - <div class="form-text"><%= t '.main_page.hint' %></div> + <%= block_component_edit :page_id %> </div> - <div class="mb-4" v-if="data.kind == 'selection'"> + <div class="mb-4" v-if="data.mode == 'selection'"> <h2 class="h3"><%= t '.selection.title' %></h2> - <a class="<%= button_classes('mb-3') %>" - v-on:click="data.elements.push({id: ''})"> - <%= t '.selection.add' %> - </a> + <%= block_component_add_element t('.selection.add') %> <draggable :list="data.elements" handle=".dragHandle" class="list-group"> - <div v-for="(page, index) in data.elements" class="list-group-item"> - <div class="d-flex"> + <div v-for="(element, index) in data.elements" class="list-group-item"> + <div class="d-flex mb-n3"> <div> <a class="btn ps-0 pt-0 dragHandle" title="Drag and drop"> <i class="fa fa-bars handle"></i> </a> </div> <div class="flex-fill"> - <label class="form-label d-none" - :for="'page-' + index + '-name'"><%= t '.selection.label' %></label> - <select :id="'page-' + index + '-name'" - class="form-select select" - v-model="page.id"> - <option value="" disabled><%= t '.selection.none' %></option> - <% pages.each_with_index do |page, index| %> - <option value="<%= page[:id] %>"><%= page[:label].html_safe %></option> - <% end %> - </select> + <%= block_component_edit :id, template: @element %> </div> <div> <a class="btn btn-sm btn-danger ms-3" @@ -83,39 +39,9 @@ </div> <div class="col-lg-6"> <h2 class="h3"><%= t '.display.title' %></h2> - <div class="mb-4"> - <div class="form-check"> - <input v-model="data.show_main_description" - class="form-check-input boolean optional" - id="show_main_description" - type="checkbox"> - <label class="form-check-label boolean optional" - for="show_main_description"> - <%= t '.display.main_description' %> - </label> - </div> - <div class="form-check"> - <input v-model="data.show_description" - class="form-check-input boolean optional" - id="show_description" - type="checkbox"> - <label class="form-check-label boolean optional" - for="show_description"> - <%= t '.display.pages_descriptions' %> - </label> - </div> - <div class="form-check"> - <input v-model="data.show_image" - class="form-check-input boolean optional" - id="show_image" - type="checkbox"> - <label class="form-check-label boolean optional" - for="show_image"> - <%= t '.display.pages_images' %> - </label> - </div> - </div> - - <%= render 'admin/communication/blocks/components/layouts/edit' %> + <%= block_component_edit :show_main_description %> + <%= block_component_edit :show_description %> + <%= block_component_edit :show_image %> + <%= block_component_edit :layout %> </div> </div> diff --git a/app/views/admin/communication/blocks/templates/pages/_preview.html.erb b/app/views/admin/communication/blocks/templates/pages/_preview.html.erb index e7b02fc82c1362f238c8e260fde632fbb06d7dd6..089fb5fcd5958c993f6ecc9af29e570360d52eaf 100644 --- a/app/views/admin/communication/blocks/templates/pages/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/pages/_preview.html.erb @@ -1,6 +1,6 @@ <% if @block.data %> - <% if @block.template.main_page %> - <h2 class="h5 mb-4"><%= @block.template.main_page.slug %></h2> + <% if @block.template.page %> + <h2 class="h5 mb-4"><%= @block.template.page.slug %></h2> <% end %> <% @block.template.selected_pages.each do |element| %> <div class="card mb-4"> diff --git a/app/views/admin/communication/blocks/templates/pages/_static.html.erb b/app/views/admin/communication/blocks/templates/pages/_static.html.erb index a56323f243b547239cd14a2caf03810da76320fc..2127039c83970e47c0f10426911dcacdb594580f 100644 --- a/app/views/admin/communication/blocks/templates/pages/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/pages/_static.html.erb @@ -1,5 +1,5 @@ -<% if block.template.main_page %> - page: <%= block.template.main_page.generated_path %> +<% if block.template.page %> + page: <%= block.template.page.generated_path %> <% end %> show_main_description: <%= block.template.show_main_description %> show_descriptions: <%= block.template.show_description %> diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index f3800e9af8bf624fef6728f5dca1d4e0d0ea27ee..7cd341a5339f9215225d7acff40420545a14e563 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -297,15 +297,24 @@ fr: label: Liste description: Le chapô de la page principale sert d'édito en gros et les pages sont présentées sous forme de liste à droite. edit: - kind: - title: Type de liste - children: La page principale et ses enfants - selection: Une sélection spécifique de pages - main_page: - title: Page principale + mode: + label: Type de liste + options: + children: La page principale et ses enfants + selection: Une sélection spécifique de pages + show_main_description: + label: Afficher la description courte de la page principale + show_description: + label: Afficher les descriptions courtes des pages + show_image: + label: Afficher les images des pages + page_id: label: Sélectionnez une page principale - none: Aucune page sélectionnée hint: Cette page principale définira le titre et le lien du bloc. Si vous choisissez une page sans remplir le titre ci-dessus, le titre de la page sera utilisé. Si le titre est rempli, il remplacera le titre de la page sélectionnée, en utilisant le lien de la page. + none: Aucune page sélectionnée + + main_page: + title: Page principale selection: add: Sélectionner une page label: Page @@ -313,9 +322,6 @@ fr: title: Pages sélectionnées display: title: Options d'affichage - main_description: Afficher la description courte de la page principale - pages_descriptions: Afficher les descriptions courtes des pages - pages_images: Afficher les images des pages partners: description: Une liste de partenaires, avec leur logo, leur site et leur nom. edit: