p_product search + filter ok
This commit is contained in:
parent
7b223648b8
commit
9f23908f7f
@ -18,9 +18,13 @@ class Admin::PProductsController < ApplicationController
|
|||||||
|
|
||||||
params[:search] = params[:search] || {}
|
params[:search] = params[:search] || {}
|
||||||
|
|
||||||
|
global_search_ids = p_product_cat_id_ids = s_brand_id_ids = @p_products.ids
|
||||||
|
|
||||||
|
if params[:search][:global].to_s != ""
|
||||||
|
global_search_ids = PProduct.global_search(params[:search][:global]).ids
|
||||||
|
end
|
||||||
|
|
||||||
params[:search][:enabled] = "Oui" if !params[:search][:enabled]
|
params[:search][:enabled] = "Oui" if !params[:search][:enabled]
|
||||||
|
|
||||||
if params[:search][:enabled].to_s == "Oui"
|
if params[:search][:enabled].to_s == "Oui"
|
||||||
@p_products = @p_products.where(:enabled => true)
|
@p_products = @p_products.where(:enabled => true)
|
||||||
elsif params[:search][:enabled].to_s == "Non"
|
elsif params[:search][:enabled].to_s == "Non"
|
||||||
@ -37,17 +41,23 @@ class Admin::PProductsController < ApplicationController
|
|||||||
|
|
||||||
if params[:search][:p_product_cat_id].to_s != ""
|
if params[:search][:p_product_cat_id].to_s != ""
|
||||||
if params[:search][:p_product_cat_id].to_s == "null"
|
if params[:search][:p_product_cat_id].to_s == "null"
|
||||||
@p_products = @p_products.where(:p_product_cat_id => nil)
|
# @p_products = @p_products.where(:p_product_cat_id => nil)
|
||||||
|
p_product_cat_id_ids = @p_product_refs.where(:cc_p_product_cat_id => nil).ids
|
||||||
else
|
else
|
||||||
@p_products = @p_products.where(:p_product_cat_id => params[:search][:p_product_cat_id])
|
# @p_products = @p_products.where(:p_product_cat_id => params[:search][:p_product_cat_id])
|
||||||
|
p_product_cat_id_ids = @p_products.where(:p_product_cat_id => params[:search][:p_product_cat_id]).ids
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if params[:search][:s_brand_id].to_s != ""
|
if params[:search][:s_brand_id].to_s != ""
|
||||||
@p_products = @p_products.where(:s_brand_id => params[:search][:s_brand_id])
|
@p_products = @p_products.where(:s_brand_id => params[:search][:s_brand_id])
|
||||||
|
s_brand_id_ids = @p_products.where(:s_brand_id => params[:search][:s_brand_id]).ids
|
||||||
end
|
end
|
||||||
|
|
||||||
|
final_ids = global_search_ids & p_product_cat_id_ids & s_brand_id_ids
|
||||||
|
@p_products = PProduct.where(id: final_ids)
|
||||||
|
|
||||||
@p_products = sort_by_sorting(@p_products, "id DESC")
|
@p_products = sort_by_sorting(@p_products, "id DESC")
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html{
|
format.html{
|
||||||
@ -60,7 +70,6 @@ class Admin::PProductsController < ApplicationController
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@ -70,6 +70,16 @@ class PProduct < ApplicationRecord
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include PgSearch::Model
|
||||||
|
pg_search_scope :global_search,
|
||||||
|
against: [:name, :code],
|
||||||
|
associated_against: {
|
||||||
|
p_product_refs: [:cc_name, :ref],
|
||||||
|
s_brand: [ :code, :name ],
|
||||||
|
},
|
||||||
|
using: {
|
||||||
|
tsearch: { prefix: true }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +14,14 @@
|
|||||||
|
|
||||||
%table
|
%table
|
||||||
%tr
|
%tr
|
||||||
|
%td{style: "min-width: 500px;"}
|
||||||
|
.input-group
|
||||||
|
=text_field_tag "search[global]", params[:search][:global],:class => "form-control", :placeholder => "Marque, modèle, couleur, code..."
|
||||||
|
.input-group-append{:onclick => "$(this).prev('input').val('');"}
|
||||||
|
.btn.btn-outline-dark
|
||||||
|
=ic(:times)
|
||||||
|
%tr
|
||||||
|
-if false
|
||||||
%td
|
%td
|
||||||
Actif :
|
Actif :
|
||||||
=select_tag "search[enabled]", options_for_select([[""], "Oui", "Non"], params[:search][:enabled])
|
=select_tag "search[enabled]", options_for_select([[""], "Oui", "Non"], params[:search][:enabled])
|
||||||
@ -27,12 +35,20 @@
|
|||||||
%tr
|
%tr
|
||||||
%td
|
%td
|
||||||
Catégorie :
|
Catégorie :
|
||||||
=select_tag "search[p_product_cat_id]", options_for_select([["",""],["Aucune","null"]]+PProductCat.order(:name).all.map{|a| [a.name, a.id]}, params[:search][:p_product_cat_id])
|
%td
|
||||||
|
.input-group
|
||||||
|
=select_tag "search[p_product_cat_id]", options_for_select([["",""],["Aucune","null"]]+PProductCat.order(:name).all.map{|a| [a.name, a.id]}, params[:search][:p_product_cat_id]), class: "custom-select"
|
||||||
|
.input-group-append{:onclick => "$(this).prev('select').val('').prop('selectedIndex',0);"}
|
||||||
|
.btn.btn-outline-dark
|
||||||
|
=ic(:times)
|
||||||
%td
|
%td
|
||||||
Marque :
|
Marque :
|
||||||
=select_tag "search[s_brand_id]", options_for_select([["",""]]+SBrand.order(:name).all.map{|a| [a.name, a.id]}, params[:search][:s_brand_id])
|
%td
|
||||||
|
.input-group
|
||||||
|
=select_tag "search[s_brand_id]", options_for_select([["",""]]+SBrand.order(:name).all.map{|a| [a.name, a.id]}, params[:search][:s_brand_id]), class: "custom-select"
|
||||||
|
.input-group-append{:onclick => "$(this).prev('select').val('').prop('selectedIndex',0);"}
|
||||||
|
.btn.btn-outline-dark
|
||||||
|
=ic(:times)
|
||||||
|
|
||||||
|
|
||||||
=render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_products}
|
=render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_products}
|
||||||
|
Reference in New Issue
Block a user