active_scaffold_export 3.11.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c5a31084ab9ee69ba6480602feacb14d935f144d26c17b90d3bd4698ceb0053
4
- data.tar.gz: 5c37fc683df4653d2b71cca0ae24f890b8210e45dc13d8cb81515c6b94250358
3
+ metadata.gz: 8b0105b59e85b77f8dd190d66cfd38a265cf0b458483945ce153fce6ac0ff3d2
4
+ data.tar.gz: 619c410bf3d66ff343149ca3ca6b13581b7d73f939f41de75186326e5642d675
5
5
  SHA512:
6
- metadata.gz: 646be1b196f36730cd8331e9f2422227b556398973ad66c97e2ff014215709a6899e219cde633b66b530c37de80d4ba15059a33ad3188e902841e4f7e6402278
7
- data.tar.gz: 5edae73a37d1b5e9caf3e85b0d071f1d3ccadf8ffce4c6adb7f6fecdf5e0d42504c1fc442c30384103f64a400b816f787ca60b64e08e16c169e908f3e971c3fa
6
+ metadata.gz: 5eccbdb3e36488d2886e3a9a60b7dc783ed1fb5aecd043a6d9800261b94340e8a2fe154ff3d02b397d62f1583e9fd24782ac44391ed28aead50df95e696d32ae
7
+ data.tar.gz: 11308e23b14071f64e59df2887ae41eb9eff5790d09c1e760d64828a9fcbf39c99caa8dd6d3f23d4e920f0f9731e81c0a0d244209670af4292955b94e1f2a127
data/README.md CHANGED
@@ -21,11 +21,9 @@ conf.export.default_file_format = 'csv' # or 'xlsx'
21
21
 
22
22
  Read important notes at the bottom about xlsx.
23
23
 
24
- Remember to bundle install.
25
- Add to application.css:
26
- ```
27
- *= require active_scaffold_export
28
- ```
24
+ Remember to run `bundle install`. ActiveScaffold automatically includes the plugin stylesheet; no entry in `application.css` is needed.
25
+
26
+ ActiveScaffold Export 3.12 requires ActiveScaffold 4.4 or newer.
29
27
 
30
28
  Now let's add it to controller, inside active_scaffold config block:
31
29
  ```ruby
@@ -36,9 +34,25 @@ conf.export.columns = %w(name last_name phone address)
36
34
  conf.export.default_deselected_columns = %w(phone address)
37
35
  conf.export.default_delimiter = ";"
38
36
  conf.export.force_quotes = "true"
37
+ # allow users to drag selected columns into export order
38
+ conf.export.draggable = true
39
39
  ```
40
40
  And enjoy happy exporting :)
41
41
 
42
+ ### UI adapter support
43
+
44
+ The export form uses ActiveScaffold 4.4's standard form elements (`fields_container`, `form_element`, and `form_attribute`) and adds two plugin-specific elements:
45
+
46
+ * `export_option` wraps one export option.
47
+ * `export_option_row` groups related options.
48
+
49
+ For example, an adapter can change their classes without overriding the export partial:
50
+
51
+ ```ruby
52
+ ActiveScaffold.add_element_attributes :export_option, class: 'form-check'
53
+ ActiveScaffold.add_element_attributes :export_option_row, class: 'd-flex gap-3'
54
+ ```
55
+
42
56
  ### Configuring
43
57
 
44
58
  There are other options for the action export, explained in the wiki [Export Configuration](https://github.com/activescaffold/active_scaffold_export/wiki/Export-Configuration),
@@ -86,4 +100,3 @@ Export supports grouped search from field_search action. When grouped search is
86
100
  ## Contact
87
101
 
88
102
  For contact, help, support, comments, please use Active Scaffold official mailing list activescaffold@googlegroups.com
89
-
@@ -4,25 +4,11 @@
4
4
  background-repeat: no-repeat;
5
5
  padding-left: 19px;
6
6
  }
