mirror of
https://github.com/internetee/registry.git
synced 2025-07-02 01:03:35 +02:00
109163582-import_files
This commit is contained in:
parent
cec3693f82
commit
1651961147
5 changed files with 86 additions and 2 deletions
|
@ -25,18 +25,50 @@ class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
|||
@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
|
||||
params[:q][:name_matches] = n_cache
|
||||
end
|
||||
end
|
||||
|
||||
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
authorize! :create, Depp::Contact
|
||||
@contact = Depp::Contact.new
|
||||
|
|
|
@ -201,6 +201,21 @@ class Contact < ActiveRecord::Base
|
|||
['DeleteProhibited', SERVER_DELETE_PROHIBITED]
|
||||
]
|
||||
end
|
||||
|
||||
def to_csv
|
||||
CSV.generate do |csv|
|
||||
csv << column_names
|
||||
all.each do |contact|
|
||||
csv << contact.attributes.values_at(*column_names)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def pdf(html)
|
||||
kit = PDFKit.new(html)
|
||||
kit.to_pdf
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def roid
|
||||
|
|
24
app/views/registrar/contacts/download_list.haml
Normal file
24
app/views/registrar/contacts/download_list.haml
Normal file
|
@ -0,0 +1,24 @@
|
|||
.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|
|
||||
%tr
|
||||
%td= contact
|
||||
%td= contact.code
|
||||
%td= ident_for(contact)
|
||||
%td= l(contact.created_at, format: :short)
|
||||
%td= contact.registrar
|
|
@ -73,6 +73,18 @@
|
|||
|
||||
%button.btn.btn-default.js-reset-form
|
||||
= t(:clear_fields)
|
||||
.row
|
||||
.col-md-3
|
||||
.btn-group{:role => "group"}
|
||||
%button.btn.btn-default.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", :type => "button"}
|
||||
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")
|
||||
.col-md-3
|
||||
.col-md-3
|
||||
.col-md-3
|
||||
|
||||
%hr
|
||||
.row
|
||||
|
|
|
@ -74,6 +74,7 @@ Rails.application.routes.draw do
|
|||
|
||||
collection do
|
||||
get 'check'
|
||||
get 'download_list'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue