This commit is contained in:
Nicolas Bally 2016-06-06 00:01:46 +02:00
parent 79c870a7ff
commit 6428aaf155
3 changed files with 9 additions and 6 deletions

View File

@ -13,7 +13,7 @@ class Public::NeedsController < ApplicationController
# Get only public needs
@needs = Need.shared
#@needs = @needs.domain_in(current_customer.domain_ids)
@needs = @needs.domain_in(current_customer.domain_ids)
# filters default value
params[:o] ||= 'created-desc'
@ -168,7 +168,7 @@ class Public::NeedsController < ApplicationController
private
def build_category_tree
@tree = NeedCategory::create_tree
@tree = NeedCategory::create_tree(NeedCategory.domain_in(current_customer.domain_ids))
end
def need_params

View File

@ -13,6 +13,9 @@ class NeedCategory < ActiveRecord::Base
has_many :categories, class_name: "NeedCategory", foreign_key: :parent_id, dependent: :destroy
validates :name, :presence => true, length: {within: 1..64}
scope :domain_in, -> (domain_ids) {
joins(:domains).where('domains.id IN(?)', domain_ids)
}
def level=(level)
@level = level
@ -24,11 +27,11 @@ class NeedCategory < ActiveRecord::Base
ancestors
end
def self.create_tree
def self.create_tree(top_level_categories=false)
collection = []
level = 0
top_level_categories = NeedCategory.order(name: :asc).top
top_level_categories = NeedCategory if !top_level_categories
top_level_categories = top_level_categories.order(name: :asc).top
self.populate_collection(collection, top_level_categories, level)
collection
end

View File

@ -24,7 +24,7 @@
= f.input :r, as: :result, selected: params[:r], input_html: {:name => 'r' }, label: 'Résultats par page', :include_blank => false , :as => :select, :collection => [6,12,24,48]
.clear
= f.inputs do
= f.input :c, as: :category, selected: params[:c], input_html: {:name => 'c' }, label: 'Filtrer par catégorie', :include_blank => "Toute catégorie" , :as => :select, :collection => @tree.map{|c| [(c.level > 0 ? ('&nbsp;&nbsp;&nbsp;' * (c.level - 1)) + "|- ": "").html_safe + c.name, c.id]}
= f.input :c, as: :category, selected: params[:c], input_html: {:name => 'c' }, label: 'Filtrer par catégorie', :include_blank => "Toute catégorie" , :as => :select, :collection => @tree.map{|c| [((c.level > 0 ? ('&nbsp;&nbsp;&nbsp;' * (c.level - 1)) + "|- ": "").html_safe + c.name if true), c.id]}
.clear
= f.inputs do
= f.input :s, as: :state, selected: params[:s], input_html: {:name => 's' }, label: 'Filter par état', :include_blank => "Tous les états" , :as => :select, :collection => [["En sondage","verified"],["En négociation","negociating"],["Négocié","negociated"]]