Add partial and wildcard search on /admin/contacts

This commit is contained in:
Thiago Youssef 2022-03-29 10:39:29 +03:00
parent 5a0c812a15
commit b46f387fcf
2 changed files with 8 additions and 10 deletions

View file

@ -9,10 +9,8 @@ module Admin
params[:q] ||= {}
search_params = params[:q].deep_dup
if search_params[:domain_contacts_type_in].is_a?(Array) &&
search_params[:registrant_domains_id_not_null] = 1 if search_params[:domain_contacts_type_in].is_a?(Array) &&
search_params[:domain_contacts_type_in].delete('registrant')
search_params[:registrant_domains_id_not_null] = 1
end
contacts = Contact.includes(:registrar).joins(:registrar)
.select('contacts.*, registrars.name as registrars_name')
@ -20,7 +18,7 @@ module Admin
contacts = filter_by_flags(contacts)
normalize_search_parameters do
@q = contacts.ransack(search_params)
@q = contacts.ransack(PartialSearchFormatter.format(search_params))
@contacts = @q.result.distinct.page(params[:page])
end
@ -33,6 +31,7 @@ module Admin
if params[:only_no_country_code].eql?('1')
contacts = contacts.where("ident_country_code is null or ident_country_code=''")
end
contacts = contacts.email_verification_failed if params[:email_verification_failed].eql?('1')
contacts
end
@ -41,8 +40,7 @@ module Admin
render json: Contact.search_by_query(params[:q])
end
def edit
end
def edit; end
def update
cp = ignore_empty_statuses

View file

@ -11,11 +11,11 @@
.col-md-3
.form-group
= f.label t(:id)
= f.search_field :code_matches, class: 'form-control', placeholder: t(:id)
= f.search_field :code_matches, value: params[:q][:code_matches], class: 'form-control', placeholder: t(:id)
.col-md-3
.form-group
= f.label t(:ident)
= f.search_field :ident_matches, class: 'form-control', placeholder: t(:ident)
= f.search_field :ident_matches, value: params[:q][:ident_matches], class: 'form-control', placeholder: t(:ident)
.col-md-3
.form-group
= label_tag t(:ident_type)
@ -24,7 +24,7 @@
.col-md-3
.form-group
= f.label t(:email)
= f.search_field :email_matches, class: 'form-control', placeholder: t(:email)
= f.search_field :email_matches, value: params[:q][:email_matches], class: 'form-control', placeholder: t(:email)
.col-md-3
.form-group
= label_tag t(:country)