mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 19:48:28 +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? }
|
params[:q].delete_if { |_k, v| v.blank? }
|
||||||
if params[:q].length == 1 && params[:q][:name_matches].present?
|
if params[:q].length == 1 && params[:q][:name_matches].present?
|
||||||
@contacts = Contact.find_by(name: params[:q][:name_matches])
|
@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
|
end
|
||||||
|
|
||||||
if params[:statuses_contains]
|
if params[:statuses_contains]
|
||||||
contacts = current_user.registrar.contacts.includes(:registrar).where(
|
contacts = current_user.registrar.contacts.includes(:registrar).where(
|
||||||
"statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
|
"contacts.statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
contacts = current_user.registrar.contacts.includes(:registrar)
|
contacts = current_user.registrar.contacts.includes(:registrar)
|
||||||
|
@ -24,13 +21,6 @@ class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
||||||
normalize_search_parameters do
|
normalize_search_parameters do
|
||||||
@q = contacts.search(params[:q])
|
@q = contacts.search(params[:q])
|
||||||
@contacts = @q.result.page(params[:page])
|
@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
|
end
|
||||||
|
|
||||||
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
@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
|
def download_list
|
||||||
authorize! :view, Depp::Contact
|
authorize! :view, Depp::Contact
|
||||||
|
|
||||||
params[:q] ||= {}
|
params[:q] ||= {}
|
||||||
if params[:statuses_contains]
|
params[:q].delete_if { |_k, v| v.blank? }
|
||||||
contacts = current_user.registrar.contacts.includes(:registrar).where(
|
if params[:q].length == 1 && params[:q][:name_matches].present?
|
||||||
"statuses @> ?::varchar[]", "{#{params[:statuses_contains].join(',')}}"
|
@contacts = Contact.find_by(name: params[:q][:name_matches])
|
||||||
)
|
|
||||||
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
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|
|
@ -1,24 +1,30 @@
|
||||||
.row
|
!!!
|
||||||
.col-md-12
|
%html
|
||||||
.table-responsive
|
%head
|
||||||
%table.table.table-hover.table-bordered.table-condensed
|
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
|
||||||
%thead
|
%title Contacts
|
||||||
%tr
|
%body
|
||||||
%th{class: 'col-xs-2'}
|
.row
|
||||||
=t(:name)
|
.col-md-12
|
||||||
%th{class: 'col-xs-2'}
|
.table-responsive
|
||||||
=t(:id)
|
%table.table.table-hover.table-bordered.table-condensed
|
||||||
%th{class: 'col-xs-2'}
|
%thead
|
||||||
=t(:ident)
|
|
||||||
%th{class: 'col-xs-2'}
|
|
||||||
=t(:created_at)
|
|
||||||
%th{class: 'col-xs-2'}
|
|
||||||
=t(:registrar)
|
|
||||||
%tbody
|
|
||||||
- @contacts.each do |contact|
|
|
||||||
%tr
|
%tr
|
||||||
%td= contact
|
%th{class: 'col-xs-2'}
|
||||||
%td= contact.code
|
=t(:name)
|
||||||
%td= ident_for(contact)
|
%th{class: 'col-xs-2'}
|
||||||
%td= l(contact.created_at, format: :short)
|
=t(:id)
|
||||||
%td= contact.registrar
|
%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
|
Download
|
||||||
%span.caret
|
%span.caret
|
||||||
%ul.dropdown-menu
|
%ul.dropdown-menu
|
||||||
%li= link_to 'PDF', download_list_registrar_contacts_path(params[:q], format: "pdf")
|
%li= link_to 'PDF', download_list_registrar_contacts_path(q: params[:q], format: "pdf")
|
||||||
%li= link_to 'CSV', download_list_registrar_contacts_path(params[:q], format: "csv")
|
%li= link_to 'CSV', download_list_registrar_contacts_path(q: params[:q], format: "csv")
|
||||||
.col-md-3
|
.col-md-3
|
||||||
.col-md-3
|
.col-md-3
|
||||||
.col-md-3
|
.col-md-3
|
||||||
|
@ -107,7 +107,7 @@
|
||||||
%tbody
|
%tbody
|
||||||
- @contacts.each do |contact|
|
- @contacts.each do |contact|
|
||||||
%tr
|
%tr
|
||||||
%td= link_to(contact, registrar_contact_path(contact))
|
%td= link_to(contact.name, registrar_contact_path(id: contact.code))
|
||||||
%td= contact.code
|
%td= contact.code
|
||||||
%td= ident_for(contact)
|
%td= ident_for(contact)
|
||||||
%td= l(contact.created_at, format: :short)
|
%td= l(contact.created_at, format: :short)
|
||||||
|
@ -115,8 +115,8 @@
|
||||||
- if contact.registrar
|
- if contact.registrar
|
||||||
= contact.registrar
|
= contact.registrar
|
||||||
%td
|
%td
|
||||||
= link_to(t(:edit), edit_registrar_contact_path(contact), class: 'btn btn-primary 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), class: 'btn btn-default btn-xs')
|
= link_to(t(:delete), delete_registrar_contact_path(contact.code), class: 'btn btn-default btn-xs')
|
||||||
|
|
||||||
.row
|
.row
|
||||||
.col-md-6
|
.col-md-6
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue