diff --git a/app/controllers/admin/communication/blocks_controller.rb b/app/controllers/admin/communication/blocks_controller.rb index ef3d597fbf0c1f8dba66ec06a4767ca879c50de5..0ce52e025d7d2b283d074e979b0dc0ce371acd42 100644 --- a/app/controllers/admin/communication/blocks_controller.rb +++ b/app/controllers/admin/communication/blocks_controller.rb @@ -18,6 +18,7 @@ class Admin::Communication::BlocksController < Admin::Communication::Application end def edit + @element = @block.template.default_element breadcrumb end diff --git a/app/models/communication/block/component/category.rb b/app/models/communication/block/component/category.rb index 9e8f192a942949bc0d2974e35bf164eb9d8c46ce..1336a6d4ce61e68b1d98bc1db1952bef87a993ba 100644 --- a/app/models/communication/block/component/category.rb +++ b/app/models/communication/block/component/category.rb @@ -1,3 +1,12 @@ class Communication::Block::Component::Category < Communication::Block::Component::Base + def category + return unless template.block.about&.website + template.block + .about + .website + .categories + .find_by(id: data) + end + end diff --git a/app/models/communication/block/component/post.rb b/app/models/communication/block/component/post.rb new file mode 100644 index 0000000000000000000000000000000000000000..964d25384df35ed975870dbfcefeda7852a8187c --- /dev/null +++ b/app/models/communication/block/component/post.rb @@ -0,0 +1,11 @@ +class Communication::Block::Component::Post < Communication::Block::Component::Base + + def post + return if data.blank? + block.about&.website + .posts + .published + .find_by(id: data) + end + +end diff --git a/app/models/communication/block/template/post.rb b/app/models/communication/block/template/post.rb index 1c9dcf1e44adcc86a7d66ec8d59a48ede3495abe..32d5f9b9649ed8331bb9e946a6b3cbc02232f29d 100644 --- a/app/models/communication/block/template/post.rb +++ b/app/models/communication/block/template/post.rb @@ -1,5 +1,6 @@ class Communication::Block::Template::Post < Communication::Block::Template::Base + has_elements Communication::Block::Template::Post::Item has_component :mode, :option, options: [:all, :category, :selection] has_component :posts_quantity, :number, options: 3 has_component :category_id, :category @@ -17,11 +18,7 @@ class Communication::Block::Template::Post < Communication::Block::Template::Bas end def category - return unless block.about&.website - block.about - .website - .categories - .find_by(id: data) + category_id_component.category end def selected_posts @@ -51,7 +48,7 @@ class Communication::Block::Template::Post < Communication::Block::Template::Bas def selected_posts_selection elements.map { |element| - post(element['id']) + post(element.id) }.compact end diff --git a/app/models/communication/block/template/post/item.rb b/app/models/communication/block/template/post/item.rb new file mode 100644 index 0000000000000000000000000000000000000000..be25c4cfbc11983d644909a507d81039fc89024c --- /dev/null +++ b/app/models/communication/block/template/post/item.rb @@ -0,0 +1,5 @@ +class Communication::Block::Template::Post::Item < Communication::Block::Template::Base + + has_component :id, :post + +end diff --git a/app/views/admin/communication/blocks/components/category/_edit.html.erb b/app/views/admin/communication/blocks/components/category/_edit.html.erb index 523f900131d2ee115d53000b269081cc28565b42..48937b1750fa19448b8de5404f43570c3ae28db0 100644 --- a/app/views/admin/communication/blocks/components/category/_edit.html.erb +++ b/app/views/admin/communication/blocks/components/category/_edit.html.erb @@ -2,10 +2,10 @@ categories = collection_tree(@block.about&.website.categories) %> <label class="form-label" - for="<%= dom_id.html_safe %>"> + :for="<%= dom_id.html_safe %>"> <%= label %> </label> -<select id="<%= dom_id.html_safe %>" +<select :id="<%= dom_id.html_safe %>" class="form-select select mb-3" v-model="<%= model %>.<%= property %>"> <% categories.each_with_index do |category, index| %> diff --git a/app/views/admin/communication/blocks/components/category/_preview.html.erb b/app/views/admin/communication/blocks/components/category/_preview.html.erb index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..1a4ddd3f77296f4bad90fa7050f29c737ef117ad 100644 --- a/app/views/admin/communication/blocks/components/category/_preview.html.erb +++ b/app/views/admin/communication/blocks/components/category/_preview.html.erb @@ -0,0 +1 @@ +<%= component.category.to_s %> diff --git a/app/views/admin/communication/blocks/components/post/_edit.html.erb b/app/views/admin/communication/blocks/components/post/_edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..e90073157dcdd06c29c5ac8e083e25f7adfe2809 --- /dev/null +++ b/app/views/admin/communication/blocks/components/post/_edit.html.erb @@ -0,0 +1,17 @@ +<% +posts = @block.about&.website.posts.ordered +%> +<label class="form-label <%= 'visually-hidden' if label.blank? %>" + :for="<%= dom_id.html_safe %>"> + <%= label %> +</label> +<select :id="<%= dom_id.html_safe %>" + class="form-select select" + v-model="<%= model %>.<%= property %>"> + <% if placeholder %> + <option value="" disabled><%= placeholder %></option> + <% end %> + <% posts.each do |post| %> + <option value="<%= post.id %>"><%= post.title %></option> + <% end %> +</select> diff --git a/app/views/admin/communication/blocks/components/post/_preview.html.erb b/app/views/admin/communication/blocks/components/post/_preview.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..0a44bd0c0588940acbbf20c5185923bef9db2d04 --- /dev/null +++ b/app/views/admin/communication/blocks/components/post/_preview.html.erb @@ -0,0 +1 @@ +<%= component.post.to_s %> diff --git a/app/views/admin/communication/blocks/components/post/_static.html.erb b/app/views/admin/communication/blocks/components/post/_static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb b/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb index c685d8e130e2cf5a9dd7d2c8d25a70c0d9ba007d..a0b22dfb45194714f742ee1e7ce8d3cd2fa10da1 100644 --- a/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb @@ -1,5 +1,3 @@ -<% element = @block.template.default_element %> - <%= block_component_edit :layout, horizontal: true %> <%= block_component_add_element t('.add_image') %> @@ -21,19 +19,19 @@ </div> <div class="card-body"> <%= block_component_edit :image, - template: element, + template: @element, label: t('admin.communication.blocks.components.image.input.label'), placeholder: t('admin.communication.blocks.components.image.input.placeholder') %> <%= block_component_edit :alt, - template: element, + template: @element, label: t('admin.communication.blocks.components.image.alt.label'), placeholder: t('admin.communication.blocks.components.image.alt.placeholder') %> <%= block_component_edit :credit, - template: element, + template: @element, label: t('admin.communication.blocks.components.image.credit.label'), placeholder: t('admin.communication.blocks.components.image.credit.placeholder') %> <%= block_component_edit :text, - template: element %> + template: @element %> </div> </div> </div> diff --git a/app/views/admin/communication/blocks/templates/posts/_edit.html.erb b/app/views/admin/communication/blocks/templates/posts/_edit.html.erb index 91ef1e58a90246c7d8e77d11e39b08d2ae6aba26..d28a4d3d3ceaf66865c669853c898d7ceb4b1bb5 100644 --- a/app/views/admin/communication/blocks/templates/posts/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/posts/_edit.html.erb @@ -12,17 +12,15 @@ </div> </div> <div v-if="data.mode === 'selection'"> - <a class="<%= button_classes('mb-3') %>" - v-on:click="data.elements.push({id: ''})"> - <%= t '.add_post' %> - </a> + <%= block_component_add_element t('.add_post') %> + <draggable :list="data.elements" class="row" handle=".dragHandle"> - <div v-for="(post, index) in data.elements" class="col-xxl-3 col-lg-4"> + <div v-for="(element, index) in data.elements" class="col-xxl-3 col-lg-4"> <div class="card"> <div class="card-body"> <div class="mb-3"> <a class="btn btn-sm btn-danger float-end" - v-on:click="data.elements.splice(data.elements.indexOf(post), 1)" + v-on:click="data.elements.splice(data.elements.indexOf(element), 1)" title="Delete"> <i class="fas fa-times"></i> </a> @@ -30,16 +28,7 @@ <i class="fa fa-bars handle"></i> </a> </div> - <label class="form-label visually-hidden" - :for="'post-' + index + '-name'"><%= t '.post_label' %></label> - <select :id="'post-' + index + '-name'" - class="form-select select" - v-model="post.id"> - <option value="" disabled>Posts</option> - <% @block.about&.website.posts.ordered.each_with_index do |post, index| %> - <option value="<%= post.id %>"><%= post.title %></option> - <% end %> - </select> + <%= block_component_edit :id, template: @element %> </div> </div> </div> diff --git a/app/views/admin/communication/blocks/templates/posts/_preview.html.erb b/app/views/admin/communication/blocks/templates/posts/_preview.html.erb index 66f447a9a9564d953b4bf9c5ca359b62b6da7b97..eeccd19a982071117e3539462fc90bf0e58a228d 100644 --- a/app/views/admin/communication/blocks/templates/posts/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/posts/_preview.html.erb @@ -1,15 +1,11 @@ <% if @block.data %> <% if @block.template.category %> - <h2 class="mb-4"><%= @block.template.category_component.object %></h2> + <h2 class="mb-4"><%= @block.template.category %></h2> <% end %> <% @block.template.selected_posts.each do |post| %> - <div class="card"> - <div class="card-header"> - <h3 class="card-title h5"><%= post %></h3> - </div> - <div class="card-body"> - <%= post.description_short %> - </div> - </div> + <h3 class="h5"><%= post %></h3> + <p> + <%= post.description_short %> + </p> <% end %> <% end %> diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 6b280638ceb4cdf40e66178a9e4e73988a6fff4c..30132f5fb59488ab9d7129c71500cd86a0186c4f 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -330,6 +330,7 @@ fr: posts: description: Une liste d'actualités mises en avant. edit: + add_post: Ajouter un article mode: label: Quelles actualités afficher ? options: @@ -339,9 +340,13 @@ fr: posts_quantity: label: Quantité d'articles placeholder: Entrer la quantité - category: + category_id: label: Catégorie placeholder: Sélectionner une catégorie + element: + id: + label: '' + placeholder: Choisir l'article testimonials: description: Un ou plusieurs témoignages, avec le texte, l'auteur, sa fonction et sa photo. edit: