From 6de4d509c5bfdfce8751a781010d1e7f7b6c2c46 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Fri, 17 Jun 2022 10:24:55 +0200 Subject: [PATCH] posts category --- .../communication/block/component/option.rb | 2 -- .../communication/block/component/rich_text.rb | 11 +++-------- app/models/communication/block/template/post.rb | 11 +++++++---- .../blocks/components/category/_edit.html.erb | 16 ++++++++++------ .../blocks/templates/posts/_edit.html.erb | 12 +----------- .../blocks/templates/posts/_preview.html.erb | 2 +- config/locales/communication/fr.yml | 5 ++++- 7 files changed, 26 insertions(+), 33 deletions(-) diff --git a/app/models/communication/block/component/option.rb b/app/models/communication/block/component/option.rb index 2cfa572e0..b665a78f3 100644 --- a/app/models/communication/block/component/option.rb +++ b/app/models/communication/block/component/option.rb @@ -1,12 +1,10 @@ class Communication::Block::Component::Option < Communication::Block::Component::Base attr_reader :options - def data @data || default_data end - def default_data options.first end diff --git a/app/models/communication/block/component/rich_text.rb b/app/models/communication/block/component/rich_text.rb index 5726cc454..428b4bff0 100644 --- a/app/models/communication/block/component/rich_text.rb +++ b/app/models/communication/block/component/rich_text.rb @@ -1,14 +1,9 @@ class Communication::Block::Component::RichText < Communication::Block::Component::Base def data=(value) - @data = clean(value) - end - - protected - - def clean(value) value = SummernoteCleaner.clean value.to_s - value = ActionView::Base.full_sanitizer.sanitize value - value + value = Osuny::Sanitizer.sanitize value, 'text' + @data = value end + end diff --git a/app/models/communication/block/template/post.rb b/app/models/communication/block/template/post.rb index 9427f7c5e..1c9dcf1e4 100644 --- a/app/models/communication/block/template/post.rb +++ b/app/models/communication/block/template/post.rb @@ -2,7 +2,7 @@ class Communication::Block::Template::Post < Communication::Block::Template::Bas has_component :mode, :option, options: [:all, :category, :selection] has_component :posts_quantity, :number, options: 3 - has_component :category, :category + has_component :category_id, :category def build_git_dependencies add_dependency category unless category.nil? @@ -17,9 +17,11 @@ class Communication::Block::Template::Post < Communication::Block::Template::Bas end def category - @category ||= block.about&.website - .categories - .find_by(id: data['category_id']) + return unless block.about&.website + block.about + .website + .categories + .find_by(id: data) end def selected_posts @@ -37,6 +39,7 @@ class Communication::Block::Template::Post < Communication::Block::Template::Bas end def selected_posts_category + return [] if category.nil? category_ids = [category.id, category.descendants.map(&:id)].flatten university.communication_website_posts.joins(:categories) .where(categories: { id: category_ids }) 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 06d6fb728..523f90013 100644 --- a/app/views/admin/communication/blocks/components/category/_edit.html.erb +++ b/app/views/admin/communication/blocks/components/category/_edit.html.erb @@ -1,12 +1,16 @@ <% categories = collection_tree(@block.about&.website.categories) %> -<label class="form-label" - for="category_id">Sélectionnez une catégorie</label> -<select id="category_id" - class="form-select select mb-3" - v-model="data.category_id"> +<label class="form-label" + for="<%= dom_id.html_safe %>"> + <%= label %> +</label> +<select id="<%= dom_id.html_safe %>" + class="form-select select mb-3" + v-model="<%= model %>.<%= property %>"> <% categories.each_with_index do |category, index| %> - <option value="<%= category[:id] %>"><%= category[:label].html_safe %></option> + <option value="<%= category[:id] %>"> + <%= category[:label].html_safe %> + </option> <% end %> </select> 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 82d434f11..91ef1e58a 100644 --- a/app/views/admin/communication/blocks/templates/posts/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/posts/_edit.html.erb @@ -6,18 +6,8 @@ <div v-if="data.mode === 'category' || data.mode === 'all'"> <%= block_component_edit :posts_quantity %> </div> - <div v-if="data.mode === 'category'"> - <%= block_component_edit :category %> - <label class="form-label" - for="category_id">Sélectionnez une catégorie</label> - <select id="category_id" - class="form-select select mb-3" - v-model="data.category_id"> - <% categories.each_with_index do |category, index| %> - <option value="<%= category[:id] %>"><%= category[:label].html_safe %></option> - <% end %> - </select> + <%= block_component_edit :category_id %> </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 1f264f7d2..66f447a9a 100644 --- a/app/views/admin/communication/blocks/templates/posts/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/posts/_preview.html.erb @@ -1,6 +1,6 @@ <% if @block.data %> <% if @block.template.category %> - <h2 class="mb-4"><%= @block.template.category %></h2> + <h2 class="mb-4"><%= @block.template.category_component.object %></h2> <% end %> <% @block.template.selected_posts.each do |post| %> <div class="card"> diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index c5192ce76..6b280638c 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -337,8 +337,11 @@ fr: category: Une catégorie spécifique selection: Une sélection d'actualités posts_quantity: - label: Quantité d'articles à afficher + label: Quantité d'articles placeholder: Entrer la quantité + category: + label: Catégorie + placeholder: Sélectionner une catégorie testimonials: description: Un ou plusieurs témoignages, avec le texte, l'auteur, sa fonction et sa photo. edit: -- GitLab