diff --git a/app/models/communication/block/component/option.rb b/app/models/communication/block/component/option.rb index 2cfa572e09be5f7c6ff829748327e4248c101449..b665a78f3ca013eed1ffdcbd2afd5f205145b8f6 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 5726cc4543f9444c339a45b2688e96aeb3c818aa..428b4bff02e81b87946183a2c1ef97f4c25add04 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 9427f7c5ec25d1881ee3eb8778818cf0ab20e03b..1c9dcf1e44adcc86a7d66ec8d59a48ede3495abe 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 06d6fb728f2ab50b8b5a31dc0d591d1bb6fc1375..523f900131d2ee115d53000b269081cc28565b42 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 82d434f11bdb74298cec01d57e668bcb98c0b60c..91ef1e58a90246c7d8e77d11e39b08d2ae6aba26 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 1f264f7d24473f489902919f986275c803850c9b..66f447a9a9564d953b4bf9c5ca359b62b6da7b97 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 c5192ce76b8cb7f5c192472099fae9264d332ec9..6b280638ceb4cdf40e66178a9e4e73988a6fff4c 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: