push_type_core 0.5.0.alpha.2 → 0.5.0.alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/fields/push_type/asset_field.rb +5 -16
- data/app/fields/push_type/date_field.rb +2 -9
- data/app/fields/push_type/markdown_field.rb +4 -12
- data/app/fields/push_type/matrix_field.rb +11 -11
- data/app/fields/push_type/node_field.rb +22 -0
- data/app/fields/push_type/number_field.rb +3 -9
- data/app/fields/push_type/repeater_field.rb +7 -9
- data/app/fields/push_type/select_field.rb +7 -10
- data/app/fields/push_type/tag_list_field.rb +5 -11
- data/app/fields/push_type/taxonomy_field.rb +6 -47
- data/app/fields/push_type/text_field.rb +3 -3
- data/app/fields/push_type/time_field.rb +2 -9
- data/app/models/concerns/push_type/customizable.rb +8 -8
- data/db/migrate/20150531183944_add_field_store_default_values.rb +6 -0
- data/lib/generators/push_type/field/templates/field.rb +1 -1
- data/lib/push_type/field_type.rb +9 -53
- data/lib/push_type/fields/arrays.rb +23 -0
- data/lib/push_type/fields/base.rb +65 -0
- data/lib/push_type/fields/class_methods.rb +21 -0
- data/lib/push_type/fields/relations.rb +39 -0
- data/lib/push_type/fields/ui.rb +16 -0
- data/lib/push_type/version.rb +1 -1
- data/test/dummy/config/initializers/push_type.rb +1 -1
- data/test/dummy/config/secrets.yml +2 -2
- data/test/dummy/db/migrate/20150601132822_add_field_store_default_values.push_type.rb +7 -0
- data/test/dummy/db/schema.rb +7 -7
- data/test/dummy/log/test.log +2390 -2383
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/-Sjd8yE8radAZWLZz1Hn9eTc5vPZke6_-U1eg-KNjy8.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/RwmiAHIoiRN917L4TQ8saQaj1DsQgMpS97RYvkK2D5M.cache +0 -0
- data/test/dummy/tmp/generators/app/models/category.rb +6 -0
- data/test/dummy/tmp/generators/app/views/taxonomies/category.html.erb +3 -0
- data/test/lib/push_type/field_type_test.rb +0 -8
- data/test/models/concerns/push_type/customizable_test.rb +1 -1
- metadata +31 -21
- data/app/fields/push_type/array_field.rb +0 -15
- data/test/dummy/tmp/generators/app/presenters/page_presenter.rb +0 -12
- /data/test/dummy/db/migrate/{20150429164551_create_push_type_users.push_type.rb → 20150601132816_create_push_type_users.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20150429164552_create_push_type_nodes.push_type.rb → 20150601132817_create_push_type_nodes.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20150429164553_create_push_type_node_hierarchies.push_type.rb → 20150601132818_create_push_type_node_hierarchies.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20150429164554_create_push_type_assets.push_type.rb → 20150601132819_create_push_type_assets.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20150429164555_create_push_type_taxonomies.push_type.rb → 20150601132820_create_push_type_taxonomies.push_type.rb} +0 -0
- /data/test/dummy/db/migrate/{20150429164556_create_push_type_taxonomy_hierarchies.push_type.rb → 20150601132821_create_push_type_taxonomy_hierarchies.push_type.rb} +0 -0
- /data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{BL-JC9Mha5EbAlzAR0-4qZvqO8u_54SF5Z2ZaoDjlfw.cache → H_FtcM4uZms6K7jOADXRW2-Q5luNbbboPJ8haQyA17A.cache} +0 -0
- /data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/{OC9Pezno0-bFKhuLASN_oxeMelP7hAYHfMDOdC916tY.cache → khjpnuHaHw24GnTbWlsRS6uIuTqIkrfvc2dY1aZWtpk.cache} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b12033b0e730c01d39ed6a7d667dcb0009418897
|
4
|
+
data.tar.gz: 09ef26e24eff460828285fdeef96107b39a1b160
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73d086627daf27c656e4b655cb76f5bf7c4d7183052d749db2f014c332762c6724e43ff4b4f22ad515c3b8af3d40b888a40dce7735e406220097c2ba672cd65e
|
7
|
+
data.tar.gz: 53e698227a5f563102d8478bfbcb20a7514f1b355df91cfd0f93531a850de316dd4f8c6d2e1b12fb3900587df201ae4e33e61cebe4685d75b3f34a8cdb6ea6a4
|
@@ -1,32 +1,21 @@
|
|
1
1
|
module PushType
|
2
2
|
class AssetField < PushType::FieldType
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
include PushType::Fields::Relations
|
5
|
+
|
6
|
+
options template: 'asset'
|
7
7
|
|
8
8
|
def id_attr
|
9
9
|
"#{ name }-asset-modal"
|
10
10
|
end
|
11
11
|
|
12
|
-
def from_json(val)
|
13
|
-
return if val.blank?
|
14
|
-
PushType::Asset.find(val)
|
15
|
-
end
|
16
|
-
|
17
12
|
initialized_on_node do |object, field|
|
18
13
|
object.class_eval do
|
19
|
-
|
20
|
-
|
21
|
-
field_store[field.name]
|
14
|
+
define_method field.name.to_sym do
|
15
|
+
PushType::Asset.find send(field.json_key) if send(field.json_key).present?
|
22
16
|
end
|
23
|
-
|
24
17
|
end
|
25
18
|
end
|
26
19
|
|
27
|
-
def relation_id_method
|
28
|
-
(name + '_id').to_sym
|
29
|
-
end
|
30
|
-
|
31
20
|
end
|
32
21
|
end
|
@@ -1,17 +1,10 @@
|
|
1
1
|
module PushType
|
2
2
|
class DateField < PushType::FieldType
|
3
3
|
|
4
|
-
|
5
|
-
@opts[:template] || 'date'
|
6
|
-
end
|
7
|
-
|
8
|
-
def form_helper
|
9
|
-
@opts[:form_helper] || :date_field
|
10
|
-
end
|
4
|
+
options template: 'date', form_helper: :date_field
|
11
5
|
|
12
6
|
def from_json(val)
|
13
|
-
|
14
|
-
val.to_date
|
7
|
+
val.to_date if val.present?
|
15
8
|
end
|
16
9
|
|
17
10
|
end
|
@@ -3,7 +3,7 @@ require 'redcarpet'
|
|
3
3
|
module PushType
|
4
4
|
class MarkdownField < PushType::FieldType
|
5
5
|
|
6
|
-
|
6
|
+
options form_helper: :text_area, renderer: Redcarpet::Render::HTML, render_options: {}, extensions: {
|
7
7
|
autolink: true,
|
8
8
|
fenced_code_blocks: true,
|
9
9
|
no_intra_emphasis: true,
|
@@ -18,26 +18,18 @@ module PushType
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def markdown
|
21
|
-
@markdown ||= Redcarpet::Markdown.new(renderer, extensions)
|
21
|
+
@markdown ||= Redcarpet::Markdown.new(renderer, @opts[:extensions])
|
22
22
|
end
|
23
23
|
|
24
24
|
def renderer
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def render_options
|
29
|
-
@opts[:render_options] || {}
|
30
|
-
end
|
31
|
-
|
32
|
-
def extensions
|
33
|
-
DEFAULT_EXTENSIONS.merge(@opts[:extensions] || {})
|
25
|
+
@opts[:renderer].new @opts[:render_options]
|
34
26
|
end
|
35
27
|
|
36
28
|
initialized_on_node do |object, field|
|
37
29
|
object.presenter_class.class_eval do
|
38
30
|
|
39
31
|
define_method field.name.to_sym do
|
40
|
-
fields[field.
|
32
|
+
fields[field.json_key].markdown.render super()
|
41
33
|
end
|
42
34
|
|
43
35
|
end
|
@@ -1,20 +1,24 @@
|
|
1
1
|
module PushType
|
2
|
-
class MatrixField <
|
2
|
+
class MatrixField < PushType::FieldType
|
3
|
+
|
4
|
+
include PushType::Fields::Arrays
|
5
|
+
|
6
|
+
options template: :matrix, mapping: [:key, :value]
|
3
7
|
|
4
8
|
def param
|
5
|
-
{
|
6
|
-
end
|
7
|
-
|
8
|
-
def template
|
9
|
-
@opts[:template] || :matrix
|
9
|
+
{ json_key => mapping.keys }
|
10
10
|
end
|
11
11
|
|
12
12
|
def mapping
|
13
|
-
@mapping ||=
|
13
|
+
@mapping ||= @opts[:mapping].reduce({}) do |h, col|
|
14
14
|
col.is_a?(Hash) ? h.merge(col) : h.update(col => form_helper)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
def struct
|
19
|
+
@struct ||= Struct.new *mapping.keys
|
20
|
+
end
|
21
|
+
|
18
22
|
def to_json(val)
|
19
23
|
return if val.blank?
|
20
24
|
super.reject { |v| v.blank? or v.values.all?(&:blank?) }
|
@@ -25,9 +29,5 @@ module PushType
|
|
25
29
|
super.reject { |v| v.blank? or v.values.all?(&:blank?) }.map { |h| struct.new(*h.values) }
|
26
30
|
end
|
27
31
|
|
28
|
-
def struct
|
29
|
-
@struct ||= Struct.new *mapping.keys
|
30
|
-
end
|
31
|
-
|
32
32
|
end
|
33
33
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module PushType
|
2
|
+
class NodeField < SelectField
|
3
|
+
|
4
|
+
include PushType::Fields::Relations
|
5
|
+
|
6
|
+
options template: 'relation', field_options: {}, root: '/'
|
7
|
+
|
8
|
+
def relation_root
|
9
|
+
root = @opts[:root] == '/' ? PushType::Node : PushType::Node.find_by_path(@opts[:root].split('/'))
|
10
|
+
root or raise "Cannot find root node at path '#{ @opts[:root] }'"
|
11
|
+
end
|
12
|
+
|
13
|
+
initialized_on_node do |object, field|
|
14
|
+
object.class_eval do
|
15
|
+
define_method field.name.to_sym do
|
16
|
+
field.relation_class.find send(field.json_key) if send(field.json_key).present?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -1,17 +1,11 @@
|
|
1
1
|
module PushType
|
2
2
|
class NumberField < PushType::FieldType
|
3
|
-
|
4
|
-
|
5
|
-
end
|
3
|
+
|
4
|
+
options form_helper: :number_field
|
6
5
|
|
7
6
|
def to_json(val)
|
8
|
-
|
9
|
-
val.to_i
|
7
|
+
val.to_i if val.present?
|
10
8
|
end
|
11
9
|
|
12
|
-
def from_json(val)
|
13
|
-
return if val.blank?
|
14
|
-
val.to_i
|
15
|
-
end
|
16
10
|
end
|
17
11
|
end
|
@@ -1,18 +1,16 @@
|
|
1
1
|
module PushType
|
2
|
-
class RepeaterField <
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class RepeaterField < FieldType
|
3
|
+
|
4
|
+
include PushType::Fields::Arrays
|
5
|
+
|
6
|
+
options template: :repeater
|
7
7
|
|
8
8
|
def to_json(val)
|
9
|
-
|
10
|
-
super.reject(&:blank?)
|
9
|
+
super.reject(&:blank?) if val.present?
|
11
10
|
end
|
12
11
|
|
13
12
|
def from_json(val)
|
14
|
-
|
15
|
-
super.reject(&:blank?)
|
13
|
+
super.reject(&:blank?) if val.present?
|
16
14
|
end
|
17
15
|
|
18
16
|
end
|
@@ -1,16 +1,17 @@
|
|
1
1
|
module PushType
|
2
2
|
class SelectField < PushType::FieldType
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
options template: 'select', choices: [], field_options: { include_blank: 'Please select...' }, multiple: false
|
5
|
+
|
6
|
+
def multiple?
|
7
|
+
@opts[:multiple]
|
6
8
|
end
|
7
9
|
|
8
|
-
def
|
9
|
-
|
10
|
+
def param
|
11
|
+
multiple? ? { json_key => [] } : super
|
10
12
|
end
|
11
13
|
|
12
14
|
def choices
|
13
|
-
return [] unless @opts[:choices]
|
14
15
|
if @opts[:choices].respond_to? :call
|
15
16
|
@opts[:choices].call
|
16
17
|
else
|
@@ -19,7 +20,7 @@ module PushType
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def field_options
|
22
|
-
|
23
|
+
@opts[:field_options]
|
23
24
|
end
|
24
25
|
|
25
26
|
def html_options
|
@@ -36,9 +37,5 @@ module PushType
|
|
36
37
|
multiple? ? Array(val).reject(&:blank?) : super
|
37
38
|
end
|
38
39
|
|
39
|
-
def multiple?
|
40
|
-
@opts[:multiple] || false
|
41
|
-
end
|
42
|
-
|
43
40
|
end
|
44
41
|
end
|
@@ -1,24 +1,18 @@
|
|
1
1
|
require 'push_type/tag_list_query'
|
2
2
|
|
3
3
|
module PushType
|
4
|
-
class TagListField <
|
4
|
+
class TagListField < PushType::FieldType
|
5
5
|
|
6
|
-
|
7
|
-
@opts[:template] || 'tag_list'
|
8
|
-
end
|
6
|
+
include PushType::Fields::Arrays
|
9
7
|
|
10
|
-
|
11
|
-
{ multiple: true, placeholder: 'Tags...' }.merge(super)
|
12
|
-
end
|
8
|
+
options template: 'tag_list', html_options: { multiple: true, placeholder: 'Tags...' }
|
13
9
|
|
14
10
|
def to_json(val)
|
15
|
-
|
16
|
-
super.reject(&:blank?)
|
11
|
+
super.reject(&:blank?) if val.present?
|
17
12
|
end
|
18
13
|
|
19
14
|
def from_json(val)
|
20
|
-
|
21
|
-
super.reject(&:blank?)
|
15
|
+
super.reject(&:blank?) if val.present?
|
22
16
|
end
|
23
17
|
|
24
18
|
initialized_on_node do |object, field|
|
@@ -1,62 +1,21 @@
|
|
1
1
|
module PushType
|
2
2
|
class TaxonomyField < SelectField
|
3
3
|
|
4
|
-
|
5
|
-
@opts[:template] || 'taxonomy'
|
6
|
-
end
|
4
|
+
include PushType::Fields::Relations
|
7
5
|
|
8
|
-
|
9
|
-
[]
|
10
|
-
end
|
6
|
+
options template: 'relation', field_options: {}
|
11
7
|
|
12
|
-
def
|
13
|
-
|
14
|
-
ids = multiple? ? Array(val).reject(&:blank?) : super
|
15
|
-
taxonomy_class.find(ids)
|
8
|
+
def relation_option
|
9
|
+
@opts[:taxonomy_class]
|
16
10
|
end
|
17
11
|
|
18
12
|
initialized_on_node do |object, field|
|
19
13
|
object.class_eval do
|
20
|
-
|
21
|
-
|
22
|
-
field_store[field.name]
|
14
|
+
define_method field.name.to_sym do
|
15
|
+
field.relation_class.find send(field.json_key) if send(field.json_key).present?
|
23
16
|
end
|
24
|
-
|
25
17
|
end
|
26
18
|
end
|
27
19
|
|
28
|
-
def singular_name
|
29
|
-
multiple? ? name.singularize : name
|
30
|
-
end
|
31
|
-
|
32
|
-
def taxonomy_class
|
33
|
-
(@opts[:taxonomy_class] || singular_name).to_s.classify.constantize
|
34
|
-
end
|
35
|
-
|
36
|
-
def taxonomy_tree_to_json
|
37
|
-
flatten_tree taxonomy_class.hash_tree
|
38
|
-
end
|
39
|
-
|
40
|
-
def relation_id_method
|
41
|
-
suffix = multiple? ? '_ids' : '_id'
|
42
|
-
(singular_name + suffix).to_sym
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def flatten_tree(hash_tree, d = 0)
|
48
|
-
hash_tree.flat_map do |parent, children|
|
49
|
-
[
|
50
|
-
{
|
51
|
-
value: parent.id,
|
52
|
-
text: parent.title,
|
53
|
-
depth: d
|
54
|
-
},
|
55
|
-
flatten_tree(children, d+1)
|
56
|
-
]
|
57
|
-
end.flatten
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
20
|
end
|
62
21
|
end
|
@@ -1,17 +1,10 @@
|
|
1
1
|
module PushType
|
2
2
|
class TimeField < PushType::FieldType
|
3
3
|
|
4
|
-
|
5
|
-
@opts[:template] || 'date'
|
6
|
-
end
|
7
|
-
|
8
|
-
def form_helper
|
9
|
-
@opts[:form_helper] || :time_field
|
10
|
-
end
|
4
|
+
options template: 'date', form_helper: :time_field
|
11
5
|
|
12
6
|
def from_json(val)
|
13
|
-
|
14
|
-
val.to_time
|
7
|
+
val.to_time if val.present?
|
15
8
|
end
|
16
9
|
|
17
10
|
end
|
@@ -26,15 +26,15 @@ module PushType
|
|
26
26
|
else [ :string, {} ]
|
27
27
|
end
|
28
28
|
|
29
|
-
fields[name] = field_factory(kind).new(name, opts)
|
30
|
-
store_accessor :field_store,
|
29
|
+
_field = fields[name] = field_factory(kind).new(name, opts)
|
30
|
+
store_accessor :field_store, _field.json_key
|
31
31
|
|
32
|
-
validates
|
32
|
+
validates _field.json_key, opts[:validates] if opts[:validates]
|
33
33
|
|
34
|
-
override_accessor
|
34
|
+
override_accessor _field
|
35
35
|
|
36
|
-
if block =
|
37
|
-
block.call(self,
|
36
|
+
if block = _field.class.initialized_blk
|
37
|
+
block.call(self, _field)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -49,10 +49,10 @@ module PushType
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def override_accessor(f)
|
52
|
-
define_method "#{f.
|
52
|
+
define_method "#{ f.json_key }=".to_sym do |val|
|
53
53
|
super f.to_json(val)
|
54
54
|
end
|
55
|
-
define_method f.
|
55
|
+
define_method f.json_key do
|
56
56
|
f.from_json super()
|
57
57
|
end
|
58
58
|
end
|
data/lib/push_type/field_type.rb
CHANGED
@@ -1,60 +1,16 @@
|
|
1
|
+
require 'push_type/fields/class_methods'
|
2
|
+
require 'push_type/fields/base'
|
3
|
+
require 'push_type/fields/ui'
|
4
|
+
require 'push_type/fields/arrays'
|
5
|
+
require 'push_type/fields/relations'
|
6
|
+
|
1
7
|
module PushType
|
2
8
|
class FieldType
|
3
9
|
|
4
|
-
|
5
|
-
|
6
|
-
class << self
|
7
|
-
attr_reader :initialized_blk
|
8
|
-
def initialized_on_node(&block)
|
9
|
-
@initialized_blk = block
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(name, opts = {})
|
14
|
-
@name = name.to_s
|
15
|
-
@opts = opts
|
16
|
-
end
|
17
|
-
|
18
|
-
def param
|
19
|
-
name.to_sym
|
20
|
-
end
|
21
|
-
|
22
|
-
def kind
|
23
|
-
self.class.name.demodulize.underscore.gsub(/_(field|type)$/, '')
|
24
|
-
end
|
25
|
-
|
26
|
-
def template
|
27
|
-
@opts[:template] || 'default'
|
28
|
-
end
|
29
|
-
|
30
|
-
def label
|
31
|
-
@opts[:label] || name.humanize
|
32
|
-
end
|
33
|
-
|
34
|
-
def html_options
|
35
|
-
@opts[:html_options] || {}
|
36
|
-
end
|
37
|
-
|
38
|
-
def form_helper
|
39
|
-
@opts[:form_helper] || :text_field
|
40
|
-
end
|
41
|
-
|
42
|
-
def column_class
|
43
|
-
case @opts[:colspan]
|
44
|
-
when 2 then 'medium-6'
|
45
|
-
when 3 then 'medium-4'
|
46
|
-
when 3 then 'medium-3'
|
47
|
-
else nil
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def to_json(val)
|
52
|
-
val
|
53
|
-
end
|
10
|
+
extend PushType::Fields::ClassMethods
|
54
11
|
|
55
|
-
|
56
|
-
|
57
|
-
end
|
12
|
+
include PushType::Fields::Base
|
13
|
+
include PushType::Fields::Ui
|
58
14
|
|
59
15
|
end
|
60
16
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PushType
|
2
|
+
module Fields
|
3
|
+
module Arrays
|
4
|
+
|
5
|
+
def param
|
6
|
+
{ json_key => [] }
|
7
|
+
end
|
8
|
+
|
9
|
+
def multiple?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_json(val)
|
14
|
+
Array(val)
|
15
|
+
end
|
16
|
+
|
17
|
+
def from_json(val)
|
18
|
+
Array(val)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module PushType
|
2
|
+
module Fields
|
3
|
+
module Base
|
4
|
+
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(name, opts = {})
|
8
|
+
@name = name.to_s
|
9
|
+
@opts = [defaults, self.class.options, opts].compact.inject(&:merge)
|
10
|
+
end
|
11
|
+
|
12
|
+
def kind
|
13
|
+
self.class.kind
|
14
|
+
end
|
15
|
+
|
16
|
+
def json_key
|
17
|
+
name.to_sym
|
18
|
+
end
|
19
|
+
|
20
|
+
def param
|
21
|
+
json_key
|
22
|
+
end
|
23
|
+
|
24
|
+
def multiple?
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
def template
|
29
|
+
@opts[:template]
|
30
|
+
end
|
31
|
+
|
32
|
+
def label
|
33
|
+
@opts[:label]
|
34
|
+
end
|
35
|
+
|
36
|
+
def html_options
|
37
|
+
@opts[:html_options]
|
38
|
+
end
|
39
|
+
|
40
|
+
def form_helper
|
41
|
+
@opts[:form_helper]
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_json(val)
|
45
|
+
val
|
46
|
+
end
|
47
|
+
|
48
|
+
def from_json(val)
|
49
|
+
val
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def defaults
|
55
|
+
{
|
56
|
+
template: 'default',
|
57
|
+
label: name.humanize,
|
58
|
+
form_helper: :text_field,
|
59
|
+
html_options: {}
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PushType
|
2
|
+
module Fields
|
3
|
+
module ClassMethods
|
4
|
+
|
5
|
+
attr_reader :initialized_blk
|
6
|
+
|
7
|
+
def options(*opts)
|
8
|
+
@options ||= opts.first
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialized_on_node(&block)
|
12
|
+
@initialized_blk = block
|
13
|
+
end
|
14
|
+
|
15
|
+
def kind
|
16
|
+
self.name.demodulize.underscore.gsub(/_(field|type)$/, '')
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module PushType
|
2
|
+
module Fields
|
3
|
+
module Relations
|
4
|
+
|
5
|
+
def json_key
|
6
|
+
suffix = multiple? ? '_ids' : 'id'
|
7
|
+
(name.singularize + suffix).to_sym
|
8
|
+
end
|
9
|
+
|
10
|
+
def relation_option
|
11
|
+
@opts[:relation_class]
|
12
|
+
end
|
13
|
+
|
14
|
+
def relation_root
|
15
|
+
(relation_option || name.singularize).to_s.classify.constantize
|
16
|
+
end
|
17
|
+
|
18
|
+
def relation_tree
|
19
|
+
flatten_tree relation_root.hash_tree
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def flatten_tree(hash_tree, d = 0)
|
25
|
+
hash_tree.flat_map do |parent, children|
|
26
|
+
[
|
27
|
+
{
|
28
|
+
value: parent.id,
|
29
|
+
text: parent.title,
|
30
|
+
depth: d
|
31
|
+
},
|
32
|
+
flatten_tree(children, d+1)
|
33
|
+
]
|
34
|
+
end.flatten
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|