7
- .active-scaffold div.show_export-view h3 {
8
- font-weight: bold;
7
+ .active-scaffold .show_export-view .export-option-row {
8
+ display: flex;
9
+ gap: 1em;
9
10
  }
10
- .active-scaffold div.show_export-view div.separator {
11
- clear: both;
12
- padding: .5em;
13
- }
14
- .active-scaffold div.show_export-view div.options div.separator {
15
- padding: 0;
16
- }
17
- .active-scaffold div.show_export-view div.options div.checkbox-wrapper {
18
- margin-bottom: .5em;
19
- }
20
- .active-scaffold div.show_export-view div div.checkbox-wrapper {
21
- min-width: 20%;
22
- margin-bottom: .25em;
23
- float: left;
24
- }
25
- .active-scaffold div.show_export-view label #delimiter {
11
+ .active-scaffold .show_export-view label [name=delimiter] {
26
12
  font-family: monospace;
27
13
  }
28
14
 
@@ -1,19 +1,22 @@
1
1
  <%
2
- require 'csv' if RUBY_VERSION >= "1.9"
2
+ require 'csv'
3
3
 
4
4
  fcsv_options = {
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) }
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 { |column|
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
- -%><%= data.html_safe -%>
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,34 +1,6 @@
1
- <h5><%=as_(:columns_for_export)%></h5>
2
- <%# TODO: use JS asset instead of inline JS %>
3
- <%= link_to as_(:select_all), '#', onclick: 'jQuery(".columnCheckbox").prop("checked", true); return false', class: 'active-scaffold-footer' %>
4
- |
5
- <%= link_to as_(:select_none), '#', onclick: 'jQuery(".columnCheckbox").prop("checked", false); return false', class: 'active-scaffold-footer' %>
6
- <div class="columns checkbox-list">
7
- <% export_columns_names(true).each_column do |column| -%>
8
- <div class="column checkbox-wrapper">
9
- <label>
10
- <%= check_box_tag("export_columns[#{column.name}]", 1, !active_scaffold_config.export.default_deselected_columns.include?(column.name), :class => 'columnCheckbox') %>
11
- <%= column_heading_label(column) %>
12
- </label>
13
- </div>
14
- <% end -%>
15
- &nbsp;
16
- </div>
17
- <div class="separator"></div>
18
- <h5><%=as_(:options)%></h5>
19
- <div class="options checkbox-list">
20
- <% export_options.each do |row_optionss| %>
21
- <% row_optionss.each do |(option, label)| %>
22
- <div class="option checkbox-wrapper">
23
- <% if label %>
24
- <%= content_tag(:label, safe_join([option, label.is_a?(Symbol) ? as_(label) : label], ' ')) %>
25
- <% else %>
26
- <%= option %>
27
- <% end %>
28
- </div>
29
- <% end %>
30
- <div class="separator"></div>
31
- <% end %>
32
- &nbsp;
33
- </div>
34
- <div class="separator"></div>
1
+ <% export_config = active_scaffold_config.export %>
2
+ <%= as_element :fields_container, class: 'form' do %>
3
+ <%= render 'export_columns_form', export_config: export_config %>
4
+ <%= render 'export_options_form' %>
5
+ <%= render 'export_download_options', export_config: export_config %>
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
- <%= render :partial => "base_form", :locals => {:xhr => false,
2
- :form_action => :export,
3
- :url_options => params_for(:action => :export),
4
- :method => :post,
5
- :cancel_link => true,
6
- :headline => as_(:export),
7
- :body_partial => 'export_form_body',
8
- :loading => false} %>
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,5 +1,5 @@
1
1
  <div class="active-scaffold">
2
2
  <div class="show-export view">
3
- <%= render :partial => 'show_export' -%>
3
+ <%= render partial: 'show_export' -%>
4
4
  </div>
5
5
  </div>
@@ -0,0 +1,9 @@
1
+ en:
2
+ active_scaffold:
3
+ all_pages: All pages
4
+ columns_for_export: Columns for export
5
+ export: Export
6
+ export_format: Format
7
+ export_options: Options
8
+ export_pages: Pages
9
+ this_page: This page
@@ -0,0 +1,9 @@
1
+ es:
2
+ active_scaffold:
3
+ all_pages: Todas las páginas
4
+ columns_for_export: Columnas a exportar
5
+ export: Exportar
6
+ export_format: Formato
7
+ export_options: Opciones
8
+ export_pages: Páginas
9
+ this_page: Esta página
@@ -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, :only => [:export]
5
- base.before_action :show_export_authorized_filter, :only => [:show_export]
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
 
@@ -21,13 +23,11 @@ module ActiveScaffold::Actions
21
23
  def export
22
24
  export_config = active_scaffold_config.export
23
25
  if params[:export_columns].nil?
24
- export_columns = {}
25
- export_columns_names.each { |col| export_columns[col.to_sym] = 1 }
26
26
  options = {
27
- :export_columns => export_columns,
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
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
31
31
  }
32
32
  params.merge!(options)
33
33
  end
@@ -41,14 +41,7 @@ module ActiveScaffold::Actions
41
41
  @list_columns = @export_columns
42
42
  @page = find_page(find_options_for_export)
43
43
 
44
- # this is required if you want this to work with IE
45
- if request.env['HTTP_USER_AGENT'] =~ /msie/i
46
- response.headers['pragma'] = "public"
47
- response.headers['cache-control'] = "no-cache, must-revalidate, post-check=0, pre-check=0"
48
- response.headers['expires'] = "0"
49
- end
50
44
  response.headers['content-disposition'] = "attachment; filename=#{export_file_name}"
51
-
52
45
  respond_to_action(:export)
53
46
  end
54
47
 
@@ -61,7 +54,7 @@ module ActiveScaffold::Actions
61
54
  self.response_body = Enumerator.new do |y|
62
55
  find_items_for_export do |records|
63
56
  @records = records
64
- str = render_to_string :partial => 'export', :layout => false, :formats => [:csv]
57
+ str = render_to_string partial: 'export', layout: false, formats: [:csv]
65
58
  y << str
66
59
  params[:skip_header] = 'true' # skip header on the next run
67
60
  end
@@ -73,55 +66,86 @@ module ActiveScaffold::Actions
73
66
  response.headers['last-modified'] = '0'
74
67
  pkg = Axlsx::Package.new
75
68
  pkg.workbook.add_worksheet(name: worksheet_name) do |sheet|
76
- styles = @export_columns.collect { |column| view_context.export_column_header_style(column, :xlsx) }
77
- widths = @export_columns.map.with_index { |column, i| styles.dig(i, :width) || column.export_options&.dig(:xlsx, :width) || :auto }
78
- unless params[:skip_header]
79
- styles.map! { |style| pkg.workbook.styles.add_style style if style }
80
- sheet.add_row(@export_columns.collect { |column| view_context.format_export_column_header_name(column) }, style: styles, widths: widths)
81
- end
82
- find_items_for_export do |records|
83
- records.each do |record|
84
- row = []
85
- styles = []
86
- @export_columns.each do |column|
87
- data, style = view_context.get_export_column_value(record, column, :xlsx)
88
- style = pkg.workbook.styles.add_style style if style
89
- row << data
90
- styles << style
91
- end
92
- sheet.add_row row, style: styles, widths: widths
93
- end
94
- end
69
+ populate_xlsx_sheet(pkg, sheet)
95
70
  end
96
71
  customize_xlsx(pkg)
97
- stream = pkg.to_stream # when adding rows to sheet, they won't pass to this stream if declared before. axlsx issue?
72
+ # Rows added after creating the stream are not included due to an Axlsx limitation.
73
+ stream = pkg.to_stream
98
74
  self.response_body = Enumerator.new do |y|
99
75
  y << stream.read
100
76
  end
101
77
  end
102
78
 
103
- def worksheet_name(options = {})
104
- active_scaffold_config.label.
105
- gsub(/[#{Regexp.quote Axlsx::WORKSHEET_NAME_FORBIDDEN_CHARS.join}]/, options[:replace] || '-').
106
- truncate(Axlsx::WORKSHEET_MAX_NAME_LENGTH, options)
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)
107
110
  end
108
111
 
109
- def customize_xlsx(package)
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)
110
116
  end
111
117
 
118
+ def customize_xlsx(package); end
119
+
112
120
  def export_columns
113
121
  return @export_columns if defined? @export_columns
114
- @export_columns = export_columns_names.reject do |col|
115
- params[:export_columns][col.to_sym].nil? ||
116
- !active_scaffold_config.model.authorized_for?(crud_type: :read, column: col.to_sym)
117
- end
122
+
123
+ selected_columns = selected_export_columns
118
124
  sorting = active_scaffold_config.list.user.sorting || active_scaffold_config.list.sorting
119
- sorting_columns = sorting.reject { |col, _| @export_columns.include?(col.name) }.map(&:first)
120
- @export_columns.map! { |col| active_scaffold_config.columns[col] }
121
- @export_columns += sorting_columns
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)
122
128
  end
