cruj_cruj_cruj_visagio 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/cruj_cruj_cruj_controller.rb +42 -31
- data/config/locales/en.yml +3 -0
- data/config/locales/pt-BR.yml +3 -0
- data/lib/cruj_cruj_cruj/services/import_rules.rb +47 -27
- data/lib/cruj_cruj_cruj/version.rb +1 -1
- metadata +1 -2
- data/app/helpers/search_helper.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 897d93cc6090fdcf792337edfc8b4093554513608250d85bd862c6a5f441b8ad
|
4
|
+
data.tar.gz: 108e146fcfea55ddc1de41fdd057baba1950ca71c78107942882137c9bc3f4cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f0c69d085fdd6d10e541307f0849629ac140e74e06d97a6a0cabf7224aeb96620ca63dbccc0529811b03e563f990392543cd04a7194004f8f585565118bd120
|
7
|
+
data.tar.gz: e3caac92c7a2c21182f6cc0cc6211d296dc3b503cf97a08e237b031e18246c96a177957191279c593f2648aba3e3f069d9be206f063ff727811c78842feabca1
|
@@ -1,16 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class CrujCrujCrujController < ApplicationController
|
2
4
|
include ActionView::Helpers::NumberHelper
|
3
5
|
|
4
|
-
before_action :before_index
|
5
|
-
before_action :before_new
|
6
|
+
before_action :before_index, only: [:index]
|
7
|
+
before_action :before_new, only: [:new]
|
6
8
|
before_action :before_create, only: [:create]
|
7
|
-
before_action :before_edit
|
9
|
+
before_action :before_edit, only: [:edit]
|
8
10
|
before_action :before_update, only: [:update]
|
9
11
|
before_action :before_destroy, only: [:destroy]
|
10
12
|
|
11
13
|
before_action :find_all_resources, only: [:index]
|
12
|
-
before_action :build_resource
|
13
|
-
before_action :find_resource
|
14
|
+
before_action :build_resource, only: %i[new create]
|
15
|
+
before_action :find_resource, only: %i[edit update destroy]
|
14
16
|
|
15
17
|
helper_method :namespace_url, :namespaces, :model_class, :snake_case_model_name,
|
16
18
|
:resource_url,
|
@@ -20,6 +22,7 @@ class CrujCrujCrujController < ApplicationController
|
|
20
22
|
:filter_for
|
21
23
|
|
22
24
|
def index; end
|
25
|
+
|
23
26
|
def new; end
|
24
27
|
|
25
28
|
def create
|
@@ -52,12 +55,13 @@ class CrujCrujCrujController < ApplicationController
|
|
52
55
|
@q.sorts = default_sort if @q.sorts.blank?
|
53
56
|
|
54
57
|
filename = CrujCrujCruj::Services::ImportRules.export_template(form_fields, @q.result)
|
55
|
-
send_file(filename,
|
58
|
+
send_file(filename, type: 'application/vnd.ms-excel')
|
56
59
|
end
|
57
60
|
|
58
61
|
def import
|
59
62
|
if params[:file].blank?
|
60
|
-
redirect_to url_for(action: :index, controller: params[:controller]),
|
63
|
+
redirect_to url_for(action: :index, controller: params[:controller]),
|
64
|
+
{ flash: { error: l(:no_file_to_import_error_message) } }
|
61
65
|
return
|
62
66
|
end
|
63
67
|
|
@@ -67,19 +71,24 @@ class CrujCrujCrujController < ApplicationController
|
|
67
71
|
redirect_to url_for(action: :index, controller: params[:controller]), notice: l(:import_success_message)
|
68
72
|
return
|
69
73
|
end
|
70
|
-
redirect_to url_for(action: :index, controller: params[:controller]),
|
74
|
+
redirect_to url_for(action: :index, controller: params[:controller]),
|
75
|
+
flash: { import_errors: errors.join('<br />') }
|
71
76
|
end
|
72
77
|
|
73
78
|
protected
|
74
79
|
|
75
|
-
def before_index
|
76
|
-
params[
|
80
|
+
def before_index
|
81
|
+
params['q'] && params['q'].permit!
|
77
82
|
end
|
78
83
|
|
79
84
|
def before_new; end
|
85
|
+
|
80
86
|
def before_create; end
|
87
|
+
|
81
88
|
def before_edit; end
|
89
|
+
|
82
90
|
def before_update; end
|
91
|
+
|
83
92
|
def before_destroy; end
|
84
93
|
|
85
94
|
def find_all_resources
|
@@ -140,7 +149,7 @@ class CrujCrujCrujController < ApplicationController
|
|
140
149
|
|
141
150
|
def resource_url(resource)
|
142
151
|
if Rails::VERSION::MAJOR >= 4
|
143
|
-
namespace_url + [resource] + [
|
152
|
+
namespace_url + [resource] + [resource.respond_to?(:type) ? { 'type' => resource.type } : {}]
|
144
153
|
else
|
145
154
|
namespace_url + [resource]
|
146
155
|
end
|
@@ -151,7 +160,7 @@ class CrujCrujCrujController < ApplicationController
|
|
151
160
|
end
|
152
161
|
|
153
162
|
def exclude_index_attributes
|
154
|
-
%w
|
163
|
+
%w[^id$ _id created_at updated_at]
|
155
164
|
end
|
156
165
|
|
157
166
|
def index_filter_attributes
|
@@ -159,7 +168,9 @@ class CrujCrujCrujController < ApplicationController
|
|
159
168
|
end
|
160
169
|
|
161
170
|
def default_sort
|
162
|
-
index_filter_attributes.map
|
171
|
+
index_filter_attributes.map do |ifa|
|
172
|
+
ifa.is_a?(Array) ? "#{ifa[0].split('_')[0..-2].join('_')} asc" : "#{ifa.split('_')[0..-2].join('_')} asc"
|
173
|
+
end
|
163
174
|
end
|
164
175
|
|
165
176
|
def exclude_index_filter_attributes
|
@@ -176,11 +187,11 @@ class CrujCrujCrujController < ApplicationController
|
|
176
187
|
else
|
177
188
|
possible_values[send("format_field_#{field.class.name.downcase}", field)]
|
178
189
|
end
|
179
|
-
rescue
|
190
|
+
rescue StandardError
|
180
191
|
field.name
|
181
192
|
end
|
182
193
|
|
183
|
-
def format_field_nilclass(
|
194
|
+
def format_field_nilclass(_field)
|
184
195
|
''
|
185
196
|
end
|
186
197
|
|
@@ -188,18 +199,18 @@ class CrujCrujCrujController < ApplicationController
|
|
188
199
|
field
|
189
200
|
end
|
190
201
|
|
191
|
-
def format_field_trueclass(
|
202
|
+
def format_field_trueclass(_field)
|
192
203
|
t(:true_field)
|
193
204
|
end
|
194
205
|
|
195
|
-
def format_field_falseclass(
|
206
|
+
def format_field_falseclass(_field)
|
196
207
|
t(:false_field)
|
197
208
|
end
|
198
209
|
|
199
210
|
def format_field_fixnum(field)
|
200
211
|
number_with_delimiter(field)
|
201
212
|
end
|
202
|
-
|
213
|
+
|
203
214
|
def format_field_integer(field)
|
204
215
|
number_with_delimiter(field)
|
205
216
|
end
|
@@ -210,13 +221,13 @@ class CrujCrujCrujController < ApplicationController
|
|
210
221
|
|
211
222
|
def filter_for(attribute)
|
212
223
|
if attribute.is_a? Array
|
213
|
-
send(
|
224
|
+
send('filter_for_enum', attribute[0], attribute[1])
|
214
225
|
elsif column = model_class.columns_hash[attribute.to_s]
|
215
226
|
send("filter_for_#{column.type}", attribute)
|
216
227
|
else
|
217
228
|
send("filter_for_#{attribute}")
|
218
229
|
end
|
219
|
-
rescue
|
230
|
+
rescue StandardError
|
220
231
|
"#{attribute}_cont"
|
221
232
|
end
|
222
233
|
|
@@ -229,47 +240,47 @@ class CrujCrujCrujController < ApplicationController
|
|
229
240
|
end
|
230
241
|
|
231
242
|
def filter_for_project
|
232
|
-
|
243
|
+
'project_name_cont'
|
233
244
|
end
|
234
245
|
|
235
246
|
def filter_for_tracker
|
236
|
-
|
247
|
+
'tracker_name_cont'
|
237
248
|
end
|
238
249
|
|
239
250
|
def filter_for_group
|
240
|
-
|
251
|
+
'group_lastname_cont'
|
241
252
|
end
|
242
253
|
|
243
254
|
def filter_for_status
|
244
|
-
|
255
|
+
'status_name_cont'
|
245
256
|
end
|
246
257
|
|
247
258
|
def filter_for_issue_status
|
248
|
-
|
259
|
+
'issue_status_name_cont'
|
249
260
|
end
|
250
261
|
|
251
262
|
def filter_for_status_to
|
252
|
-
|
263
|
+
'status_to_name_cont'
|
253
264
|
end
|
254
265
|
|
255
266
|
def filter_for_status_from
|
256
|
-
|
267
|
+
'status_from_name_cont'
|
257
268
|
end
|
258
269
|
|
259
270
|
def filter_for_custom_field
|
260
|
-
|
271
|
+
'custom_field_name_cont'
|
261
272
|
end
|
262
273
|
|
263
274
|
def filter_for_author
|
264
|
-
|
275
|
+
'author_firstname_or_author_lastname_cont'
|
265
276
|
end
|
266
277
|
|
267
278
|
def filter_for_principal
|
268
|
-
|
279
|
+
'principal_firstname_or_principal_lastname_cont'
|
269
280
|
end
|
270
281
|
|
271
282
|
def filter_for_role
|
272
|
-
|
283
|
+
'role_name_cont'
|
273
284
|
end
|
274
285
|
|
275
286
|
def filter_for_enum(attribute, values)
|
data/config/locales/en.yml
CHANGED
@@ -9,6 +9,9 @@ en:
|
|
9
9
|
label_name: Name
|
10
10
|
label_type: Type
|
11
11
|
|
12
|
+
no_file_to_import_error_message: No file was uploaded. Please try again after uploading a file.
|
13
|
+
column_invalid_rows: "The column %{column} was invalid in the following rows: %{rows}"
|
14
|
+
|
12
15
|
project_name_cont: Project Name contains
|
13
16
|
tracker_name_cont: Tracker Name contains
|
14
17
|
custom_field_name_cont: Custom Field Name contains
|
data/config/locales/pt-BR.yml
CHANGED
@@ -9,6 +9,9 @@ pt-BR:
|
|
9
9
|
label_name: Nome
|
10
10
|
label_type: Tipo
|
11
11
|
|
12
|
+
no_file_to_import_error_message: Nenhum arquivo foi submetido. Tente novamente depois de escolher um arquivo.
|
13
|
+
column_invalid_rows: "A coluna %{column} está inválida nas seguintes fileiras: %{rows}"
|
14
|
+
|
12
15
|
project_name_cont: Nome do projeto contém
|
13
16
|
tracker_name_cont: Nome do tipo da tarefa contém
|
14
17
|
custom_field_name_cont: Nome do campo customizado contém
|
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module CrujCrujCruj
|
3
4
|
module Services
|
4
5
|
class ImportRules
|
5
|
-
|
6
6
|
def self.export_template(fields, data)
|
7
7
|
package = Axlsx::Package.new
|
8
8
|
workbook = package.workbook
|
@@ -10,7 +10,8 @@ module CrujCrujCruj
|
|
10
10
|
parameters_sheet_name = 'PARAMETERS'
|
11
11
|
|
12
12
|
workbook.add_worksheet(name: 'TEMPLATE') do |sheet|
|
13
|
-
title = sheet.styles.add_style(bg_color: 'FF007E7A', fg_color: 'FFFFFFFF', sz: 12,
|
13
|
+
title = sheet.styles.add_style(bg_color: 'FF007E7A', fg_color: 'FFFFFFFF', sz: 12, b: true,
|
14
|
+
border: { style: :thin, color: 'FF000000' })
|
14
15
|
|
15
16
|
fields.each_with_index do |field, idx|
|
16
17
|
validation = field[:data_validation][:validation]
|
@@ -18,10 +19,16 @@ module CrujCrujCruj
|
|
18
19
|
add_data_validation(sheet, idx + 1, validation, allow_blank, parameters_sheet_name) if validation
|
19
20
|
end
|
20
21
|
|
21
|
-
sheet.add_row (([:id] |fields.map
|
22
|
+
sheet.add_row (([:id] | fields.map do |field|
|
23
|
+
field[:field_name]
|
24
|
+
end).map { |t| I18n.t("#{t}_label") }), style: title
|
22
25
|
|
23
|
-
data.map
|
24
|
-
|
26
|
+
data.map do |resource|
|
27
|
+
[resource.id].concat(fields.map do |field|
|
28
|
+
resource_field_value(resource, field)
|
29
|
+
end)
|
30
|
+
end.each do |row|
|
31
|
+
sheet.add_row row, types: row.map { |_| :string }
|
25
32
|
end
|
26
33
|
end
|
27
34
|
|
@@ -36,37 +43,45 @@ module CrujCrujCruj
|
|
36
43
|
spreadsheet = Roo::Spreadsheet.open(file.path, extension: :xlsx)
|
37
44
|
|
38
45
|
errors = []
|
39
|
-
|
40
|
-
if Rails::VERSION::MAJOR < 4
|
41
|
-
|
42
|
-
|
43
|
-
|
46
|
+
|
47
|
+
invalid_rows = if Rails::VERSION::MAJOR < 4
|
48
|
+
validate_id_array(spreadsheet, clazz)
|
49
|
+
else
|
50
|
+
validate_id(spreadsheet, clazz)
|
51
|
+
end
|
52
|
+
unless invalid_rows.blank?
|
53
|
+
errors << I18n.t(:column_invalid_rows, column: :id,
|
54
|
+
rows: invalid_rows.first(25).join(', '))
|
44
55
|
end
|
45
|
-
errors << I18n.t(:column_invalid_rows, column: :id, rows: invalid_rows.first(25).join(', ')) unless invalid_rows.blank?
|
46
56
|
|
47
57
|
fields.each_with_index do |field, idx|
|
48
58
|
col = idx + 1
|
49
59
|
unless field[:data_validation][:allow_blank]
|
50
60
|
invalid_rows = validate_not_blank(col, spreadsheet)
|
51
|
-
|
61
|
+
unless invalid_rows.blank?
|
62
|
+
errors << I18n.t(:column_invalid_rows, column: field[:field_name],
|
63
|
+
rows: invalid_rows.first(25).join(', '))
|
64
|
+
end
|
52
65
|
end
|
53
66
|
|
54
|
-
|
55
|
-
|
56
|
-
|
67
|
+
next unless field[:data_validation][:validation]
|
68
|
+
|
69
|
+
invalid_rows = validate_in_array(col, field_validation_values(field), spreadsheet)
|
70
|
+
unless invalid_rows.blank?
|
71
|
+
errors << I18n.t(:column_invalid_rows, column: field[:field_name],
|
72
|
+
rows: invalid_rows.first(25).join(', '))
|
57
73
|
end
|
58
74
|
end
|
59
75
|
|
60
76
|
return errors unless errors.blank?
|
61
77
|
|
62
|
-
|
63
78
|
(2..spreadsheet.last_row).each do |i|
|
64
79
|
row = spreadsheet.row(i)
|
65
80
|
id = row[0]
|
66
81
|
resource = id ? clazz.find(id) : clazz.new
|
67
82
|
|
68
83
|
fields.each_with_index do |field, idx|
|
69
|
-
resource.send("#{field[:field_name]}=", row_value(row, idx+1, field, spreadsheet))
|
84
|
+
resource.send("#{field[:field_name]}=", row_value(row, idx + 1, field, spreadsheet))
|
70
85
|
resource.save!
|
71
86
|
end
|
72
87
|
end
|
@@ -74,13 +89,11 @@ module CrujCrujCruj
|
|
74
89
|
{}
|
75
90
|
end
|
76
91
|
|
77
|
-
protected
|
78
|
-
|
79
|
-
|
80
92
|
def self.add_data_validation(sheet, column_number, validation, allowBlank, parameters_sheet_name)
|
81
93
|
column_letter = number2column(column_number)
|
82
94
|
values_size = validation.is_a?(Array) ? validation.size : validation[:clazz].all.count
|
83
|
-
sheet.add_data_validation("#{column_letter}2:#{column_letter}1048576", type: :list, allowBlank: allowBlank,
|
95
|
+
sheet.add_data_validation("#{column_letter}2:#{column_letter}1048576", type: :list, allowBlank: allowBlank,
|
96
|
+
formula1: "#{parameters_sheet_name}!$#{column_letter}$2:$#{column_letter}$#{values_size + 1}")
|
84
97
|
end
|
85
98
|
|
86
99
|
def self.create_validations(fields, workbook, parameters_sheet_name)
|
@@ -91,7 +104,7 @@ module CrujCrujCruj
|
|
91
104
|
|
92
105
|
cols_values.map { |values| values.size }.max.times do |i|
|
93
106
|
row = cols_values.map { |v| v[i] }
|
94
|
-
sheet.add_row row, types: row.map{ |_| :string }
|
107
|
+
sheet.add_row row, types: row.map { |_| :string }
|
95
108
|
end
|
96
109
|
end
|
97
110
|
end
|
@@ -120,7 +133,7 @@ module CrujCrujCruj
|
|
120
133
|
end
|
121
134
|
|
122
135
|
def self.number2column(number)
|
123
|
-
Hash.new {|hash,key| hash[key] = hash[key - 1].next }.merge({0 =>
|
136
|
+
Hash.new { |hash, key| hash[key] = hash[key - 1].next }.merge({ 0 => 'A' })[number]
|
124
137
|
end
|
125
138
|
|
126
139
|
def self.validate_id(spreadsheet, clazz)
|
@@ -133,7 +146,7 @@ module CrujCrujCruj
|
|
133
146
|
|
134
147
|
def self.validate_not_blank(col, spreadsheet)
|
135
148
|
(2..spreadsheet.last_row)
|
136
|
-
.map { |i| {i => !spreadsheet.row(i)[col].blank? } }
|
149
|
+
.map { |i| { i => !spreadsheet.row(i)[col].blank? } }
|
137
150
|
.select { |e| !e.values.first }
|
138
151
|
.map { |e| e.keys.first }
|
139
152
|
end
|
@@ -146,12 +159,19 @@ module CrujCrujCruj
|
|
146
159
|
end
|
147
160
|
|
148
161
|
def self.fetch(row, col, spreadsheet)
|
149
|
-
spreadsheet.celltype(row,
|
162
|
+
if spreadsheet.celltype(row,
|
163
|
+
col + 1) == :float
|
164
|
+
spreadsheet.send(:cell_to_csv, row, col + 1,
|
165
|
+
spreadsheet.default_sheet)
|
166
|
+
else
|
167
|
+
row[col]
|
168
|
+
end
|
150
169
|
end
|
151
170
|
|
152
171
|
def self.row_value(row, col, field, spreadsheet)
|
153
172
|
if field[:data_validation][:validation] && !field[:data_validation][:validation].is_a?(Array)
|
154
|
-
field[:data_validation][:validation][:clazz].send("find_by_#{field[:data_validation][:validation][:field]}",
|
173
|
+
field[:data_validation][:validation][:clazz].send("find_by_#{field[:data_validation][:validation][:field]}",
|
174
|
+
fetch(row, col, spreadsheet))
|
155
175
|
else
|
156
176
|
fetch(row, col, spreadsheet)
|
157
177
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cruj_cruj_cruj_visagio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Visagio
|
@@ -107,7 +107,6 @@ files:
|
|
107
107
|
- app/assets/javascripts/cruj_cruj_cruj/application.js
|
108
108
|
- app/assets/stylesheets/cruj_cruj_cruj/application.css
|
109
109
|
- app/controllers/cruj_cruj_cruj_controller.rb
|
110
|
-
- app/helpers/search_helper.rb
|
111
110
|
- app/views/cruj_cruj_cruj/_filters.html.erb
|
112
111
|
- app/views/cruj_cruj_cruj/_import_export_template.html.erb
|
113
112
|
- app/views/cruj_cruj_cruj/_list_table.html.erb
|
File without changes
|