super 0.0.16 → 0.17.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/app/assets/javascripts/super/application.js +146 -13
- data/app/assets/stylesheets/super/application.css +0 -1
- data/app/controllers/super/application_controller.rb +15 -2
- data/app/controllers/super/substructure_controller.rb +19 -8
- data/app/views/super/application/_display_actions.html.erb +1 -1
- data/app/views/super/application/_filter.html.erb +62 -2
- data/app/views/super/application/_member_header.html.erb +1 -1
- data/app/views/super/application/_sort_expression.html.erb +2 -2
- data/frontend/super-frontend/dist/application.css +0 -1
- data/frontend/super-frontend/dist/application.js +146 -13
- data/lib/super.rb +1 -0
- data/lib/super/display/guesser.rb +1 -1
- data/lib/super/display/schema_types.rb +0 -1
- data/lib/super/error.rb +2 -0
- data/lib/super/filter.rb +1 -1
- data/lib/super/filter/form_object.rb +74 -48
- data/lib/super/filter/guesser.rb +2 -0
- data/lib/super/filter/operator.rb +90 -64
- data/lib/super/filter/schema_types.rb +63 -80
- data/lib/super/form/builder.rb +6 -3
- data/lib/super/form/field_transcript.rb +43 -0
- data/lib/super/form/guesser.rb +1 -1
- data/lib/super/form/schema_types.rb +11 -20
- data/lib/super/link.rb +1 -1
- data/lib/super/schema.rb +4 -0
- data/lib/super/version.rb +1 -1
- metadata +4 -7
- data/app/views/super/application/_filter_type_select.html.erb +0 -21
- data/app/views/super/application/_filter_type_text.html.erb +0 -18
- data/app/views/super/application/_filter_type_timestamp.html.erb +0 -24
- data/app/views/super/application/_form_field_select.html.erb +0 -1
@@ -2,112 +2,95 @@
|
|
2
2
|
|
3
3
|
module Super
|
4
4
|
class Filter
|
5
|
-
# This schema type is used to configure the filtering form on your +#index+
|
6
|
-
# action.
|
7
|
-
#
|
8
|
-
# The +operators:+ keyword argument can be left out in each case. There is
|
9
|
-
# a default set of operators that are provided.
|
10
|
-
#
|
11
5
|
# Note: The constants under "Defined Under Namespace" are considered
|
12
6
|
# private.
|
13
|
-
#
|
14
|
-
# class MemberDashboard
|
15
|
-
# # ...
|
16
|
-
#
|
17
|
-
# def filter_schema
|
18
|
-
# Super::Filter.new do |fields, type|
|
19
|
-
# fields[:name] = type.text(operators: [
|
20
|
-
# Super::Filter::Operator.eq,
|
21
|
-
# Super::Filter::Operator.contain,
|
22
|
-
# Super::Filter::Operator.ncontain,
|
23
|
-
# Super::Filter::Operator.start,
|
24
|
-
# Super::Filter::Operator.end,
|
25
|
-
# ])
|
26
|
-
# fields[:rank] = type.select(collection: Member.ranks.values)
|
27
|
-
# fields[:position] = type.text(operators: [
|
28
|
-
# Super::Filter::Operator.eq,
|
29
|
-
# Super::Filter::Operator.neq,
|
30
|
-
# Super::Filter::Operator.contain,
|
31
|
-
# Super::Filter::Operator.ncontain,
|
32
|
-
# ])
|
33
|
-
# fields[:ship_id] = type.select(
|
34
|
-
# collection: Ship.all.map { |s| ["#{s.name} (Ship ##{s.id})", s.id] },
|
35
|
-
# )
|
36
|
-
# fields[:created_at] = type.timestamp
|
37
|
-
# fields[:updated_at] = type.timestamp
|
38
|
-
# end
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
# # ...
|
42
|
-
# end
|
43
7
|
class SchemaTypes
|
44
|
-
class
|
45
|
-
|
46
|
-
@partial_path = partial_path
|
47
|
-
@operators = operators
|
48
|
-
end
|
8
|
+
class OperatorList
|
9
|
+
include Enumerable
|
49
10
|
|
50
|
-
|
11
|
+
def initialize(*new_operators)
|
12
|
+
@operators = {}
|
13
|
+
@operator_transcript = {}
|
14
|
+
@fallback_transcript = nil
|
51
15
|
|
52
|
-
|
53
|
-
@partial_path
|
16
|
+
push(*new_operators)
|
54
17
|
end
|
55
18
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
19
|
+
def push(*new_operators)
|
20
|
+
new_operators.flatten.map(&:dup).each do |new_operator|
|
21
|
+
new_identifier = new_operator.identifier.to_s
|
22
|
+
|
23
|
+
raise Error::AlreadyRegistered if @operators.key?(new_identifier)
|
60
24
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
25
|
+
@operators[new_identifier] = new_operator
|
26
|
+
end
|
27
|
+
|
28
|
+
nil
|
65
29
|
end
|
66
30
|
|
67
|
-
|
68
|
-
|
31
|
+
alias add push
|
32
|
+
|
33
|
+
def each
|
34
|
+
return enum_for(:each) if !block_given?
|
69
35
|
|
70
|
-
|
71
|
-
|
36
|
+
@operators.each do |identifier, operator|
|
37
|
+
yield(
|
38
|
+
OperatorWithFieldTranscript.new(
|
39
|
+
operator,
|
40
|
+
@operator_transcript[identifier] || @fallback_transcript
|
41
|
+
)
|
42
|
+
)
|
43
|
+
end
|
72
44
|
end
|
73
45
|
|
74
|
-
def
|
75
|
-
|
46
|
+
def transcribe(operator_identifier = nil)
|
47
|
+
transcript = Form::FieldTranscript.new
|
48
|
+
yield transcript
|
49
|
+
|
50
|
+
if operator_identifier.nil?
|
51
|
+
@fallback_transcript = transcript
|
52
|
+
else
|
53
|
+
@operator_transcript[operator_identifier.to_s] = transcript
|
54
|
+
end
|
55
|
+
|
56
|
+
self
|
76
57
|
end
|
77
58
|
end
|
78
59
|
|
79
|
-
class
|
80
|
-
def initialize(
|
81
|
-
@
|
60
|
+
class OperatorWithFieldTranscript
|
61
|
+
def initialize(operator, field_transcript)
|
62
|
+
@operator = operator
|
63
|
+
@field_transcript = field_transcript
|
82
64
|
end
|
83
65
|
|
84
|
-
|
85
|
-
|
86
|
-
def to_partial_path
|
87
|
-
"filter_type_timestamp"
|
66
|
+
Super::Filter::Operator.instance_methods(false).each do |name|
|
67
|
+
delegate name, to: :@operator
|
88
68
|
end
|
89
69
|
|
90
|
-
|
91
|
-
|
92
|
-
|
70
|
+
attr_reader :field_transcript
|
71
|
+
end
|
72
|
+
|
73
|
+
def use(*identifiers)
|
74
|
+
found_operators = identifiers.flatten.map { |id| Operator[id] }
|
75
|
+
OperatorList.new(*found_operators)
|
76
|
+
end
|
77
|
+
|
78
|
+
def select(collection)
|
79
|
+
use("eq", "null", "nnull")
|
80
|
+
.transcribe { |f| f.super.select(collection) }
|
93
81
|
end
|
94
82
|
|
95
|
-
def
|
96
|
-
|
97
|
-
collection: collection,
|
98
|
-
operators: operators
|
99
|
-
)
|
83
|
+
def text
|
84
|
+
use("contain", "ncontain", "blank", "nblank")
|
100
85
|
end
|
101
86
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
105
|
-
operators: operators
|
106
|
-
)
|
87
|
+
def timestamp
|
88
|
+
use("between", "null", "nnull")
|
89
|
+
.transcribe { |f| f.super.datetime_flatpickr }
|
107
90
|
end
|
108
91
|
|
109
|
-
def
|
110
|
-
|
92
|
+
def boolean
|
93
|
+
use("true", "false", "null", "nnull")
|
111
94
|
end
|
112
95
|
end
|
113
96
|
end
|
data/lib/super/form/builder.rb
CHANGED
@@ -71,7 +71,8 @@ module Super
|
|
71
71
|
)
|
72
72
|
options[:class] = join_classes(defaults[:class], options[:class])
|
73
73
|
options[:data] = defaults[:data].deep_merge(options[:data] || {})
|
74
|
-
options[:value] = @builder.object.public_send(attribute).presence
|
74
|
+
options[:value] = @builder.object.public_send(attribute).presence
|
75
|
+
options[:value] = options[:value].iso8601 if options[:value].respond_to?(:iso8601)
|
75
76
|
|
76
77
|
@builder.text_field(attribute, options)
|
77
78
|
end
|
@@ -91,7 +92,8 @@ module Super
|
|
91
92
|
)
|
92
93
|
options[:class] = join_classes(defaults[:class], options[:class])
|
93
94
|
options[:data] = defaults[:data].deep_merge(options[:data] || {})
|
94
|
-
options[:value] = @builder.object.public_send(attribute).presence
|
95
|
+
options[:value] = @builder.object.public_send(attribute).presence
|
96
|
+
options[:value] = options[:value].iso8601 if options[:value].respond_to?(:iso8601)
|
95
97
|
|
96
98
|
@builder.text_field(attribute, options)
|
97
99
|
end
|
@@ -112,7 +114,8 @@ module Super
|
|
112
114
|
)
|
113
115
|
options[:class] = join_classes(defaults[:class], options[:class])
|
114
116
|
options[:data] = defaults[:data].deep_merge(options[:data] || {})
|
115
|
-
options[:value] = @builder.object.public_send(attribute).presence
|
117
|
+
options[:value] = @builder.object.public_send(attribute).presence
|
118
|
+
options[:value] = options[:value].strftime("%H:%M:%S") if options[:value].respond_to?(:strftime)
|
116
119
|
|
117
120
|
@builder.text_field(attribute, options)
|
118
121
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Super
|
4
|
+
class Form
|
5
|
+
# Holds a recording of a form field definition
|
6
|
+
class FieldTranscript
|
7
|
+
def initialize
|
8
|
+
@super = false
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :method_name
|
12
|
+
attr_reader :args
|
13
|
+
attr_reader :kwargs
|
14
|
+
|
15
|
+
def super
|
16
|
+
@super = true
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def super?
|
21
|
+
@super
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(new_method_name, *args, **kwargs)
|
25
|
+
if @method_name.present?
|
26
|
+
method_chain =
|
27
|
+
if super?
|
28
|
+
"super.#{@method_name}"
|
29
|
+
else
|
30
|
+
@method_name.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
raise Error::AlreadyTranscribed, "This instance already holds a transcription for: #{method_chain}"
|
34
|
+
end
|
35
|
+
|
36
|
+
@method_name = new_method_name
|
37
|
+
@args = args
|
38
|
+
@kwargs = kwargs
|
39
|
+
@method_name
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/super/form/guesser.rb
CHANGED
@@ -97,7 +97,7 @@ module Super
|
|
97
97
|
@fields = fields
|
98
98
|
end
|
99
99
|
|
100
|
-
def
|
100
|
+
def partial(partial_path, **extras)
|
101
101
|
Generic.new(partial_path: partial_path, extras: extras, nested: {})
|
102
102
|
end
|
103
103
|
|
@@ -105,17 +105,14 @@ module Super
|
|
105
105
|
Direct.new(super_builder: super_builder, method_name: method_name, args: args, kwargs: kwargs)
|
106
106
|
end
|
107
107
|
|
108
|
-
def select(**
|
109
|
-
|
108
|
+
def select(*args, **kwargs)
|
109
|
+
Direct.new(super_builder: true, method_name: :select!, args: args, kwargs: kwargs)
|
110
110
|
end
|
111
111
|
|
112
112
|
def text_field(*args, **kwargs)
|
113
113
|
Direct.new(super_builder: true, method_name: :text_field!, args: args, kwargs: kwargs)
|
114
114
|
end
|
115
115
|
|
116
|
-
alias string text_field
|
117
|
-
alias text text_field
|
118
|
-
|
119
116
|
def rich_text_area(*args, **kwargs)
|
120
117
|
Direct.new(super_builder: true, method_name: :rich_text_area!, args: args, kwargs: kwargs)
|
121
118
|
end
|
@@ -124,20 +121,14 @@ module Super
|
|
124
121
|
Direct.new(super_builder: true, method_name: :check_box!, args: args, kwargs: kwargs)
|
125
122
|
end
|
126
123
|
|
127
|
-
alias checkbox check_box
|
128
|
-
|
129
124
|
def date_flatpickr(*args, **kwargs)
|
130
125
|
Direct.new(super_builder: true, method_name: :date_flatpickr!, args: args, kwargs: kwargs)
|
131
126
|
end
|
132
127
|
|
133
|
-
alias flatpickr_date date_flatpickr
|
134
|
-
|
135
128
|
def datetime_flatpickr(*args, **kwargs)
|
136
129
|
Direct.new(super_builder: true, method_name: :datetime_flatpickr!, args: args, kwargs: kwargs)
|
137
130
|
end
|
138
131
|
|
139
|
-
alias flatpickr_datetime datetime_flatpickr
|
140
|
-
|
141
132
|
def hidden_field(*args, **kwargs)
|
142
133
|
Direct.new(super_builder: false, method_name: :hidden_field, args: args, kwargs: kwargs)
|
143
134
|
end
|
@@ -150,29 +141,29 @@ module Super
|
|
150
141
|
Direct.new(super_builder: true, method_name: :time_flatpickr!, args: args, kwargs: kwargs)
|
151
142
|
end
|
152
143
|
|
153
|
-
alias flatpickr_time time_flatpickr
|
154
|
-
|
155
144
|
def has_many(reader, **extras)
|
156
|
-
|
157
|
-
|
145
|
+
subfields = Schema::Fields.new
|
146
|
+
@fields.nested do
|
147
|
+
yield subfields
|
158
148
|
end
|
159
149
|
|
160
150
|
Generic.new(
|
161
151
|
partial_path: "form_has_many",
|
162
152
|
extras: extras.merge(reader: reader),
|
163
|
-
nested:
|
153
|
+
nested: subfields.to_h
|
164
154
|
)
|
165
155
|
end
|
166
156
|
|
167
157
|
def has_one(reader, **extras)
|
168
|
-
|
169
|
-
|
158
|
+
subfields = Schema::Fields.new
|
159
|
+
@fields.nested do
|
160
|
+
yield subfields
|
170
161
|
end
|
171
162
|
|
172
163
|
Generic.new(
|
173
164
|
partial_path: "form_has_one",
|
174
165
|
extras: extras.merge(reader: reader),
|
175
|
-
nested:
|
166
|
+
nested: subfields.to_h
|
176
167
|
)
|
177
168
|
end
|
178
169
|
|
data/lib/super/link.rb
CHANGED
@@ -107,7 +107,7 @@ module Super
|
|
107
107
|
@href = Super::Compatability.polymorphic_path_container.polymorphic_path(@href)
|
108
108
|
end
|
109
109
|
|
110
|
-
def to_s(default_options: nil)
|
110
|
+
def to_s(default_options: nil, **)
|
111
111
|
default_options ||= {}
|
112
112
|
ActionController::Base.helpers.link_to(
|
113
113
|
text,
|
data/lib/super/schema.rb
CHANGED
data/lib/super/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: super
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Ahn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -235,14 +235,10 @@ files:
|
|
235
235
|
- app/views/super/application/_display_rich_text.html.erb
|
236
236
|
- app/views/super/application/_display_show.html.erb
|
237
237
|
- app/views/super/application/_filter.html.erb
|
238
|
-
- app/views/super/application/_filter_type_select.html.erb
|
239
|
-
- app/views/super/application/_filter_type_text.html.erb
|
240
|
-
- app/views/super/application/_filter_type_timestamp.html.erb
|
241
238
|
- app/views/super/application/_flash.html.erb
|
242
239
|
- app/views/super/application/_form.html.erb
|
243
240
|
- app/views/super/application/_form_field.html.erb
|
244
241
|
- app/views/super/application/_form_field__destroy.html.erb
|
245
|
-
- app/views/super/application/_form_field_select.html.erb
|
246
242
|
- app/views/super/application/_form_fieldset.html.erb
|
247
243
|
- app/views/super/application/_form_has_many.html.erb
|
248
244
|
- app/views/super/application/_form_has_one.html.erb
|
@@ -300,6 +296,7 @@ files:
|
|
300
296
|
- lib/super/filter/schema_types.rb
|
301
297
|
- lib/super/form.rb
|
302
298
|
- lib/super/form/builder.rb
|
299
|
+
- lib/super/form/field_transcript.rb
|
303
300
|
- lib/super/form/guesser.rb
|
304
301
|
- lib/super/form/inline_errors.rb
|
305
302
|
- lib/super/form/schema_types.rb
|
@@ -348,7 +345,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
348
345
|
- !ruby/object:Gem::Version
|
349
346
|
version: '0'
|
350
347
|
requirements: []
|
351
|
-
rubygems_version: 3.
|
348
|
+
rubygems_version: 3.0.3.1
|
352
349
|
signing_key:
|
353
350
|
specification_version: 4
|
354
351
|
summary: A simple, powerful, zero dependency Rails admin framework
|
@@ -1,21 +0,0 @@
|
|
1
|
-
<div class="super-field-group" data-controller="clean-filter-param">
|
2
|
-
<%= form.fields_for(filter_type_select.field_name, filter_type_select) do |form_field| %>
|
3
|
-
<%= form_field.label(:q, filter_type_select.humanized_field_name) %>
|
4
|
-
<div class="inline-block">
|
5
|
-
<%= form_field.super.select(
|
6
|
-
:op,
|
7
|
-
filter_type_select.operators,
|
8
|
-
{ include_blank: false },
|
9
|
-
data: { clean_filter_param_target: "candidate" }
|
10
|
-
) %>
|
11
|
-
</div>
|
12
|
-
<div class="mt-3">
|
13
|
-
<%= form_field.super.select(
|
14
|
-
:q,
|
15
|
-
filter_type_select.field_type.collection,
|
16
|
-
{},
|
17
|
-
data: { clean_filter_param_target: "control candidate" }
|
18
|
-
) %>
|
19
|
-
</div>
|
20
|
-
<% end %>
|
21
|
-
</div>
|