super 0.0.16 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/super/application.js +146 -13
  3. data/app/assets/stylesheets/super/application.css +0 -1
  4. data/app/controllers/super/application_controller.rb +15 -2
  5. data/app/controllers/super/substructure_controller.rb +19 -8
  6. data/app/views/super/application/_display_actions.html.erb +1 -1
  7. data/app/views/super/application/_filter.html.erb +62 -2
  8. data/app/views/super/application/_member_header.html.erb +1 -1
  9. data/app/views/super/application/_sort_expression.html.erb +2 -2
  10. data/frontend/super-frontend/dist/application.css +0 -1
  11. data/frontend/super-frontend/dist/application.js +146 -13
  12. data/lib/super.rb +1 -0
  13. data/lib/super/display/guesser.rb +1 -1
  14. data/lib/super/display/schema_types.rb +0 -1
  15. data/lib/super/error.rb +2 -0
  16. data/lib/super/filter.rb +1 -1
  17. data/lib/super/filter/form_object.rb +74 -48
  18. data/lib/super/filter/guesser.rb +2 -0
  19. data/lib/super/filter/operator.rb +90 -64
  20. data/lib/super/filter/schema_types.rb +63 -80
  21. data/lib/super/form/builder.rb +6 -3
  22. data/lib/super/form/field_transcript.rb +43 -0
  23. data/lib/super/form/guesser.rb +1 -1
  24. data/lib/super/form/schema_types.rb +11 -20
  25. data/lib/super/link.rb +1 -1
  26. data/lib/super/schema.rb +4 -0
  27. data/lib/super/version.rb +1 -1
  28. metadata +4 -7
  29. data/app/views/super/application/_filter_type_select.html.erb +0 -21
  30. data/app/views/super/application/_filter_type_text.html.erb +0 -18
  31. data/app/views/super/application/_filter_type_timestamp.html.erb +0 -24
  32. 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 Text
45
- def initialize(partial_path:, operators:)
46
- @partial_path = partial_path
47
- @operators = operators
48
- end
8
+ class OperatorList
9
+ include Enumerable
49
10
 
50
- attr_reader :operators
11
+ def initialize(*new_operators)
12
+ @operators = {}
13
+ @operator_transcript = {}
14
+ @fallback_transcript = nil
51
15
 
52
- def to_partial_path
53
- @partial_path
16
+ push(*new_operators)
54
17
  end
55
18
 
56
- def q
57
- [:q]
58
- end
59
- end
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
- class Select
62
- def initialize(collection:, operators:)
63
- @collection = collection
64
- @operators = operators
25
+ @operators[new_identifier] = new_operator
26
+ end
27
+
28
+ nil
65
29
  end
66
30
 
67
- attr_reader :collection
68
- attr_reader :operators
31
+ alias add push
32
+
33
+ def each
34
+ return enum_for(:each) if !block_given?
69
35
 
70
- def to_partial_path
71
- "filter_type_select"
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 q
75
- [:q]
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 Timestamp
80
- def initialize(operators:)
81
- @operators = operators
60
+ class OperatorWithFieldTranscript
61
+ def initialize(operator, field_transcript)
62
+ @operator = operator
63
+ @field_transcript = field_transcript
82
64
  end
83
65
 
84
- attr_reader :operators
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
- def q
91
- [:q0, :q1]
92
- end
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 select(collection:, operators: Filter::Operator.select_defaults)
96
- Select.new(
97
- collection: collection,
98
- operators: operators
99
- )
83
+ def text
84
+ use("contain", "ncontain", "blank", "nblank")
100
85
  end
101
86
 
102
- def text(operators: Filter::Operator.text_defaults)
103
- Text.new(
104
- partial_path: "filter_type_text",
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 timestamp(operators: Filter::Operator.range_defaults)
110
- Timestamp.new(operators: operators)
92
+ def boolean
93
+ use("true", "false", "null", "nnull")
111
94
  end
112
95
  end
113
96
  end
@@ -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&.iso8601
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&.iso8601
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&.strftime("%H:%M:%S")
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
@@ -30,7 +30,7 @@ module Super
30
30
  when :date
31
31
  @type.date_flatpickr
32
32
  else
33
- @type.string
33
+ @type.text_field
34
34
  end
35
35
  end
36
36
  end
@@ -97,7 +97,7 @@ module Super
97
97
  @fields = fields
98
98
  end
99
99
 
100
- def generic(partial_path, **extras)
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(**extras)
109
- Generic.new(partial_path: "form_field_select", extras: extras, nested: {})
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
- nested = @fields.nested do
157
- yield
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: nested
153
+ nested: subfields.to_h
164
154
  )
165
155
  end
166
156
 
167
157
  def has_one(reader, **extras)
168
- nested = @fields.nested do
169
- yield
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: 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
@@ -42,6 +42,10 @@ module Super
42
42
  enum_for(:each)
43
43
  end
44
44
 
45
+ def delete(key)
46
+ @backing.delete(key)
47
+ end
48
+
45
49
  def replace(other)
46
50
  @backing = other
47
51
  end
data/lib/super/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Super
4
- VERSION = "0.0.16"
4
+ VERSION = "0.17.0"
5
5
  end
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.16
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-05-15 00:00:00.000000000 Z
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.2.4
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>