katalyst-tables 3.6.2 → 3.7.0
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/CHANGELOG.md +19 -0
- data/app/models/katalyst/tables/suggestions/constant_value.rb +1 -3
- data/app/models/katalyst/tables/suggestions/database_value.rb +1 -5
- data/lib/katalyst/tables/collection/type/boolean.rb +2 -4
- data/lib/katalyst/tables/collection/type/date.rb +4 -6
- data/lib/katalyst/tables/collection/type/enum.rb +10 -2
- data/lib/katalyst/tables/collection/type/string.rb +24 -5
- data/lib/katalyst/tables/collection/type/value.rb +33 -28
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5362e93821945472e9bc8c20574ab9325d6273f6f28f673722746ae9fec38f25
|
|
4
|
+
data.tar.gz: 36035838a96c61dab64a945dcee186771f5f83e74b2e28692d0a7da1558b9ef5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 576d8272e2a6d5c9c8a8d043e2550191d7fc989f763876287db925b07c9b7336a9044e155ded05d48410331cb37b2bfeddae25dbe0b6e4e244c94932559b80bf
|
|
7
|
+
data.tar.gz: 6e198574c8eecd43ee24d042a2ef23669142a8c434637285471a7aef6d71f079b27b26e095a9b227356c2c4bfdb6b7cef97e187cd6735fb5596e3f16568fd81f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## [3.7.0]
|
|
2
|
+
|
|
3
|
+
Adds support for generating filter expressions for self-referencing models.
|
|
4
|
+
|
|
5
|
+
## [3.6.0]
|
|
6
|
+
|
|
7
|
+
Keyboard navigation for query suggestions.
|
|
8
|
+
|
|
9
|
+
## [3.5.0]
|
|
10
|
+
|
|
11
|
+
Adds a new query input for creating text-based filtering expressions.
|
|
12
|
+
See [query](docs/developers/collections/query.md) for collection extensions and
|
|
13
|
+
[filtering](docs/developers/frontend/filtering.md) for frontend support.
|
|
14
|
+
|
|
15
|
+
## [3.4.0]
|
|
16
|
+
|
|
17
|
+
Support for selection columns and bulk actions.
|
|
18
|
+
See [docs](docs/developers/frontend/bulk-actions.md).
|
|
19
|
+
|
|
1
20
|
## [3.3.0]
|
|
2
21
|
- Custom types for collections which support extensions for filtering with ranges and arrays.
|
|
3
22
|
|
|
@@ -6,12 +6,10 @@ module Katalyst
|
|
|
6
6
|
class ConstantValue < Base
|
|
7
7
|
delegate :to_param, to: :@attribute_type
|
|
8
8
|
|
|
9
|
-
def initialize(name:, type:,
|
|
9
|
+
def initialize(name:, type:, value:)
|
|
10
10
|
super(value)
|
|
11
11
|
|
|
12
12
|
@attribute_type = type
|
|
13
|
-
@model = model
|
|
14
|
-
@column = column
|
|
15
13
|
@name = name
|
|
16
14
|
end
|
|
17
15
|
|
|
@@ -4,16 +4,12 @@ module Katalyst
|
|
|
4
4
|
module Tables
|
|
5
5
|
module Suggestions
|
|
6
6
|
class DatabaseValue < Base
|
|
7
|
-
attr_reader :model, :column
|
|
8
|
-
|
|
9
7
|
delegate :to_param, to: :@attribute_type
|
|
10
8
|
|
|
11
|
-
def initialize(name:, type:,
|
|
9
|
+
def initialize(name:, type:, value:)
|
|
12
10
|
super(value)
|
|
13
11
|
|
|
14
12
|
@attribute_type = type
|
|
15
|
-
@model = model
|
|
16
|
-
@column = column
|
|
17
13
|
@name = name
|
|
18
14
|
end
|
|
19
15
|
|
|
@@ -22,16 +22,14 @@ module Katalyst
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
def suggestions(
|
|
26
|
-
_, model, column = model_and_column_for(scope, attribute)
|
|
27
|
-
|
|
25
|
+
def suggestions(_scope, attribute)
|
|
28
26
|
values = %w[true false]
|
|
29
27
|
|
|
30
28
|
if attribute.value_before_type_cast.present?
|
|
31
29
|
values = values.select { |value| value.include?(attribute.value_before_type_cast) }
|
|
32
30
|
end
|
|
33
31
|
|
|
34
|
-
values.map { |v| constant_suggestion(attribute:,
|
|
32
|
+
values.map { |v| constant_suggestion(attribute:, value: deserialize(v)) }
|
|
35
33
|
end
|
|
36
34
|
end
|
|
37
35
|
end
|
|
@@ -23,14 +23,12 @@ module Katalyst
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def suggestions(scope, attribute)
|
|
26
|
-
_, model, column = model_and_column_for(scope, attribute)
|
|
27
|
-
|
|
28
26
|
[
|
|
29
27
|
*super(scope, attribute, limit: 6, order: :desc),
|
|
30
|
-
database_suggestion(attribute:,
|
|
31
|
-
database_suggestion(attribute:,
|
|
32
|
-
database_suggestion(attribute:,
|
|
33
|
-
database_suggestion(attribute:,
|
|
28
|
+
database_suggestion(attribute:, value: ::Date.current.beginning_of_week..),
|
|
29
|
+
database_suggestion(attribute:, value: ::Date.current.beginning_of_month..),
|
|
30
|
+
database_suggestion(attribute:, value: 1.month.ago.all_month),
|
|
31
|
+
database_suggestion(attribute:, value: 1.year.ago.all_year),
|
|
34
32
|
]
|
|
35
33
|
end
|
|
36
34
|
|
|
@@ -16,7 +16,15 @@ module Katalyst
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def suggestions(scope, attribute)
|
|
19
|
-
|
|
19
|
+
model = scope.model
|
|
20
|
+
column = attribute.name
|
|
21
|
+
|
|
22
|
+
if attribute.name.include?(".")
|
|
23
|
+
table_name, column = attribute.name.split(".")
|
|
24
|
+
model = scope.model.reflections[table_name].klass
|
|
25
|
+
|
|
26
|
+
raise(ArgumentError, "Unknown association '#{table_name}' for #{scope.model}") unless model
|
|
27
|
+
end
|
|
20
28
|
|
|
21
29
|
raise ArgumentError, "Unknown enum #{column} for #{model}" unless model.defined_enums.has_key?(column)
|
|
22
30
|
|
|
@@ -26,7 +34,7 @@ module Katalyst
|
|
|
26
34
|
values = values.select { |key| key.include?(attribute.value_before_type_cast) }
|
|
27
35
|
end
|
|
28
36
|
|
|
29
|
-
values.map { |value| constant_suggestion(attribute:,
|
|
37
|
+
values.map { |value| constant_suggestion(attribute:, value:) }
|
|
30
38
|
end
|
|
31
39
|
|
|
32
40
|
private
|
|
@@ -5,8 +5,6 @@ module Katalyst
|
|
|
5
5
|
module Collection
|
|
6
6
|
module Type
|
|
7
7
|
class String < Value
|
|
8
|
-
include ActiveRecord::Sanitization::ClassMethods
|
|
9
|
-
|
|
10
8
|
attr_reader :exact
|
|
11
9
|
alias_method :exact?, :exact
|
|
12
10
|
|
|
@@ -21,11 +19,32 @@ module Katalyst
|
|
|
21
19
|
|
|
22
20
|
private
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
class Match
|
|
23
|
+
include ActiveRecord::Sanitization::ClassMethods
|
|
24
|
+
|
|
25
|
+
attr_reader :value
|
|
26
|
+
|
|
27
|
+
def initialize(value)
|
|
28
|
+
@value = value
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def to_sql
|
|
32
|
+
"%#{sanitize_sql_like(value)}%"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class MatchHandler
|
|
37
|
+
def call(attribute, value)
|
|
38
|
+
attribute.matches(value.to_sql)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def apply_filter(scope, model, attribute, value)
|
|
43
|
+
if exact?
|
|
26
44
|
super
|
|
27
45
|
else
|
|
28
|
-
model.
|
|
46
|
+
model.predicate_builder.register_handler(Match, MatchHandler.new)
|
|
47
|
+
scope.where(attribute.name => Match.new(value))
|
|
29
48
|
end
|
|
30
49
|
end
|
|
31
50
|
end
|
|
@@ -33,10 +33,18 @@ module Katalyst
|
|
|
33
33
|
def filter(scope, attribute, value: filter_value(attribute))
|
|
34
34
|
return scope unless filter?(attribute, value)
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
if self.scope.present?
|
|
37
|
+
scope.public_send(self.scope, value)
|
|
38
|
+
elsif attribute.name.include?(".")
|
|
39
|
+
table_name, = attribute.name.split(".")
|
|
40
|
+
association = scope.model.reflections[table_name]
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
raise(ArgumentError, "Unknown association '#{table_name}' for #{scope.model}") unless association
|
|
43
|
+
|
|
44
|
+
apply_filter(scope.joins(table_name.to_sym), association.klass, attribute, value)
|
|
45
|
+
else
|
|
46
|
+
apply_filter(scope, scope.model, attribute, value)
|
|
47
|
+
end
|
|
40
48
|
end
|
|
41
49
|
|
|
42
50
|
def to_param(value)
|
|
@@ -44,54 +52,51 @@ module Katalyst
|
|
|
44
52
|
end
|
|
45
53
|
|
|
46
54
|
def suggestions(scope, attribute, limit: 10, order: :asc)
|
|
47
|
-
|
|
55
|
+
model = scope.model
|
|
56
|
+
column = attribute.name
|
|
57
|
+
|
|
58
|
+
if attribute.name.include?(".")
|
|
59
|
+
table_name, column = attribute.name.split(".")
|
|
60
|
+
model = scope.model.reflections[table_name].klass
|
|
61
|
+
|
|
62
|
+
raise(ArgumentError, "Unknown association '#{table_name}' for #{scope.model}") unless model
|
|
63
|
+
|
|
64
|
+
scope = scope.joins(table_name.to_sym)
|
|
65
|
+
end
|
|
48
66
|
|
|
49
67
|
unless model.attribute_types.has_key?(column)
|
|
50
68
|
raise(ArgumentError, "Unknown column '#{column}' for #{model}. " \
|
|
51
69
|
"Consider defining '#{attribute.name.parameterize.underscore}_suggestions'")
|
|
52
70
|
end
|
|
53
71
|
|
|
54
|
-
arel_column = model.arel_table[column]
|
|
55
|
-
|
|
56
72
|
filter(scope, attribute)
|
|
57
|
-
.group(
|
|
73
|
+
.group(attribute.name)
|
|
58
74
|
.distinct
|
|
59
75
|
.limit(limit)
|
|
60
|
-
.reorder(
|
|
61
|
-
.pluck(
|
|
62
|
-
.map { |v| database_suggestion(attribute:,
|
|
76
|
+
.reorder(attribute.name => order)
|
|
77
|
+
.pluck(attribute.name)
|
|
78
|
+
.map { |v| database_suggestion(attribute:, value: deserialize(v)) }
|
|
63
79
|
end
|
|
64
80
|
|
|
65
81
|
private
|
|
66
82
|
|
|
67
|
-
def constant_suggestion(attribute:,
|
|
68
|
-
Tables::Suggestions::ConstantValue.new(name: attribute.name, type: attribute.type,
|
|
83
|
+
def constant_suggestion(attribute:, value:)
|
|
84
|
+
Tables::Suggestions::ConstantValue.new(name: attribute.name, type: attribute.type, value:)
|
|
69
85
|
end
|
|
70
86
|
|
|
71
|
-
def database_suggestion(attribute:,
|
|
72
|
-
Tables::Suggestions::DatabaseValue.new(name: attribute.name, type: attribute.type,
|
|
87
|
+
def database_suggestion(attribute:, value:)
|
|
88
|
+
Tables::Suggestions::DatabaseValue.new(name: attribute.name, type: attribute.type, value:)
|
|
73
89
|
end
|
|
74
90
|
|
|
75
91
|
def filter_value(attribute)
|
|
76
92
|
attribute.value
|
|
77
93
|
end
|
|
78
94
|
|
|
79
|
-
def
|
|
95
|
+
def apply_filter(scope, _model, attribute, value)
|
|
80
96
|
if value.nil?
|
|
81
|
-
|
|
82
|
-
elsif scope
|
|
83
|
-
model.public_send(scope, value)
|
|
84
|
-
else
|
|
85
|
-
model.where(column => serialize(value))
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def model_and_column_for(scope, attribute)
|
|
90
|
-
if attribute.name.include?(".")
|
|
91
|
-
table, column = attribute.name.split(".")
|
|
92
|
-
[scope.joins(table.to_sym), scope.model.reflections[table].klass, column]
|
|
97
|
+
scope.none
|
|
93
98
|
else
|
|
94
|
-
|
|
99
|
+
scope.where(attribute.name => serialize(value))
|
|
95
100
|
end
|
|
96
101
|
end
|
|
97
102
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: katalyst-tables
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Katalyst Interactive
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2025-01-13 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: katalyst-html-attributes
|
|
@@ -175,7 +174,6 @@ metadata:
|
|
|
175
174
|
homepage_uri: https://github.com/katalyst/tables
|
|
176
175
|
source_code_uri: https://github.com/katalyst/tables
|
|
177
176
|
changelog_uri: https://github.com/katalyst/tables/blobs/main/CHANGELOG.md
|
|
178
|
-
post_install_message:
|
|
179
177
|
rdoc_options: []
|
|
180
178
|
require_paths:
|
|
181
179
|
- lib
|
|
@@ -190,8 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
190
188
|
- !ruby/object:Gem::Version
|
|
191
189
|
version: '0'
|
|
192
190
|
requirements: []
|
|
193
|
-
rubygems_version: 3.
|
|
194
|
-
signing_key:
|
|
191
|
+
rubygems_version: 3.6.2
|
|
195
192
|
specification_version: 4
|
|
196
193
|
summary: HTML table generator for Rails views
|
|
197
194
|
test_files: []
|