super 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
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 Controls
3
5
  # Methods for `Controls` that must be defined for Super to work properly
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Controls
3
5
  # Methods that are called by controller actions. All of these methods have
@@ -66,48 +68,38 @@ module Super
66
68
  record.destroy
67
69
  end
68
70
 
69
- def build_index_view
70
- Super::Layout.new(
71
- mains: [
72
- Super::Panel.new(
73
- Super::Partial.new("collection_header"),
74
- :@display
75
- ),
76
- ]
71
+ def initialize_query_form(params:, current_path:)
72
+ Super::Query::FormObject.new(
73
+ model: model,
74
+ params: params,
75
+ namespace: :q,
76
+ current_path: current_path,
77
77
  )
78
78
  end
79
79
 
80
- def build_show_view
81
- Super::Layout.new(
82
- mains: [
83
- Super::Panel.new(
84
- Super::Partial.new("member_header"),
85
- :@display
86
- ),
87
- ]
88
- )
80
+ def apply_queries(query_form:, records:)
81
+ query_form.apply_changes(records)
89
82
  end
90
83
 
91
- def build_new_view
92
- Super::Layout.new(
93
- mains: [
94
- Super::Panel.new(
95
- Super::Partial.new("collection_header"),
96
- :@form
97
- ),
98
- ]
99
- )
84
+ def initialize_filter_form(query_form:)
85
+ if filters_enabled?
86
+ query_form.add(
87
+ Super::Filter::FormObject,
88
+ namespace: :f,
89
+ schema: filter_schema
90
+ )
91
+ end
100
92
  end
101
93
 
102
- def build_edit_view
103
- Super::Layout.new(
104
- mains: [
105
- Super::Panel.new(
106
- Super::Partial.new("member_header"),
107
- :@form
108
- ),
109
- ]
110
- )
94
+ def initialize_sort_form(query_form:)
95
+ if sort_enabled?
96
+ query_form.add(
97
+ Super::Sort::FormObject,
98
+ namespace: :s,
99
+ default: default_sort,
100
+ sortable_columns: sortable_columns
101
+ )
102
+ end
111
103
  end
112
104
  end
113
105
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ class Controls
5
+ # Methods for `Controls` that have a sane default implementation
6
+ module View
7
+ def index_view
8
+ Super::Layout.new(
9
+ mains: [
10
+ Super::Panel.new(
11
+ Super::Partial.new("collection_header"),
12
+ :@display
13
+ ),
14
+ ],
15
+ asides: [
16
+ :@query_form,
17
+ ]
18
+ )
19
+ end
20
+
21
+ def show_view
22
+ Super::Layout.new(
23
+ mains: [
24
+ Super::Panel.new(
25
+ Super::Partial.new("member_header"),
26
+ :@display
27
+ ),
28
+ ]
29
+ )
30
+ end
31
+
32
+ def new_view
33
+ Super::Layout.new(
34
+ mains: [
35
+ Super::Panel.new(
36
+ Super::Partial.new("collection_header"),
37
+ :@form
38
+ ),
39
+ ]
40
+ )
41
+ end
42
+
43
+ def edit_view
44
+ Super::Layout.new(
45
+ mains: [
46
+ Super::Panel.new(
47
+ Super::Partial.new("member_header"),
48
+ :@form
49
+ ),
50
+ ]
51
+ )
52
+ end
53
+ end
54
+ end
55
+ end
data/lib/super/display.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  # This schema type is meant to be used for +#index+ or +#show+ actions to
3
5
  # transform database fields into something that is human friendly.
@@ -23,20 +25,26 @@ module Super
23
25
  class Display
24
26
  include Schema::Common
25
27
 
26
- def initialize(action:)
27
- @action_inquirer = action
28
+ def initialize
28
29
  @fields = Super::Schema::Fields.new
29
30
  @schema_types = SchemaTypes.new(fields: @fields)
30
31
 
31
32
  yield(@fields, @schema_types)
33
+ end
32
34
 
33
- return if !@action_inquirer.index?
34
- return if @schema_types.actions_called?
35
+ def apply(action:)
36
+ @action_inquirer = action
37
+ return self if !@action_inquirer.index?
38
+ return self if @schema_types.actions_called?
35
39
  @fields[:actions] = @schema_types.actions
40
+ self
36
41
  end
37
42
 
38
43
  def to_partial_path
39
- if @action_inquirer.index?
44
+ if @action_inquirer.nil?
45
+ raise Super::Error::Initalization,
46
+ "You must call the `#apply` method after instantiating Super::Display"
47
+ elsif @action_inquirer.index?
40
48
  "super_schema_display_index"
41
49
  elsif @action_inquirer.show?
42
50
  "super_schema_display_show"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Display
3
5
  class Guesser
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Display
3
5
  class SchemaTypes
data/lib/super/engine.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  # Configures the host Rails app to work with Super
3
5
  class Engine < ::Rails::Engine
data/lib/super/error.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  # A container class for all internal errors thrown by this library
3
5
  #
@@ -22,5 +24,8 @@ module Super
22
24
  )