123
129
 
124
- def export_columns_names(action_columns = false)
130
+ def selected_export_columns
131
+ available_columns = export_columns_names.map(&:to_s)
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)
135
+ end
136
+ end
137
+
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)
125
149
  if grouped_search?
126
150
  list_columns_names.then do |cols|
127
151
  action_columns ? active_scaffold_config.build_action_columns(:export, cols) : cols
@@ -133,7 +157,7 @@ module ActiveScaffold::Actions
133
157
 
134
158
  def find_options_for_export
135
159
  find_options = {sorting: active_scaffold_config.list.sorting, pagination: true}
136
- do_search rescue nil
160
+ do_search if respond_to? :do_search, true
137
161
 
138
162
  if params[:full_download] == 'true'
139
163
  find_options.merge!(per_page: 3000, page: 1)
@@ -148,7 +172,7 @@ module ActiveScaffold::Actions
148
172
  end
149
173
 
150
174
  # The actual algorithm to do the export
151
- def find_items_for_export(&block)
175
+ def find_items_for_export(&)
152
176
  if params[:full_download] == 'true'
153
177
  @page.pager.each do |page|
154
178
  yield page.items
@@ -161,21 +185,22 @@ module ActiveScaffold::Actions
161
185
  # The default name of the downloaded file.
