search to p_article
This commit is contained in:
parent
7e65e3374e
commit
bf92abf5a0
@ -12,6 +12,11 @@ class Admin::PArticlesController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@p_articles = PArticle.all
|
@p_articles = PArticle.all
|
||||||
|
global_search_ids = @p_articles.ids
|
||||||
|
|
||||||
|
if params[:search][:global].to_s != ""
|
||||||
|
global_search_ids = PArticle.global_search(params[:search][:global]).ids
|
||||||
|
end
|
||||||
|
|
||||||
if params[:search][:p_product_color].to_s != ""
|
if params[:search][:p_product_color].to_s != ""
|
||||||
if params[:search][:p_product_color].to_s == "null"
|
if params[:search][:p_product_color].to_s == "null"
|
||||||
@ -38,6 +43,11 @@ class Admin::PArticlesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
final_ids = global_search_ids
|
||||||
|
|
||||||
|
@p_articles = PArticle.where(id: final_ids)
|
||||||
|
|
||||||
@p_articles = sort_by_sorting(@p_articles, "id DESC")
|
@p_articles = sort_by_sorting(@p_articles, "id DESC")
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html{
|
format.html{
|
||||||
|
@ -3,9 +3,10 @@ class PArticle < ApplicationRecord
|
|||||||
belongs_to :p_product_ref
|
belongs_to :p_product_ref
|
||||||
has_one :p_product, through: :p_product_ref
|
has_one :p_product, through: :p_product_ref
|
||||||
has_one :p_product_color, through: :p_product_ref
|
has_one :p_product_color, through: :p_product_ref
|
||||||
|
has_one :s_brand, through: :p_product_ref
|
||||||
|
|
||||||
has_many :p_article_serial_nums, dependent: :destroy
|
has_many :p_article_serial_nums, dependent: :destroy
|
||||||
has_many :p_serial_num_values, through: :p_article_serial_nums
|
# has_many :p_serial_num_values, through: :p_article_serial_nums
|
||||||
accepts_nested_attributes_for :p_article_serial_nums
|
accepts_nested_attributes_for :p_article_serial_nums
|
||||||
|
|
||||||
validates_presence_of :p_product_ref
|
validates_presence_of :p_product_ref
|
||||||
@ -15,7 +16,7 @@ class PArticle < ApplicationRecord
|
|||||||
if PGrade::ACTIVATED
|
if PGrade::ACTIVATED
|
||||||
acts_as_sorting :fields => {
|
acts_as_sorting :fields => {
|
||||||
:id => {:name => "id", :reorder => true},
|
:id => {:name => "id", :reorder => true},
|
||||||
:p_product_ref_code => {:name => "Code ref", :reorder => true},
|
:p_product_ref_ref => {:name => "Code ref", :reorder => true},
|
||||||
:p_product_ref => {:name => "Désignation", :reorder => true},
|
:p_product_ref => {:name => "Désignation", :reorder => true},
|
||||||
:p_grade => {:name => "Grade", :reorder => true},
|
:p_grade => {:name => "Grade", :reorder => true},
|
||||||
:color => {:name => "Couleur"},
|
:color => {:name => "Couleur"},
|
||||||
@ -25,13 +26,26 @@ class PArticle < ApplicationRecord
|
|||||||
else
|
else
|
||||||
acts_as_sorting :fields => {
|
acts_as_sorting :fields => {
|
||||||
:id => {:name => "id", :reorder => true},
|
:id => {:name => "id", :reorder => true},
|
||||||
:p_product_ref_code => {:name => "Code ref", :reorder => true},
|
:p_product_ref_ref => {:name => "Code ref", :reorder => true},
|
||||||
:p_product_ref => {:name => "Désignation", :reorder => true},
|
:p_product_ref => {:name => "Désignation", :reorder => true},
|
||||||
:color => {:name => "Couleur"},
|
:color => {:name => "Couleur"},
|
||||||
:p_article_serial_nums => {:name => "N° identifiants"},
|
:p_article_serial_nums => {:name => "N° identifiants"},
|
||||||
:actions => {:name => "Actions", :reorder => false},
|
:actions => {:name => "Actions", :reorder => false},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
include PgSearch::Model
|
||||||
|
pg_search_scope :global_search,
|
||||||
|
associated_against: {
|
||||||
|
p_product_ref: [:cc_name, :ref],
|
||||||
|
s_brand: [ :code, :name ],
|
||||||
|
p_product_color: [:name, :color],
|
||||||
|
p_article_serial_nums: [:value]
|
||||||
|
},
|
||||||
|
using: {
|
||||||
|
tsearch: { prefix: true }
|
||||||
|
}
|
||||||
|
|
||||||
def member_label
|
def member_label
|
||||||
"#{p_product_ref.cc_name}"
|
"#{p_product_ref.cc_name}"
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
class PSerialNumValue < ApplicationRecord
|
class PSerialNumValue < ApplicationRecord
|
||||||
|
# USELESS MODEL : VALUES A ON p_article_serial_nums TABLE
|
||||||
has_many :p_article_serial_nums, inverse_of: :p_serial_num_value
|
has_many :p_article_serial_nums, inverse_of: :p_serial_num_value
|
||||||
has_many :p_articles, through: :p_article_serial_nums
|
has_many :p_articles, through: :p_article_serial_nums
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
%tr#p_article_row{:id => p_article.id}
|
%tr#p_article_row{:id => p_article.id}
|
||||||
-tr = {}
|
-tr = {}
|
||||||
|
|
||||||
-tr[:p_product_ref_code] = capture do
|
-tr[:p_product_ref_ref] = capture do
|
||||||
%td
|
%td
|
||||||
= p_article.p_product_ref.code
|
= p_article.p_product_ref.ref
|
||||||
|
|
||||||
-tr[:p_grade] = capture do
|
-tr[:p_grade] = capture do
|
||||||
%td
|
%td
|
||||||
|
@ -12,19 +12,30 @@
|
|||||||
|
|
||||||
%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, IMEI, SN..."
|
||||||
|
.input-group-append{:onclick => "$(this).prev('input').val('');"}
|
||||||
|
.btn.btn-outline-dark
|
||||||
|
=ic(:times)
|
||||||
|
|
||||||
|
%tr
|
||||||
|
-if false
|
||||||
%td=text_field_tag "search[p_product_ref_cc_code]", params[:search][:p_product_ref_cc_code],:class => "form-control", :placeholder => "Code"
|
%td=text_field_tag "search[p_product_ref_cc_code]", params[:search][:p_product_ref_cc_code],:class => "form-control", :placeholder => "Code"
|
||||||
|
|
||||||
%td=text_field_tag "search[p_product_ref_cc_name]", params[:search][:p_product_ref_cc_name],:class => "form-control", :placeholder => "Article"
|
%td=text_field_tag "search[p_product_ref_cc_name]", params[:search][:p_product_ref_cc_name],:class => "form-control", :placeholder => "Article"
|
||||||
|
|
||||||
%td=text_field_tag "search[p_article_serial_num]", params[:search][:p_article_serial_num],:class => "form-control", :placeholder => "N° de serie"
|
%td=text_field_tag "search[p_article_serial_num]", params[:search][:p_article_serial_num],:class => "form-control", :placeholder => "N° de serie"
|
||||||
|
|
||||||
%td.pl-2 Grade :
|
|
||||||
%td=select_tag "search[p_grade_id]", options_for_select([["",""],["Aucune","null"]]+PGrade.pluck(:grade, :id), params[:search][:p_grade_id]), class: "custom-select"
|
|
||||||
|
|
||||||
%td.pl-2 Couleur :
|
%td.pl-2 Couleur :
|
||||||
%td
|
%td
|
||||||
=select_tag "search[p_product_color]", options_for_select([["",""],["Aucune","null"]]+PProductColor.pluck(:color, :id), params[:search][:p_product_color]),class: "custom-select"
|
=select_tag "search[p_product_color]", options_for_select([["",""],["Aucune","null"]]+PProductColor.pluck(:color, :id), params[:search][:p_product_color]),class: "custom-select"
|
||||||
|
|
||||||
|
-if PGrade::ACTIVATED
|
||||||
|
%td.pl-2 Grade :
|
||||||
|
%td=select_tag "search[p_grade_id]", options_for_select([["",""],["Aucune","null"]]+PGrade.pluck(:grade, :id), params[:search][:p_grade_id]), class: "custom-select"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
=render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_articles}
|
=render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_articles}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user