terrazzo 0.5.0 → 0.5.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45571db8ac5c20c765feaf02cfe7be1ab1bba1c84e77be02b8b72ca4a749875e
4
- data.tar.gz: f221316bc43fe5d871c3603297afb9fceff9a942a07ede4bdade9186ed455598
3
+ metadata.gz: c8d1fb21a6af1c708437891c1e3216a2749fb682513c40c4c583a950e92750f5
4
+ data.tar.gz: 47a449b824bf9f5a2cf00e7619aa5d008526f7b8d764258022a3d3ff43109c58
5
5
  SHA512:
6
- metadata.gz: ce93ab9c2c0a420128006d9cf67e33f083bcf5298cfbe493884970c255153e6ef71d948691ad10c5838c47cfe98c5fa46fb8de4c878eb154ae8ed29a5ff17b15
7
- data.tar.gz: 5d98160ec096c04a93a4aa5a5a8aadb3390126e2cddf9a780f519ad16eff2d2783b2e6843d91adbb15bbb4e23c06a7d2e95ad96e615d4204860e0ed84bd6f151
6
+ metadata.gz: e3970087e358e8ef4988ff18d3dff5c9a28de0253f5358afb0b54aeada98878ac16ad2b1f85a057e0c101bea47a74d6c79a63c259781571cc1b7d95327712bf8
7
+ data.tar.gz: c85f00757f7f54a86fa37d7f9509e109f672cf074eb9e88370132e74d5ccbc1e4bf0345c9410e396f85770a9b936658f5f637554e94bf7a7de46fc379c901e23
@@ -129,7 +129,7 @@ module Terrazzo
129
129
  end
130
130
 
131
131
  def find_resource(id)
132
- scoped_resource.find(id)
132
+ @_find_resource ||= scoped_resource.find(id)
133
133
  end
134
134
 
135
135
  def resource_params(action = nil)
@@ -29,7 +29,7 @@ json.form do
29
29
  json.label field.attribute.to_s.humanize
30
30
  json.fieldType field.field_type
31
31
  json.value field.serialize_value(:form)
32
- json.options field.serializable_options
32
+ json.options field.serializable_options(:form)
33
33
  json.required field.required?
34
34
  json.input field.form_input_attributes(param_key)
35
35
  end
@@ -43,7 +43,7 @@ json.form do
43
43
  json.label field.attribute.to_s.humanize
44
44
  json.fieldType field.field_type
45
45
  json.value field.serialize_value(:form)
46
- json.options field.serializable_options
46
+ json.options field.serializable_options(:form)
47
47
  json.required field.required?
48
48
  json.input field.form_input_attributes(param_key)
49
49
  end
@@ -25,7 +25,7 @@ json.form do
25
25
  json.label field.attribute.to_s.humanize
26
26
  json.fieldType field.field_type
27
27
  json.value field.serialize_value(:form)
28
- json.options field.serializable_options
28
+ json.options field.serializable_options(:form)
29
29
  json.required field.required?
30
30
  json.input field.form_input_attributes(param_key)
31
31
  end
@@ -39,7 +39,7 @@ json.form do
39
39
  json.label field.attribute.to_s.humanize
40
40
  json.fieldType field.field_type
41
41
  json.value field.serialize_value(:form)
42
- json.options field.serializable_options
42
+ json.options field.serializable_options(:form)
43
43
  json.required field.required?
44
44
  json.input field.form_input_attributes(param_key)
45
45
  end
@@ -21,7 +21,7 @@ show_field_json = ->(json, field) do
21
21
  end
22
22
  end
23
23
 
24
- json.attributeGroups do
24
+ json.attributes do
25
25
  json.array! @page.grouped_attributes do |group|
26
26
  json.name group[:name]
27
27
  json.attributes do
@@ -32,12 +32,6 @@ json.attributeGroups do
32
32
  end
33
33
  end
34
34
 
35
- json.attributes do
36
- json.array! @page.attributes do |field|
37
- show_field_json.call(json, field)
38
- end
39
- end
40
-
41
35
  json.editPath route_exists?(:edit) ? (edit_polymorphic_path([namespace, @resource]) rescue nil) : nil
42
36
  json.deletePath route_exists?(:destroy) ? (polymorphic_path([namespace, @resource]) rescue nil) : nil
43
37
  json.indexPath begin
@@ -5,7 +5,7 @@ module Terrazzo
5
5
  data
6
6
  end
7
7
 
8
- def serializable_options
8
+ def serializable_options(page = nil)
9
9
  {}
10
10
  end
11
11
 
@@ -9,7 +9,7 @@ export default function AdminShow() {
9
9
  const Layout = getLayout();
10
10
  const {
11
11
  pageTitle,
12
- attributeGroups,
12
+ attributes,
13
13
  editPath,
14
14
  deletePath,
15
15
  indexPath,
@@ -54,7 +54,7 @@ export default function AdminShow() {
54
54
  </div>
55
55
  }>
56
56
 
57
- {attributeGroups.map((group, groupIndex) =>
57
+ {attributes.map((group, groupIndex) =>
58
58
  <Card key={groupIndex}>
59
59
  {group.name && (
60
60
  <CardHeader>
@@ -20,7 +20,7 @@ module Terrazzo
20
20
  data
21
21
  end
22
22
 
23
- def serializable_options
23
+ def serializable_options(page = nil)
24
24
  {}
25
25
  end
26
26
 
@@ -11,16 +11,13 @@ module Terrazzo
11
11
  end
12
12
  end
13
13
 
14
- def serializable_options
15
- opts = {}
16
- if resource
17
- collection = ordered_resource_options
18
- if options[:include_blank]
19
- collection = [["", nil]] + collection
20
- end
21
- opts[:resourceOptions] = collection
14
+ def serializable_options(page = nil)
15
+ return {} unless page == :form && resource
16
+ collection = ordered_resource_options
17
+ if options[:include_blank]
18
+ collection = [["", nil]] + collection
22
19
  end
23
- opts
20
+ { resourceOptions: collection }
24
21
  end
25
22
 
26
23
  class << self
@@ -19,12 +19,9 @@ module Terrazzo
19
19
  end
20
20
  end
21
21
 
22
- def serializable_options
23
- opts = {}
24
- if resource
25
- opts[:resourceOptions] = resource_options
26
- end
27
- opts
22
+ def serializable_options(page = nil)
23
+ return {} unless page == :form && resource
24
+ { resourceOptions: resource_options }
28
25
  end
29
26
 
30
27
  class << self
@@ -115,7 +112,13 @@ module Terrazzo
115
112
  return records unless sort_by
116
113
 
117
114
  direction = options.fetch(:direction, :asc)
118
- records.reorder(sort_by => direction)
115
+
116
+ if records.respond_to?(:reorder)
117
+ records.reorder(sort_by => direction)
118
+ else
119
+ sorted = records.sort_by { |r| r.public_send(sort_by) }
120
+ direction.to_sym == :desc ? sorted.reverse : sorted
121
+ end
119
122
  end
120
123
 
121
124
  def find_associated_dashboard
@@ -11,12 +11,9 @@ module Terrazzo
11
11
  end
12
12
  end
13
13
 
14
- def serializable_options
15
- opts = {}
16
- if resource
17
- opts[:resourceOptions] = resource_options
18
- end
19
- opts
14
+ def serializable_options(page = nil)
15
+ return {} unless page == :form && resource
16
+ { resourceOptions: resource_options }
20
17
  end
21
18
 
22
19
  class << self
@@ -11,7 +11,7 @@ module Terrazzo
11
11
  end
12
12
  end
13
13
 
14
- def serializable_options
14
+ def serializable_options(page = nil)
15
15
  opts = {}
16
16
  opts[:prefix] = options[:prefix] if options.key?(:prefix)
17
17
  opts[:suffix] = options[:suffix] if options.key?(:suffix)
@@ -17,7 +17,7 @@ module Terrazzo
17
17
  end
18
18
  end
19
19
 
20
- def serializable_options
20
+ def serializable_options(page = nil)
21
21
  opts = {}
22
22
  opts[:prefix] = options[:prefix] if options.key?(:prefix)
23
23
  opts[:suffix] = options[:suffix] if options.key?(:suffix)
@@ -12,16 +12,16 @@ module Terrazzo
12
12
  end
13
13
  end
14
14
 
15
- def serializable_options
16
- opts = {}
15
+ def serializable_options(page = nil)
16
+ return {} unless page == :form
17
17
  classes = options[:classes] || []
18
18
  order = options[:order]
19
- opts[:groupedOptions] = classes.each_with_object({}) do |klass, hash|
19
+ grouped = classes.each_with_object({}) do |klass, hash|
20
20
  klass = klass.constantize if klass.is_a?(::String)
21
21
  scope = order ? klass.order(order) : klass.all
22
22
  hash[klass.name] = scope.map { |r| [display_name(r), r.id.to_s] }
23
23
  end
24
- opts
24
+ { groupedOptions: grouped }
25
25
  end
26
26
 
27
27
  class << self
@@ -5,7 +5,8 @@ module Terrazzo
5
5
  data
6
6
  end
7
7
 
8
- def serializable_options
8
+ def serializable_options(page = nil)
9
+ return {} unless page == :form
9
10
  { selectableOptions: resolve_collection }
10
11
  end
11
12
 
@@ -1,3 +1,3 @@
1
1
  module Terrazzo
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terrazzo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Terrazzo Contributors