mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
Add missing partial and wildcard search on /admin/contact_versions
This commit is contained in:
parent
2cff7d93fd
commit
7b47eab0d8
3 changed files with 15 additions and 24 deletions
|
@ -7,23 +7,9 @@ module Admin
|
||||||
def index
|
def index
|
||||||
params[:q] ||= {}
|
params[:q] ||= {}
|
||||||
|
|
||||||
search_params = params[:q].deep_dup.except(:created_at_gteq, :created_at_lteq)
|
search_params = PartialSearchFormatter.format(params[:q])
|
||||||
|
versions = Version::ContactVersion.includes(:item).order(created_at: :desc, id: :desc)
|
||||||
where_s = '1=1'
|
@q = versions.ransack(polymorphic_association(search_params))
|
||||||
|
|
||||||
search_params.each do |key, value|
|
|
||||||
next if value.empty?
|
|
||||||
|
|
||||||
where_s += case key
|
|
||||||
when 'event'
|
|
||||||
" AND event = '#{value}'"
|
|
||||||
else
|
|
||||||
create_where_string(key, value)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
versions = Version::ContactVersion.includes(:item).where(where_s).order(created_at: :desc, id: :desc)
|
|
||||||
@q = versions.ransack(params[:q])
|
|
||||||
|
|
||||||
@versions = @q.result.page(params[:page])
|
@versions = @q.result.page(params[:page])
|
||||||
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
|
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
|
||||||
|
@ -53,8 +39,14 @@ module Admin
|
||||||
render json: Version::ContactVersion.search_by_query(params[:q])
|
render json: Version::ContactVersion.search_by_query(params[:q])
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_where_string(key, value)
|
private
|
||||||
" AND object->>'#{key}' ~* '#{value}'"
|
|
||||||
|
def polymorphic_association(search_params)
|
||||||
|
record_type = {}
|
||||||
|
fields = %w[name code ident]
|
||||||
|
fields.each { |field| record_type[:"item_of_Contact_type_#{field}_matches"] = search_params[:"#{field}_matches"] }
|
||||||
|
|
||||||
|
record_type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
class PartialSearchFormatter
|
class PartialSearchFormatter
|
||||||
def self.format(params)
|
def self.format(params)
|
||||||
percentage = '%'
|
|
||||||
search_params = params.deep_dup
|
search_params = params.deep_dup
|
||||||
|
|
||||||
search_params.each do |key, value|
|
search_params.each do |key, value|
|
||||||
next unless key.include?('matches') && value.present?
|
next unless key.include?('matches') && value.present?
|
||||||
|
|
||||||
value << percentage
|
value << '%'
|
||||||
end
|
end
|
||||||
|
|
||||||
search_params
|
search_params
|
||||||
|
|
|
@ -7,15 +7,15 @@
|
||||||
.col-md-3
|
.col-md-3
|
||||||
.form-group
|
.form-group
|
||||||
= f.label :name
|
= f.label :name
|
||||||
= f.search_field :name, value: params[:q][:name], class: 'form-control', placeholder: t(:name)
|
= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name)
|
||||||
.col-md-3
|
.col-md-3
|
||||||
.form-group
|
.form-group
|
||||||
= f.label :id
|
= f.label :id
|
||||||
= f.search_field :code, value: params[:q][:code], 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
|
.col-md-3
|
||||||
.form-group
|
.form-group
|
||||||
= f.label :ident
|
= f.label :ident
|
||||||
= f.search_field :ident, value: params[:q][:ident], 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
|
.col-md-3
|
||||||
.form-group
|
.form-group
|
||||||
= label_tag :action
|
= label_tag :action
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue