katalyst-tables 3.3.1 → 3.3.3
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/README.md +1 -1
- data/app/assets/builds/katalyst/tables.esm.js +332 -6
- data/app/assets/builds/katalyst/tables.js +332 -6
- data/app/assets/builds/katalyst/tables.min.js +1 -1
- data/app/assets/builds/katalyst/tables.min.js.map +1 -1
- data/app/assets/stylesheets/katalyst/tables/_index.scss +1 -1
- data/app/assets/stylesheets/katalyst/tables/_query.scss +109 -0
- data/app/assets/stylesheets/katalyst/tables/typed-columns/_date.scss +1 -1
- data/app/assets/stylesheets/katalyst/tables/typed-columns/_datetime.scss +1 -1
- data/app/components/katalyst/table_component.rb +13 -2
- data/app/components/katalyst/tables/cells/currency_component.rb +21 -2
- data/app/components/katalyst/tables/cells/number_component.rb +31 -1
- data/app/components/katalyst/tables/query/input_component.html.erb +13 -0
- data/app/components/katalyst/tables/query/input_component.rb +50 -0
- data/app/components/katalyst/tables/query/modal_component.html.erb +33 -0
- data/app/components/katalyst/tables/query/modal_component.rb +89 -0
- data/app/components/katalyst/tables/query_component.html.erb +8 -0
- data/app/components/katalyst/tables/{filter_component.rb → query_component.rb} +37 -30
- data/app/controllers/concerns/katalyst/tables/backend.rb +14 -0
- data/app/helpers/katalyst/tables/frontend.rb +14 -8
- data/app/javascript/tables/application.js +8 -3
- data/app/javascript/tables/query_controller.js +108 -0
- data/app/javascript/tables/query_input_controller.js +228 -0
- data/app/models/concerns/katalyst/tables/collection/core.rb +2 -2
- data/app/models/concerns/katalyst/tables/collection/query/array_value_parser.rb +13 -26
- data/app/models/concerns/katalyst/tables/collection/query/parser.rb +16 -13
- data/app/models/concerns/katalyst/tables/collection/query/single_value_parser.rb +11 -3
- data/app/models/concerns/katalyst/tables/collection/query/value_parser.rb +10 -5
- data/app/models/concerns/katalyst/tables/collection/query.rb +42 -5
- data/app/models/concerns/katalyst/tables/collection/sorting.rb +11 -1
- data/app/models/katalyst/tables/collection/base.rb +10 -0
- data/app/models/katalyst/tables/collection/filter.rb +10 -0
- data/config/locales/tables.en.yml +2 -0
- data/{app/models → lib}/katalyst/tables/collection/type/boolean.rb +11 -1
- data/lib/katalyst/tables/collection/type/date.rb +57 -0
- data/lib/katalyst/tables/collection/type/enum.rb +32 -0
- data/lib/katalyst/tables/collection/type/float.rb +21 -0
- data/lib/katalyst/tables/collection/type/helpers/delegate.rb +32 -0
- data/{app/models → lib}/katalyst/tables/collection/type/helpers/extensions.rb +14 -0
- data/lib/katalyst/tables/collection/type/helpers/multiple.rb +60 -0
- data/lib/katalyst/tables/collection/type/helpers/range.rb +59 -0
- data/lib/katalyst/tables/collection/type/integer.rb +21 -0
- data/{app/models → lib}/katalyst/tables/collection/type/value.rb +22 -2
- data/{app/models → lib}/katalyst/tables/collection/type.rb +16 -0
- data/lib/katalyst/tables/collection.rb +11 -0
- data/lib/katalyst/tables.rb +6 -0
- metadata +26 -21
- data/app/assets/stylesheets/katalyst/tables/_filter.scss +0 -43
- data/app/components/katalyst/tables/filter/modal_component.html.erb +0 -25
- data/app/components/katalyst/tables/filter/modal_component.rb +0 -112
- data/app/components/katalyst/tables/filter_component.html.erb +0 -18
- data/app/javascript/tables/filter/modal_controller.js +0 -13
- data/app/models/katalyst/tables/collection/type/date.rb +0 -60
- data/app/models/katalyst/tables/collection/type/enum.rb +0 -21
- data/app/models/katalyst/tables/collection/type/float.rb +0 -57
- data/app/models/katalyst/tables/collection/type/helpers/delegate.rb +0 -50
- data/app/models/katalyst/tables/collection/type/helpers/multiple.rb +0 -30
- data/app/models/katalyst/tables/collection/type/integer.rb +0 -57
- /data/{app/models → lib}/katalyst/tables/collection/type/query.rb +0 -0
- /data/{app/models → lib}/katalyst/tables/collection/type/search.rb +0 -0
- /data/{app/models → lib}/katalyst/tables/collection/type/string.rb +0 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "katalyst/tables/collection/type/helpers/extensions"
|
4
|
+
|
5
|
+
module Katalyst
|
6
|
+
module Tables
|
7
|
+
module Collection
|
8
|
+
module Type
|
9
|
+
module Helpers
|
10
|
+
# Lifts a delegating type from value to arrays of values
|
11
|
+
module Delegate
|
12
|
+
delegate :type, :deserialize, :serialize, to: :@delegate
|
13
|
+
|
14
|
+
def initialize(delegate:, **arguments)
|
15
|
+
super(**arguments)
|
16
|
+
|
17
|
+
@delegate = delegate.new(**arguments.except(:filter, :multiple, :scope))
|
18
|
+
end
|
19
|
+
|
20
|
+
using Extensions
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def cast_value(value)
|
25
|
+
@delegate.cast(value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -19,6 +19,20 @@ module Katalyst
|
|
19
19
|
def filterable?
|
20
20
|
false
|
21
21
|
end
|
22
|
+
|
23
|
+
def examples_for(...)
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
refine(::ActiveModel::Attribute) do
|
29
|
+
def query_range=(range)
|
30
|
+
@query_range = range
|
31
|
+
end
|
32
|
+
|
33
|
+
def query_range
|
34
|
+
@query_range
|
35
|
+
end
|
22
36
|
end
|
23
37
|
end
|
24
38
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Katalyst
|
4
|
+
module Tables
|
5
|
+
module Collection
|
6
|
+
module Type
|
7
|
+
module Helpers
|
8
|
+
# Adds support for multiple: true
|
9
|
+
module Multiple
|
10
|
+
def initialize(multiple: false, **)
|
11
|
+
super(**)
|
12
|
+
|
13
|
+
@multiple = multiple
|
14
|
+
end
|
15
|
+
|
16
|
+
def multiple?
|
17
|
+
@multiple
|
18
|
+
end
|
19
|
+
|
20
|
+
def cast(value)
|
21
|
+
return (multiple? ? [] : nil) if value.nil?
|
22
|
+
|
23
|
+
if multiple? && value.is_a?(::Array)
|
24
|
+
value.map { |v| super(v) }
|
25
|
+
elsif multiple?
|
26
|
+
[super]
|
27
|
+
else
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def deserialize(value)
|
33
|
+
if multiple? && value.is_a?(::Array)
|
34
|
+
value.map { |v| super(v) }.flatten
|
35
|
+
elsif multiple?
|
36
|
+
[super].flatten.compact
|
37
|
+
else
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def serialize(value)
|
43
|
+
if multiple? && value.is_a?(::Array)
|
44
|
+
value.map { |v| super(v) }.flatten
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
using Extensions
|
51
|
+
|
52
|
+
def default_value
|
53
|
+
multiple? ? [] : super
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Katalyst
|
4
|
+
module Tables
|
5
|
+
module Collection
|
6
|
+
module Type
|
7
|
+
module Helpers
|
8
|
+
# Adds support for ranges
|
9
|
+
module Range
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
class_methods do
|
13
|
+
# @param single_value [Regex] pattern for accepting a single value
|
14
|
+
def define_range_patterns(single_value)
|
15
|
+
const_set(:SINGLE_VALUE, /\A(?<value>#{single_value})\z/)
|
16
|
+
const_set(:LOWER_BOUND, /\A(?<lower>#{single_value})\.\.\z/)
|
17
|
+
const_set(:UPPER_BOUND, /\A\.\.(?<upper>#{single_value})\z/)
|
18
|
+
const_set(:BOUNDED, /\A(?<lower>#{single_value})\.\.(?<upper>#{single_value})\z/)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def serialize(value)
|
23
|
+
if value.is_a?(::Range)
|
24
|
+
if value.begin.nil?
|
25
|
+
"..#{serialize(value.end)}"
|
26
|
+
elsif value.end.nil?
|
27
|
+
"#{serialize(value.begin)}.."
|
28
|
+
else
|
29
|
+
"#{serialize(value.begin)}..#{serialize(value.end)}"
|
30
|
+
end
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def cast(value)
|
37
|
+
case value
|
38
|
+
when nil
|
39
|
+
nil
|
40
|
+
when ::Range
|
41
|
+
value
|
42
|
+
when self.class.const_get(:SINGLE_VALUE)
|
43
|
+
super($~[:value])
|
44
|
+
when self.class.const_get(:LOWER_BOUND)
|
45
|
+
((super($~[:lower]))..)
|
46
|
+
when self.class.const_get(:UPPER_BOUND)
|
47
|
+
(..(super($~[:upper])))
|
48
|
+
when self.class.const_get(:BOUNDED)
|
49
|
+
((super($~[:lower]))..(super($~[:upper])))
|
50
|
+
else
|
51
|
+
super
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Katalyst
|
4
|
+
module Tables
|
5
|
+
module Collection
|
6
|
+
module Type
|
7
|
+
class Integer < Value
|
8
|
+
include Helpers::Delegate
|
9
|
+
include Helpers::Multiple
|
10
|
+
include Helpers::Range
|
11
|
+
|
12
|
+
define_range_patterns(/-?\d+/)
|
13
|
+
|
14
|
+
def initialize(**)
|
15
|
+
super(**, delegate: ActiveModel::Type::Integer)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -21,7 +21,13 @@ module Katalyst
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def filter?(attribute, value)
|
24
|
-
|
24
|
+
return false unless filterable?
|
25
|
+
|
26
|
+
if attribute.came_from_user?
|
27
|
+
attribute.value_before_type_cast.present?
|
28
|
+
else
|
29
|
+
value.present?
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
33
|
def filter(scope, attribute)
|
@@ -30,11 +36,25 @@ module Katalyst
|
|
30
36
|
return scope unless filter?(attribute, value)
|
31
37
|
|
32
38
|
scope, model, column = model_and_column_for(scope, attribute)
|
33
|
-
condition
|
39
|
+
condition = filter_condition(model, column, value)
|
34
40
|
|
35
41
|
scope.merge(condition)
|
36
42
|
end
|
37
43
|
|
44
|
+
def examples_for(scope, attribute)
|
45
|
+
scope, model, column = model_and_column_for(scope, attribute)
|
46
|
+
|
47
|
+
return unless model.attribute_types.has_key?(column)
|
48
|
+
|
49
|
+
filter(scope, attribute)
|
50
|
+
.group(column)
|
51
|
+
.distinct
|
52
|
+
.limit(10)
|
53
|
+
.reorder(column => :asc)
|
54
|
+
.pluck(column)
|
55
|
+
.map { |v| serialize(v) }
|
56
|
+
end
|
57
|
+
|
38
58
|
private
|
39
59
|
|
40
60
|
def filter_value(attribute)
|
@@ -2,6 +2,22 @@
|
|
2
2
|
|
3
3
|
require "active_model/type"
|
4
4
|
|
5
|
+
require "katalyst/tables/collection/type/helpers/delegate"
|
6
|
+
require "katalyst/tables/collection/type/helpers/extensions"
|
7
|
+
require "katalyst/tables/collection/type/helpers/multiple"
|
8
|
+
require "katalyst/tables/collection/type/helpers/range"
|
9
|
+
|
10
|
+
require "katalyst/tables/collection/type/value"
|
11
|
+
|
12
|
+
require "katalyst/tables/collection/type/boolean"
|
13
|
+
require "katalyst/tables/collection/type/date"
|
14
|
+
require "katalyst/tables/collection/type/enum"
|
15
|
+
require "katalyst/tables/collection/type/float"
|
16
|
+
require "katalyst/tables/collection/type/integer"
|
17
|
+
require "katalyst/tables/collection/type/query"
|
18
|
+
require "katalyst/tables/collection/type/search"
|
19
|
+
require "katalyst/tables/collection/type/string"
|
20
|
+
|
5
21
|
module Katalyst
|
6
22
|
module Tables
|
7
23
|
module Collection
|
data/lib/katalyst/tables.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_support"
|
4
|
+
require "active_support/rails"
|
3
5
|
require "view_component"
|
4
6
|
require "katalyst/html_attributes"
|
5
7
|
|
@@ -8,6 +10,10 @@ require_relative "tables/engine"
|
|
8
10
|
|
9
11
|
module Katalyst
|
10
12
|
module Tables
|
13
|
+
extend ActiveSupport::Autoload
|
14
|
+
|
15
|
+
autoload :Collection
|
16
|
+
|
11
17
|
class Error < StandardError; end
|
12
18
|
|
13
19
|
def self.config
|
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.3.
|
4
|
+
version: 3.3.3
|
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-
|
11
|
+
date: 2024-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: katalyst-html-attributes
|
@@ -54,9 +54,9 @@ files:
|
|
54
54
|
- app/assets/builds/katalyst/tables.min.js
|
55
55
|
- app/assets/builds/katalyst/tables.min.js.map
|
56
56
|
- app/assets/config/katalyst-tables.js
|
57
|
-
- app/assets/stylesheets/katalyst/tables/_filter.scss
|
58
57
|
- app/assets/stylesheets/katalyst/tables/_index.scss
|
59
58
|
- app/assets/stylesheets/katalyst/tables/_ordinal.scss
|
59
|
+
- app/assets/stylesheets/katalyst/tables/_query.scss
|
60
60
|
- app/assets/stylesheets/katalyst/tables/_select.scss
|
61
61
|
- app/assets/stylesheets/katalyst/tables/_summary.scss
|
62
62
|
- app/assets/stylesheets/katalyst/tables/_table.scss
|
@@ -92,15 +92,17 @@ files:
|
|
92
92
|
- app/components/katalyst/tables/data.rb
|
93
93
|
- app/components/katalyst/tables/empty_caption_component.html.erb
|
94
94
|
- app/components/katalyst/tables/empty_caption_component.rb
|
95
|
-
- app/components/katalyst/tables/filter/modal_component.html.erb
|
96
|
-
- app/components/katalyst/tables/filter/modal_component.rb
|
97
|
-
- app/components/katalyst/tables/filter_component.html.erb
|
98
|
-
- app/components/katalyst/tables/filter_component.rb
|
99
95
|
- app/components/katalyst/tables/header_row_component.html.erb
|
100
96
|
- app/components/katalyst/tables/header_row_component.rb
|
101
97
|
- app/components/katalyst/tables/label.rb
|
102
98
|
- app/components/katalyst/tables/orderable/form_component.rb
|
103
99
|
- app/components/katalyst/tables/pagy_nav_component.rb
|
100
|
+
- app/components/katalyst/tables/query/input_component.html.erb
|
101
|
+
- app/components/katalyst/tables/query/input_component.rb
|
102
|
+
- app/components/katalyst/tables/query/modal_component.html.erb
|
103
|
+
- app/components/katalyst/tables/query/modal_component.rb
|
104
|
+
- app/components/katalyst/tables/query_component.html.erb
|
105
|
+
- app/components/katalyst/tables/query_component.rb
|
104
106
|
- app/components/katalyst/tables/selectable/form_component.html.erb
|
105
107
|
- app/components/katalyst/tables/selectable/form_component.rb
|
106
108
|
- app/components/katalyst/tables/summary/body_component.html.erb
|
@@ -112,10 +114,11 @@ files:
|
|
112
114
|
- app/controllers/concerns/katalyst/tables/backend.rb
|
113
115
|
- app/helpers/katalyst/tables/frontend.rb
|
114
116
|
- app/javascript/tables/application.js
|
115
|
-
- app/javascript/tables/filter/modal_controller.js
|
116
117
|
- app/javascript/tables/orderable/form_controller.js
|
117
118
|
- app/javascript/tables/orderable/item_controller.js
|
118
119
|
- app/javascript/tables/orderable/list_controller.js
|
120
|
+
- app/javascript/tables/query_controller.js
|
121
|
+
- app/javascript/tables/query_input_controller.js
|
119
122
|
- app/javascript/tables/selection/form_controller.js
|
120
123
|
- app/javascript/tables/selection/item_controller.js
|
121
124
|
- app/models/concerns/katalyst/tables/collection/core.rb
|
@@ -132,22 +135,24 @@ files:
|
|
132
135
|
- app/models/katalyst/tables/collection/array.rb
|
133
136
|
- app/models/katalyst/tables/collection/base.rb
|
134
137
|
- app/models/katalyst/tables/collection/filter.rb
|
135
|
-
- app/models/katalyst/tables/collection/type.rb
|
136
|
-
- app/models/katalyst/tables/collection/type/boolean.rb
|
137
|
-
- app/models/katalyst/tables/collection/type/date.rb
|
138
|
-
- app/models/katalyst/tables/collection/type/enum.rb
|
139
|
-
- app/models/katalyst/tables/collection/type/float.rb
|
140
|
-
- app/models/katalyst/tables/collection/type/helpers/delegate.rb
|
141
|
-
- app/models/katalyst/tables/collection/type/helpers/extensions.rb
|
142
|
-
- app/models/katalyst/tables/collection/type/helpers/multiple.rb
|
143
|
-
- app/models/katalyst/tables/collection/type/integer.rb
|
144
|
-
- app/models/katalyst/tables/collection/type/query.rb
|
145
|
-
- app/models/katalyst/tables/collection/type/search.rb
|
146
|
-
- app/models/katalyst/tables/collection/type/string.rb
|
147
|
-
- app/models/katalyst/tables/collection/type/value.rb
|
148
138
|
- config/importmap.rb
|
149
139
|
- config/locales/tables.en.yml
|
150
140
|
- lib/katalyst/tables.rb
|
141
|
+
- lib/katalyst/tables/collection.rb
|
142
|
+
- lib/katalyst/tables/collection/type.rb
|
143
|
+
- lib/katalyst/tables/collection/type/boolean.rb
|
144
|
+
- lib/katalyst/tables/collection/type/date.rb
|
145
|
+
- lib/katalyst/tables/collection/type/enum.rb
|
146
|
+
- lib/katalyst/tables/collection/type/float.rb
|
147
|
+
- lib/katalyst/tables/collection/type/helpers/delegate.rb
|
148
|
+
- lib/katalyst/tables/collection/type/helpers/extensions.rb
|
149
|
+
- lib/katalyst/tables/collection/type/helpers/multiple.rb
|
150
|
+
- lib/katalyst/tables/collection/type/helpers/range.rb
|
151
|
+
- lib/katalyst/tables/collection/type/integer.rb
|
152
|
+
- lib/katalyst/tables/collection/type/query.rb
|
153
|
+
- lib/katalyst/tables/collection/type/search.rb
|
154
|
+
- lib/katalyst/tables/collection/type/string.rb
|
155
|
+
- lib/katalyst/tables/collection/type/value.rb
|
151
156
|
- lib/katalyst/tables/config.rb
|
152
157
|
- lib/katalyst/tables/engine.rb
|
153
158
|
homepage: https://github.com/katalyst/tables
|
@@ -1,43 +0,0 @@
|
|
1
|
-
[data-controller="tables--filter--modal"] {
|
2
|
-
position: relative;
|
3
|
-
}
|
4
|
-
|
5
|
-
.filter-keys-modal {
|
6
|
-
position: absolute;
|
7
|
-
top: 100%;
|
8
|
-
left: 0;
|
9
|
-
right: 0;
|
10
|
-
border: 1px solid rgba(0, 0, 0, 0.16);
|
11
|
-
box-shadow:
|
12
|
-
0 3px 6px rgba(0, 0, 0, 0.16),
|
13
|
-
0 3px 6px rgba(0, 0, 0, 0.23);
|
14
|
-
padding-inline: 1rem;
|
15
|
-
padding-block: 0.5rem 0;
|
16
|
-
margin-top: 0.5rem;
|
17
|
-
background: white;
|
18
|
-
border-radius: 4px;
|
19
|
-
z-index: 1;
|
20
|
-
opacity: 0;
|
21
|
-
transition: opacity 0.125s;
|
22
|
-
pointer-events: none;
|
23
|
-
|
24
|
-
&[data-open] {
|
25
|
-
opacity: 1;
|
26
|
-
pointer-events: unset;
|
27
|
-
}
|
28
|
-
|
29
|
-
table {
|
30
|
-
table-layout: fixed;
|
31
|
-
}
|
32
|
-
|
33
|
-
th.label,
|
34
|
-
th.key {
|
35
|
-
width: 15%;
|
36
|
-
}
|
37
|
-
|
38
|
-
.footer {
|
39
|
-
display: flex;
|
40
|
-
justify-content: flex-end;
|
41
|
-
padding-block: 1rem;
|
42
|
-
}
|
43
|
-
}
|
@@ -1,25 +0,0 @@
|
|
1
|
-
<%= tag.div(**html_attributes) do %>
|
2
|
-
<table>
|
3
|
-
<thead>
|
4
|
-
<tr>
|
5
|
-
<th class="label"></th>
|
6
|
-
<th class="key">Key</th>
|
7
|
-
<th class="values">Values</th>
|
8
|
-
</tr>
|
9
|
-
</thead>
|
10
|
-
<tbody>
|
11
|
-
<% attributes.each do |key, attribute| %>
|
12
|
-
<tr>
|
13
|
-
<th class="label"><%= collection.model.human_attribute_name(key) %></th>
|
14
|
-
<td class="key"><%= key %></td>
|
15
|
-
<td class="values"><%= values_for(key, attribute) %></td>
|
16
|
-
</tr>
|
17
|
-
<% end %>
|
18
|
-
</tbody>
|
19
|
-
</table>
|
20
|
-
<% if footer? %>
|
21
|
-
<div class="footer">
|
22
|
-
<%= footer %>
|
23
|
-
</div>
|
24
|
-
<% end %>
|
25
|
-
<% end %>
|
@@ -1,112 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Katalyst
|
4
|
-
module Tables
|
5
|
-
module Filter
|
6
|
-
class ModalComponent < ViewComponent::Base
|
7
|
-
include Katalyst::HtmlAttributes
|
8
|
-
include Katalyst::Tables::Frontend
|
9
|
-
|
10
|
-
DEFAULT_ATTRIBUTES = %w[page sort search query].freeze
|
11
|
-
|
12
|
-
renders_one :footer
|
13
|
-
|
14
|
-
attr_reader :collection, :url
|
15
|
-
|
16
|
-
def initialize(collection:, **)
|
17
|
-
super(**)
|
18
|
-
|
19
|
-
@collection = collection
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def default_html_attributes
|
25
|
-
{
|
26
|
-
class: "filter-keys-modal",
|
27
|
-
data: {
|
28
|
-
tables__filter__modal_target: "modal",
|
29
|
-
},
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
using Collection::Type::Helpers::Extensions
|
34
|
-
|
35
|
-
def attributes
|
36
|
-
collection.class.attribute_types
|
37
|
-
.select { |_, a| a.filterable? && a.type != :search }
|
38
|
-
end
|
39
|
-
|
40
|
-
def values_for(key, attribute)
|
41
|
-
values_method = "#{key.parameterize.underscore}_values"
|
42
|
-
if collection.respond_to?(values_method)
|
43
|
-
return scope_values(attribute, values_method)
|
44
|
-
end
|
45
|
-
|
46
|
-
case attribute.type
|
47
|
-
when :boolean
|
48
|
-
render_options(true, false)
|
49
|
-
when :date
|
50
|
-
date_values
|
51
|
-
when :integer
|
52
|
-
integer_values(attribute)
|
53
|
-
when :float
|
54
|
-
float_values(attribute)
|
55
|
-
when :enum
|
56
|
-
enum_values(key)
|
57
|
-
when :string
|
58
|
-
string_values(attribute)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def scope_values(attribute, values_method)
|
63
|
-
values = collection.public_send(values_method)
|
64
|
-
attribute.multiple? ? render_array(*values) : render_options(*values)
|
65
|
-
end
|
66
|
-
|
67
|
-
def date_values
|
68
|
-
render_options("YYYY-MM-DD", ">YYYY-MM-DD", "<YYYY-MM-DD", "YYYY-MM-DD..YYYY-MM-DD")
|
69
|
-
end
|
70
|
-
|
71
|
-
def string_values(attribute)
|
72
|
-
options = render_options("example", '"an example"')
|
73
|
-
safe_join([options, attribute.exact? ? "(exact match)" : "(fuzzy match)"], " ")
|
74
|
-
end
|
75
|
-
|
76
|
-
def enum_values(key)
|
77
|
-
enums = collection.model.defined_enums
|
78
|
-
|
79
|
-
render_array(*enums[key].keys) if enums.has_key?(key)
|
80
|
-
end
|
81
|
-
|
82
|
-
def float_values(attribute)
|
83
|
-
if attribute.multiple?
|
84
|
-
render_array("0.5", "1", "...")
|
85
|
-
else
|
86
|
-
render_options("0.5", ">0.5", "<0.5", "-0.5..0.5")
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def integer_values(attribute)
|
91
|
-
if attribute.multiple?
|
92
|
-
render_array("0", "1", "...")
|
93
|
-
else
|
94
|
-
render_options("10", ">10", "<10", "0..10")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def render_option(value)
|
99
|
-
tag.code(value.to_s)
|
100
|
-
end
|
101
|
-
|
102
|
-
def render_options(*values)
|
103
|
-
safe_join(values.map { |value| render_option(value) }, ", ")
|
104
|
-
end
|
105
|
-
|
106
|
-
def render_array(*values)
|
107
|
-
safe_join(["[", render_options(*values), "]"])
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
<%= tag.div(**html_attributes) do %>
|
2
|
-
<% if content? %>
|
3
|
-
<%= content %>
|
4
|
-
<% else %>
|
5
|
-
<%= form do |form| %>
|
6
|
-
<%= form.text_field(
|
7
|
-
:query,
|
8
|
-
type: :search,
|
9
|
-
autocomplete: "off",
|
10
|
-
**input_attributes,
|
11
|
-
) %>
|
12
|
-
|
13
|
-
<%= form.button("Apply", type: :submit, name: nil) %>
|
14
|
-
<% end %>
|
15
|
-
<% end %>
|
16
|
-
|
17
|
-
<%= modal %>
|
18
|
-
<% end %>
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { Controller } from "@hotwired/stimulus";
|
2
|
-
|
3
|
-
export default class FilterModalController extends Controller {
|
4
|
-
static targets = ["modal"];
|
5
|
-
|
6
|
-
close(e) {
|
7
|
-
delete this.modalTarget.dataset.open;
|
8
|
-
}
|
9
|
-
|
10
|
-
open(e) {
|
11
|
-
this.modalTarget.dataset.open = "true";
|
12
|
-
}
|
13
|
-
}
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Katalyst
|
4
|
-
module Tables
|
5
|
-
module Collection
|
6
|
-
module Type
|
7
|
-
class Date < Value
|
8
|
-
def type
|
9
|
-
:date
|
10
|
-
end
|
11
|
-
|
12
|
-
def serialize(value)
|
13
|
-
if value.is_a?(Date)
|
14
|
-
value.to_fs(:db)
|
15
|
-
elsif value.is_a?(Range)
|
16
|
-
if value.begin.nil?
|
17
|
-
"<#{value.end.to_fs(:db)}"
|
18
|
-
elsif value.end.nil?
|
19
|
-
">#{value.begin.to_fs(:db)}"
|
20
|
-
else
|
21
|
-
"#{value.begin.to_fs(:db)}..#{value.end.to_fs(:db)}"
|
22
|
-
end
|
23
|
-
else
|
24
|
-
value.to_s
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
ISO_DATE = /\A(\d{4})-(\d\d)-(\d\d)\z/
|
31
|
-
LOWER_BOUND = /\A>(\d{4})-(\d\d)-(\d\d)\z/
|
32
|
-
UPPER_BOUND = /\A<(\d{4})-(\d\d)-(\d\d)\z/
|
33
|
-
BOUNDED = /\A(\d{4})-(\d\d)-(\d\d)\.\.(\d{4})-(\d\d)-(\d\d)\z/
|
34
|
-
|
35
|
-
def cast_value(value)
|
36
|
-
return value unless value.is_a?(::String)
|
37
|
-
|
38
|
-
if value =~ ISO_DATE
|
39
|
-
new_date($1.to_i, $2.to_i, $3.to_i)
|
40
|
-
elsif value =~ LOWER_BOUND
|
41
|
-
(new_date($1.to_i, $2.to_i, $3.to_i)..)
|
42
|
-
elsif value =~ UPPER_BOUND
|
43
|
-
(..new_date($1.to_i, $2.to_i, $3.to_i))
|
44
|
-
elsif value =~ BOUNDED
|
45
|
-
(new_date($1.to_i, $2.to_i, $3.to_i)..new_date($4.to_i, $5.to_i, $6.to_i))
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def new_date(year, mon, mday)
|
50
|
-
return nil if year.nil? || (year.zero? && mon.zero? && mday.zero?)
|
51
|
-
|
52
|
-
::Date.new(year, mon, mday)
|
53
|
-
rescue ArgumentError, TypeError
|
54
|
-
nil
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|