super 0.0.10 → 0.0.11

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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +16 -14
  3. data/app/assets/javascripts/super/application.js +191 -1
  4. data/app/controllers/super/application_controller.rb +14 -8
  5. data/app/helpers/super/form_builder_helper.rb +2 -0
  6. data/app/views/super/application/_filter.html.erb +5 -13
  7. data/app/views/super/application/_filter_type_select.html.erb +4 -1
  8. data/app/views/super/application/_filter_type_text.html.erb +5 -3
  9. data/app/views/super/application/_filter_type_timestamp.html.erb +5 -4
  10. data/app/views/super/application/_query.html.erb +18 -0
  11. data/app/views/super/application/_sort.html.erb +18 -0
  12. data/app/views/super/application/_sort_expression.html.erb +25 -0
  13. data/app/views/super/feather/README.md +1 -0
  14. data/app/views/super/feather/_x.html +15 -0
  15. data/config/routes.rb +2 -0
  16. data/docs/action_text.md +1 -1
  17. data/docs/yard_customizations.rb +2 -0
  18. data/frontend/super-frontend/dist/application.js +191 -1
  19. data/lib/generators/super/action_text/action_text_generator.rb +2 -0
  20. data/lib/generators/super/install/install_generator.rb +2 -0
  21. data/lib/generators/super/resource/resource_generator.rb +2 -0
  22. data/lib/generators/super/webpacker/webpacker_generator.rb +2 -0
  23. data/lib/super.rb +4 -1
  24. data/lib/super/action_inquirer.rb +2 -0
  25. data/lib/super/assets.rb +2 -0
  26. data/lib/super/client_error.rb +2 -0
  27. data/lib/super/compatibility.rb +2 -0
  28. data/lib/super/configuration.rb +2 -1
  29. data/lib/super/controls.rb +4 -0
  30. data/lib/super/controls/optional.rb +34 -1
  31. data/lib/super/controls/required.rb +2 -0
  32. data/lib/super/controls/steps.rb +27 -35
  33. data/lib/super/controls/view.rb +55 -0
  34. data/lib/super/display.rb +13 -5
  35. data/lib/super/display/guesser.rb +2 -0
  36. data/lib/super/display/schema_types.rb +2 -0
  37. data/lib/super/engine.rb +2 -0
  38. data/lib/super/error.rb +5 -0
  39. data/lib/super/filter.rb +2 -0
  40. data/lib/super/filter/form_object.rb +5 -8
  41. data/lib/super/filter/guesser.rb +2 -0
  42. data/lib/super/filter/operator.rb +2 -0
  43. data/lib/super/filter/schema_types.rb +2 -0
  44. data/lib/super/form.rb +2 -0
  45. data/lib/super/form/builder.rb +2 -0
  46. data/lib/super/form/guesser.rb +2 -0
  47. data/lib/super/form/inline_errors.rb +2 -0
  48. data/lib/super/form/schema_types.rb +2 -0
  49. data/lib/super/form/strong_params.rb +2 -0
  50. data/lib/super/layout.rb +2 -0
  51. data/lib/super/link.rb +2 -0
  52. data/lib/super/navigation/automatic.rb +2 -0
  53. data/lib/super/pagination.rb +2 -0
  54. data/lib/super/panel.rb +2 -0
  55. data/lib/super/partial.rb +2 -0
  56. data/lib/super/partial/resolving.rb +2 -0
  57. data/lib/super/plugin.rb +2 -0
  58. data/lib/super/query/form_object.rb +48 -0
  59. data/lib/super/schema.rb +2 -0
  60. data/lib/super/schema/common.rb +2 -0
  61. data/lib/super/schema/guesser.rb +2 -0
  62. data/lib/super/sort.rb +110 -0
  63. data/lib/super/version.rb +3 -1
  64. data/lib/super/view_helper.rb +2 -0
  65. metadata +23 -3
  66. data/lib/super/filter/plugin.rb +0 -47
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Schema
3
5
  class Guesser
data/lib/super/sort.rb ADDED
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ module Sort
5
+ class FormObject
6
+ DIRECTIONS = ["asc", "desc"]
7
+
8
+ def initialize(model:, params:, default:, sortable_columns:)
9
+ @model = model
10
+ @params = params.dup
11
+ @default = default
12
+ @sortable_columns = sortable_columns.map(&:to_s)
13
+
14
+ @params.permit!
15
+ end
16
+
17
+ attr_reader :sortable_columns
18
+
19
+ def to_partial_path
20
+ "sort"
21
+ end
22
+
23
+ def exprs
24
+ sanitized_expr_params.map { |ordering| Expression.new(**ordering) }
25
+ end
26
+
27
+ def new_expr
28
+ Expression.new(a: nil, d: :desc)
29
+ end
30
+
31
+ class Expression
32
+ attr_accessor :a # attribute
33
+ attr_accessor :d # direction
34
+
35
+ def initialize(a:, d:)
36
+ @a = a
37
+ @d = d.to_s
38
+ end
39
+
40
+ def with_index(index)
41
+ @index = index
42
+ self
43
+ end
44
+
45
+ # This is for `fields_for` to work
46
+ def id
47
+ @index
48
+ end
49
+
50
+ def persisted?
51
+ false
52
+ end
53
+ end
54
+
55
+ def persisted?
56
+ false
57
+ end
58
+
59
+ def apply_changes(query)
60
+ exprs.each do |expr|
61
+ query = query.order(expr.a => expr.d)
62
+ end
63
+
64
+ query
65
+ end
66
+
67
+ private
68
+
69
+ # Stringifies the values
70
+ def sanitized_expr_params
71
+ seen = {}
72
+ normalized_expr_params
73
+ .each do |p|
74
+ p[:a] = p[:a].presence&.to_s&.strip
75
+ p[:d] = p[:d].presence&.to_s&.strip
76
+ end
77
+ .select { |p| p[:a].present? && DIRECTIONS.include?(p[:d]) }
78
+ .select { |p| @sortable_columns.include?(p[:a]) }
79
+ .select do |p|
80
+ next false if seen.key?(p[:a])
81
+
82
+ seen[p[:a]] = true
83
+ true
84
+ end
85
+ end
86
+
87
+ # Symbolizes the keys
88
+ def normalized_expr_params
89
+ from_params = @params[:exprs]
90
+
91
+ return default_as_query if from_params.nil?
92
+
93
+ if from_params.is_a?(Array)
94
+ return from_params.map(&:to_h).map(&:symbolize_keys)
95
+ end
96
+
97
+ from_params.to_h.values.map(&:symbolize_keys)
98
+ end
99
+
100
+ def default_as_query
101
+ @default.map do |attribute_name, direction|
102
+ {
103
+ a: attribute_name,
104
+ d: direction,
105
+ }
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
data/lib/super/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
- VERSION = "0.0.10"
4
+ VERSION = "0.0.11"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  module ViewHelper
3
5
  module_function
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.10
4
+ version: 0.0.11
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-01-17 00:00:00.000000000 Z
11
+ date: 2021-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -198,6 +198,20 @@ dependencies:
198
198
  - - ">="
199
199
  - !ruby/object:Gem::Version
200
200
  version: '0'
201
+ - !ruby/object:Gem::Dependency
202
+ name: simplecov
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ type: :development
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
201
215
  description:
202
216
  email:
203
217
  - engineering@zachahn.com
@@ -233,6 +247,9 @@ files:
233
247
  - app/views/super/application/_form_has_many.html.erb
234
248
  - app/views/super/application/_form_has_one.html.erb
235
249
  - app/views/super/application/_member_header.html.erb
250
+ - app/views/super/application/_query.html.erb
251
+ - app/views/super/application/_sort.html.erb
252
+ - app/views/super/application/_sort_expression.html.erb
236
253
  - app/views/super/application/_super_layout.html.erb
237
254
  - app/views/super/application/_super_pagination.html.erb
238
255
  - app/views/super/application/_super_panel.html.erb
@@ -247,6 +264,7 @@ files:
247
264
  - app/views/super/application/show.html.erb
248
265
  - app/views/super/feather/README.md
249
266
  - app/views/super/feather/_chevron_down.html
267
+ - app/views/super/feather/_x.html
250
268
  - config/locales/en.yml
251
269
  - config/routes.rb
252
270
  - docs/README.md
@@ -283,6 +301,7 @@ files:
283
301
  - lib/super/controls/optional.rb
284
302
  - lib/super/controls/required.rb
285
303
  - lib/super/controls/steps.rb
304
+ - lib/super/controls/view.rb
286
305
  - lib/super/display.rb
287
306
  - lib/super/display/guesser.rb
288
307
  - lib/super/display/schema_types.rb
@@ -292,7 +311,6 @@ files:
292
311
  - lib/super/filter/form_object.rb
293
312
  - lib/super/filter/guesser.rb
294
313
  - lib/super/filter/operator.rb
295
- - lib/super/filter/plugin.rb
296
314
  - lib/super/filter/schema_types.rb
297
315
  - lib/super/form.rb
298
316
  - lib/super/form/builder.rb
@@ -308,9 +326,11 @@ files:
308
326
  - lib/super/partial.rb
309
327
  - lib/super/partial/resolving.rb
310
328
  - lib/super/plugin.rb
329
+ - lib/super/query/form_object.rb
311
330
  - lib/super/schema.rb
312
331
  - lib/super/schema/common.rb
313
332
  - lib/super/schema/guesser.rb
333
+ - lib/super/sort.rb
314
334
  - lib/super/version.rb
315
335
  - lib/super/view_helper.rb
316
336
  homepage:
@@ -1,47 +0,0 @@
1
- module Super
2
- class Filter
3
- module ControllerMethods
4
- def index
5
- super
6
- @filter_form = controls.initialize_filtering(params: params, query_params: request.GET)
7
- @records = controls.filter_records(filter_form: @filter_form, records: @records)
8
- @view.asides.push(:@filter_form)
9
- end
10
- end
11
- end
12
-
13
- class Controls
14
- module Optional
15
- def filters_enabled?
16
- true
17
- end
18
-
19
- def filter_schema
20
- Filter.new do |fields, type|
21
- Filter::Guesser.new(model: model, fields: fields, type: type).call
22
- end
23
- end
24
- end
25
-
26
- module Steps
27
- def initialize_filtering(params:, query_params:)
28
- if filters_enabled?
29
- Super::Filter::FormObject.new(
30
- model: model,
31
- schema: filter_schema,
32
- params: params[:q],
33
- url: query_params
34
- )
35
- end
36
- end
37
-
38
- def filter_records(filter_form:, records:)
39
- if filters_enabled? && records
40
- filter_form.to_search_query(records)
41
- else
42
- records
43
- end
44
- end
45
- end
46
- end
47
- end