katalyst-tables 3.4.1 → 3.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/components/katalyst/tables/query/modal_component.html.erb +6 -5
- data/app/components/katalyst/tables/query/modal_component.rb +5 -5
- data/app/models/concerns/katalyst/tables/collection/query.rb +1 -1
- data/lib/katalyst/tables/collection/type/boolean.rb +1 -1
- data/lib/katalyst/tables/collection/type/date.rb +11 -10
- data/lib/katalyst/tables/collection/type/enum.rb +10 -3
- data/lib/katalyst/tables/collection/type/example.rb +30 -0
- data/lib/katalyst/tables/collection/type/helpers/multiple.rb +23 -4
- data/lib/katalyst/tables/collection/type/helpers/range.rb +44 -6
- data/lib/katalyst/tables/collection/type/value.rb +13 -5
- data/lib/katalyst/tables/collection/type.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b072cb596f235569c734c00f85602d8942c30fdf7352e67a07a3d7ed0470964
|
4
|
+
data.tar.gz: 40b3eb109d0b752b82ab86e7f9b8335c17f076d229286be6edce7afcc07533ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbd90a0224464a0961768428eac24df7b9242ca3805bddce60fbdb28fbcfb9e8271945ac623c478b655c502b115517dfc6609645eadccfa81c60f14bd2b35b7c
|
7
|
+
data.tar.gz: d6f1697681c96fe1d9346e68044d799e95c6547e6936afddb396a5cd782e49890434696aaff9454aa32064960ba1e9af2bd4a84693145e5c3deb4c592d4d31d0
|
@@ -8,13 +8,14 @@
|
|
8
8
|
</header>
|
9
9
|
<% end %>
|
10
10
|
<div class="content">
|
11
|
-
<% if
|
11
|
+
<% if show_examples? %>
|
12
12
|
<h4>Possible values for <code><%= current_key %>:</code></h4>
|
13
|
-
<
|
14
|
-
<%
|
15
|
-
<
|
13
|
+
<dl>
|
14
|
+
<% examples_for(current_key).each do |example| %>
|
15
|
+
<dt><code><%= format_value(example.value) %></code></dt>
|
16
|
+
<% if example.description.present? %><dd><%= example.description %></dd><% end %>
|
16
17
|
<% end %>
|
17
|
-
</
|
18
|
+
</dl>
|
18
19
|
<% else %>
|
19
20
|
<h4>Available filters:</h4>
|
20
21
|
<dl>
|
@@ -31,7 +31,7 @@ module Katalyst
|
|
31
31
|
|
32
32
|
using Collection::Type::Helpers::Extensions
|
33
33
|
|
34
|
-
def
|
34
|
+
def show_examples?
|
35
35
|
current_key && attributes[current_key]
|
36
36
|
end
|
37
37
|
|
@@ -63,13 +63,13 @@ module Katalyst
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
def
|
67
|
-
collection.examples_for(key).
|
66
|
+
def examples_for(key)
|
67
|
+
collection.examples_for(key)&.reject { |e| e.value.to_s.blank? } || []
|
68
68
|
end
|
69
69
|
|
70
70
|
def format_value(value)
|
71
|
-
if /\A[\w.-]*\z/.match?(value)
|
72
|
-
value
|
71
|
+
if /\A[\w.-]*\z/.match?(value.to_s)
|
72
|
+
value.to_s
|
73
73
|
else
|
74
74
|
%("#{value}")
|
75
75
|
end
|
@@ -32,7 +32,7 @@ module Katalyst
|
|
32
32
|
key = key.to_s
|
33
33
|
examples_method = "#{key.parameterize.underscore}_examples"
|
34
34
|
if respond_to?(examples_method)
|
35
|
-
public_send(examples_method)
|
35
|
+
public_send(examples_method)&.map { |e| e.is_a?(Example) ? e : Example.new(example) }
|
36
36
|
elsif @attributes.key?(key)
|
37
37
|
@attributes[key].type.examples_for(unscoped_items, @attributes[key])
|
38
38
|
end
|
@@ -13,22 +13,23 @@ module Katalyst
|
|
13
13
|
:date
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
16
|
+
def to_param(value)
|
17
|
+
case value
|
18
|
+
when ::Date, ::DateTime, ::Time, ActiveSupport::TimeWithZone
|
19
|
+
value.to_date.to_fs(:db)
|
19
20
|
else
|
20
21
|
super
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
|
-
def examples_for(
|
25
|
+
def examples_for(scope, attribute)
|
25
26
|
[
|
26
|
-
|
27
|
-
::Date.
|
28
|
-
::Date.current.
|
29
|
-
|
30
|
-
|
31
|
-
]
|
27
|
+
*super(scope, attribute, limit: 6),
|
28
|
+
example(::Date.current.beginning_of_week.., "this week"),
|
29
|
+
example(::Date.current.beginning_of_month.., "this month"),
|
30
|
+
example(1.month.ago.all_month, "last month"),
|
31
|
+
example(1.year.ago.all_year, "last year"),
|
32
|
+
]
|
32
33
|
end
|
33
34
|
|
34
35
|
private
|
@@ -20,10 +20,17 @@ module Katalyst
|
|
20
20
|
keys = model.defined_enums[column]&.keys
|
21
21
|
|
22
22
|
if attribute.value_before_type_cast.present?
|
23
|
-
keys.select { |key| key.include?(attribute.value_before_type_cast.last) }
|
24
|
-
else
|
25
|
-
keys
|
23
|
+
keys = keys.select { |key| key.include?(attribute.value_before_type_cast.last) }
|
26
24
|
end
|
25
|
+
|
26
|
+
keys.map { |key| example(key, describe_key(model, attribute.name, key)) }
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def describe_key(model, attribute, key)
|
32
|
+
key = I18n.t("active_record.attributes.#{model.model_name.i18n_key}/#{key}", default: key.to_s.titleize)
|
33
|
+
"#{model.model_name.human} #{model.human_attribute_name(attribute).downcase} is #{key}"
|
27
34
|
end
|
28
35
|
end
|
29
36
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Katalyst
|
4
|
+
module Tables
|
5
|
+
module Collection
|
6
|
+
module Type
|
7
|
+
class Example
|
8
|
+
attr_reader :value, :description
|
9
|
+
|
10
|
+
def initialize(value, description = "")
|
11
|
+
@value = value
|
12
|
+
@description = description
|
13
|
+
end
|
14
|
+
|
15
|
+
def hash
|
16
|
+
value.hash
|
17
|
+
end
|
18
|
+
|
19
|
+
def eql?(other)
|
20
|
+
value.eql?(other.value)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
value.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -21,9 +21,9 @@ module Katalyst
|
|
21
21
|
return (multiple? ? [] : nil) if value.nil?
|
22
22
|
|
23
23
|
if multiple? && value.is_a?(::Array)
|
24
|
-
value.
|
24
|
+
value_for_multiple(value.flat_map { |v| cast(v) })
|
25
25
|
elsif multiple?
|
26
|
-
|
26
|
+
value_for_multiple(super)
|
27
27
|
else
|
28
28
|
super
|
29
29
|
end
|
@@ -31,7 +31,7 @@ module Katalyst
|
|
31
31
|
|
32
32
|
def deserialize(value)
|
33
33
|
if multiple? && value.is_a?(::Array)
|
34
|
-
value.map { |v|
|
34
|
+
value.map { |v| deserialize(v) }.flatten
|
35
35
|
elsif multiple?
|
36
36
|
[super].flatten.compact
|
37
37
|
else
|
@@ -41,7 +41,15 @@ module Katalyst
|
|
41
41
|
|
42
42
|
def serialize(value)
|
43
43
|
if multiple? && value.is_a?(::Array)
|
44
|
-
value.map { |v|
|
44
|
+
value.map { |v| serialize(v) }.flatten
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_param(value)
|
51
|
+
if multiple? && value.is_a?(::Array)
|
52
|
+
"[#{value.map { |v| to_param(v) }.flatten.join(', ')}]"
|
45
53
|
else
|
46
54
|
super
|
47
55
|
end
|
@@ -52,6 +60,17 @@ module Katalyst
|
|
52
60
|
def default_value
|
53
61
|
multiple? ? [] : super
|
54
62
|
end
|
63
|
+
|
64
|
+
def value_for_multiple(value)
|
65
|
+
case value
|
66
|
+
when ::Array
|
67
|
+
value.reject { |v| v.is_a?(::Range) }
|
68
|
+
when ::Range
|
69
|
+
value
|
70
|
+
else
|
71
|
+
[value]
|
72
|
+
end
|
73
|
+
end
|
55
74
|
end
|
56
75
|
end
|
57
76
|
end
|
@@ -19,14 +19,42 @@ module Katalyst
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
def deserialize(value)
|
23
|
+
if value.is_a?(::Range)
|
24
|
+
if value.begin.nil?
|
25
|
+
make_range(nil, deserialize(value.end))
|
26
|
+
elsif value.end.nil?
|
27
|
+
make_range(deserialize(value.begin), nil)
|
28
|
+
else
|
29
|
+
make_range(deserialize(value.begin), deserialize(value.end))
|
30
|
+
end
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
22
36
|
def serialize(value)
|
23
37
|
if value.is_a?(::Range)
|
24
38
|
if value.begin.nil?
|
25
|
-
|
39
|
+
make_range(nil, serialize(value.end))
|
26
40
|
elsif value.end.nil?
|
27
|
-
|
41
|
+
make_range(serialize(value.begin), nil)
|
28
42
|
else
|
29
|
-
|
43
|
+
make_range(serialize(value.begin), serialize(value.end))
|
44
|
+
end
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_param(value)
|
51
|
+
if value.is_a?(::Range)
|
52
|
+
if value.begin.nil?
|
53
|
+
"..#{to_param(value.end)}"
|
54
|
+
elsif value.end.nil?
|
55
|
+
"#{to_param(value.begin)}.."
|
56
|
+
else
|
57
|
+
"#{to_param(value.begin)}..#{to_param(value.end)}"
|
30
58
|
end
|
31
59
|
else
|
32
60
|
super
|
@@ -42,15 +70,25 @@ module Katalyst
|
|
42
70
|
when self.class.const_get(:SINGLE_VALUE)
|
43
71
|
super($~[:value])
|
44
72
|
when self.class.const_get(:LOWER_BOUND)
|
45
|
-
(
|
73
|
+
make_range(super($~[:lower]), nil)
|
46
74
|
when self.class.const_get(:UPPER_BOUND)
|
47
|
-
(
|
75
|
+
make_range(nil, super($~[:upper]))
|
48
76
|
when self.class.const_get(:BOUNDED)
|
49
|
-
(
|
77
|
+
make_range(super($~[:lower]), super($~[:upper]))
|
50
78
|
else
|
51
79
|
super
|
52
80
|
end
|
53
81
|
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def make_range(from, to)
|
86
|
+
# when a value that accepts multiple is given a range, it double-packs the value so we get ..[0]
|
87
|
+
# unpack the array value
|
88
|
+
from = from.first if from.is_a?(::Array) && from.length == 1
|
89
|
+
to = to.first if to.is_a?(::Array) && to.length == 1
|
90
|
+
(from..to)
|
91
|
+
end
|
54
92
|
end
|
55
93
|
end
|
56
94
|
end
|
@@ -41,7 +41,11 @@ module Katalyst
|
|
41
41
|
scope.merge(condition)
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
44
|
+
def to_param(value)
|
45
|
+
serialize(value)
|
46
|
+
end
|
47
|
+
|
48
|
+
def examples_for(scope, attribute, limit: 10, order: :asc)
|
45
49
|
scope, model, column = model_and_column_for(scope, attribute)
|
46
50
|
|
47
51
|
return unless model.attribute_types.has_key?(column)
|
@@ -51,14 +55,18 @@ module Katalyst
|
|
51
55
|
filter(scope, attribute)
|
52
56
|
.group(column)
|
53
57
|
.distinct
|
54
|
-
.limit(
|
55
|
-
.reorder(column =>
|
58
|
+
.limit(limit)
|
59
|
+
.reorder(column => order)
|
56
60
|
.pluck(column)
|
57
|
-
.map { |v|
|
61
|
+
.map { |v| example(deserialize(v)) }
|
58
62
|
end
|
59
63
|
|
60
64
|
private
|
61
65
|
|
66
|
+
def example(value, description = "")
|
67
|
+
Example.new(to_param(value), description)
|
68
|
+
end
|
69
|
+
|
62
70
|
def filter_value(attribute)
|
63
71
|
attribute.value
|
64
72
|
end
|
@@ -69,7 +77,7 @@ module Katalyst
|
|
69
77
|
elsif scope
|
70
78
|
model.public_send(scope, value)
|
71
79
|
else
|
72
|
-
model.where(column => value)
|
80
|
+
model.where(column => serialize(value))
|
73
81
|
end
|
74
82
|
end
|
75
83
|
|
@@ -7,6 +7,7 @@ require "katalyst/tables/collection/type/helpers/extensions"
|
|
7
7
|
require "katalyst/tables/collection/type/helpers/multiple"
|
8
8
|
require "katalyst/tables/collection/type/helpers/range"
|
9
9
|
|
10
|
+
require "katalyst/tables/collection/type/example"
|
10
11
|
require "katalyst/tables/collection/type/value"
|
11
12
|
|
12
13
|
require "katalyst/tables/collection/type/boolean"
|
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.2
|
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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: katalyst-html-attributes
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- lib/katalyst/tables/collection/type/boolean.rb
|
145
145
|
- lib/katalyst/tables/collection/type/date.rb
|
146
146
|
- lib/katalyst/tables/collection/type/enum.rb
|
147
|
+
- lib/katalyst/tables/collection/type/example.rb
|
147
148
|
- lib/katalyst/tables/collection/type/float.rb
|
148
149
|
- lib/katalyst/tables/collection/type/helpers/delegate.rb
|
149
150
|
- lib/katalyst/tables/collection/type/helpers/extensions.rb
|