mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 03:06:14 +02:00
109163582-search_filters+changes
This commit is contained in:
parent
1651961147
commit
14673f1ffc
3 changed files with 64 additions and 67 deletions
|
@ -8,14 +8,11 @@ class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
|||
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
|
||||
end
|
||||
|
||||
if params[:statuses_contains]
|
||||
contacts = current_user.registrar.contacts.includes(:registrar).where(
|
||||
"statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
|
||||
contacts = current_user.registrar.contacts.includes(:registrar).where(
|
||||
"contacts.statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
|
||||
)
|
||||
else
|
||||
contacts = current_user.registrar.contacts.includes(:registrar)
|
||||
|
@ -24,13 +21,6 @@ class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
|||
normalize_search_parameters do
|
||||
@q = contacts.search(params[:q])
|
||||
@contacts = @q.result.page(params[:page])
|
||||
if @contacts.count == 0 && params[:q][:name_matches] !~ /^%.+%$/
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||
|
@ -39,34 +29,35 @@ class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
|||
def download_list
|
||||
authorize! :view, Depp::Contact
|
||||
|
||||
params[:q] ||= {}
|
||||
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] !~ /^%.+%$/
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.csv { render text: @contacts.to_csv }
|
||||
format.pdf do
|
||||
pdf = @contacts.pdf(render_to_string('registrar/contacts/download_list', layout: false))
|
||||
send_data pdf, filename: 'contacts.pdf'
|
||||
end
|
||||
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])
|
||||
end
|
||||
|
||||
if params[:statuses_contains]
|
||||
contacts = current_user.registrar.contacts.includes(:registrar).where(
|
||||
"contacts.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])
|
||||
end
|
||||
|
||||
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||
|
||||
respond_to do |format|
|
||||
format.csv { render text: @contacts.to_csv }
|
||||
format.pdf do
|
||||
pdf = @contacts.pdf(render_to_string('registrar/contacts/download_list', layout: false))
|
||||
send_data pdf, filename: 'contacts.pdf'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def new
|
||||
|
|
|
@ -1,24 +1,30 @@
|
|||
.row
|
||||
.col-md-12
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th{class: 'col-xs-2'}
|
||||
=t(:name)
|
||||
%th{class: 'col-xs-2'}
|
||||
=t(:id)
|
||||
%th{class: 'col-xs-2'}
|
||||
=t(:ident)
|
||||
%th{class: 'col-xs-2'}
|
||||
=t(:created_at)
|
||||
%th{class: 'col-xs-2'}
|
||||
=t(:registrar)
|
||||
%tbody
|
||||
- @contacts.each do |contact|
|
||||
!!!
|
||||
%html
|
||||
%head
|
||||
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
|
||||
%title Contacts
|
||||
%body
|
||||
.row
|
||||
.col-md-12
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%td= contact
|
||||
%td= contact.code
|
||||
%td= ident_for(contact)
|
||||
%td= l(contact.created_at, format: :short)
|
||||
%td= contact.registrar
|
||||
%th{class: 'col-xs-2'}
|
||||
=t(:name)
|
||||
%th{class: 'col-xs-2'}
|
||||
=t(:id)
|
||||
%th{class: 'col-xs-2'}
|
||||
=t(:ident)
|
||||
%th{class: 'col-xs-2'}
|
||||
=t(:created_at)
|
||||
%th{class: 'col-xs-2'}
|
||||
=t(:registrar)
|
||||
%tbody
|
||||
- @contacts.each do |contact|
|
||||
%tr
|
||||
%td= contact
|
||||
%td= contact.code
|
||||
%td= ident_for(contact)
|
||||
%td= l(contact.created_at, format: :short)
|
||||
%td= contact.registrar
|
||||
|
|
|
@ -80,8 +80,8 @@
|
|||
Download
|
||||
%span.caret
|
||||
%ul.dropdown-menu
|
||||
%li= link_to 'PDF', download_list_registrar_contacts_path(params[:q], format: "pdf")
|
||||
%li= link_to 'CSV', download_list_registrar_contacts_path(params[:q], format: "csv")
|
||||
%li= link_to 'PDF', download_list_registrar_contacts_path(q: params[:q], format: "pdf")
|
||||
%li= link_to 'CSV', download_list_registrar_contacts_path(q: params[:q], format: "csv")
|
||||
.col-md-3
|
||||
.col-md-3
|
||||
.col-md-3
|
||||
|
@ -107,7 +107,7 @@
|
|||
%tbody
|
||||
- @contacts.each do |contact|
|
||||
%tr
|
||||
%td= link_to(contact, registrar_contact_path(contact))
|
||||
%td= link_to(contact.name, registrar_contact_path(id: contact.code))
|
||||
%td= contact.code
|
||||
%td= ident_for(contact)
|
||||
%td= l(contact.created_at, format: :short)
|
||||
|
@ -115,8 +115,8 @@
|
|||
- 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')
|
||||
= link_to(t(:edit), edit_registrar_contact_path(contact.code), class: 'btn btn-primary btn-xs')
|
||||
= link_to(t(:delete), delete_registrar_contact_path(contact.code), class: 'btn btn-default btn-xs')
|
||||
|
||||
.row
|
||||
.col-md-6
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue