xsdk-scaffold-rails 0.1.4.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +13 -3
- data/Gemfile.lock +48 -4
- data/lib/xsdk/scaffold/rails/base_datatable.rb +246 -215
- data/lib/xsdk/scaffold/rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a74cad8d98a8df248f79c1d710ace09c66a2392c5e3bcf4668e86d68596e2ddc
|
4
|
+
data.tar.gz: ad0dc5bbeb6790674a0f85f5263341fde64370732d8c090e3065f7e6d864bd9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 823c9c9c86b3fda4f9b062c1ce5bdfa75bbf2140fd1d1f19772f89908ea0f73e6ae59055ca1250a29989d78ffe954fc7f66d9981e3ead71f96acc45c093b9c04
|
7
|
+
data.tar.gz: ab30c2621e46ff55efcb9ea0cef893d1f7a4d8c7f42cb56e5203b5785ae73133f70f0567696274ec6426a4edfdb9ef9aa90bc20708167d3ae15e7ad2e4c0b80a
|
data/Gemfile
CHANGED
@@ -1,7 +1,17 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in xsdk-scaffold-rails.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem
|
7
|
-
gem
|
6
|
+
gem 'rake', '~> 12.0'
|
7
|
+
gem 'rspec', '~> 3.0'
|
8
|
+
|
9
|
+
group :development do
|
10
|
+
gem 'rubocop'
|
11
|
+
gem 'rubocop-gitlab-security'
|
12
|
+
gem 'rubocop-performance'
|
13
|
+
gem 'rubocop-rails'
|
14
|
+
gem 'rubocop-rspec' # or gem 'rubocop-minitest'
|
15
|
+
|
16
|
+
gem 'solargraph'
|
17
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
xsdk-scaffold-rails (0.1.
|
4
|
+
xsdk-scaffold-rails (0.1.5)
|
5
5
|
activerecord (>= 6.0.0)
|
6
6
|
pg (>= 1.1)
|
7
7
|
|
@@ -20,18 +20,36 @@ GEM
|
|
20
20
|
tzinfo (~> 1.1)
|
21
21
|
zeitwerk (~> 2.2, >= 2.2.2)
|
22
22
|
ast (2.4.2)
|
23
|
+
backport (1.1.2)
|
24
|
+
benchmark (0.1.1)
|
23
25
|
concurrent-ruby (1.1.8)
|
24
26
|
diff-lcs (1.4.4)
|
27
|
+
e2mmap (0.1.0)
|
25
28
|
i18n (1.8.10)
|
26
29
|
concurrent-ruby (~> 1.0)
|
30
|
+
jaro_winkler (1.5.4)
|
31
|
+
kramdown (2.3.1)
|
32
|
+
rexml
|
33
|
+
kramdown-parser-gfm (1.1.0)
|
34
|
+
kramdown (~> 2.0)
|
35
|
+
mini_portile2 (2.5.1)
|
27
36
|
minitest (5.14.4)
|
37
|
+
nokogiri (1.11.5)
|
38
|
+
mini_portile2 (~> 2.5.0)
|
39
|
+
racc (~> 1.4)
|
40
|
+
nokogiri (1.11.5-x86_64-darwin)
|
41
|
+
racc (~> 1.4)
|
28
42
|
parallel (1.20.1)
|
29
43
|
parser (3.0.1.1)
|
30
44
|
ast (~> 2.4.1)
|
31
45
|
pg (1.2.3)
|
46
|
+
racc (1.5.2)
|
47
|
+
rack (2.2.3)
|
32
48
|
rainbow (3.0.0)
|
33
49
|
rake (12.3.3)
|
34
50
|
regexp_parser (2.1.1)
|
51
|
+
reverse_markdown (2.0.0)
|
52
|
+
nokogiri
|
35
53
|
rexml (3.2.5)
|
36
54
|
rspec (3.10.0)
|
37
55
|
rspec-core (~> 3.10.0)
|
@@ -57,17 +75,40 @@ GEM
|
|
57
75
|
unicode-display_width (>= 1.4.0, < 2.0)
|
58
76
|
rubocop-ast (1.5.0)
|
59
77
|
parser (>= 3.0.1.1)
|
78
|
+
rubocop-gitlab-security (0.1.1)
|
79
|
+
rubocop (>= 0.51)
|
60
80
|
rubocop-performance (1.9.2)
|
61
81
|
rubocop (>= 0.90.0, < 2.0)
|
62
82
|
rubocop-ast (>= 0.4.0)
|
83
|
+
rubocop-rails (2.9.1)
|
84
|
+
activesupport (>= 4.2.0)
|
85
|
+
rack (>= 1.1)
|
86
|
+
rubocop (>= 0.90.0, < 2.0)
|
63
87
|
rubocop-rspec (2.0.1)
|
64
88
|
rubocop (~> 1.0)
|
65
89
|
rubocop-ast (>= 1.1.0)
|
66
90
|
ruby-progressbar (1.11.0)
|
91
|
+
solargraph (0.40.4)
|
92
|
+
backport (~> 1.1)
|
93
|
+
benchmark
|
94
|
+
bundler (>= 1.17.2)
|
95
|
+
e2mmap
|
96
|
+
jaro_winkler (~> 1.5)
|
97
|
+
kramdown (~> 2.3)
|
98
|
+
kramdown-parser-gfm (~> 1.1)
|
99
|
+
parser (~> 3.0)
|
100
|
+
reverse_markdown (>= 1.0.5, < 3)
|
101
|
+
rubocop (>= 0.52)
|
102
|
+
thor (~> 1.0)
|
103
|
+
tilt (~> 2.0)
|
104
|
+
yard (~> 0.9, >= 0.9.24)
|
105
|
+
thor (1.1.0)
|
67
106
|
thread_safe (0.3.6)
|
107
|
+
tilt (2.0.10)
|
68
108
|
tzinfo (1.2.9)
|
69
109
|
thread_safe (~> 0.1)
|
70
110
|
unicode-display_width (1.7.0)
|
111
|
+
yard (0.9.26)
|
71
112
|
zeitwerk (2.4.2)
|
72
113
|
|
73
114
|
PLATFORMS
|
@@ -77,9 +118,12 @@ PLATFORMS
|
|
77
118
|
DEPENDENCIES
|
78
119
|
rake (~> 12.0)
|
79
120
|
rspec (~> 3.0)
|
80
|
-
rubocop
|
81
|
-
rubocop-
|
82
|
-
rubocop-
|
121
|
+
rubocop
|
122
|
+
rubocop-gitlab-security
|
123
|
+
rubocop-performance
|
124
|
+
rubocop-rails
|
125
|
+
rubocop-rspec
|
126
|
+
solargraph
|
83
127
|
xsdk-scaffold-rails!
|
84
128
|
|
85
129
|
BUNDLED WITH
|
@@ -1,221 +1,252 @@
|
|
1
1
|
module Xsdk
|
2
2
|
module Scaffold
|
3
3
|
module Rails
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
4
|
+
class BaseDatatable
|
5
|
+
def initialize(params, clazz)
|
6
|
+
@options = JSON.parse(params[:options]).with_indifferent_access
|
7
|
+
@clazz = clazz
|
8
|
+
@foreign_keys = get_foreign_key_map(clazz)
|
9
|
+
@only_schema = @options[:only_schema]
|
10
|
+
@default_values = @options.try(:[], :default) || {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def as_json(*)
|
14
|
+
return { columns: build_headers } if @only_schema
|
15
|
+
|
16
|
+
{
|
17
|
+
rows: paginate(get_data),
|
18
|
+
total_rows: get_count,
|
19
|
+
columns: build_headers
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
# Build rows
|
24
|
+
|
25
|
+
def paginate(data)
|
26
|
+
per_page = @options[:itemsPerPage]
|
27
|
+
page = @options[:page] - 1
|
28
|
+
data.limit(per_page)
|
29
|
+
.offset(page * per_page)
|
30
|
+
.as_json(methods: enum_methods, except: keys_to_exclude, include: has_many_include)
|
31
|
+
end
|
32
|
+
|
33
|
+
def keys_to_exclude
|
34
|
+
[]
|
35
|
+
end
|
36
|
+
|
37
|
+
def enum_methods
|
38
|
+
enum_methods = []
|
39
|
+
@clazz.defined_enums.each do |k, _v|
|
40
|
+
enum_methods << "#{k}_text"
|
41
|
+
end
|
42
|
+
enum_methods
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_raw_data
|
46
|
+
@clazz.all
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_data
|
50
|
+
data = get_raw_data
|
51
|
+
associations.reject { |_k, v| v[:association_type] == :has_many }.each do |_, value|
|
52
|
+
data = data.send(value[:join_type] || :joins, value[:relation])
|
53
|
+
end
|
54
|
+
to_select = associations.reject do |_k, v|
|
55
|
+
v[:association_type] == :has_many
|
56
|
+
end.reject { |_k, v| v[:source] == 'id' }.map do |key, value|
|
57
|
+
table_name = @foreign_keys[key][0][:class_name].constantize.table_name
|
58
|
+
"#{table_name}.#{value[:source]} AS #{value[:relation]}_#{value[:source]}"
|
59
|
+
end
|
60
|
+
data = data.select("#{@clazz.to_s.underscore.pluralize}.*", *to_select)
|
61
|
+
|
62
|
+
associations.select { |_k, v| v[:association_type] == :has_many }.each do |_, v|
|
63
|
+
data = data.includes(v[:join]).references(v[:join])
|
64
|
+
end
|
65
|
+
|
66
|
+
data
|
67
|
+
end
|
68
|
+
|
69
|
+
def has_many_include
|
70
|
+
associations.select { |_, v| v[:association_type] == :has_many }.map { |_, v| v[:include] }
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_if_can_show_new_record(key)
|
74
|
+
key = key.to_sym
|
75
|
+
(associations.select { |k, v| k == key && v[:show_new_record] }).any?
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_entity_name(key)
|
79
|
+
key = key.to_sym
|
80
|
+
assoc = associations[key]
|
81
|
+
return nil if assoc.nil?
|
82
|
+
|
83
|
+
assoc[:relation]
|
84
|
+
end
|
85
|
+
|
86
|
+
# Build columns
|
87
|
+
def build_headers
|
88
|
+
headers = columns.map do |c|
|
89
|
+
{
|
90
|
+
value: c, # warehouse_id
|
91
|
+
table_value: get_table_value(c), # "mag1"
|
92
|
+
text: get_text(c), # "Identificatore"
|
93
|
+
type: get_type(c), # "string"
|
94
|
+
in_form: get_in_form(c), # true/false
|
95
|
+
in_table: table_columns.include?(c), # true/false
|
96
|
+
table: get_table(c), # warehouses
|
97
|
+
source: get_source(c), # identifier
|
98
|
+
in_form_disabled: disabled_form_columns.include?(c), # true/false
|
99
|
+
min_search_size: get_min_search_size(c),
|
100
|
+
enum_cols: get_enum_cols(c),
|
101
|
+
subschema: get_subschema(c),
|
102
|
+
show_new_record: get_if_can_show_new_record(c),
|
103
|
+
entity_name: get_entity_name(c),
|
104
|
+
default: get_default_value(c)
|
105
|
+
}
|
106
|
+
end
|
107
|
+
headers << { text: 'Azioni', value: 'actions', type: '', in_form: false, in_table: true }
|
108
|
+
headers
|
109
|
+
end
|
110
|
+
|
111
|
+
def get_in_form(key)
|
112
|
+
(@options[:form_columns] || form_columns).include?(key)
|
113
|
+
end
|
114
|
+
|
115
|
+
def get_subschema(c)
|
116
|
+
subschema = nil
|
117
|
+
ax = associations.with_indifferent_access
|
118
|
+
if ax.key?(c) && (ax[c][:association_type] == :has_many)
|
119
|
+
child_options = '{}'
|
120
|
+
child_options = { options: ax[c][:options].to_json } if ax[c][:options].present?
|
121
|
+
begin
|
122
|
+
datatable = "#{ax[c][:clazz]}Datatable".constantize
|
123
|
+
dt = datatable.new(child_options)
|
124
|
+
rescue StandardError
|
125
|
+
dt = BaseDatatable.new(child_options, ax[c][:clazz])
|
126
|
+
end
|
127
|
+
subschema = dt.build_headers
|
128
|
+
subschema = subschema.reject { |sc| sc[:type] == 'foreign_key' && sc[:table] == @clazz.table_name }
|
129
|
+
subschema << { text: 'Elimina', value: '_destroy', type: '', in_form: false, in_table: false }
|
130
|
+
subschema << { text: 'Uuid', value: '_uuid', type: 'uuid', in_form: false, in_table: false }
|
131
|
+
subschema.each { |s| s[:is_subschema] = true }
|
132
|
+
end
|
133
|
+
subschema
|
134
|
+
end
|
135
|
+
|
136
|
+
def get_default_value(c)
|
137
|
+
@default_values[c]
|
138
|
+
end
|
139
|
+
|
140
|
+
def get_enum_cols(c)
|
141
|
+
arr = []
|
142
|
+
if @clazz.defined_enums.key?(c)
|
143
|
+
@clazz.defined_enums[c].each do |k, _v|
|
144
|
+
arr << {
|
145
|
+
value: k,
|
146
|
+
text: @clazz.human_attribute_name("#{c}_enum.#{k}")
|
147
|
+
}
|
148
|
+
end
|
149
|
+
end
|
150
|
+
arr
|
151
|
+
end
|
152
|
+
|
153
|
+
def get_min_search_size(c)
|
154
|
+
ax = associations.with_indifferent_access
|
155
|
+
if ax.key?(c) && ax[c][:source] == 'id'
|
156
|
+
ax[c][:min_search_size]
|
157
|
+
else
|
158
|
+
3
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def columns
|
163
|
+
@clazz.column_names - %w[created_at updated_at]
|
164
|
+
end
|
165
|
+
|
166
|
+
def table_columns
|
167
|
+
columns
|
168
|
+
end
|
169
|
+
|
170
|
+
def form_columns
|
171
|
+
columns - ['id']
|
172
|
+
end
|
173
|
+
|
174
|
+
def disabled_form_columns
|
175
|
+
[]
|
176
|
+
end
|
177
|
+
|
178
|
+
def get_table(c)
|
179
|
+
ax = associations.with_indifferent_access
|
180
|
+
if @foreign_keys.key?(c)
|
181
|
+
@foreign_keys[c][0][:class_name].constantize.table_name
|
182
|
+
elsif ax.key?(c) && (ax[c][:association_type] == :has_many)
|
183
|
+
ax[c][:clazz].table_name
|
184
|
+
else
|
185
|
+
@clazz.table_name
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def get_source(c)
|
190
|
+
ax = associations.with_indifferent_access
|
191
|
+
if ax.key?(c) && (ax[c][:association_type] != :has_many)
|
192
|
+
ax[c][:source]
|
193
|
+
else
|
194
|
+
c
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def get_text(c)
|
199
|
+
ax = associations.with_indifferent_access
|
200
|
+
if @foreign_keys.key?(c)
|
201
|
+
@foreign_keys[c][0][:class_name].constantize.model_name.human.capitalize
|
202
|
+
elsif ax.key?(c) && (ax[c][:association_type] == :has_many)
|
203
|
+
ax[c][:clazz].model_name.human.capitalize
|
204
|
+
else
|
205
|
+
@clazz.human_attribute_name(c).capitalize
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def get_type(c)
|
210
|
+
ax = associations.with_indifferent_access
|
211
|
+
if @foreign_keys.key?(c)
|
212
|
+
'foreign_key'
|
213
|
+
elsif ax.key?(c) && (ax[c][:association_type] == :has_many)
|
214
|
+
'has_many'
|
215
|
+
elsif @clazz.defined_enums.key?(c)
|
216
|
+
'enum'
|
217
|
+
else
|
218
|
+
@clazz.type_for_attribute(c).type
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def get_table_value(c)
|
223
|
+
ax = associations.with_indifferent_access
|
224
|
+
if ax.key?(c)
|
225
|
+
if ax[c][:association_type] == :has_many
|
226
|
+
c
|
227
|
+
else
|
228
|
+
"#{ax[c][:relation]}_#{ax[c][:source]}"
|
229
|
+
end
|
230
|
+
else
|
231
|
+
c
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def get_count
|
236
|
+
@clazz.count
|
237
|
+
end
|
238
|
+
|
239
|
+
def get_foreign_key_map(clazz)
|
240
|
+
clazz.reflect_on_all_associations.select { |a| a.macro == :belongs_to }
|
241
|
+
.map { |a| { key: a.foreign_key, class_name: a.class_name } }
|
242
|
+
.group_by { |a| a[:key] }
|
243
|
+
.with_indifferent_access
|
244
|
+
end
|
245
|
+
|
246
|
+
def associations
|
247
|
+
{}
|
248
|
+
end
|
249
|
+
end
|
219
250
|
end
|
220
251
|
end
|
221
252
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xsdk-scaffold-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Davide Croci
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
127
|
+
rubygems_version: 3.2.3
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: Gem for automatic scaffolding by Ermes-x.
|