active_scaffold_export 3.12.0 → 3.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/views/active_scaffold_overrides/_export.csv.erb +11 -8
- data/app/views/active_scaffold_overrides/_export_columns_form.html.erb +23 -0
- data/app/views/active_scaffold_overrides/_export_download_options.html.erb +25 -0
- data/app/views/active_scaffold_overrides/_export_form_body.html.erb +3 -58
- data/app/views/active_scaffold_overrides/_export_options_form.html.erb +13 -0
- data/app/views/active_scaffold_overrides/_show_export.html.erb +13 -8
- data/app/views/active_scaffold_overrides/show_export.html.erb +1 -1
- data/lib/active_scaffold/actions/export.rb +83 -64
- data/lib/active_scaffold/config/export.rb +41 -32
- data/lib/active_scaffold/helpers/export_helpers.rb +25 -21
- data/lib/active_scaffold_export/column.rb +3 -0
- data/lib/active_scaffold_export/engine.rb +10 -2
- data/lib/active_scaffold_export/extensions.rb +16 -0
- data/lib/active_scaffold_export/version.rb +3 -1
- data/lib/active_scaffold_export.rb +5 -17
- metadata +22 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8b0105b59e85b77f8dd190d66cfd38a265cf0b458483945ce153fce6ac0ff3d2
|
|
4
|
+
data.tar.gz: 619c410bf3d66ff343149ca3ca6b13581b7d73f939f41de75186326e5642d675
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5eccbdb3e36488d2886e3a9a60b7dc783ed1fb5aecd043a6d9800261b94340e8a2fe154ff3d02b397d62f1583e9fd24782ac44391ed28aead50df95e696d32ae
|
|
7
|
+
data.tar.gz: 11308e23b14071f64e59df2887ae41eb9eff5790d09c1e760d64828a9fcbf39c99caa8dd6d3f23d4e920f0f9731e81c0a0d244209670af4292955b94e1f2a127
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
<%
|
|
2
|
-
require 'csv'
|
|
2
|
+
require 'csv'
|
|
3
3
|
|
|
4
4
|
fcsv_options = {
|
|
5
|
-
:
|
|
6
|
-
:
|
|
7
|
-
:
|
|
8
|
-
:
|
|
5
|
+
row_sep: "\n",
|
|
6
|
+
col_sep: params[:delimiter],
|
|
7
|
+
force_quotes: @export_config.force_quotes,
|
|
8
|
+
headers: @export_columns.collect { |column| format_export_column_header_name(column) }
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
data = CSV.generate(**fcsv_options) do |csv|
|
|
12
12
|
csv << fcsv_options[:headers] unless params[:skip_header]
|
|
13
13
|
@records.each do |record|
|
|
14
|
-
csv << @export_columns.collect
|
|
14
|
+
csv << @export_columns.collect do |column|
|
|
15
15
|
get_export_column_value(record, column, :csv)&.first
|
|
16
|
-
|
|
16
|
+
end
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
|
-
|
|
19
|
+
-%>
|
|
20
|
+
<%# CSV is not HTML; it must bypass Action View's HTML escaping. %>
|
|
21
|
+
<%= data.html_safe # rubocop:disable Rails/OutputSafety
|
|
22
|
+
-%>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<%= as_element :form_element, class: 'form-element' do %>
|
|
2
|
+
<%
|
|
3
|
+
columns = export_columns_names(action_columns: true).visible_columns
|
|
4
|
+
selected_columns = columns.map(&:name).reject do |name|
|
|
5
|
+
export_config.default_deselected_columns.include?(name)
|
|
6
|
+
end
|
|
7
|
+
content = active_scaffold_checkbox_list(
|
|
8
|
+
nil,
|
|
9
|
+
columns.map { |column| [column_heading_label(column), column.name] },
|
|
10
|
+
selected_columns,
|
|
11
|
+
{
|
|
12
|
+
name: 'export_columns',
|
|
13
|
+
id: "#{element_form_id(action: :export)}-columns",
|
|
14
|
+
class: 'columns'
|
|
15
|
+
},
|
|
16
|
+
ui_options: {
|
|
17
|
+
draggable_lists: export_config.draggable,
|
|
18
|
+
item_options: {class: 'sortable'}
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
%>
|
|
22
|
+
<%= form_attribute_html(nil, as_(:columns_for_export), content, nil, {}) %>
|
|
23
|
+
<% end %>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<% if export_config.allow_full_download %>
|
|
2
|
+
<%= as_element :form_element, class: 'form-element' do %>
|
|
3
|
+
<%
|
|
4
|
+
content = [
|
|
5
|
+
[radio_button_tag('full_download', false, !export_config.default_full_download), as_(:this_page)],
|
|
6
|
+
[radio_button_tag('full_download', true, export_config.default_full_download), as_(:all_pages)]
|
|
7
|
+
].map { |option| content_tag(:label, safe_join(option, ' ')) }
|
|
8
|
+
%>
|
|
9
|
+
<%= form_attribute_html(nil, as_(:export_pages), safe_join(content), nil, {}) %>
|
|
10
|
+
<% end %>
|
|
11
|
+
<% end %>
|
|
12
|
+
|
|
13
|
+
<% if export_config.formats.many? %>
|
|
14
|
+
<%= as_element :form_element, class: 'form-element' do %>
|
|
15
|
+
<%
|
|
16
|
+
content = export_config.formats.map do |format|
|
|
17
|
+
radio = radio_button_tag('format', format, export_config.default_file_format.to_sym == format)
|
|
18
|
+
content_tag(:label, safe_join([radio, format.upcase.to_s], ' '))
|
|
19
|
+
end
|
|
20
|
+
%>
|
|
21
|
+
<%= form_attribute_html(nil, as_(:export_format), safe_join(content), nil, {}) %>
|
|
22
|
+
<% end %>
|
|
23
|
+
<% else %>
|
|
24
|
+
<%= hidden_field_tag('format', export_config.formats[0]) %>
|
|
25
|
+
<% end %>
|
|
@@ -1,61 +1,6 @@
|
|
|
1
1
|
<% export_config = active_scaffold_config.export %>
|
|
2
2
|
<%= as_element :fields_container, class: 'form' do %>
|
|
3
|
-
<%=
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
selected_columns = columns.map(&:name).reject { |name| export_config.default_deselected_columns.include?(name) }
|
|
7
|
-
content = active_scaffold_checkbox_list(
|
|
8
|
-
nil,
|
|
9
|
-
columns.map { |column| [column_heading_label(column), column.name] },
|
|
10
|
-
selected_columns,
|
|
11
|
-
{
|
|
12
|
-
name: 'export_columns',
|
|
13
|
-
id: "#{element_form_id(action: :export)}-columns",
|
|
14
|
-
class: 'columns'
|
|
15
|
-
},
|
|
16
|
-
ui_options: {draggable_lists: export_config.draggable, item_options: {class: 'sortable'}}
|
|
17
|
-
)
|
|
18
|
-
%>
|
|
19
|
-
<%= form_attribute_html(nil, as_(:columns_for_export), content, nil, {}) %>
|
|
20
|
-
<% end %>
|
|
21
|
-
|
|
22
|
-
<%= as_element :form_element, class: 'form-element' do %>
|
|
23
|
-
<%
|
|
24
|
-
content = export_options.map do |row_options|
|
|
25
|
-
row_html = row_options.map do |(option, label)|
|
|
26
|
-
as_element(:export_option) do
|
|
27
|
-
label ? content_tag(:label, safe_join([option, label.is_a?(Symbol) ? as_(label) : label], ' ')) : option
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
as_element :export_option_row, safe_join(row_html)
|
|
31
|
-
end
|
|
32
|
-
%>
|
|
33
|
-
<%= form_attribute_html(nil, as_(:export_options), safe_join(content), nil, {}) %>
|
|
34
|
-
<% end %>
|
|
35
|
-
|
|
36
|
-
<% if export_config.allow_full_download %>
|
|
37
|
-
<%= as_element :form_element, class: 'form-element' do %>
|
|
38
|
-
<%
|
|
39
|
-
content = [
|
|
40
|
-
[radio_button_tag('full_download', false, !export_config.default_full_download), as_(:this_page)],
|
|
41
|
-
[radio_button_tag('full_download', true, export_config.default_full_download), as_(:all_pages)]
|
|
42
|
-
].map { |option| content_tag(:label, safe_join(option, ' ')) }
|
|
43
|
-
%>
|
|
44
|
-
<%= form_attribute_html(nil, as_(:export_pages), safe_join(content), nil, {}) %>
|
|
45
|
-
<% end %>
|
|
46
|
-
<% end %>
|
|
47
|
-
|
|
48
|
-
<% if export_config.formats.many? %>
|
|
49
|
-
<%= as_element :form_element, class: 'form-element' do %>
|
|
50
|
-
<%
|
|
51
|
-
content = export_config.formats.map do |format|
|
|
52
|
-
radio = radio_button_tag('format', format, export_config.default_file_format.to_sym == format)
|
|
53
|
-
content_tag(:label, safe_join([radio, format.upcase.to_s], ' '))
|
|
54
|
-
end
|
|
55
|
-
%>
|
|
56
|
-
<%= form_attribute_html(nil, as_(:export_format), safe_join(content), nil, {}) %>
|
|
57
|
-
<% end %>
|
|
58
|
-
<% else %>
|
|
59
|
-
<%= hidden_field_tag('format', export_config.formats[0]) %>
|
|
60
|
-
<% end %>
|
|
3
|
+
<%= render 'export_columns_form', export_config: export_config %>
|
|
4
|
+
<%= render 'export_options_form' %>
|
|
5
|
+
<%= render 'export_download_options', export_config: export_config %>
|
|
61
6
|
<% end %>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<%= as_element :form_element, class: 'form-element' do %>
|
|
2
|
+
<%
|
|
3
|
+
content = export_options.map do |row_options|
|
|
4
|
+
row_html = row_options.map do |(option, label)|
|
|
5
|
+
translated_label = label.is_a?(Symbol) ? as_(label) : label
|
|
6
|
+
option_with_label = label ? safe_join([option, translated_label], ' ') : option
|
|
7
|
+
as_element(:export_option, option_with_label)
|
|
8
|
+
end
|
|
9
|
+
as_element :export_option_row, safe_join(row_html)
|
|
10
|
+
end
|
|
11
|
+
%>
|
|
12
|
+
<%= form_attribute_html(nil, as_(:export_options), safe_join(content), nil, {}) %>
|
|
13
|
+
<% end %>
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
<%
|
|
2
|
+
form_locals = {
|
|
3
|
+
xhr: false,
|
|
4
|
+
form_action: :export,
|
|
5
|
+
url_options: params_for(action: :export),
|
|
6
|
+
method: :post,
|
|
7
|
+
cancel_link: true,
|
|
8
|
+
headline: as_(:export),
|
|
9
|
+
body_partial: 'export_form_body',
|
|
10
|
+
loading: false
|
|
11
|
+
}
|
|
12
|
+
%>
|
|
13
|
+
<%= render partial: 'base_form', locals: form_locals %>
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffold::Actions
|
|
2
4
|
module Export
|
|
3
5
|
def self.included(base)
|
|
4
|
-
base.before_action :export_authorized_filter, :
|
|
5
|
-
base.before_action :show_export_authorized_filter, :
|
|
6
|
+
base.before_action :export_authorized_filter, only: [:export]
|
|
7
|
+
base.before_action :show_export_authorized_filter, only: [:show_export]
|
|
6
8
|
base.helper_method :export_columns_names
|
|
7
9
|
end
|
|
8
10
|
|
|
@@ -22,10 +24,10 @@ module ActiveScaffold::Actions
|
|
|
22
24
|
export_config = active_scaffold_config.export
|
|
23
25
|
if params[:export_columns].nil?
|
|
24
26
|
options = {
|
|
25
|
-
:
|
|
26
|
-
:
|
|
27
|
-
:
|
|
28
|
-
:
|
|
27
|
+
export_columns: export_columns_names.map(&:to_s),
|
|
28
|
+
full_download: export_config.default_full_download.to_s,
|
|
29
|
+
delimiter: export_config.default_delimiter,
|
|
30
|
+
skip_header: export_config.default_skip_header.to_s
|
|
29
31
|
}
|
|
30
32
|
params.merge!(options)
|
|
31
33
|
end
|
|
@@ -39,14 +41,7 @@ module ActiveScaffold::Actions
|
|
|
39
41
|
@list_columns = @export_columns
|
|
40
42
|
@page = find_page(find_options_for_export)
|
|
41
43
|
|
|
42
|
-
# this is required if you want this to work with IE
|
|
43
|
-
if request.env['HTTP_USER_AGENT'] =~ /msie/i
|
|
44
|
-
response.headers['pragma'] = "public"
|
|
45
|
-
response.headers['cache-control'] = "no-cache, must-revalidate, post-check=0, pre-check=0"
|
|
46
|
-
response.headers['expires'] = "0"
|
|
47
|
-
end
|
|
48
44
|
response.headers['content-disposition'] = "attachment; filename=#{export_file_name}"
|
|
49
|
-
|
|
50
45
|
respond_to_action(:export)
|
|
51
46
|
end
|
|
52
47
|
|
|
@@ -59,7 +54,7 @@ module ActiveScaffold::Actions
|
|
|
59
54
|
self.response_body = Enumerator.new do |y|
|
|
60
55
|
find_items_for_export do |records|
|
|
61
56
|
@records = records
|
|
62
|
-
str = render_to_string :
|
|
57
|
+
str = render_to_string partial: 'export', layout: false, formats: [:csv]
|
|
63
58
|
y << str
|
|
64
59
|
params[:skip_header] = 'true' # skip header on the next run
|
|
65
60
|
end
|
|
@@ -71,62 +66,86 @@ module ActiveScaffold::Actions
|
|
|
71
66
|
response.headers['last-modified'] = '0'
|
|
72
67
|
pkg = Axlsx::Package.new
|
|
73
68
|
pkg.workbook.add_worksheet(name: worksheet_name) do |sheet|
|
|
74
|
-
|
|
75
|
-
widths = @export_columns.map.with_index { |column, i| styles.dig(i, :width) || column.export_options&.dig(:xlsx, :width) || :auto }
|
|
76
|
-
unless params[:skip_header]
|
|
77
|
-
styles.map! { |style| pkg.workbook.styles.add_style style if style }
|
|
78
|
-
sheet.add_row(@export_columns.collect { |column| view_context.format_export_column_header_name(column) }, style: styles, widths: widths)
|
|
79
|
-
end
|
|
80
|
-
find_items_for_export do |records|
|
|
81
|
-
records.each do |record|
|
|
82
|
-
row = []
|
|
83
|
-
styles = []
|
|
84
|
-
@export_columns.each do |column|
|
|
85
|
-
data, style = view_context.get_export_column_value(record, column, :xlsx)
|
|
86
|
-
style = pkg.workbook.styles.add_style style if style
|
|
87
|
-
row << data
|
|
88
|
-
styles << style
|
|
89
|
-
end
|
|
90
|
-
sheet.add_row row, style: styles, widths: widths
|
|
91
|
-
end
|
|
92
|
-
end
|
|
69
|
+
populate_xlsx_sheet(pkg, sheet)
|
|
93
70
|
end
|
|
94
71
|
customize_xlsx(pkg)
|
|
95
|
-
|
|
72
|
+
# Rows added after creating the stream are not included due to an Axlsx limitation.
|
|
73
|
+
stream = pkg.to_stream
|
|
96
74
|
self.response_body = Enumerator.new do |y|
|
|
97
75
|
y << stream.read
|
|
98
76
|
end
|
|
99
77
|
end
|
|
100
78
|
|
|
101
|
-
def
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
79
|
+
def populate_xlsx_sheet(package, sheet)
|
|
80
|
+
header_styles = @export_columns.map do |column|
|
|
81
|
+
view_context.export_column_header_style(column, :xlsx)
|
|
82
|
+
end
|
|
83
|
+
widths = xlsx_column_widths(header_styles)
|
|
84
|
+
add_xlsx_header(package, sheet, header_styles, widths) unless params[:skip_header]
|
|
85
|
+
|
|
86
|
+
find_items_for_export do |records|
|
|
87
|
+
records.each { |record| add_xlsx_record(package, sheet, record, widths) }
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def xlsx_column_widths(header_styles)
|
|
92
|
+
@export_columns.map.with_index do |column, index|
|
|
93
|
+
header_styles.dig(index, :width) || column.export_options&.dig(:xlsx, :width) || :auto
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def add_xlsx_header(package, sheet, header_styles, widths)
|
|
98
|
+
styles = header_styles.map { |style| package.workbook.styles.add_style(style) if style }
|
|
99
|
+
headers = @export_columns.map { |column| view_context.format_export_column_header_name(column) }
|
|
100
|
+
sheet.add_row(headers, style: styles, widths: widths)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def add_xlsx_record(package, sheet, record, widths)
|
|
104
|
+
cells = @export_columns.map do |column|
|
|
105
|
+
data, style = view_context.get_export_column_value(record, column, :xlsx)
|
|
106
|
+
style = package.workbook.styles.add_style(style) if style
|
|
107
|
+
[data, style]
|
|
108
|
+
end
|
|
109
|
+
sheet.add_row(cells.map(&:first), style: cells.map(&:last), widths: widths)
|
|
105
110
|
end
|
|
106
111
|
|
|
107
|
-
def
|
|
112
|
+
def worksheet_name(options = {})
|
|
113
|
+
active_scaffold_config.label
|
|
114
|
+
.gsub(/[#{Regexp.quote Axlsx::WORKSHEET_NAME_FORBIDDEN_CHARS.join}]/, options[:replace] || '-')
|
|
115
|
+
.truncate(Axlsx::WORKSHEET_MAX_NAME_LENGTH, options)
|
|
108
116
|
end
|
|
109
117
|
|
|
118
|
+
def customize_xlsx(package); end
|
|
119
|
+
|
|
110
120
|
def export_columns
|
|
111
121
|
return @export_columns if defined? @export_columns
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
122
|
+
|
|
123
|
+
selected_columns = selected_export_columns
|
|
124
|
+
sorting = active_scaffold_config.list.user.sorting || active_scaffold_config.list.sorting
|
|
125
|
+
sorting_columns = sorting.reject { |column, _| selected_columns.include?(column.name) }.map(&:first)
|
|
126
|
+
@export_columns = selected_columns.map { |column| active_scaffold_config.columns[column] }
|
|
127
|
+
@export_columns.concat(sorting_columns)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def selected_export_columns
|
|
117
131
|
available_columns = export_columns_names.map(&:to_s)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
col
|
|
132
|
+
requested_export_columns.uniq.select do |column|
|
|
133
|
+
available_columns.include?(column) &&
|
|
134
|
+
active_scaffold_config.model.authorized_for?(crud_type: :read, column: column.to_sym)
|
|
122
135
|
end
|
|
123
|
-
sorting = active_scaffold_config.list.user.sorting || active_scaffold_config.list.sorting
|
|
124
|
-
sorting_columns = sorting.reject { |col, _| @export_columns.include?(col.name) }.map(&:first)
|
|
125
|
-
@export_columns.map! { |col| active_scaffold_config.columns[col] }
|
|
126
|
-
@export_columns += sorting_columns
|
|
127
136
|
end
|
|
128
137
|
|
|
129
|
-
def
|
|
138
|
+
def requested_export_columns
|
|
139
|
+
if params[:export_columns].respond_to?(:each_pair)
|
|
140
|
+
params[:export_columns].each_pair.filter_map do |name, selected|
|
|
141
|
+
name.to_s if selected.present?
|
|
142
|
+
end
|
|
143
|
+
else
|
|
144
|
+
Array(params[:export_columns]).compact_blank.map(&:to_s)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def export_columns_names(action_columns: false)
|
|
130
149
|
if grouped_search?
|
|
131
150
|
list_columns_names.then do |cols|
|
|
132
151
|
action_columns ? active_scaffold_config.build_action_columns(:export, cols) : cols
|
|
@@ -138,7 +157,7 @@ module ActiveScaffold::Actions
|
|
|
138
157
|
|
|
139
158
|
def find_options_for_export
|
|
140
159
|
find_options = {sorting: active_scaffold_config.list.sorting, pagination: true}
|
|
141
|
-
do_search
|
|
160
|
+
do_search if respond_to? :do_search, true
|
|
142
161
|
|
|
143
162
|
if params[:full_download] == 'true'
|
|
144
163
|
find_options.merge!(per_page: 3000, page: 1)
|
|
@@ -153,7 +172,7 @@ module ActiveScaffold::Actions
|
|
|
153
172
|
end
|
|
154
173
|
|
|
155
174
|
# The actual algorithm to do the export
|
|
156
|
-
def find_items_for_export(&
|
|
175
|
+
def find_items_for_export(&)
|
|
157
176
|
if params[:full_download] == 'true'
|
|
158
177
|
@page.pager.each do |page|
|
|
159
178
|
yield page.items
|
|
@@ -166,21 +185,22 @@ module ActiveScaffold::Actions
|
|
|
166
185
|
# The default name of the downloaded file.
|
|
167
186
|
# You may override the method to specify your own file name generation.
|
|
168
187
|
def export_file_name
|
|
169
|
-
filename =
|
|
188
|
+
filename = controller_name.dup
|
|
170
189
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
190
|
+
filename <<
|
|
191
|
+
if params[:format] && active_scaffold_config.export.formats.map(&:to_s).include?(params[:format])
|
|
192
|
+
".#{params[:format]}"
|
|
193
|
+
else
|
|
194
|
+
".#{active_scaffold_config.export.default_file_format}"
|
|
195
|
+
end
|
|
176
196
|
|
|
177
|
-
|
|
197
|
+
filename
|
|
178
198
|
end
|
|
179
199
|
|
|
180
200
|
# The default security delegates to ActiveRecordPermissions.
|
|
181
201
|
# You may override the method to customize.
|
|
182
202
|
def export_authorized?
|
|
183
|
-
authorized_for?(:
|
|
203
|
+
authorized_for?(action: :read)
|
|
184
204
|
end
|
|
185
205
|
|
|
186
206
|
def export_authorized_filter
|
|
@@ -198,6 +218,5 @@ module ActiveScaffold::Actions
|
|
|
198
218
|
def export_formats
|
|
199
219
|
active_scaffold_config.export.formats
|
|
200
220
|
end
|
|
201
|
-
|
|
202
221
|
end
|
|
203
222
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffold::Config
|
|
2
4
|
class Export < ActiveScaffold::Config::Form
|
|
3
5
|
self.crud_type = :read
|
|
@@ -5,6 +7,7 @@ module ActiveScaffold::Config
|
|
|
5
7
|
def initialize(core_config)
|
|
6
8
|
super
|
|
7
9
|
@core = core_config
|
|
10
|
+
@link = nil
|
|
8
11
|
self.show_form = self.class.show_form
|
|
9
12
|
self.allow_full_download = self.class.allow_full_download
|
|
10
13
|
self.force_quotes = self.class.force_quotes
|
|
@@ -13,68 +16,72 @@ module ActiveScaffold::Config
|
|
|
13
16
|
self.default_skip_header = self.class.default_skip_header
|
|
14
17
|
self.default_file_format = self.class.default_file_format
|
|
15
18
|
self.draggable = self.class.draggable
|
|
16
|
-
@formats = [
|
|
19
|
+
@formats = %i[csv xlsx]
|
|
17
20
|
end
|
|
18
21
|
|
|
19
22
|
# global level configuration
|
|
20
23
|
# --------------------------
|
|
21
24
|
# the ActionLink for this action
|
|
22
|
-
cattr_accessor :link
|
|
23
|
-
|
|
25
|
+
cattr_accessor :link,
|
|
26
|
+
instance_accessor: false,
|
|
27
|
+
default: ActiveScaffold::DataStructures::ActionLink.new(
|
|
28
|
+
'show_export', label: :export, type: :collection, security_method: :export_authorized?
|
|
29
|
+
)
|
|
24
30
|
|
|
25
31
|
# configures where the plugin itself is located. there is no instance version of this.
|
|
26
|
-
cattr_accessor :plugin_directory
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
cattr_accessor :plugin_directory,
|
|
33
|
+
instance_accessor: false,
|
|
34
|
+
default: File.expand_path(__FILE__).match(%r{(^.*)/lib/active_scaffold/config/export.rb})[1]
|
|
29
35
|
|
|
30
36
|
# instance-level configuration
|
|
31
37
|
# ----------------------------
|
|
32
38
|
|
|
33
39
|
attr_writer :link
|
|
40
|
+
|
|
34
41
|
def link
|
|
35
|
-
@link ||=
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
@link ||=
|
|
43
|
+
if show_form
|
|
44
|
+
self.class.link.clone
|
|
45
|
+
else
|
|
46
|
+
ActiveScaffold::DataStructures::ActionLink.new(
|
|
47
|
+
'export', label: :export, type: :collection, inline: false, security_method: :export_authorized?
|
|
48
|
+
)
|
|
49
|
+
end
|
|
40
50
|
end
|
|
41
51
|
|
|
42
|
-
# whether open a form to allow selecting columns and format settings,
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
# whether open a form to allow selecting columns and format settings,
|
|
53
|
+
# or export directly with the defined settings in the controller
|
|
54
|
+
cattr_accessor :show_form, instance_accessor: false, default: true
|
|
45
55
|
|
|
46
56
|
# whether user can ask for full or page export, or default is forced
|
|
47
|
-
cattr_accessor :allow_full_download, instance_accessor: false
|
|
48
|
-
@@allow_full_download = true
|
|
57
|
+
cattr_accessor :allow_full_download, instance_accessor: false, default: true
|
|
49
58
|
|
|
50
59
|
# force_quotes option for CSV library
|
|
51
|
-
cattr_accessor :force_quotes, instance_accessor: false
|
|
52
|
-
@@force_quotes = false
|
|
60
|
+
cattr_accessor :force_quotes, instance_accessor: false, default: false
|
|
53
61
|
|
|
54
62
|
# default setting for full export or page export, it can be changed in the form if show_form is enabled
|
|
55
|
-
cattr_accessor :default_full_download, instance_accessor: false
|
|
56
|
-
@@default_full_download = true
|
|
63
|
+
cattr_accessor :default_full_download, instance_accessor: false, default: true
|
|
57
64
|
|
|
58
65
|
# default column separator for CSV, it can be changed in the form if show_form is enabled
|
|
59
|
-
cattr_accessor :default_delimiter, instance_accessor: false
|
|
60
|
-
@@default_delimiter = ','
|
|
66
|
+
cattr_accessor :default_delimiter, instance_accessor: false, default: ','
|
|
61
67
|
|
|
62
|
-
# wheter export a header (false) or skip exporting a header (true),
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
# wheter export a header (false) or skip exporting a header (true),
|
|
69
|
+
# it can be changed in the form if show_form is enabled
|
|
70
|
+
cattr_accessor :default_skip_header, instance_accessor: false, default: false
|
|
65
71
|
|
|
66
72
|
# default file format to export, it can be changed in the form if show_form is enabled
|
|
67
|
-
cattr_accessor :default_file_format,
|
|
68
|
-
|
|
73
|
+
cattr_accessor :default_file_format,
|
|
74
|
+
instance_accessor: false,
|
|
75
|
+
default: Gem::Specification.find_all_by_name('caxlsx').any? ? 'xlsx' : 'csv'
|
|
69
76
|
|
|
70
77
|
# whether selected export columns can be reordered with drag and drop
|
|
71
|
-
cattr_accessor :draggable, instance_accessor: false
|
|
72
|
-
@@draggable = false
|
|
78
|
+
cattr_accessor :draggable, instance_accessor: false, default: false
|
|
73
79
|
|
|
74
80
|
# instance-level configuration
|
|
75
81
|
# ----------------------------
|
|
76
82
|
|
|
77
|
-
# whether open a form to allow selecting columns and format settings,
|
|
83
|
+
# whether open a form to allow selecting columns and format settings,
|
|
84
|
+
# or export directly with the defined settings in the controller
|
|
78
85
|
attr_accessor :show_form
|
|
79
86
|
|
|
80
87
|
# whether user can ask for full or page export, or default is forced
|
|
@@ -89,7 +96,8 @@ module ActiveScaffold::Config
|
|
|
89
96
|
# default column separator for CSV, it can be changed in the form if show_form is enabled
|
|
90
97
|
attr_accessor :default_delimiter
|
|
91
98
|
|
|
92
|
-
# wheter export a header (false) or skip exporting a header (true),
|
|
99
|
+
# wheter export a header (false) or skip exporting a header (true),
|
|
100
|
+
# it can be changed in the form if show_form is enabled
|
|
93
101
|
attr_accessor :default_skip_header
|
|
94
102
|
|
|
95
103
|
# default file format to export, it can be changed in the form if show_form is enabled
|
|
@@ -115,7 +123,7 @@ module ActiveScaffold::Config
|
|
|
115
123
|
|
|
116
124
|
UserSettings.class_eval do
|
|
117
125
|
user_attr :show_form, :allow_full_download, :force_quotes, :default_file_format,
|
|
118
|
-
:default_delimiter, :default_skip_header
|
|
126
|
+
:default_delimiter, :default_skip_header
|
|
119
127
|
|
|
120
128
|
def default_deselected_columns=(val)
|
|
121
129
|
@default_deselected_columns = ActiveScaffold::DataStructures::Set.new(*val)
|
|
@@ -125,6 +133,7 @@ module ActiveScaffold::Config
|
|
|
125
133
|
if @default_deselected_columns.nil? && @conf.default_deselected_columns
|
|
126
134
|
return @conf.default_deselected_columns
|
|
127
135
|
end
|
|
136
|
+
|
|
128
137
|
@default_deselected_columns ||= ActiveScaffold::DataStructures::Set.new
|
|
129
138
|
end
|
|
130
139
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffold
|
|
2
4
|
module Helpers
|
|
3
5
|
# Helpers that assist with the rendering of a Export Column
|
|
@@ -11,28 +13,31 @@ module ActiveScaffold
|
|
|
11
13
|
# format_plural_association_export_column(association_records)
|
|
12
14
|
def get_export_column_value(record, column, format)
|
|
13
15
|
return unless record.authorized_for?(crud_type: :read, column: column.name)
|
|
16
|
+
|
|
17
|
+
value, options = export_column_value(record, column, format)
|
|
18
|
+
[value, options || export_column_style(column, format)]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def export_column_value(record, column, format)
|
|
14
22
|
if (method = export_column_override(column))
|
|
15
|
-
|
|
16
|
-
[value, options || export_column_style(column, format)]
|
|
23
|
+
send(method, record, format)
|
|
17
24
|
elsif column.list_ui && (method = override_export_ui(column.list_ui))
|
|
18
|
-
|
|
19
|
-
[value, options || export_column_style(column, format)]
|
|
25
|
+
send(method, record, column, format, ui_options: column.list_ui_options || column.options)
|
|
20
26
|
elsif grouped_search? && column == search_group_column && search_group_function
|
|
21
|
-
[format_grouped_search_column(record[column.name], column.options),
|
|
27
|
+
[format_grouped_search_column(record[column.name], column.options), nil]
|
|
22
28
|
else
|
|
23
|
-
|
|
29
|
+
[format_export_record_value(record, column, format), nil]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def format_export_record_value(record, column, format)
|
|
34
|
+
raw_value = record.send(column.name)
|
|
35
|
+
return format_export_column(raw_value, format) if column.association.nil? || column_empty?(raw_value)
|
|
24
36
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if column.association.collection?
|
|
30
|
-
format_plural_association_export_column(raw_value, format)
|
|
31
|
-
else
|
|
32
|
-
format_singular_association_export_column(raw_value, format)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
[value, export_column_style(column, format)]
|
|
37
|
+
if column.association.collection?
|
|
38
|
+
format_plural_association_export_column(raw_value, format)
|
|
39
|
+
else
|
|
40
|
+
format_singular_association_export_column(raw_value, format)
|
|
36
41
|
end
|
|
37
42
|
end
|
|
38
43
|
|
|
@@ -63,7 +68,7 @@ module ActiveScaffold
|
|
|
63
68
|
if column_empty?(column_value)
|
|
64
69
|
active_scaffold_config.list.empty_field_text
|
|
65
70
|
elsif column_value.is_a?(Time) || column_value.is_a?(Date)
|
|
66
|
-
l(column_value, :
|
|
71
|
+
l(column_value, format: :default)
|
|
67
72
|
elsif [FalseClass, TrueClass].include?(column_value.class)
|
|
68
73
|
as_(column_value.to_s.to_sym)
|
|
69
74
|
else
|
|
@@ -76,7 +81,7 @@ module ActiveScaffold
|
|
|
76
81
|
end
|
|
77
82
|
|
|
78
83
|
def format_plural_association_export_column(association_records, format)
|
|
79
|
-
firsts = association_records.first(4).collect
|
|
84
|
+
firsts = association_records.first(4).collect(&:to_label)
|
|
80
85
|
firsts[3] = ' ' if firsts.length == 4
|
|
81
86
|
format_value(firsts.join(','))
|
|
82
87
|
end
|
|
@@ -90,7 +95,7 @@ module ActiveScaffold
|
|
|
90
95
|
## This helper can be overridden to change the style of the headers
|
|
91
96
|
def export_column_header_style(column, format)
|
|
92
97
|
if format == :xlsx
|
|
93
|
-
@default_style ||= {sz: 11, b: true, bg_color:
|
|
98
|
+
@default_style ||= {sz: 11, b: true, bg_color: '69B5EF', fg_color: 'FF', alignment: {horizontal: :center}}
|
|
94
99
|
end
|
|
95
100
|
end
|
|
96
101
|
|
|
@@ -102,7 +107,6 @@ module ActiveScaffold
|
|
|
102
107
|
[text_field_tag('delimiter', export_config.default_delimiter, size: 1, maxlength: 1, id: nil), :delimiter]
|
|
103
108
|
]
|
|
104
109
|
end
|
|
105
|
-
|
|
106
110
|
end
|
|
107
111
|
end
|
|
108
112
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffoldExport
|
|
2
4
|
class Engine < ::Rails::Engine
|
|
3
5
|
initializer 'active_scaffold_export.routes' do
|
|
@@ -14,9 +16,15 @@ module ActiveScaffoldExport
|
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
initializer 'active_scaffold_export.extensions' do
|
|
17
|
-
ActiveScaffold::DataStructures::Column.
|
|
19
|
+
ActiveScaffold::DataStructures::Column.include ActiveScaffoldExport::Column
|
|
18
20
|
if defined? ActiveScaffold::DataStructures::ProxyColumn
|
|
19
|
-
ActiveScaffold::DataStructures::ProxyColumn.
|
|
21
|
+
ActiveScaffold::DataStructures::ProxyColumn.include ActiveScaffoldExport::Column
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
initializer 'active_scaffold_export.action_view' do
|
|
26
|
+
ActiveSupport.on_load :action_view do
|
|
27
|
+
include ActiveScaffold::Helpers::ExportHelpers
|
|
20
28
|
end
|
|
21
29
|
end
|
|
22
30
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# ActiveScaffold extension namespaces provided by the export plugin.
|
|
4
|
+
module ActiveScaffold
|
|
5
|
+
module Actions
|
|
6
|
+
ActiveScaffold.autoload_subdir('actions', self, File.expand_path('..', __dir__))
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module Config
|
|
10
|
+
ActiveScaffold.autoload_subdir('config', self, File.expand_path('..', __dir__))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module Helpers
|
|
14
|
+
ActiveScaffold.autoload_subdir('helpers', self, File.expand_path('..', __dir__))
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -1,28 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'active_scaffold_export/engine'
|
|
4
|
+
require 'active_scaffold_export/extensions'
|
|
2
5
|
require 'active_scaffold_export/version'
|
|
3
6
|
|
|
4
7
|
module ActiveScaffoldExport
|
|
5
8
|
def self.root
|
|
6
|
-
File.dirname(__FILE__)
|
|
7
|
-
end
|
|
8
|
-
autoload 'Column', 'active_scaffold_export/column.rb'
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
module ActiveScaffold
|
|
12
|
-
module Actions
|
|
13
|
-
ActiveScaffold.autoload_subdir('actions', self, File.dirname(__FILE__))
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
module Config
|
|
17
|
-
ActiveScaffold.autoload_subdir('config', self, File.dirname(__FILE__))
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
module Helpers
|
|
21
|
-
ActiveScaffold.autoload_subdir('helpers', self, File.dirname(__FILE__))
|
|
9
|
+
"#{File.dirname(__FILE__)}/.."
|
|
22
10
|
end
|
|
11
|
+
autoload :Column, 'active_scaffold_export/column.rb'
|
|
23
12
|
end
|
|
24
13
|
|
|
25
|
-
ActionView::Base.send(:include, ActiveScaffold::Helpers::ExportHelpers)
|
|
26
14
|
ActiveScaffold.stylesheets << 'active_scaffold_export'
|
|
27
15
|
ActiveScaffold.set_element :export_option, tag: :div, attributes: {class: 'export-option'}
|
|
28
16
|
ActiveScaffold.set_element :export_option_row, tag: :div, attributes: {class: 'export-option-row'}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_scaffold_export
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.12.
|
|
4
|
+
version: 3.12.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Volker Hochstein
|
|
@@ -25,6 +25,20 @@ dependencies:
|
|
|
25
25
|
- - ">="
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
27
|
version: 4.4.0
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: csv
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
type: :runtime
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
28
42
|
description: Exporting Records with ActiveScaffold
|
|
29
43
|
email: activescaffold@googlegroups.com
|
|
30
44
|
executables: []
|
|
@@ -39,7 +53,10 @@ files:
|
|
|
39
53
|
- app/assets/stylesheets/active_scaffold_export.css
|
|
40
54
|
- app/assets/stylesheets/export-stylesheet-ie.css
|
|
41
55
|
- app/views/active_scaffold_overrides/_export.csv.erb
|
|
56
|
+
- app/views/active_scaffold_overrides/_export_columns_form.html.erb
|
|
57
|
+
- app/views/active_scaffold_overrides/_export_download_options.html.erb
|
|
42
58
|
- app/views/active_scaffold_overrides/_export_form_body.html.erb
|
|
59
|
+
- app/views/active_scaffold_overrides/_export_options_form.html.erb
|
|
43
60
|
- app/views/active_scaffold_overrides/_show_export.html.erb
|
|
44
61
|
- app/views/active_scaffold_overrides/show_export.html.erb
|
|
45
62
|
- config/locales/en.yml
|
|
@@ -50,11 +67,13 @@ files:
|
|
|
50
67
|
- lib/active_scaffold_export.rb
|
|
51
68
|
- lib/active_scaffold_export/column.rb
|
|
52
69
|
- lib/active_scaffold_export/engine.rb
|
|
70
|
+
- lib/active_scaffold_export/extensions.rb
|
|
53
71
|
- lib/active_scaffold_export/version.rb
|
|
54
72
|
homepage: http://github.com/active_scaffold/active_scaffold_export
|
|
55
73
|
licenses:
|
|
56
74
|
- MIT
|
|
57
|
-
metadata:
|
|
75
|
+
metadata:
|
|
76
|
+
rubygems_mfa_required: 'true'
|
|
58
77
|
rdoc_options: []
|
|
59
78
|
require_paths:
|
|
60
79
|
- lib
|
|
@@ -62,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
62
81
|
requirements:
|
|
63
82
|
- - ">="
|
|
64
83
|
- !ruby/object:Gem::Version
|
|
65
|
-
version: '2
|
|
84
|
+
version: '3.2'
|
|
66
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
86
|
requirements:
|
|
68
87
|
- - ">="
|