162
186
  # You may override the method to specify your own file name generation.
163
187
  def export_file_name
164
- filename = self.controller_name.dup
188
+ filename = controller_name.dup
165
189
 
166
- if params[:format] && active_scaffold_config.export.formats.map(&:to_s).include?(params[:format])
167
- filename << ".#{params[:format]}"
168
- else
169
- filename << ".#{active_scaffold_config.export.default_file_format}"
170
- end
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
171
196
 
172
- return filename
197
+ filename
173
198
  end
174
199
 
175
200
  # The default security delegates to ActiveRecordPermissions.
176
201
  # You may override the method to customize.
177
202
  def export_authorized?
178
- authorized_for?(:action => :read)
203
+ authorized_for?(action: :read)
179
204
  end
180
205
 
181
206
  def export_authorized_filter
@@ -193,6 +218,5 @@ module ActiveScaffold::Actions
193
218
  def export_formats
194
219
  active_scaffold_config.export.formats
195
220
  end
196
-
197
221
  end
198
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
@@ -12,64 +15,73 @@ module ActiveScaffold::Config
12
15
  self.default_delimiter = self.class.default_delimiter
13
16
  self.default_skip_header = self.class.default_skip_header
14
17
  self.default_file_format = self.class.default_file_format
15
- @formats = [:csv, :xlsx]
18
+ self.draggable = self.class.draggable
19
+ @formats = %i[csv xlsx]
16
20
  end
17
21
 
18
22
  # global level configuration
19
23
  # --------------------------
20
24
  # the ActionLink for this action
21
- cattr_accessor :link
22
- @@link = ActiveScaffold::DataStructures::ActionLink.new('show_export', :label => :export, :type => :collection, :security_method => :export_authorized?)
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
+ )
23
30
 
24
31
  # configures where the plugin itself is located. there is no instance version of this.
25
- cattr_accessor :plugin_directory
26
- @@plugin_directory = File.expand_path(__FILE__).match(%{(^.*)/lib/active_scaffold/config/export.rb})[1]
27
-
32
+ cattr_accessor :plugin_directory,
33
+ instance_accessor: false,
34
+ default: File.expand_path(__FILE__).match(%r{(^.*)/lib/active_scaffold/config/export.rb})[1]
28
35
 
29
36
  # instance-level configuration
30
37
  # ----------------------------
31
38
 
32
39
  attr_writer :link
40
+
33
41
  def link
34
- @link ||= if show_form
35
- self.class.link.clone
36
- else
37
- ActiveScaffold::DataStructures::ActionLink.new('export', :label => :export, :type => :collection, :inline => false, :security_method => :export_authorized?)
38
- end
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
39
50
  end
40
51
 
41
- # whether open a form to allow selecting columns and format settings, or export directly with the defined settings in the controller
42
- cattr_accessor :show_form, instance_accessor: false
43
- @@show_form = true
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
44
55
 
45
56
  # whether user can ask for full or page export, or default is forced
46
- cattr_accessor :allow_full_download, instance_accessor: false
47
- @@allow_full_download = true
57
+ cattr_accessor :allow_full_download, instance_accessor: false, default: true
48
58
 
49
59
  # force_quotes option for CSV library
50
- cattr_accessor :force_quotes, instance_accessor: false
51
- @@force_quotes = false
60
+ cattr_accessor :force_quotes, instance_accessor: false, default: false
52
61
 
53
62
  # default setting for full export or page export, it can be changed in the form if show_form is enabled
54
- cattr_accessor :default_full_download, instance_accessor: false
55
- @@default_full_download = true
63
+ cattr_accessor :default_full_download, instance_accessor: false, default: true
56
64
 
57
65
  # default column separator for CSV, it can be changed in the form if show_form is enabled
58
- cattr_accessor :default_delimiter, instance_accessor: false
59
- @@default_delimiter = ','
66
+ cattr_accessor :default_delimiter, instance_accessor: false, default: ','
60
67
 
61
- # wheter export a header (false) or skip exporting a header (true), it can be changed in the form if show_form is enabled
62
- cattr_accessor :default_skip_header, instance_accessor: false
63
- @@default_skip_header = false
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
64
71
 
65
72
  # default file format to export, it can be changed in the form if show_form is enabled
66
- cattr_accessor :default_file_format, instance_accessor: false
67
- @@default_file_format = Gem::Specification::find_all_by_name('caxlsx').any? ? 'xlsx' : 'csv'
73
+ cattr_accessor :default_file_format,
74
+ instance_accessor: false,
75
+ default: Gem::Specification.find_all_by_name('caxlsx').any? ? 'xlsx' : 'csv'
76
+
77
+ # whether selected export columns can be reordered with drag and drop
78
+ cattr_accessor :draggable, instance_accessor: false, default: false
68
79
 
69
80
  # instance-level configuration
70
81
  # ----------------------------
71
82
 
72
- # whether open a form to allow selecting columns and format settings, or export directly with the defined settings in the controller
83
+ # whether open a form to allow selecting columns and format settings,
84
+ # or export directly with the defined settings in the controller
73
85
  attr_accessor :show_form
74
86
 
75
87
  # whether user can ask for full or page export, or default is forced
@@ -84,12 +96,16 @@ module ActiveScaffold::Config
84
96
  # default column separator for CSV, it can be changed in the form if show_form is enabled
85
97
  attr_accessor :default_delimiter
86
98
 
87
- # wheter export a header (false) or skip exporting a header (true), it can be changed in the form if show_form is enabled
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
88
101
  attr_accessor :default_skip_header
89
102
 
90
103
  # default file format to export, it can be changed in the form if show_form is enabled
91
104
  attr_accessor :default_file_format
92
105
 
106
+ # whether selected export columns can be reordered with drag and drop
107
+ attr_accessor :draggable
108
+
93
109
  def default_deselected_columns=(val)
94
110
  @default_deselected_columns = ActiveScaffold::DataStructures::Set.new(*val)
95
111
  end
@@ -107,7 +123,7 @@ module ActiveScaffold::Config
107
123
 
108
124
  UserSettings.class_eval do
109
125
  user_attr :show_form, :allow_full_download, :force_quotes, :default_file_format,
110
- :default_delimiter, :default_skip_header, :default_file_format
126
+ :default_delimiter, :default_skip_header
111
127
 
112
128
  def default_deselected_columns=(val)
113
129
  @default_deselected_columns = ActiveScaffold::DataStructures::Set.new(*val)
@@ -117,6 +133,7 @@ module ActiveScaffold::Config
117
133
  if @default_deselected_columns.nil? && @conf.default_deselected_columns
118
134
  return @conf.default_deselected_columns
119
135
  end
136
+
120
137
  @default_deselected_columns ||= ActiveScaffold::DataStructures::Set.new
121
138
  end
122
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
- value, options = send(method, record, format)
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
- value, options = send(method, record, column, format, ui_options: column.list_ui_options || column.options)
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), export_column_style(column, format)]
27
+ [format_grouped_search_column(record[column.name], column.options), nil]
22
28
  else
23
- raw_value = record.send(column.name)
29
+ [format_export_record_value(record, column, format), nil]
30
+ end
31
+ end
24
32
 
25
- value =
26
- if column.association.nil? or column_empty?(raw_value)
27
- format_export_column(raw_value, format)
28
- elsif column.association
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)]
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)
36
+
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, :format => :default)
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 { |v| v.to_label }
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: "69B5EF", fg_color: "FF", alignment: {horizontal: :center}}
98
+ @default_style ||= {sz: 11, b: true, bg_color: '69B5EF', fg_color: 'FF', alignment: {horizontal: :center}}
94
99
  end
95
100
  end
96
101
 
@@ -99,23 +104,9 @@ module ActiveScaffold
99
104
  rows = []
100
105
  rows << [
101
106
  [check_box_tag('skip_header', 1, export_config.default_skip_header), :omit_header],
102
- [text_field_tag('delimiter', export_config.default_delimiter, :size => 1, :maxlength => 1), :delimiter]
107
+ [text_field_tag('delimiter', export_config.default_delimiter, size: 1, maxlength: 1, id: nil), :delimiter]
103
108
  ]
104
- if export_config.allow_full_download
105
- rows << [
106
- [radio_button_tag('full_download', false, !export_config.default_full_download), :this_page],
107
- [radio_button_tag('full_download', true, export_config.default_full_download), :all_pages]
108
- ]
109
- end
110
- if export_config.formats.many?
111
- rows << export_config.formats.map do |format|
112
- [radio_button_tag('format', format, export_config.default_file_format.to_sym == format), format.upcase.to_s]
113
- end
114
- else
115
- rows << [hidden_field_tag('format', export_config.formats[0])]
116
- end
117
109
  end
118
-
119
110
  end
120
111
  end
121
112
  end
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveScaffoldExport
2
4
  module Column
