mirror of
https://github.com/internetee/registry.git
synced 2025-07-20 09:46:09 +02:00
109163582-filter_for_contacts
This commit is contained in:
parent
b1207c4128
commit
cec3693f82
2 changed files with 158 additions and 29 deletions
|
@ -3,18 +3,38 @@ class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
|||
|
||||
def index
|
||||
authorize! :view, Depp::Contact
|
||||
limit, offset = pagination_details
|
||||
|
||||
res = depp_current_user.repp_request('contacts', { details: true, limit: limit, offset: offset })
|
||||
if res.code == '200'
|
||||
@response = res.parsed_body.with_indifferent_access
|
||||
@contacts = @response ? @response[:contacts] : []
|
||||
|
||||
@paginatable_array = Kaminari.paginate_array(
|
||||
[], total_count: @response[:total_number_of_records]
|
||||
).page(params[:page]).per(limit)
|
||||
params[:q] ||= {}
|
||||
params[:q].delete_if { |_k, v| v.blank? }
|
||||
if params[:q].length == 1 && params[:q][:name_matches].present?
|
||||
@contacts = Contact.find_by(name: params[:q][:name_matches])
|
||||
if @contact
|
||||
redirect_to info_registrar_domains_path(contact_name: @contact.name) and return
|
||||
end
|
||||
flash.now[:epp_results] = [{ 'code' => res.code, 'msg' => res.message }]
|
||||
end
|
||||
|
||||
if params[:statuses_contains]
|
||||
contacts = current_user.registrar.contacts.includes(:registrar).where(
|
||||
"statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
|
||||
)
|
||||
else
|
||||
contacts = current_user.registrar.contacts.includes(:registrar)
|
||||
end
|
||||
|
||||
normalize_search_parameters do
|
||||
@q = contacts.search(params[:q])
|
||||
@contacts = @q.result.page(params[:page])
|
||||
if @contacts.count == 0 && params[:q][:name_matches] !~ /^%.+%$/
|
||||
# if we do not get any results, add wildcards to the name field and search again
|
||||
n_cache = params[:q][:name_matches]
|
||||
params[:q][:name_matches] = "%#{params[:q][:name_matches]}%"
|
||||
@q = contacts.search(params[:q])
|
||||
@contacts = @q.result.page(params[:page])
|
||||
params[:q][:name_matches] = n_cache # we don't want to show wildcards in search form
|
||||
end
|
||||
end
|
||||
|
||||
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||
end
|
||||
|
||||
def new
|
||||
|
@ -75,4 +95,18 @@ class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
|||
def init_epp_contact
|
||||
Depp::Contact.user = depp_current_user
|
||||
end
|
||||
|
||||
def normalize_search_parameters
|
||||
ca_cache = params[:q][:valid_to_lteq]
|
||||
begin
|
||||
end_time = params[:q][:valid_to_lteq].try(:to_date)
|
||||
params[:q][:valid_to_lteq] = end_time.try(:end_of_day)
|
||||
rescue
|
||||
logger.warn('Invalid date')
|
||||
end
|
||||
|
||||
yield
|
||||
|
||||
params[:q][:valid_to_lteq] = ca_cache
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,23 +2,118 @@
|
|||
= link_to(t(:new), new_registrar_contact_path, class: 'btn btn-primary')
|
||||
= render 'shared/title', name: t(:contacts)
|
||||
|
||||
- if @response
|
||||
.row
|
||||
.col-md-12
|
||||
= search_form_for [:registrar, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f|
|
||||
.row
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label :name
|
||||
= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= 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
|
||||
= label_tag t(:ident_type)
|
||||
= select_tag '[q][ident_type_eq]', options_for_select(Contact::IDENT_TYPES, params[:q][:ident_type_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' }
|
||||
.row
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:email)
|
||||
= f.search_field :email_matches, class: 'form-control', placeholder: t(:email)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= label_tag t(:country)
|
||||
= select_tag '[q][country_code_eq]', SortedCountry.all_options(params[:q][:country_code_eq]), { include_blank: true, placeholder: t(:choose), class: 'form-control selectize' }
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:is_registrant)
|
||||
%div
|
||||
= f.check_box :registrant_domains_id_not_null
|
||||
.col-md-3
|
||||
.form-group
|
||||
= label_tag t(:contact_type)
|
||||
= select_tag '[q][domain_contacts_type_in]', options_for_select([['admin', 'AdminDomainContact'], ['tech', 'TechDomainContact']], params[:q][:domain_contacts_type_in]), { multiple: true, placeholder: t(:choose), class: 'form-control js-combobox' }
|
||||
.row
|
||||
.col-md-3
|
||||
.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)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:updated_at)
|
||||
= f.search_field :updated_at_gteq, value: params[:q][:updated_at_gteq], class: 'form-control datepicker', placeholder: t(:updated_at)
|
||||
.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-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
|
||||
.row
|
||||
.col-md-12
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-condensed
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th{class: 'col-xs-3'}= t(:name)
|
||||
%th{class: 'col-xs-3'}= t(:id)
|
||||
%th{class: 'col-xs-3'}= t(:ident)
|
||||
%th{class: 'col-xs-3'}= t(:actions)
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'name', t(:name))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'code', t(:id))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'ident', t(:ident))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'email', t(:created_at))
|
||||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'registrar_name', t(:registrar))
|
||||
%th{class: 'col-xs-2'}= t(:actions)
|
||||
%tbody
|
||||
- @contacts.each do |c|
|
||||
- @contacts.each do |contact|
|
||||
%tr
|
||||
%td= link_to(c[:name], registrar_contact_path(id: c[:code]))
|
||||
%td= c[:code]
|
||||
%td= ident_for(c)
|
||||
%td= link_to(contact, registrar_contact_path(contact))
|
||||
%td= contact.code
|
||||
%td= ident_for(contact)
|
||||
%td= l(contact.created_at, format: :short)
|
||||
%td
|
||||
= link_to(t(:edit), edit_registrar_contact_path(c[:code]), class: 'btn btn-primary btn-xs')
|
||||
= link_to(t(:delete), delete_registrar_contact_path(c[:code]), class: 'btn btn-default btn-xs')
|
||||
- if contact.registrar
|
||||
= contact.registrar
|
||||
%td
|
||||
= link_to(t(:edit), edit_registrar_contact_path(contact), class: 'btn btn-primary btn-xs')
|
||||
= link_to(t(:delete), delete_registrar_contact_path(contact), class: 'btn btn-default btn-xs')
|
||||
|
||||
= paginate @paginatable_array
|
||||
.row
|
||||
.col-md-6
|
||||
= paginate @contacts
|
||||
.col-md-6.text-right
|
||||
.pagination
|
||||
= t(:result_count, count: @contacts.total_count)
|
||||
|
||||
:coffee
|
||||
$(".js-reset-form").on "click", (e) ->
|
||||
e.preventDefault();
|
||||
window.location = "#{registrar_contacts_path}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue