mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 12:08:27 +02:00
parent
9a152b8289
commit
1784980e6c
10 changed files with 171 additions and 2 deletions
|
@ -14,7 +14,7 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller
|
|||
if params[:q].length == 1 && params[:q][:name_matches].present?
|
||||
@domain = Domain.find_by(name: params[:q][:name_matches])
|
||||
if @domain
|
||||
redirect_to info_registrar_domains_path(domain_name: @domain.name) and return
|
||||
redirect_to info_registrar_domains_url(domain_name: @domain.name) and return
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -40,6 +40,20 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller
|
|||
end
|
||||
|
||||
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.csv do
|
||||
domain_presenters = []
|
||||
|
||||
@domains.find_each do |domain|
|
||||
domain_presenters << ::DomainPresenter.new(domain: domain, view: view_context)
|
||||
end
|
||||
|
||||
csv = Registrar::DomainListCSVPresenter.new(domains: domain_presenters, view: view_context).to_s
|
||||
send_data(csv)
|
||||
end
|
||||
end
|
||||
end
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class DomainPresenter
|
||||
delegate :name, :registrant_name, :registrant_id, to: :domain
|
||||
delegate :name, :registrant_name, :registrant_id, :registrant_code, to: :domain
|
||||
|
||||
def initialize(domain:, view:)
|
||||
@domain = domain
|
||||
|
|
45
app/presenters/registrar/domain_list_csv_presenter.rb
Normal file
45
app/presenters/registrar/domain_list_csv_presenter.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
class Registrar::DomainListCSVPresenter
|
||||
def initialize(domains:, view:)
|
||||
@domains = domains
|
||||
@view = view
|
||||
end
|
||||
|
||||
def to_s
|
||||
table = CSV::Table.new([header])
|
||||
|
||||
domains.each do |domain|
|
||||
table << domain_to_row(domain: domain)
|
||||
end
|
||||
|
||||
table.to_s
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def header
|
||||
columns = %w(
|
||||
domain_name
|
||||
registrant_name
|
||||
registrant_code
|
||||
expire_time
|
||||
)
|
||||
|
||||
columns.map! { |column| view.t("registrar.domains.index.csv.#{column}") }
|
||||
|
||||
CSV::Row.new(columns, [], true)
|
||||
end
|
||||
|
||||
def domain_to_row(domain:)
|
||||
row = []
|
||||
row[0] = domain.name
|
||||
row[1] = domain.registrant_name
|
||||
row[2] = domain.registrant_code
|
||||
row[3] = domain.expire_date
|
||||
row
|
||||
|
||||
CSV::Row.new([], row)
|
||||
end
|
||||
|
||||
attr_reader :domains
|
||||
attr_reader :view
|
||||
end
|
|
@ -52,6 +52,10 @@
|
|||
|
||||
%button.btn.btn-default.js-reset-form
|
||||
= t(:clear_fields)
|
||||
.row
|
||||
.col-md-2
|
||||
= button_tag t('.export_csv_btn'), class: 'btn btn-primary export-domains-csv-btn',
|
||||
formaction: registrar_domains_path(format: 'csv')
|
||||
%hr
|
||||
|
||||
.row
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue