ntq_excelsior 1.2.2 → 1.4.0

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: 6c3cb9fc73c0fa504c6688f4ee4c2da018b66af2234f083a10a1f4ee4811068a
4
- data.tar.gz: abd746af68004464bf1557e0ecb7d1a428d446330017fd853b69ed7cf17af38d
3
+ metadata.gz: b6a5e24a80fa3a23cb825780ed3d507a35fd431c17fc6bf0cebef21136bd76b4
4
+ data.tar.gz: 1a82ce13bfcb6fa6cee43183506c971f5f5c603dc2c7889c4c9cec75de87f584
5
5
  SHA512:
6
- metadata.gz: a87e8c0ac39d28069d2c8c054bf070bc4fb6394414130f0f32b3378f92eba19ca59517b95aacb4b2002bc56105a125b5e013c2c99c1483b3da04dc4a52bf9d07
7
- data.tar.gz: b2238ec59fc5f4a4a216e1ec6dc57991024c1a19f44ddfdcf82e2f900aad9b6e6023161c9b286f974f6d2ca791e57ffde1011b19ac7283f31036db70ea13d1dd
6
+ metadata.gz: fc0f3a348f3287e7853f7dd5e95a50ec36814b99a51b32a2e296a086512e69ac09febc3e6ce0eaf1ba25c910b498e65d09693b1bca8c5ae7cf66c551d6d3cc72
7
+ data.tar.gz: '0481f21e47076aba37d617814989d18735977edf0d78f74542b1791ab6a91a09ae891c4695a38e516c97692b737a39ac085c270cced400c5af2324f82a14dbb5'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ntq_excelsior (1.2.2)
4
+ ntq_excelsior (1.4.0)
5
5
  caxlsx (< 4)
6
6
  roo (< 3)
7
7
 
@@ -72,4 +72,4 @@ DEPENDENCIES
72
72
  rubocop (~> 1.21)
73
73
 
74
74
  BUNDLED WITH
75
- 2.3.8
75
+ 2.5.3
data/README.md CHANGED
@@ -34,7 +34,7 @@ class UserExporter < NtqExcelsior::Exporter
34
34
  [
35
35
  {
36
36
  title: "Utilisateurs",
37
- width: -> (context) { context[:current_user].can?(:access_to_email, User) ? 4 : 3 }
37
+ width: -> (context) { context[:current_user].can?(:access_to_email, User) ? 4 : 3 },
38
38
  # width: 4,
39
39
  styles: [:bold]
40
40
  }
@@ -69,7 +69,25 @@ class UserExporter < NtqExcelsior::Exporter
69
69
  title: 'Age',
70
70
  resolve: 'age',
71
71
  type: :number
72
- }
72
+ },
73
+ {
74
+ title: 'Civilité',
75
+ list: ['M', 'Ms', 'Autres']
76
+ },
77
+ {
78
+ title: 'Active',
79
+ resolve: -> (record) { record.active ? 'Oui' : 'Non' }
80
+ # See axlsx example at https://github.com/caxlsx/caxlsx/blob/master/examples/list_validation_example.md for more options
81
+ list: {
82
+ options: ['Oui', 'Non'],
83
+ show_error_message: true,
84
+ error_title: 'Active', # Optional
85
+ error: 'Authorized value: Oui non',
86
+ errorStyle: :stop, # :informations, :warning
87
+ showInputMessage: true,
88
+ prompt: 'Choose a value'
89
+ }
90
+ },
73
91
  ]
74
92
  })
75
93
 
@@ -96,8 +114,7 @@ send_data stream, type: 'application/xlsx', filename: "filename.xlsx"
96
114
  user_exporter = UserExporter.new(@user_data)
97
115
  product_exporter = ProductExporter.new(@product_data)
98
116
 
99
- exporter = NtqExcelsior::MultiWorkbookExporter.new([user_exporter, product_exporter])
100
- stream = exporter.export.to_stream.read
117
+ exporter = NtqExcelsior::MultiWorkbookExporter.new([export1, export2])
101
118
 
102
119
  # In ruby file
103
120
  File.open("export.xlsx", "w") do |tmp|
@@ -4,6 +4,7 @@ module NtqExcelsior
4
4
  class Exporter
5
5
  attr_accessor :data
6
6
  attr_accessor :context
7
+ attr_accessor :progression_tracker
7
8
 
8
9
  DEFAULT_STYLES = {
9
10
  date_format: {
@@ -36,6 +37,7 @@ module NtqExcelsior
36
37
 
37
38
  def initialize(data)
38
39
  @data = data
40
+ @data_count = data.size.to_d
39
41
  end
40
42
 
41
43
  def schema
@@ -61,7 +63,7 @@ module NtqExcelsior
61
63
  letters.reverse.map { |i| COLUMN_NAMES[i] }.join
62
64
  end
63
65
 
64
- def cell_name(col, row, *lock)
66
+ def cell_name(col, row = nil, *lock)
65
67
  "#{lock.include?(:col) ? '$' : ''}#{column_name(col)}#{lock.include?(:row) ? '$' : ''}#{row}"
66
68
  end
67
69
 
@@ -116,13 +118,19 @@ module NtqExcelsior
116
118
  width = column_width(header)
117
119
  row[:values] << header[:title] || ''
118
120
  row[:styles] << get_styles(header[:header_styles] || header[:styles])
121
+ row[:data_validations] ||= []
122
+ if header[:list]
123
+ row[:data_validations].push({
124
+ range: cells_range([col_index, index + 1], [col_index, 1_000_000]),
125
+ config: list_data_validation_for_column(header[:list])
126
+ })
127
+ end
119
128
  if width > 1
120
129
  colspan = width - 1
121
130
  row[:values].push(*Array.new(colspan, nil))
122
131
  row[:merge_cells].push cells_range([col_index, index], [col_index + colspan, index])
123
132
  col_index += colspan
124
133
  end
125
-
126
134
  col_index += 1
127
135
  end
128
136
  row
@@ -188,6 +196,35 @@ module NtqExcelsior
188
196
  row
189
197
  end
190
198
 
199
+ def list_data_validation_for_column(list_config)
200
+ if list_config.is_a?(Array)
201
+ return {
202
+ type: :list,
203
+ formula1: "\"#{list_config.join(', ')}\""
204
+ }
205
+ end
206
+
207
+ config = {
208
+ type: :list,
209
+ formula1: "\"#{list_config[:options].join(', ')}\"",
210
+ showErrorMessage: list_config[:show_error_message] || false,
211
+ showInputMessage: list_config[:show_input_message] || false,
212
+ }
213
+
214
+ if list_config[:show_error_message]
215
+ config[:error] = list_config[:error] || ''
216
+ config[:errorStyle] = list_config[:error_style] || :stop
217
+ config[:errorTitle] = list_config[:error_title] || ''
218
+ end
219
+
220
+ if list_config[:show_input_message]
221
+ config[:promptTitle] = list_config[:prompt_title] || ''
222
+ config[:prompt] = list_config[:prompt] || ''
223
+ end
224
+
225
+ config
226
+ end
227
+
191
228
  def content
192
229
  content = { rows: [] }
193
230
  index = 0
@@ -197,15 +234,19 @@ module NtqExcelsior
197
234
  end
198
235
  index += 1
199
236
  content[:rows] << resolve_header_row(schema[:columns], index)
200
- @data.each do |record|
237
+ @data.each_with_index do |record, index|
201
238
  index += 1
239
+ if progression_tracker&.is_a?(Proc)
240
+ at = ((((index + 1).to_d / @data_count) * 100.to_d) / 2).round(2)
241
+ progression_tracker.call(at) if at % 5 == 0
242
+ end
202
243
  content[:rows] << resolve_record_row(schema[:columns], record, index)
203
244
  end
204
245
  content
205
246
  end
206
247
 
207
248
  def add_sheet_content(content, wb_styles, sheet)
208
- content[:rows].each do |row|
249
+ content[:rows].each_with_index do |row, index|
209
250
  row_style = []
210
251
  if row[:styles].is_a?(Array) && row[:styles].any?
211
252
  row[:styles].each do |style|
@@ -213,6 +254,15 @@ module NtqExcelsior
213
254
  end
214
255
  end
215
256
  sheet.add_row row[:values], style: row_style, height: row[:height], types: row[:types]
257
+ if progression_tracker&.is_a?(Proc)
258
+ at = 50 + ((((index + 1).to_d / @data_count) * 100.to_d) / 2).round(2)
259
+ progression_tracker.call(at) if at % 5 == 0 || index == content[:rows].length - 1
260
+ end
261
+ if row[:data_validations]
262
+ row[:data_validations].each do |validation|
263
+ sheet.add_data_validation(validation[:range], validation[:config])
264
+ end
265
+ end
216
266
  if row[:merge_cells]
217
267
  row[:merge_cells]&.each do |range|
218
268
  sheet.merge_cells range
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NtqExcelsior
4
- VERSION = "1.2.2"
4
+ VERSION = "1.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ntq_excelsior
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-24 00:00:00.000000000 Z
11
+ date: 2024-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: caxlsx