added csv download

This commit is contained in:
dinsmol 2021-08-11 22:28:20 +03:00
parent c7e92452af
commit 7f8eee52f4
41 changed files with 259 additions and 35 deletions

View file

@ -8,6 +8,18 @@ module Admin
@q = domains.search(params[:q])
@domains = @q.result.page(params[:page])
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
respond_to do |format|
format.html do
render 'admin/blocked_domains/index'
end
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "blocked_domains_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
def new

View file

@ -28,6 +28,17 @@ module Admin
@versions = @q.result.page(params[:page])
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
respond_to do |format|
format.html do
render 'admin/contact_versions/index'
end
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "contact_history_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
def show

View file

@ -24,6 +24,18 @@ module Admin
end
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
respond_to do |format|
format.html do
@contacts
end
format.csv do
raw_csv = @q.result.distinct.to_csv
send_data raw_csv,
filename: "contacts_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
def filter_by_flags(contacts)

View file

@ -10,6 +10,18 @@ module Admin
params[:q] ||= {}
@disputes = sortable_dispute_query_for(Dispute.active.all, params[:q])
@closed_disputes = sortable_dispute_query_for(Dispute.closed.all, params[:q], closed: true)
respond_to do |format|
format.html do
render 'admin/disputes/index'
end
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "disputes_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
# GET /admin/disputes/1

View file

@ -44,7 +44,18 @@ module Admin
@q = versions.search(params[:q])
@versions = @q.result.page(params[:page])
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
render "admin/domain_versions/archive"
respond_to do |format|
format.html do
render 'admin/domain_versions/archive'
end
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "domain_history_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
def show

View file

@ -13,6 +13,18 @@ module Admin
@epp_logs = @epp_logs.page(params[:page])
@count = @q.result.count
@epp_logs = @epp_logs.per(params[:results_per_page]) if paginate?
respond_to do |format|
format.html do
render 'admin/epp_logs/index'
end
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "epp_logs_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
def show

View file

@ -13,6 +13,18 @@ module Admin
@repp_logs = @repp_logs.page(params[:page])
@count = @q.result.count
@repp_logs = @repp_logs.per(params[:results_per_page]) if paginate?
respond_to do |format|
format.html do
render 'admin/repp_logs/index'
end
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "repp_logs_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
def show

View file

@ -9,6 +9,18 @@ module Admin
@q = domains.search(params[:q])
@domains = @q.result.page(params[:page])
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
respond_to do |format|
format.html do
render 'admin/reserved_domains/index'
end
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "reserved_domains_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
def new

View file

@ -0,0 +1,10 @@
module CsvReportHelper
def to_csv
CSV.generate do |csv|
csv << column_names
all.each do |item|
csv << item.attributes.values_at(*column_names)
end
end
end
end

View file

@ -1,4 +1,5 @@
module ApiLog
class EppLog < Db
extend CsvReportHelper
end
end

View file

@ -1,4 +1,5 @@
module ApiLog
class ReppLog < Db
extend CsvReportHelper
end
end

View file

@ -1,5 +1,6 @@
class BlockedDomain < ApplicationRecord
include Versions
extend CsvReportHelper
before_save :generate_data
after_destroy :remove_data

View file

@ -1,4 +1,5 @@
class Dispute < ApplicationRecord
extend CsvReportHelper
include WhoisStatusPopulate
validates :domain_name, :password, :starts_at, :expires_at, presence: true
before_validation :fill_empty_passwords, :set_expiry_date

View file

@ -1,4 +1,5 @@
class Domain < ApplicationRecord
extend CsvReportHelper
include UserEvents
include Roids
include Versions # version/domain_version.rb
@ -720,15 +721,6 @@ class Domain < ApplicationRecord
contacts.select(&:email_verification_failed?)&.map(&:email)&.uniq
end
def self.to_csv
CSV.generate do |csv|
csv << column_names
all.each do |domain|
csv << domain.attributes.values_at(*column_names)
end
end
end
def self.pdf(html)
kit = PDFKit.new(html)
kit.to_pdf

View file

@ -1,4 +1,5 @@
class ReservedDomain < ApplicationRecord
extend CsvReportHelper
include Versions # version/reserved_domain_version.rb
include WhoisStatusPopulate
before_save :fill_empty_passwords

View file

@ -1,7 +1,7 @@
class Version::ContactVersion < PaperTrail::Version
extend CsvReportHelper
include VersionSession
self.table_name = :log_contacts
self.sequence_name = :log_contacts_id_seq
# scope :deleted, -> { where(event: 'destroy') }
end

View file

@ -1,4 +1,5 @@
class Version::DomainVersion < PaperTrail::Version
extend CsvReportHelper
include VersionSession
self.table_name = :log_domains

View file

@ -23,11 +23,12 @@
.form-group
= label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;'}
.col-md-4{style: 'padding-top: 25px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.csv_btn'), admin_blocked_domains_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_blocked_domains_path, class: 'btn btn-default')
%hr
.row

View file

@ -21,18 +21,19 @@
= label_tag :action
= select_tag '[q][event]', options_for_select([['Update', 'update'], ['Destroy', 'destroy'], ['Create', 'create']], params[:q][:event]), { include_blank:true, multiple: false, placeholder: t(:choose), class: 'form-control js-combobox' }
.row
.col-md-3
.col-md-3
.col-md-3
.form-group
= label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.reset_btn'), admin_contact_versions_path, class: 'btn btn-default')
.col-md-3
.col-md-3
.col-md-3
.form-group
= label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.csv_btn'), admin_contact_versions_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_contact_versions_path, class: 'btn btn-default')
%hr

View file

@ -69,11 +69,12 @@
= check_box_tag :email_verification_failed, '1',params[:email_verification_failed].eql?('1'), style: 'width:auto;height:auto;float:right'
.row
.col-md-3{style: 'padding-top: 25px;float:right;'}
.col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.csv_btn'), admin_contacts_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_contacts_path, class: 'btn btn-default')
%hr
.row

View file

@ -32,12 +32,13 @@
<%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %>
</div>
</div>
<div class="col-md-3" style="padding-top: 25px;">
<div class="col-md-4" style="padding-top: 25px;">
<button class="btn btn-primary">
&nbsp;
<span class="glyphicon glyphicon-search"></span>
&nbsp;
</button>
<%= link_to(t('.csv_btn'), admin_disputes_path(format: :csv, params: params.permit!), class: 'btn btn-default') %>
<%= link_to(t('.reset_btn'), admin_disputes_path, class: 'btn btn-default') %>
</div>
</div>

View file

@ -27,11 +27,12 @@
.form-group
= label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;'}
.col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.csv_btn'), admin_domain_versions_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_domain_versions_path, class: 'btn btn-default')
%hr

View file

@ -36,11 +36,12 @@
.form-group
= f.label t(:created_before)
= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_before)
.col-md-3{style: 'padding-top: 25px;'}
.col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.csv_btn'), admin_epp_logs_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_epp_logs_path, class: 'btn btn-default')
.row
.col-md-12
@ -49,6 +50,7 @@
.pull-right
.pagination
= t(:result_count, count: @count) if @count > 0
.row
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead

View file

@ -35,11 +35,12 @@
.form-group
= f.label t(:created_before)
= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_before)
.col-md-3{style: 'padding-top: 25px;'}
.col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.csv_btn'), admin_repp_logs_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_repp_logs_path, class: 'btn btn-default')
%hr
.row
@ -48,6 +49,7 @@
.pull-right
.pagination
= t(:result_count, count: @count) if @count > 0
.row
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead

View file

@ -23,11 +23,12 @@
.form-group
= label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;'}
.col-md-4{style: 'padding-top: 25px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.csv_btn'), admin_reserved_domains_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_reserved_domains_path, class: 'btn btn-default')
%hr
.row