mirror of
https://github.com/internetee/registry.git
synced 2025-07-06 03:03:21 +02:00
Work in progress search for contacts #2866
This commit is contained in:
parent
5b01c4d39b
commit
bc6c4213f7
3 changed files with 97 additions and 11 deletions
|
@ -3,8 +3,24 @@ class Admin::ContactsController < AdminController
|
||||||
before_action :set_contact, only: [:show]
|
before_action :set_contact, only: [:show]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
params[:q] ||= {}
|
||||||
@q = Contact.includes(:registrar).search(params[:q])
|
@q = Contact.includes(:registrar).search(params[:q])
|
||||||
@contacts = @q.result.page(params[:page])
|
@contacts = @q.result.page(params[:page])
|
||||||
|
|
||||||
|
if params[:statuses_contains]
|
||||||
|
contacts = Contact.includes(:registrar).where(
|
||||||
|
"statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
|
||||||
|
)
|
||||||
|
else
|
||||||
|
contacts = Contact.includes(:registrar)
|
||||||
|
end
|
||||||
|
|
||||||
|
normalize_search_parameters do
|
||||||
|
@q = contacts.search(params[:q])
|
||||||
|
@contacts = @q.result.page(params[:page])
|
||||||
|
end
|
||||||
|
|
||||||
|
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def search
|
def search
|
||||||
|
@ -45,4 +61,18 @@ class Admin::ContactsController < AdminController
|
||||||
dp[:statuses].reject!(&:blank?)
|
dp[:statuses].reject!(&:blank?)
|
||||||
dp
|
dp
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def normalize_search_parameters
|
||||||
|
ca_cache = params[:q][:created_at_lteq]
|
||||||
|
begin
|
||||||
|
end_time = params[:q][:created_at_lteq].try(:to_date)
|
||||||
|
params[:q][:created_at_lteq] = end_time.try(:end_of_day)
|
||||||
|
rescue
|
||||||
|
logger.warn('Invalid date')
|
||||||
|
end
|
||||||
|
|
||||||
|
yield
|
||||||
|
|
||||||
|
params[:q][:created_at_lteq] = ca_cache
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,17 +1,71 @@
|
||||||
= render 'shared/title', name: t(:contacts)
|
= render 'shared/title', name: t(:contacts)
|
||||||
|
|
||||||
|
/ .row
|
||||||
|
/ .col-md-12
|
||||||
|
/ = search_form_for [:admin, @q], html: { class: 'form-horizontal' } do |f|
|
||||||
|
/ .col-md-11
|
||||||
|
/ .form-group
|
||||||
|
/ = f.search_field :name_cont, class: 'form-control'
|
||||||
|
/ .col-md-1.text-right.text-center-xs
|
||||||
|
/ .form-group
|
||||||
|
/ %button.btn.btn-primary
|
||||||
|
/
|
||||||
|
/ %span.glyphicon.glyphicon-search
|
||||||
|
/
|
||||||
|
/ %hr
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
= search_form_for [:admin, @q], html: { class: 'form-horizontal' } do |f|
|
= search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f|
|
||||||
.col-md-11
|
.row
|
||||||
.form-group
|
.col-md-3
|
||||||
= f.search_field :name_cont, class: 'form-control'
|
.form-group
|
||||||
.col-md-1.text-right.text-center-xs
|
= f.label :name
|
||||||
.form-group
|
= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name)
|
||||||
%button.btn.btn-primary
|
.col-md-3
|
||||||
|
.form-group
|
||||||
%span.glyphicon.glyphicon-search
|
= f.label t(:id)
|
||||||
|
= f.search_field :code_eq, 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)
|
||||||
|
.col-md-3
|
||||||
|
.form-group
|
||||||
|
= f.label t(:email)
|
||||||
|
= f.search_field :email_matches, class: 'form-control', placeholder: t(:email)
|
||||||
|
.row
|
||||||
|
.col-md-6
|
||||||
|
.form-group
|
||||||
|
= f.label t(:registrar)
|
||||||
|
= f.select :registrar_id_eq, Registrar.all.map { |x| [x, x.id] }, { include_blank: true }, class: 'form-control selectize', placeholder: t(:choose)
|
||||||
|
.col-md-3
|
||||||
|
.form-group
|
||||||
|
= f.label t(:created_at_from)
|
||||||
|
= f.search_field :created_at_gteq, value: params[:q][:created_at_gteq], class: 'form-control datepicker', placeholder: t(:created_at_from)
|
||||||
|
.col-md-3
|
||||||
|
.form-group
|
||||||
|
= f.label t(:created_at_until)
|
||||||
|
= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control datepicker', placeholder: t(:created_at_until)
|
||||||
|
.row
|
||||||
|
.col-md-6
|
||||||
|
.form-group
|
||||||
|
= label_tag t(:status)
|
||||||
|
= select_tag :statuses_contains, options_for_select(Contact::STATUSES, params[:statuses_contains]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' }
|
||||||
|
.col-md-6
|
||||||
|
.form-group
|
||||||
|
= label_tag t(:status)
|
||||||
|
= select_tag '[q][domain_contacts_type_in]', options_for_select(['AdminDomainContact', 'TechDomainContact'], params[:q][:domain_contacts_type_in]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' }
|
||||||
|
/ .col-md-3
|
||||||
|
/ .form-group
|
||||||
|
/ = label_tag t(:results_per_page)
|
||||||
|
/ = text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
|
||||||
|
.col-md-3{style: 'padding-top: 25px;'}
|
||||||
|
%button.btn.btn-primary
|
||||||
|
|
||||||
|
%span.glyphicon.glyphicon-search
|
||||||
|
|
||||||
|
%button.btn.btn-default.js-reset-form
|
||||||
|
= t(:clear_fields)
|
||||||
%hr
|
%hr
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
|
|
|
@ -911,3 +911,5 @@ en:
|
||||||
pending_epp: Pending epp
|
pending_epp: Pending epp
|
||||||
id: ID
|
id: ID
|
||||||
hidden: '[hidden]'
|
hidden: '[hidden]'
|
||||||
|
created_at_from: 'Created at from'
|
||||||
|
created_at_until: 'Created at until'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue