mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
Improve default csv generation
This commit is contained in:
parent
e50501f13f
commit
aef30eeb4d
5 changed files with 19 additions and 19 deletions
|
@ -35,7 +35,8 @@ module Admin
|
|||
respond_to do |format|
|
||||
format.html
|
||||
format.csv do
|
||||
send_data CsvGenerator.generate_csv(@q.result), filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv"
|
||||
raw_csv = CsvGenerator.generate_csv(@q.result)
|
||||
send_data raw_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -20,7 +20,8 @@ class Registrar
|
|||
respond_to do |format|
|
||||
format.html { @account_activities = @q.result.page(params[:page]) }
|
||||
format.csv do
|
||||
send_data CsvGenerator.generate_csv(@q.result), filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv"
|
||||
raw_csv = CsvGenerator.generate_csv(@q.result)
|
||||
send_data raw_csv, filename: "account_activities_#{Time.zone.now.to_formatted_s(:number)}.csv"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -748,7 +748,7 @@ class Domain < ApplicationRecord
|
|||
statuses,
|
||||
contacts.pluck(:code),
|
||||
force_delete_date,
|
||||
force_delete_data
|
||||
force_delete_data,
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -764,7 +764,10 @@ class Domain < ApplicationRecord
|
|||
end
|
||||
|
||||
def self.csv_header
|
||||
['Domain', 'Registrant', 'Valid to', 'Registrar', 'Created at', 'Statuses', 'Contacts code', 'Force delete date', 'Force delete data']
|
||||
[
|
||||
'Domain', 'Registrant', 'Valid to', 'Registrar', 'Created at',
|
||||
'Statuses', 'Contacts code', 'Force delete date', 'Force delete data',
|
||||
]
|
||||
end
|
||||
|
||||
def self.pdf(html)
|
||||
|
|
|
@ -125,7 +125,7 @@ class Invoice < ApplicationRecord
|
|||
issue_date,
|
||||
total,
|
||||
currency,
|
||||
seller_name
|
||||
seller_name,
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class CsvGenerator
|
||||
class << self
|
||||
def generate_csv(objects)
|
||||
@class_name = objects.first.class
|
||||
return default_generation(objects) unless custom_csv?
|
||||
class_name = objects.first.class
|
||||
return default_generation(objects) unless custom_csv?(class_name)
|
||||
|
||||
CSV.generate do |csv|
|
||||
csv << @class_name.csv_header
|
||||
csv << class_name.csv_header
|
||||
objects.each { |object| csv << object.as_csv_row }
|
||||
end
|
||||
end
|
||||
|
@ -14,21 +14,16 @@ class CsvGenerator
|
|||
|
||||
def default_generation(objects)
|
||||
CSV.generate do |csv|
|
||||
csv << @class_name.column_names
|
||||
objects.each { |object| csv << object.attributes.values_at(*@class_name.column_names) }
|
||||
csv << objects.column_names
|
||||
objects.all.find_each { |object| csv << object.attributes.values_at(*objects.column_names) }
|
||||
end
|
||||
end
|
||||
|
||||
def custom_csv?
|
||||
def custom_csv?(class_name)
|
||||
[
|
||||
Version::DomainVersion,
|
||||
Version::ContactVersion,
|
||||
Domain,
|
||||
Contact,
|
||||
Invoice,
|
||||
Account,
|
||||
AccountActivity
|
||||
].include?(@class_name)
|
||||
Version::DomainVersion, Version::ContactVersion, Domain,
|
||||
Contact, Invoice, Account, AccountActivity
|
||||
].include?(class_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue