ntq_excelsior 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7623610b856ec03f9eb51aee437b8e7d1357f6cf2a0cf0e28277fe5aca5adb9
4
- data.tar.gz: db0984b6a3545570b9d44a24b2e53570b3b2fe15c445488619fee1d9fef07716
3
+ metadata.gz: 6a4efa937725b46c65a0ed4b23ebba4a10dc359835b6e7b563c2c7d7fa269404
4
+ data.tar.gz: a65826c126a6e9485dbb8227a439960a944ed4481138dca5bb2b5598db9d2490
5
5
  SHA512:
6
- metadata.gz: 21ea936bacb155d5da8cf1785bb45a3ed2054a871cbcc7797f90ef979954a5e1fb806027527fb130b453cbbee2a32465a4793fb458aa048e280f8ec2e9ce3905
7
- data.tar.gz: dcc68660a9802823c1333634fda1d9ca9e41640c3b24af44a1ccb5f08a72f94a79631f435a7a22ac2295d54953686ea26152ac1449f315ea595715a096d74db1
6
+ metadata.gz: d70936785c973e0d76ecb3d26ab0e676acfaa09c6c69e8bf7902a9b3c31608a8b81deef35ffb593ffbe0fbdeff76b04a9296ac757ccd7d5788a8c5059b4d7403
7
+ data.tar.gz: 5cb1daf2aef2b3829275277184af5bef789b73a33c2fc8e60ae5b4e4efc09db3f71591241ab6975417c2074d6cb82a622a33bd924b4742cb5b9f4b7400e567a9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ntq_excelsior (1.2.1)
4
+ ntq_excelsior (1.3.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 [here](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|
@@ -61,7 +61,7 @@ module NtqExcelsior
61
61
  letters.reverse.map { |i| COLUMN_NAMES[i] }.join
62
62
  end
63
63
 
64
- def cell_name(col, row, *lock)
64
+ def cell_name(col, row = nil, *lock)
65
65
  "#{lock.include?(:col) ? '$' : ''}#{column_name(col)}#{lock.include?(:row) ? '$' : ''}#{row}"
66
66
  end
67
67
 
@@ -116,13 +116,19 @@ module NtqExcelsior
116
116
  width = column_width(header)
117
117
  row[:values] << header[:title] || ''
118
118
  row[:styles] << get_styles(header[:header_styles] || header[:styles])
119
+ row[:data_validations] ||= []
120
+ if header[:list]
121
+ row[:data_validations].push({
122
+ range: cells_range([col_index, index + 1], [col_index, 1_000_000]),
123
+ config: list_data_validation_for_column(header[:list])
124
+ })
125
+ end
119
126
  if width > 1
120
127
  colspan = width - 1
121
128
  row[:values].push(*Array.new(colspan, nil))
122
129
  row[:merge_cells].push cells_range([col_index, index], [col_index + colspan, index])
123
130
  col_index += colspan
124
131
  end
125
-
126
132
  col_index += 1
127
133
  end
128
134
  row
@@ -188,6 +194,35 @@ module NtqExcelsior
188
194
  row
189
195
  end
190
196
 
197
+ def list_data_validation_for_column(list_config)
198
+ if list_config.is_a?(Array)
199
+ return {
200
+ type: :list,
201
+ formula1: "\"#{list_config.join(', ')}\""
202
+ }
203
+ end
204
+
205
+ config = {
206
+ type: :list,
207
+ formula1: "\"#{list_config[:options].join(', ')}\"",
208
+ showErrorMessage: list_config[:show_error_message] || false,
209
+ showInputMessage: list_config[:show_input_message] || false,
210
+ }
211
+
212
+ if list_config[:show_error_message]
213
+ config[:error] = list_config[:error] || ''
214
+ config[:errorStyle] = list_config[:error_style] || :stop
215
+ config[:errorTitle] = list_config[:error_title] || ''
216
+ end
217
+
218
+ if list_config[:show_input_message]
219
+ config[:promptTitle] = list_config[:prompt_title] || ''
220
+ config[:prompt] = list_config[:prompt] || ''
221
+ end
222
+
223
+ config
224
+ end
225
+
191
226
  def content
192
227
  content = { rows: [] }
193
228
  index = 0
@@ -213,6 +248,11 @@ module NtqExcelsior
213
248
  end
214
249
  end
215
250
  sheet.add_row row[:values], style: row_style, height: row[:height], types: row[:types]
251
+ if row[:data_validations]
252
+ row[:data_validations].each do |validation|
253
+ sheet.add_data_validation(validation[:range], validation[:config])
254
+ end
255
+ end
216
256
  if row[:merge_cells]
217
257
  row[:merge_cells]&.each do |range|
218
258
  sheet.merge_cells range
@@ -70,7 +70,7 @@ module NtqExcelsior
70
70
  rescue Roo::HeaderRowNotFoundError => e
71
71
  missing_headers = []
72
72
 
73
- e.message.slice(1..-1).chop.split(",").map(&:strip).each do |header_missing|
73
+ e.message.delete_prefix('[').delete_suffix(']').split(",").map(&:strip).each do |header_missing|
74
74
  header_missing_regex = transform_header_to_regexp(header_missing, true)
75
75
  header_found = @required_columns.values.find do |column|
76
76
  transform_header_to_regexp(get_column_header(column)) == header_missing_regex
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NtqExcelsior
4
- VERSION = "1.2.1"
4
+ VERSION = "1.3.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.1
4
+ version: 1.3.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-23 00:00:00.000000000 Z
11
+ date: 2024-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: caxlsx