23
25
  end
24
26
  end
27
+ # Error raised when something wasn't initalized correctly, and if there isn't
28
+ # a more specific error
29
+ class Initalization < Error; end
25
30
  end
26
31
  end
data/lib/super/filter.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Filter
3
5
  def initialize
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Filter
3
5
  class FormObject
@@ -42,11 +44,10 @@ module Super
42
44
  end
43
45
  end
44
46
 
45
- def initialize(model:, url:, schema:, params:)
47
+ def initialize(model:, params:, schema:)
46
48
  @model = model
47
- @url = url
48
- @schema = schema
49
49
  @params = params
50
+ @schema = schema
50
51
 
51
52
  @form_fields = {}
52
53
  end
@@ -57,15 +58,11 @@ module Super
57
58
  end
58
59
  end
59
60
 
60
- def url
61
- @url
62
- end
63
-
64
61
  def to_partial_path
65
62
  "filter"
66
63
  end
67
64
 
68
- def to_search_query(relation)
65
+ def apply_changes(relation)
69
66
  each_field do |form_field|
70
67
  next if form_field.specified_values.values.map(&:to_s).map(&:strip).all? { |specified_value| specified_value == "" }
71
68
  next if !Super::Filter::Operator.registry.key?(form_field.op)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Filter
3
5
  class Guesser
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Filter
3
5
  module Operator
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Filter
3
5
  # This schema type is used to configure the filtering form on your +#index+
data/lib/super/form.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  # This schema type is used on your +#edit+ and +#new+ forms
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Form
3
5
  # Example
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Form
3
5
  class Guesser
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Form
3
5
  module InlineErrors
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Form
3
5
  class SchemaTypes
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Form
3
5
  class StrongParams
data/lib/super/layout.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "super/partial/resolving"
2
4
 
3
5
  module Super
data/lib/super/link.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  # Links have three required attributes that are passed directly into Rails'
3
5
  # `link_to` helper
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Navigation
3
5
  # Traverses the defined Rails Routes and attempts to build a list of links.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Pagination
3
5
  include Enumerable
data/lib/super/panel.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "super/partial/resolving"
2
4
 
3
5
  module Super
data/lib/super/partial.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Partial
3
5
  def self.render(partialish, template:)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Partial
3
5
  module Resolving
data/lib/super/plugin.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  module Plugin
3
5
  class Registry
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ class Query
5
+ class FormObject
6
+ def initialize(model:, params:, namespace:, current_path:)
7
+ @model = model
8
+ @all_params = params.dup
9
+ @namespace = namespace
10
+ @params = params[namespace] || ActionController::Parameters.new
11
+ @path = current_path
12
+ @addons = {}
13
+ end
14
+
15
+ attr_reader :namespace
16
+ attr_reader :path
17
+ attr_reader :addons
18
+
19
+ def add(klass, namespace:, **additional_initialization_arguments)
20
+ instance = klass.new(
21
+ model: @model,
22
+ params: params_dig(namespace),
23
+ **additional_initialization_arguments
24
+ )
25
+
26
+ addons[namespace] = instance
27
+ end
28
+
29
+ def apply_changes(records)
30
+ addons.each_value do |addon|
31
+ records = addon.apply_changes(records)
32
+ end
33
+
34
+ records
35
+ end
36
+
37
+ def to_partial_path
38
+ "query"
39
+ end
40
+
41
+ private
42
+
43
+ def params_dig(*keys)
44
+ @params.dig(*keys) || ActionController::Parameters.new
45
+ end
46
+ end
47
+ end
48
+ end
data/lib/super/schema.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  # The Schema is a general purpose container for describing the "schema"
3
5
  # for various purposes. It primarily exists to provide a cohesive user-facing
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class Schema
3
5
  module Common