super 0.0.14 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/assets/javascripts/super/application.js +148 -15
  4. data/app/assets/stylesheets/super/application.css +15 -22
  5. data/app/controllers/super/application_controller.rb +44 -42
  6. data/app/controllers/super/substructure_controller.rb +313 -0
  7. data/app/helpers/super/form_builder_helper.rb +7 -0
  8. data/app/views/layouts/super/application.html.erb +3 -21
  9. data/app/views/super/application/_collection_header.html.erb +2 -2
  10. data/app/views/super/application/_display_actions.html.erb +1 -1
  11. data/app/views/super/application/_display_index.html.erb +2 -2
  12. data/app/views/super/application/_display_show.html.erb +1 -1
  13. data/app/views/super/application/_filter.html.erb +62 -2
  14. data/app/views/super/application/_form_field.html.erb +5 -0
  15. data/app/views/super/application/_member_header.html.erb +2 -2
  16. data/app/views/super/application/_pagination.html.erb +1 -1
  17. data/app/views/super/application/_site_footer.html.erb +3 -0
  18. data/app/views/super/application/_site_header.html.erb +17 -0
  19. data/app/views/super/application/_sort_expression.html.erb +2 -2
  20. data/app/views/super/application/index.csv.erb +14 -0
  21. data/app/views/super/feather/README.md +0 -1
  22. data/frontend/super-frontend/dist/application.css +15 -22
  23. data/frontend/super-frontend/dist/application.js +148 -15
  24. data/lib/generators/super/install/install_generator.rb +0 -16
  25. data/lib/generators/super/install/templates/base_controller.rb.tt +0 -8
  26. data/lib/generators/super/resource/templates/resources_controller.rb.tt +4 -4
  27. data/lib/super/action_inquirer.rb +18 -3
  28. data/lib/super/badge.rb +60 -0
  29. data/lib/super/cheat.rb +6 -6
  30. data/lib/super/display/guesser.rb +1 -1
  31. data/lib/super/display/schema_types.rb +49 -1
  32. data/lib/super/display.rb +2 -1
  33. data/lib/super/error.rb +3 -0
  34. data/lib/super/filter/form_object.rb +74 -48
  35. data/lib/super/filter/guesser.rb +2 -0
  36. data/lib/super/filter/operator.rb +90 -64
  37. data/lib/super/filter/schema_types.rb +63 -80
  38. data/lib/super/filter.rb +1 -1
  39. data/lib/super/form/builder.rb +30 -39
  40. data/lib/super/form/field_transcript.rb +43 -0
  41. data/lib/super/form/guesser.rb +4 -4
  42. data/lib/super/form/schema_types.rb +66 -22
  43. data/lib/super/link.rb +2 -2
  44. data/lib/super/pagination.rb +2 -44
  45. data/lib/super/reset.rb +25 -0
  46. data/lib/super/schema.rb +4 -0
  47. data/lib/super/useful/builder.rb +4 -4
  48. data/lib/super/version.rb +1 -1
  49. data/lib/super.rb +3 -1
  50. data/lib/tasks/super/cheat.rake +1 -1
  51. metadata +25 -19
  52. data/app/views/super/application/_filter_type_select.html.erb +0 -21
  53. data/app/views/super/application/_filter_type_text.html.erb +0 -18
  54. data/app/views/super/application/_filter_type_timestamp.html.erb +0 -24
  55. data/app/views/super/application/_form_field_checkbox.html.erb +0 -1
  56. data/app/views/super/application/_form_field_flatpickr_date.html.erb +0 -8
  57. data/app/views/super/application/_form_field_flatpickr_datetime.html.erb +0 -8
  58. data/app/views/super/application/_form_field_flatpickr_time.html.erb +0 -8
  59. data/app/views/super/application/_form_field_rich_text_area.html.erb +0 -1
  60. data/app/views/super/application/_form_field_select.html.erb +0 -1
  61. data/app/views/super/application/_form_field_text.html.erb +0 -1
  62. data/app/views/super/feather/_chevron_down.html +0 -1
  63. data/docs/cheat.md +0 -41
  64. data/lib/super/controls/optional.rb +0 -113
  65. data/lib/super/controls/steps.rb +0 -106
  66. data/lib/super/controls/view.rb +0 -55
  67. data/lib/super/controls.rb +0 -22
@@ -1,113 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Super
4
- class Controls
5
- # Methods for `Controls` that have a sane default implementation
6
- module Optional
7
- # This is an optional method
8
- #
9
- # @return [String]
10
- def title
11
- model.name.pluralize
12
- end
13
-
14
- # Configures what database records are visible on load. This is an optional
15
- # method, it defaults to "`all`" methods
16
- #
17
- # @param action [ActionInquirer]
18
- # @return [ActiveRecord::Relation]
19
- def scope(action:)
20
- model.all
21
- end
22
-
23
- # Configures the fields that are displayed on the index and show actions.
24
- # This is a required method
25
- #
26
- # @param action [ActionInquirer]
27
- # @return [Display]
28
- def display_schema(action:)
29
- Display.new do |fields, type|
30
- Display::Guesser.new(model: model, action: action, fields: fields, type: type).call
31
- end
32
- end
33
-
34
- # Configures the editable fields on the new and edit actions. This is a
35
- # required method
36
- #
37
- # @param action [ActionInquirer]
38
- # @return [Form]
39
- def form_schema(action:)
40
- Form.new do |fields, type|
41
- Form::Guesser.new(model: model, fields: fields, type: type).call
42
- end
43
- end
44
-
45
- # Configures which parameters could be written to the database. This is a
46
- # required method
47
- #
48
- # @param params [ActionController::Parameters]
49
- # @param action [ActionInquirer]
50
- # @return [ActionController::Parameters]
51
- def permitted_params(params, action:)
52
- strong_params = Super::Form::StrongParams.new(form_schema(action: action))
53
- params.require(strong_params.require(model)).permit(strong_params.permit)
54
- end
55
-
56
- # Configures the actions linked to on the index page. This is an optional
57
- # method
58
- #
59
- # @param action [ActionInquirer]
60
- # @return [Array<Link>]
61
- def collection_actions(action:)
62
- Super::Link.find_all(:new)
63
- end
64
-
65
- # Configures the actions linked to on the show page as well as each row of
66
- # the table on the index page. This is an optional method
67
- #
68
- # @param action [ActionInquirer]
69
- # @return [Array<Link>]
70
- def member_actions(action:)
71
- if action.show?
72
- Super::Link.find_all(:edit, :destroy)
73
- elsif action.edit?
74
- Super::Link.find_all(:show, :destroy)
75
- else
76
- Super::Link.find_all(:show, :edit, :destroy)
77
- end
78
- end
79
-
80
- def filters_enabled?
81
- true
82
- end
83
-
84
- def filter_schema
85
- Super::Filter.new do |fields, type|
86
- Super::Filter::Guesser.new(model: model, fields: fields, type: type).call
87
- end
88
- end
89
-
90
- def sort_enabled?
91
- true
92
- end
93
-
94
- def sortable_columns
95
- action = ActionInquirer.new(
96
- ActionInquirer.default_for_resources,
97
- "index"
98
- )
99
- attribute_names =
100
- display_schema(action: action).each_attribute.map do |key, val|
101
- val = val.build if val.respond_to?(:build)
102
- key if val.real?
103
- end
104
-
105
- attribute_names.compact
106
- end
107
-
108
- def default_sort
109
- { id: :desc }
110
- end
111
- end
112
- end
113
- end
@@ -1,106 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Super
4
- class Controls
5
- # Methods that are called by controller actions. All of these methods have
6
- # a default implementation, but feel free to override as needed.
7
- module Steps
8
- # Tells the controller how to load records in the index action using
9
- # `#scope`
10
- #
11
- # @param action [ActionInquirer]
12
- # @param params [ActionController::Parameters]
13
- # @return [ActiveRecord::Relation]
14
- def load_records(action:, params:)
15
- scope(action: action)
16
- end
17
-
18
- # Loads a record using `#scope`
19
- #
20
- # @param action [ActionInquirer]
21
- # @param params [ActionController::Parameters]
22
- # @return [ActiveRecord::Base]
23
- def load_record(action:, params:)
24
- scope(action: action).find(params[:id])
25
- end
26
-
27
- # Builds a record using `#scope`
28
- #
29
- # @param action [ActionInquirer]
30
- # @return [ActiveRecord::Base]
31
- def build_record(action:)
32
- scope(action: action).build
33
- end
34
-
35
- # Builds and populates a record using `#scope`
36
- #
37
- # @param action [ActionInquirer]
38
- # @param params [ActionController::Parameters]
39
- # @return [ActiveRecord::Base]
40
- def build_record_with_params(action:, params:)
41
- scope(action: action).build(permitted_params(params, action: action))
42
- end
43
-
44
- # Saves a record
45
- #
46
- # @param action [ActionInquirer]
47
- # @param params [ActionController::Parameters]
48
- # @return [true, false]
49
- def save_record(action:, record:, params:)
50
- record.save
51
- end
52
-
53
- # Saves a record
54
- #
55
- # @param action [ActionInquirer]
56
- # @param params [ActionController::Parameters]
57
- # @return [true, false]
58
- def update_record(action:, record:, params:)
59
- record.update(permitted_params(params, action: action))
60
- end
61
-
62
- # Destroys a record
63
- #
64
- # @param action [ActionInquirer]
65
- # @param params [ActionController::Parameters]
66
- # @return [ActiveRecord::Base, false]
67
- def destroy_record(action:, record:, params:)
68
- record.destroy
69
- end
70
-
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
- )
78
- end
79
-
80
- def apply_queries(query_form:, records:)
81
- query_form.apply_changes(records)
82
- end
83
-
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
92
- end
93
-
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
103
- end
104
- end
105
- end
106
- end
@@ -1,55 +0,0 @@
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
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "super/controls/optional"
4
- require "super/controls/steps"
5
- require "super/controls/view"
6
-
7
- module Super
8
- # The base Controls class. Most parts of Super can be configured by
9
- # customizing its methods.
10
- class Controls
11
- include Optional
12
- include Steps
13
- include View
14
-
15
- # Specifies the model. This is a required method
16
- #
17
- # @return [ActiveRecord::Base]
18
- def model
19
- raise NotImplementedError
20
- end
21
- end
22
- end