3
5
  extend ActiveSupport::Concern
6
+
4
7
  included do
5
8
  attr_accessor :export_options
6
9
  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.send :include, ActiveScaffoldExport::Column
19
+ ActiveScaffold::DataStructures::Column.include ActiveScaffoldExport::Column
18
20
  if defined? ActiveScaffold::DataStructures::ProxyColumn
19
- ActiveScaffold::DataStructures::ProxyColumn.send :include, ActiveScaffoldExport::Column
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,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveScaffoldExport
2
4
  module Version
3
5
  MAJOR = 3
4
- MINOR = 11
5
- PATCH = 2
6
+ MINOR = 12
7
+ PATCH = 1
6
8
 
7
9
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
10
  end
@@ -1,26 +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'
15
+ ActiveScaffold.set_element :export_option, tag: :div, attributes: {class: 'export-option'}
16
+ ActiveScaffold.set_element :export_option_row, tag: :div, attributes: {class: 'export-option-row'}
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold_export
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.11.2
4
+ version: 3.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volker Hochstein
8
8
  - Sergio Cambra
9
9
  - Hernan Astudillo
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2026-03-24 00:00:00.000000000 Z
12
+ date: 1980-01-02 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: active_scaffold
@@ -18,14 +17,28 @@ dependencies:
18
17
  requirements:
19
18
  - - ">="
20
19
  - !ruby/object:Gem::Version
21
- version: 4.0.0.rc1
20
+ version: 4.4.0
22
21
  type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
24
  requirements:
26
25
  - - ">="
27
26
  - !ruby/object:Gem::Version
28
- version: 4.0.0.rc1
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'
29
42
  description: Exporting Records with ActiveScaffold
30
43
  email: activescaffold@googlegroups.com
31
44
  executables: []
@@ -40,21 +53,27 @@ files:
40
53
  - app/assets/stylesheets/active_scaffold_export.css
41
54
  - app/assets/stylesheets/export-stylesheet-ie.css
42
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
43
58
  - app/views/active_scaffold_overrides/_export_form_body.html.erb
59
+ - app/views/active_scaffold_overrides/_export_options_form.html.erb
44
60
  - app/views/active_scaffold_overrides/_show_export.html.erb
45
61
  - app/views/active_scaffold_overrides/show_export.html.erb
62
+ - config/locales/en.yml
63
+ - config/locales/es.yml
46
64
  - lib/active_scaffold/actions/export.rb
47
65
  - lib/active_scaffold/config/export.rb
48
66
  - lib/active_scaffold/helpers/export_helpers.rb
49
67
  - lib/active_scaffold_export.rb
50
68
  - lib/active_scaffold_export/column.rb
51
69
  - lib/active_scaffold_export/engine.rb
70
+ - lib/active_scaffold_export/extensions.rb
52
71
  - lib/active_scaffold_export/version.rb
53
72
  homepage: http://github.com/active_scaffold/active_scaffold_export
54
73
  licenses:
55
74
  - MIT
56
- metadata: {}
57
- post_install_message:
75
+ metadata:
76
+ rubygems_mfa_required: 'true'
58
77
  rdoc_options: []
59
78
  require_paths:
60
79
  - lib
@@ -62,15 +81,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
81
  requirements:
63
82
  - - ">="
64
83
  - !ruby/object:Gem::Version
65
- version: '2.5'
84
+ version: '3.2'
66
85
  required_rubygems_version: !ruby/object:Gem::Requirement
67
86
  requirements:
68
87
  - - ">="
69
88
  - !ruby/object:Gem::Version
70
89
  version: '0'
71
90
  requirements: []
72
- rubygems_version: 3.5.11
73
- signing_key:
91
+ rubygems_version: 3.6.9
74
92
  specification_version: 4
75
93
  summary: Ability to export records to CSV/XLSX with ActiveScaffold
76
94
  test_files: []