activeadmin_json_editor 0.0.9 → 0.0.10
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 +4 -4
- data/.gitignore +2 -0
- data/README.md +4 -4
- data/app/assets/javascripts/active_admin/json_editor.js +30 -24
- data/lib/activeadmin/json_editor/version.rb +1 -1
- data/lib/activeadmin/resource_dsl.rb +27 -13
- metadata +4 -6
- data/vendor/assets/javascripts/.gitkeep +0 -0
- data/vendor/assets/stylesheets/.gitkeep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5021390f27b703a617625a391cf18257ae2833cfe5db14799e48e80c56484128
|
4
|
+
data.tar.gz: '049bf46fd8194ad2f8b5d685de90ebfa73f30fc05fa500c2d514c8162cba8b50'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df9e9dc2c3fc1ed90aeacedba58c0dc823a2830a4581194196430c11a90062f5481f37f1c0b5e84a6cd04c759ce85f196e9034263ce9387466ce38d8c211acc3
|
7
|
+
data.tar.gz: ba2c72fce9a7a72f5cd6e0609b74524731b239457b02892211a64cbb4fe73bcf2ffd5b9b3a3dc3f460c852283ec34dc85a7e5716b1dc9b8f98686483d26241aa
|
data/.gitignore
ADDED
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Data shown by using jsoneditor.js from http://jsoneditoronline.org
|
|
9
9
|
|
10
10
|
Add this line to your application's Gemfile:
|
11
11
|
|
12
|
-
gem 'activeadmin_json_editor', '~> 0.0.
|
12
|
+
gem 'activeadmin_json_editor', '~> 0.0.10'
|
13
13
|
|
14
14
|
And then execute:
|
15
15
|
|
@@ -30,12 +30,12 @@ This Gem provides you formtastic input called :json to edit json data and parse
|
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
ActiveAdmin.register User do
|
33
|
-
|
33
|
+
permit_params :settings
|
34
34
|
|
35
|
-
|
35
|
+
json_editor
|
36
36
|
|
37
37
|
# specify the type does not necessarily
|
38
|
-
|
38
|
+
form do |f|
|
39
39
|
f.inputs do
|
40
40
|
f.input :settings, as: :json
|
41
41
|
f.input :other_settings, as: :jsonb
|
@@ -2,30 +2,36 @@
|
|
2
2
|
//= require jsoneditor/asset/jsonlint/jsonlint.js
|
3
3
|
|
4
4
|
;(function(window, $) {
|
5
|
-
|
6
|
-
$(
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
editor.options.error(e);
|
22
|
-
}
|
23
|
-
},
|
24
|
-
error: function(e){
|
25
|
-
$(fieldset).toggleClass('error',true);
|
5
|
+
var initEditor = function(i,wrap){
|
6
|
+
var fieldset = $(wrap).parents('li:eq(0)');
|
7
|
+
var container = $(wrap)[0];
|
8
|
+
var textarea = $($(wrap).find('textarea'));
|
9
|
+
var editor;
|
10
|
+
var options = {
|
11
|
+
modes: ['tree', 'text'],
|
12
|
+
mode: 'tree',
|
13
|
+
change: function(ev){
|
14
|
+
try {
|
15
|
+
var text = JSON.stringify(editor.get());
|
16
|
+
textarea.text(text);
|
17
|
+
$(fieldset).toggleClass('error',false);
|
18
|
+
textarea.text(JSON.stringify(editor.get()));
|
19
|
+
} catch (e) {
|
20
|
+
editor.options.error(e);
|
26
21
|
}
|
27
|
-
}
|
28
|
-
|
29
|
-
|
22
|
+
},
|
23
|
+
error: function(e){
|
24
|
+
$(fieldset).toggleClass('error',true);
|
25
|
+
}
|
26
|
+
};
|
27
|
+
editor = new JSONEditor(container, options,JSON.parse(textarea.val()));
|
28
|
+
}
|
29
|
+
|
30
|
+
$(function() {
|
31
|
+
$('div.jsoneditor-wrap').each(initEditor);
|
32
|
+
|
33
|
+
$(document).on('has_many_add:after', '.has_many_container', function(e, fieldset, container) {
|
34
|
+
$('div.jsoneditor-wrap', fieldset).each(initEditor)
|
35
|
+
})
|
30
36
|
});
|
31
37
|
})(window, jQuery);
|
@@ -5,21 +5,35 @@ module ActiveAdmin
|
|
5
5
|
class ResourceDSL
|
6
6
|
def json_editor
|
7
7
|
before_save do |object, _args|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
else
|
16
|
-
JSON.parse(json_data)
|
17
|
-
end
|
18
|
-
object.attributes = { key => data }
|
8
|
+
object.class.columns_hash.select { |_key, attr| attr.type.in? [:json, :jsonb] }.keys.each do |key|
|
9
|
+
next unless params[resource_request_name].key? key
|
10
|
+
json_data = params[resource_request_name][key]
|
11
|
+
data = if json_data == 'null' || json_data.blank?
|
12
|
+
{}
|
13
|
+
else
|
14
|
+
JSON.parse(json_data)
|
19
15
|
end
|
20
|
-
|
21
|
-
raise ActionController::ParameterMissing, request_namespace
|
16
|
+
object.attributes = { key => data }
|
22
17
|
end
|
18
|
+
object.nested_attributes_options.keys.each {|_nested_key|
|
19
|
+
nested_attributes_with_index = params[resource_request_name]["#{_nested_key}_attributes"]
|
20
|
+
next if nested_attributes_with_index.nil?
|
21
|
+
nested_klass = _nested_key.to_s.singularize.camelize.constantize
|
22
|
+
nested_klass.columns_hash.select { |_key, attr| attr.type.in? [:json, :jsonb] }.keys.each do |key|
|
23
|
+
nested_attributes_with_index.each {|_index, nested_attributes|
|
24
|
+
next unless nested_attributes.key? key
|
25
|
+
json_data = nested_attributes[key]
|
26
|
+
data = if json_data == 'null' || json_data.blank?
|
27
|
+
{}
|
28
|
+
else
|
29
|
+
JSON.parse(json_data)
|
30
|
+
end
|
31
|
+
object.send(_nested_key).each {|nested_object|
|
32
|
+
nested_object.attributes = { key => data }
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
}
|
23
37
|
end
|
24
38
|
end
|
25
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_json_editor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- allanbreyes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ executables: []
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
+
- ".gitignore"
|
63
64
|
- Gemfile
|
64
65
|
- Gemfile.lock
|
65
66
|
- LICENSE.txt
|
@@ -76,7 +77,6 @@ files:
|
|
76
77
|
- lib/activeadmin_json_editor.rb
|
77
78
|
- vendor/assets/images/img/jsoneditor-icons.png
|
78
79
|
- vendor/assets/images/jsoneditor/img/jsoneditor-icons.png
|
79
|
-
- vendor/assets/javascripts/.gitkeep
|
80
80
|
- vendor/assets/javascripts/jsoneditor/asset/ace/ace.js
|
81
81
|
- vendor/assets/javascripts/jsoneditor/asset/ace/ext-searchbox.js
|
82
82
|
- vendor/assets/javascripts/jsoneditor/asset/ace/mode-json.js
|
@@ -87,7 +87,6 @@ files:
|
|
87
87
|
- vendor/assets/javascripts/jsoneditor/jsoneditor.js
|
88
88
|
- vendor/assets/javascripts/jsoneditor/jsoneditor.map
|
89
89
|
- vendor/assets/javascripts/jsoneditor/jsoneditor.min.js
|
90
|
-
- vendor/assets/stylesheets/.gitkeep
|
91
90
|
- vendor/assets/stylesheets/jsoneditor/jsoneditor.min.css
|
92
91
|
- vendor/assets/stylesheets/jsoneditor/jsoneditor.scss
|
93
92
|
homepage: https://github.com/allanbreyes/activeadmin_json_editor
|
@@ -109,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
108
|
- !ruby/object:Gem::Version
|
110
109
|
version: 1.3.6
|
111
110
|
requirements: []
|
112
|
-
|
113
|
-
rubygems_version: 2.7.6
|
111
|
+
rubygems_version: 3.1.2
|
114
112
|
signing_key:
|
115
113
|
specification_version: 4
|
116
114
|
summary: add "json_input" and "jsonb_input" field type to active_admin that allow
|
File without changes
|
File without changes
|