Skip to content
Snippets Groups Projects
Commit 0158d5ae authored by pabois's avatar pabois
Browse files

categories affichées en arbre clean

parent 8a19f7d0
No related branches found
No related tags found
No related merge requests found
......@@ -89,6 +89,14 @@ class Communication::Website < ApplicationRecord
all_pages
end
def list_of_categories
all_categories = []
categories.root.ordered.each do |category|
all_categories.concat(category.self_and_children(0))
end
all_categories
end
protected
def create_home
......
......@@ -69,12 +69,7 @@ class Communication::Website::Category < ApplicationRecord
before_create :set_position
def list_of_other_categories
categories = []
website.categories.where.not(id: id).root.ordered.each do |category|
categories.concat(category.self_and_children(0))
end
categories.reject! { |p| p[:id] == id }
categories
website.list_of_categories.reject! { |p| p[:id] == id }
end
def to_s
......
......@@ -9,6 +9,10 @@
<%= f.input :title %>
<%= f.input :description %>
<%= f.input :text, as: :rich_text_area %>
<%= f.association :related_category,
collection: @website.list_of_categories,
label_method: ->(p) { sanitize p[:label] },
value_method: ->(p) { p[:id] } if @website.categories.any? %>
</div>
</div>
</div>
......@@ -25,8 +29,10 @@
data: { source: '#communication_website_page_title' }
} %>
<%= f.input :published %>
<%= f.association :parent, collection: page.persisted? ? page.list_of_other_pages : @website.list_of_pages, label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %>
<%= f.association :related_category, collection: page.website.categories.ordered %>
<%= f.association :parent,
collection: page.persisted? ? page.list_of_other_pages : page.website.list_of_pages,
label_method: ->(p) { sanitize p[:label] },
value_method: ->(p) { p[:id] } %>
<ul>
</ul>
</div>
......
......@@ -27,7 +27,11 @@
<%= f.input :published %>
<%= f.input :published_at, html5: true %>
<%= f.association :author, collection: @website.authors.ordered if @website.authors.any? %>
<%= f.association :categories, as: :check_boxes if @website.categories.any? %>
<%= f.association :categories,
as: :check_boxes,
collection: @website.list_of_categories,
label_method: ->(p) { sanitize p[:label] },
value_method: ->(p) { p[:id] } if @website.categories.any? %>
</div>
</div>
<div class="card flex-fill w-100">
......
......@@ -20,15 +20,15 @@
</div>
</div>
<div class="row">
<div class="col-md-4">
<%= render 'admin/communication/websites/show/categories' %>
</div>
<div class="col-md-4">
<%= render 'admin/communication/websites/show/authors' %>
</div>
<div class="col-md-4">
<%= render 'admin/communication/websites/show/menus' %>
</div>
<div class="col-md-4">
<%= render 'admin/communication/websites/show/categories' %>
</div>
</div>
<% content_for :action_bar_left do %>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment