dynamic_scaffold 1.7.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/app/views/dynamic_scaffold/bootstrap/form/_row.html.erb +7 -1
- data/lib/dynamic_scaffold.rb +8 -2
- data/lib/dynamic_scaffold/controller.rb +4 -1
- data/lib/dynamic_scaffold/form/item/base.rb +5 -1
- data/lib/dynamic_scaffold/form/item/cocoon.rb +1 -0
- data/lib/dynamic_scaffold/form/item/json_object.rb +32 -0
- data/lib/dynamic_scaffold/form/item/type.rb +3 -1
- data/lib/dynamic_scaffold/form_builder.rb +6 -1
- data/lib/dynamic_scaffold/json_object/attribute.rb +24 -0
- data/lib/dynamic_scaffold/json_object/model.rb +18 -0
- data/lib/dynamic_scaffold/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83178747c82566649957d2845a6e425dd16b320b8fe8ef3954432981c941aa16
|
4
|
+
data.tar.gz: c8e689ee3fd60cb006f29cf053009de07799b45542c6187f91332eca005d2046
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4fb71172557f91a3241555f6469ec2bb9c8aa7f264b0c284a134c05f4392f8b362c46dcf53a9447ba4efb91188939f066337286bca694f55fb6b71025cc16c7
|
7
|
+
data.tar.gz: 3fc6eadf855760330b0840a4148f18a37a42a4aa2d37e433b5c9c09a9293a4d1571f8adb80e0ee70932be77903dab830dcc324080b1d7196604961d5009f77f3
|
data/README.md
CHANGED
@@ -364,6 +364,12 @@ We support [cocoon](https://github.com/nathanvda/cocoon).
|
|
364
364
|
end
|
365
365
|
```
|
366
366
|
|
367
|
+
##### json_object
|
368
|
+
|
369
|
+
You can save json object string in a column using each form items and validations.
|
370
|
+
Check this [wiki](https://github.com/gomo/dynamic_scaffold/wiki/Handling-json-object-string-column)
|
371
|
+
|
372
|
+
|
367
373
|
#### Overwrite actions
|
368
374
|
|
369
375
|
You can pass the block to super in index/create/update actions.
|
@@ -68,7 +68,7 @@
|
|
68
68
|
<%end%>
|
69
69
|
<% end %>
|
70
70
|
<% elsif elem.type? :cocoon %>
|
71
|
-
<%= form.fields_for
|
71
|
+
<%= form.fields_for(elem.name, elem.build_children(@record)) do |child_form| %>
|
72
72
|
<%= render 'dynamic_scaffold/bootstrap/form/cocoon', f: child_form, items: elem.form.items, depth: depth %>
|
73
73
|
<% end %>
|
74
74
|
<%= link_to_add_association(
|
@@ -86,6 +86,12 @@
|
|
86
86
|
.gsub(/ : /, '<span class="mr-2" style="display: inline-block;">:</span>')
|
87
87
|
%>
|
88
88
|
</div>
|
89
|
+
<% elsif elem.type?(:json_object) %>
|
90
|
+
<%= form.fields_for(elem.name, @record.public_send(elem.name)) do |child_form| %>
|
91
|
+
<%- elem.form.items.each do |child_elem|-%>
|
92
|
+
<%= render 'dynamic_scaffold/bootstrap/form/row', form: child_form, elem: child_elem, depth: depth %>
|
93
|
+
<% end %>
|
94
|
+
<% end %>
|
89
95
|
<% else %>
|
90
96
|
<%= elem.render(self, form, class_names('form-control', {'is-invalid': errors.present?})) %>
|
91
97
|
<% end %>
|
data/lib/dynamic_scaffold.rb
CHANGED
@@ -32,8 +32,14 @@ module DynamicScaffold
|
|
32
32
|
autoload :SingleOption, 'dynamic_scaffold/form/item/single_option'
|
33
33
|
autoload :TwoOptionsWithBlock, 'dynamic_scaffold/form/item/two_options_with_block'
|
34
34
|
autoload :TwoOptions, 'dynamic_scaffold/form/item/two_options'
|
35
|
-
autoload :GlobalizeFields,
|
36
|
-
autoload :Cocoon,
|
35
|
+
autoload :GlobalizeFields, 'dynamic_scaffold/form/item/globalize_fields'
|
36
|
+
autoload :Cocoon, 'dynamic_scaffold/form/item/cocoon'
|
37
|
+
autoload :JSONObject, 'dynamic_scaffold/form/item/json_object'
|
37
38
|
end
|
38
39
|
end
|
40
|
+
|
41
|
+
module JSONObject
|
42
|
+
autoload :Attribute, 'dynamic_scaffold/json_object/attribute'
|
43
|
+
autoload :Model, 'dynamic_scaffold/json_object/model'
|
44
|
+
end
|
39
45
|
end
|
@@ -77,7 +77,7 @@ module DynamicScaffold
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
def update # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
80
|
+
def update # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
81
81
|
values = update_values
|
82
82
|
@record = find_record(dynamic_scaffold.model.primary_key => params['id'])
|
83
83
|
datetime_select_keys = []
|
@@ -93,6 +93,9 @@ module DynamicScaffold
|
|
93
93
|
# globalize
|
94
94
|
next [:translations_attributes, @record.translations] if k == 'translations_attributes'
|
95
95
|
|
96
|
+
# skip nested_attributes
|
97
|
+
next unless @record.respond_to? k
|
98
|
+
|
96
99
|
[k, @record.public_send(k)]
|
97
100
|
end.compact.to_h.with_indifferent_access
|
98
101
|
|
@@ -15,6 +15,7 @@ module DynamicScaffold
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
attr_accessor :parent_item
|
18
19
|
attr_reader :name
|
19
20
|
def initialize(config, type, name, html_attributes = {})
|
20
21
|
@config = config
|
@@ -32,7 +33,10 @@ module DynamicScaffold
|
|
32
33
|
end
|
33
34
|
|
34
35
|
def unique_name
|
35
|
-
|
36
|
+
results = [@config.model.table_name]
|
37
|
+
results << parent_item.name if parent_item.present?
|
38
|
+
results << name
|
39
|
+
results.join('_')
|
36
40
|
end
|
37
41
|
|
38
42
|
def notes?
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module DynamicScaffold
|
2
|
+
module Form
|
3
|
+
module Item
|
4
|
+
class JSONObject < Base
|
5
|
+
attr_reader :form
|
6
|
+
def initialize(config, type, name, options = {})
|
7
|
+
super
|
8
|
+
@options = options
|
9
|
+
@form = FormBuilder.new(config)
|
10
|
+
@form.parent_item = self
|
11
|
+
yield(@form)
|
12
|
+
end
|
13
|
+
|
14
|
+
# the lable is always empty.
|
15
|
+
def render_label(_view, _depth)
|
16
|
+
''
|
17
|
+
end
|
18
|
+
|
19
|
+
def extract_parameters(permitting)
|
20
|
+
hash = permitting.find {|e| e.is_a?(Hash) && e.key?(name) }
|
21
|
+
if hash.nil?
|
22
|
+
hash = {}
|
23
|
+
hash[name] = form.items.map(&:name)
|
24
|
+
permitting << hash
|
25
|
+
else
|
26
|
+
hash[name].concat(form.items.map(&:name))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module DynamicScaffold
|
2
2
|
class FormBuilder
|
3
|
+
attr_accessor :parent_item
|
4
|
+
|
3
5
|
def initialize(config)
|
4
6
|
@config = config
|
5
7
|
@items = []
|
@@ -11,7 +13,9 @@ module DynamicScaffold
|
|
11
13
|
@config.model.column_names.each do |column|
|
12
14
|
type = :text_field
|
13
15
|
type = :hidden_field if @config.scope && @config.scope.include?(column.to_sym)
|
14
|
-
|
16
|
+
item = Form::Item::SingleOption.new(@config, type, column)
|
17
|
+
item.parent_item = parent_item
|
18
|
+
@items << item
|
15
19
|
end
|
16
20
|
end
|
17
21
|
@items
|
@@ -28,6 +32,7 @@ module DynamicScaffold
|
|
28
32
|
|
29
33
|
def item(type, *args, &block)
|
30
34
|
item = Form::Item::Base.create(@config, type, *args, &block)
|
35
|
+
item.parent_item = parent_item
|
31
36
|
@items << item
|
32
37
|
item
|
33
38
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module DynamicScaffold
|
2
|
+
module JSONObject
|
3
|
+
module Attribute
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
@json_object_attribute_names ||= []
|
8
|
+
|
9
|
+
define_method :valid? do |context = nil|
|
10
|
+
result = super(context)
|
11
|
+
json_object_attribute_names = self.class.instance_variable_get(:@json_object_attribute_names)
|
12
|
+
json_object_attribute_names.all? {|method| public_send(method).valid?(context) } && result
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def json_object_attributte(attribute_name, model)
|
18
|
+
@json_object_attribute_names << attribute_name
|
19
|
+
serialize attribute_name, model
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module DynamicScaffold
|
2
|
+
module JSONObject
|
3
|
+
module Model
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def dump(obj)
|
8
|
+
obj = obj.attributes if obj.is_a? ActiveModel::Attributes
|
9
|
+
obj.to_json if obj
|
10
|
+
end
|
11
|
+
|
12
|
+
def load(source)
|
13
|
+
new(source ? JSON.parse(source) : {})
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masamoto Miyata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01
|
11
|
+
date: 2021-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: classnames-rails-view
|
@@ -295,12 +295,15 @@ files:
|
|
295
295
|
- lib/dynamic_scaffold/form/item/carrier_wave_image.rb
|
296
296
|
- lib/dynamic_scaffold/form/item/cocoon.rb
|
297
297
|
- lib/dynamic_scaffold/form/item/globalize_fields.rb
|
298
|
+
- lib/dynamic_scaffold/form/item/json_object.rb
|
298
299
|
- lib/dynamic_scaffold/form/item/single_option.rb
|
299
300
|
- lib/dynamic_scaffold/form/item/two_options.rb
|
300
301
|
- lib/dynamic_scaffold/form/item/two_options_with_block.rb
|
301
302
|
- lib/dynamic_scaffold/form/item/type.rb
|
302
303
|
- lib/dynamic_scaffold/form_builder.rb
|
303
304
|
- lib/dynamic_scaffold/icons/fontawesome.rb
|
305
|
+
- lib/dynamic_scaffold/json_object/attribute.rb
|
306
|
+
- lib/dynamic_scaffold/json_object/model.rb
|
304
307
|
- lib/dynamic_scaffold/list/item.rb
|
305
308
|
- lib/dynamic_scaffold/list/pagination.rb
|
306
309
|
- lib/dynamic_scaffold/list_builder.rb
|