suite
This commit is contained in:
parent
79c870a7ff
commit
6428aaf155
@ -13,7 +13,7 @@ class Public::NeedsController < ApplicationController
|
|||||||
|
|
||||||
# Get only public needs
|
# Get only public needs
|
||||||
@needs = Need.shared
|
@needs = Need.shared
|
||||||
#@needs = @needs.domain_in(current_customer.domain_ids)
|
@needs = @needs.domain_in(current_customer.domain_ids)
|
||||||
|
|
||||||
# filters default value
|
# filters default value
|
||||||
params[:o] ||= 'created-desc'
|
params[:o] ||= 'created-desc'
|
||||||
@ -168,7 +168,7 @@ class Public::NeedsController < ApplicationController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def build_category_tree
|
def build_category_tree
|
||||||
@tree = NeedCategory::create_tree
|
@tree = NeedCategory::create_tree(NeedCategory.domain_in(current_customer.domain_ids))
|
||||||
end
|
end
|
||||||
|
|
||||||
def need_params
|
def need_params
|
||||||
|
@ -13,6 +13,9 @@ class NeedCategory < ActiveRecord::Base
|
|||||||
has_many :categories, class_name: "NeedCategory", foreign_key: :parent_id, dependent: :destroy
|
has_many :categories, class_name: "NeedCategory", foreign_key: :parent_id, dependent: :destroy
|
||||||
validates :name, :presence => true, length: {within: 1..64}
|
validates :name, :presence => true, length: {within: 1..64}
|
||||||
|
|
||||||
|
scope :domain_in, -> (domain_ids) {
|
||||||
|
joins(:domains).where('domains.id IN(?)', domain_ids)
|
||||||
|
}
|
||||||
|
|
||||||
def level=(level)
|
def level=(level)
|
||||||
@level = level
|
@level = level
|
||||||
@ -24,11 +27,11 @@ class NeedCategory < ActiveRecord::Base
|
|||||||
ancestors
|
ancestors
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_tree
|
def self.create_tree(top_level_categories=false)
|
||||||
collection = []
|
collection = []
|
||||||
level = 0
|
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)
|
self.populate_collection(collection, top_level_categories, level)
|
||||||
collection
|
collection
|
||||||
end
|
end
|
||||||
|
@ -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]
|
= 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
|
.clear
|
||||||
= f.inputs do
|
= 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 ? (' ' * (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 ? (' ' * (c.level - 1)) + "|- ": "").html_safe + c.name if true), c.id]}
|
||||||
.clear
|
.clear
|
||||||
= f.inputs do
|
= 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"]]
|
= 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"]]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user