p_product search + filter ok

This commit is contained in:
Barnabé 2021-09-29 16:56:13 +02:00
parent 7b223648b8
commit 9f23908f7f
3 changed files with 49 additions and 14 deletions

View File

@ -18,9 +18,13 @@ class Admin::PProductsController < ApplicationController
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]
if params[:search][:enabled].to_s == "Oui"
@p_products = @p_products.where(:enabled => true)
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 == "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
@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
if params[:search][:s_brand_id].to_s != ""
@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
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")
respond_to do |format|
format.html{
@ -60,7 +70,6 @@ class Admin::PProductsController < ApplicationController
}
end
end
def show

View File

@ -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 }
}

View File

@ -14,6 +14,14 @@
%table
%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
Actif :
=select_tag "search[enabled]", options_for_select([[""], "Oui", "Non"], params[:search][:enabled])
@ -27,12 +35,20 @@
%tr
%td
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
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}