diff --git a/app/assets/images/communication/blocks/templates/pages.jpg b/app/assets/images/communication/blocks/templates/pages.jpg new file mode 100644 index 0000000000000000000000000000000000000000..22f28b0c20e2a2e71e1ada963bdd49e3594a3f64 Binary files /dev/null and b/app/assets/images/communication/blocks/templates/pages.jpg differ diff --git a/app/models/communication/block.rb b/app/models/communication/block.rb index c6e84a454ff8619ee47b60825f6a28cecee1a40e..dfc4f715b54ac36618b04332745f890d521d0939 100644 --- a/app/models/communication/block.rb +++ b/app/models/communication/block.rb @@ -36,7 +36,8 @@ class Communication::Block < ApplicationRecord partners: 200, gallery: 300, testimonials: 400, - posts: 500 + posts: 500, + pages: 600 } before_save :update_template_images diff --git a/app/models/communication/block/template/page.rb b/app/models/communication/block/template/page.rb new file mode 100644 index 0000000000000000000000000000000000000000..a7cfe7225a1113835967c0f3a73855085d347145 --- /dev/null +++ b/app/models/communication/block/template/page.rb @@ -0,0 +1,38 @@ +class Communication::Block::Template::Page < Communication::Block::Template + def build_git_dependencies + # add_dependency category unless category.nil? + # add_dependency selected_posts + # selected_posts.each do |post| + # add_dependency post.active_storage_blobs + # if post.author.present? + # add_dependency [post.author, post.author.author] + # add_dependency post.author.active_storage_blobs + # end + # end + end + + # def category + # @category ||= block.about&.website.categories.find_by(id: data['category_id']) + # end + + # def selected_posts + # @selected_posts ||= category.nil? ? free_posts : category_posts + # end + + protected + + # def category_posts + # quantity = data['posts_quantity'] || 3 + # category.posts.ordered.limit(quantity) + # end + + # def free_posts + # elements.map { |element| post(element['id']) } + # .compact + # end + + # def post(id) + # return if id.blank? + # block.about&.website.posts.find_by id: id + # end +end diff --git a/app/views/admin/communication/blocks/templates/pages/_edit.html.erb b/app/views/admin/communication/blocks/templates/pages/_edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..852d7fbcf01c2141e7bb9ddbd02a096bd9287aec --- /dev/null +++ b/app/views/admin/communication/blocks/templates/pages/_edit.html.erb @@ -0,0 +1,76 @@ +<div class="row mb-1"> + <div class="col-md-6"> + <label class="form-label" + for="page_id">Sélectionnez une page principale</label> + <select id="page_id" + class="form-select select" + v-model="data.page_id"> + <option value="" disabled>Aucune page sélectionnée</option> + <% @block.about&.website.pages.ordered.each_with_index do |page, index| %> + <option value="<%= page.id %>"><%= page %></option> + <% end %> + </select> + </div> + <div class="col-md-6"> + <label class="form-label">Options d'affichage</label> + <div class="form-check"> + <input v-model="data.show_main_page_short_description" class="form-check-input boolean optional" id="show_main_page_short_description" type="checkbox"> + <label class="form-check-label boolean optional" + for="show_main_page_short_description">Afficher la description courte</label> + </div> + </div> + <div v-if="!data.category_id" class="col-md-12 mt-5"> + <h2>Ajouter des pages</h2> + <a class="<%= button_classes('my-4') %>" + v-on:click="data.elements.push({id: ''})"> + <%= t '.add_page' %> + </a> + <draggable :list="data.elements" handle=".dragHandle"> + <div v-for="(page, index) in data.elements"> + <div class="card"> + <div class="card-body"> + <div class="row"> + <div class="mb-2"> + <a class="btn btn-sm btn-danger float-end" + v-on:click="data.elements.splice(data.elements.indexOf(page), 1)" + title="Delete"> + <i class="fas fa-times"></i> + </a> + <a class="btn ps-0 pt-0 dragHandle" title="Drag and drop"> + <i class="fa fa-bars handle"></i> + </a> + </div> + <div class="col-6"> + <label class="form-label visually-hidden" + :for="'page-' + index + '-name'"><%= t '.page_label' %></label> + <select :id="'page-' + index + '-name'" + class="form-select select" + v-model="page.id"> + <option value="" disabled>Page</option> + <% @block.about&.website.pages.ordered.each_with_index do |page, index| %> + <option value="<%= page.id %>"><%= page.title %></option> + <% end %> + </select> + </div> + <div class="col-6"> + <div class="col-md-6"> + <label class="form-label">Options d'affichage</label> + <div class="form-check"> + <input v-model="page.show_short_description" class="form-check-input boolean optional" :id="'page-' + index + '-show_short_description'" type="checkbox"> + <label class="form-check-label boolean optional" + :for="'page-' + index + '-short_description'">Afficher la description courte</label> + </div> + <div class="form-check"> + <input v-model="page.show_image" class="form-check-input boolean optional" :id="'page-' + index + '-show_image'" type="checkbox"> + <label class="form-check-label boolean optional" + :for="'page-' + index + '-show_image'">Afficher l'image</label> + </div> + </div> + </div> + </div> + </div> + </div> + </div> + </draggable> + </div> +</div> diff --git a/app/views/admin/communication/blocks/templates/pages/_show.html.erb b/app/views/admin/communication/blocks/templates/pages/_show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..06a38ef4d9c3781774271dd075a20b6fa58ad964 --- /dev/null +++ b/app/views/admin/communication/blocks/templates/pages/_show.html.erb @@ -0,0 +1,21 @@ +<% if @block.data %> + <% if @block.template.category %> + <h2 class="mb-4"><%= @block.template.category %></h2> + <% end %> + <% if @block.template.selected_posts.any? %> + <div class="row"> + <% @block.template.selected_posts.each do |post| %> + <div class="col-md-4"> + <div class="card"> + <div class="card-header"> + <h3 class="card-title h5"><%= post %></h3> + </div> + <div class="card-body"> + <%= post.description_short %> + </div> + </div> + </div> + <% end %> + </div> + <% end %> +<% end %> diff --git a/app/views/admin/communication/blocks/templates/pages/_static.html.erb b/app/views/admin/communication/blocks/templates/pages/_static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..959fad4a6f157971c86dcb5804efcd2f7dfe07f2 --- /dev/null +++ b/app/views/admin/communication/blocks/templates/pages/_static.html.erb @@ -0,0 +1,7 @@ +<% if block.template.category %> + category: <%= block.template.category.slug %> +<% end %> + posts: +<% block.template.selected_posts.each do |post| %> + - <%= post.slug %> +<% end %>