katalyst-tables 3.4.3 → 3.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/katalyst/tables/typed-columns/_enum.scss +5 -1
- data/app/components/katalyst/tables/cells/enum_component.rb +1 -5
- data/app/components/katalyst/tables/query/modal_component.rb +8 -1
- data/lib/katalyst/tables/collection/type/enum.rb +23 -4
- data/lib/katalyst/tables/collection/type/value.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc68e986f0047e4a30844861ec4cf0222649fa9635ca59a466846862090033da
|
4
|
+
data.tar.gz: fc12160c9acca555b6d5041ef49170af9630e8f6e67f81d6bec32564105e963a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d4334a6bb9b7edd4092ff131cc59a6e43ee9ce66c48c29c6aa5725585914da6c6b94e9e8cb9aa3babd8bcdaf35f24b3fc83f3d861f04e2a6294af6a8f8e3de0
|
7
|
+
data.tar.gz: 4a4a96c779a4ad08d0a5e1a4b415b465eb85a22b071d40321dd85f49856b372b63fd5a64ad41719a38d8bd282146eedb11982ca7821237f8ade93271b6de19d5
|
@@ -7,7 +7,7 @@ module Katalyst
|
|
7
7
|
class EnumComponent < CellComponent
|
8
8
|
def rendered_value
|
9
9
|
if (value = self.value).present?
|
10
|
-
label =
|
10
|
+
label = collection.model.human_attribute_name("#{column}.#{value}")
|
11
11
|
content_tag(:small, label, data: { enum: column, value: })
|
12
12
|
end
|
13
13
|
end
|
@@ -17,10 +17,6 @@ module Katalyst
|
|
17
17
|
def default_html_attributes
|
18
18
|
{ class: "type-enum" }
|
19
19
|
end
|
20
|
-
|
21
|
-
def i18n_enum_label_key(value)
|
22
|
-
"active_record.attributes.#{collection.model_name.i18n_key}/#{column}.#{value}"
|
23
|
-
end
|
24
20
|
end
|
25
21
|
end
|
26
22
|
end
|
@@ -64,7 +64,14 @@ module Katalyst
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def examples_for(key)
|
67
|
-
collection.examples_for(key)
|
67
|
+
collection.examples_for(key).filter_map do |example|
|
68
|
+
case example
|
69
|
+
when Collection::Type::Example
|
70
|
+
example if example.value.to_s.present?
|
71
|
+
else
|
72
|
+
raise ArgumentError, "Invalid example #{example.inspect} for #{collection.model_name}.#{key}"
|
73
|
+
end
|
74
|
+
end
|
68
75
|
end
|
69
76
|
|
70
77
|
def format_value(value)
|
@@ -17,20 +17,39 @@ module Katalyst
|
|
17
17
|
|
18
18
|
def examples_for(scope, attribute)
|
19
19
|
_, model, column = model_and_column_for(scope, attribute)
|
20
|
-
|
20
|
+
|
21
|
+
raise ArgumentError, "Unknown enum #{column} for #{model}" unless model.defined_enums.has_key?(column)
|
22
|
+
|
23
|
+
keys = model.defined_enums[column].keys
|
21
24
|
|
22
25
|
if attribute.value_before_type_cast.present?
|
23
26
|
keys = keys.select { |key| key.include?(attribute.value_before_type_cast.last) }
|
24
27
|
end
|
25
28
|
|
26
|
-
keys.map { |key| example(key, describe_key(model, attribute
|
29
|
+
keys.map { |key| example(key, describe_key(model, attribute, key)) }
|
27
30
|
end
|
28
31
|
|
29
32
|
private
|
30
33
|
|
34
|
+
def cast_value(value)
|
35
|
+
value.to_s
|
36
|
+
end
|
37
|
+
|
31
38
|
def describe_key(model, attribute, key)
|
32
|
-
|
33
|
-
|
39
|
+
label = model.human_attribute_name(attribute.name).downcase
|
40
|
+
value = model.human_attribute_name("#{attribute.name}.#{key}").downcase
|
41
|
+
|
42
|
+
description = "#{model.model_name.human} #{label} is #{value}"
|
43
|
+
description += " (default)" if default?(attribute, key)
|
44
|
+
description
|
45
|
+
end
|
46
|
+
|
47
|
+
def default?(attribute, value)
|
48
|
+
if multiple?
|
49
|
+
attribute.original_value&.intersection(cast(value))&.any?
|
50
|
+
else
|
51
|
+
attribute.default_value.eql?(cast(value))
|
52
|
+
end
|
34
53
|
end
|
35
54
|
end
|
36
55
|
end
|
@@ -48,7 +48,10 @@ module Katalyst
|
|
48
48
|
def examples_for(scope, attribute, limit: 10, order: :asc)
|
49
49
|
scope, model, column = model_and_column_for(scope, attribute)
|
50
50
|
|
51
|
-
|
51
|
+
unless model.attribute_types.has_key?(column)
|
52
|
+
raise(ArgumentError, "Unknown column '#{column}' for #{model}. " \
|
53
|
+
"Consider defining '#{attribute.name.parameterize.underscore}_examples'")
|
54
|
+
end
|
52
55
|
|
53
56
|
column = model.arel_table[column]
|
54
57
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katalyst-tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.4.
|
4
|
+
version: 3.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katalyst Interactive
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: katalyst-html-attributes
|