mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
Refactor admin/contact_version
and admin/domain_version
csv generation logic
This commit is contained in:
parent
807419bc3a
commit
9fb4a6d7e6
19 changed files with 117 additions and 156 deletions
|
@ -1,12 +1,7 @@
|
|||
module Admin
|
||||
class DomainVersionsController < BaseController
|
||||
include ObjectVersionsHelper
|
||||
|
||||
load_and_authorize_resource class: Version::DomainVersion
|
||||
|
||||
MODEL = Domain
|
||||
CSV_HEADER = ['Name', 'Registrant', 'Registrar', 'Action', 'Created at'].freeze
|
||||
|
||||
def index
|
||||
params[:q] ||= {}
|
||||
|
||||
|
@ -85,23 +80,10 @@ module Admin
|
|||
|
||||
def fix_date_params
|
||||
params_copy = params[:q].deep_dup
|
||||
if params_copy['created_at_lteq'].present?
|
||||
params_copy['created_at_lteq'] = Date.parse(params_copy['created_at_lteq']) + 1.day
|
||||
end
|
||||
created_at = params_copy['created_at_lteq']
|
||||
params_copy['created_at_lteq'] = Date.parse(created_at) + 1.day if created_at.present?
|
||||
|
||||
params_copy
|
||||
end
|
||||
|
||||
def render_by_format(page, filename)
|
||||
respond_to do |format|
|
||||
format.html { render page }
|
||||
format.csv do
|
||||
raw_csv = csv_generate(MODEL, CSV_HEADER, @q.result)
|
||||
send_data raw_csv,
|
||||
filename: "#{filename}_#{Time.zone.now.to_formatted_s(:number)}.csv",
|
||||
type: "#{Mime[:csv]}; charset=utf-8"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue