super 0.0.12 → 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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +0 -1
  3. data/README.md +38 -46
  4. data/app/assets/javascripts/super/application.js +5747 -3803
  5. data/app/assets/stylesheets/super/application.css +114686 -71486
  6. data/app/controllers/super/application_controller.rb +44 -37
  7. data/app/controllers/super/substructure_controller.rb +276 -0
  8. data/app/helpers/super/form_builder_helper.rb +7 -0
  9. data/app/views/layouts/super/application.html.erb +4 -19
  10. data/app/views/super/application/_collection_header.html.erb +2 -2
  11. data/app/views/super/application/_display_actions.html.erb +1 -1
  12. data/app/views/super/application/_display_index.html.erb +2 -2
  13. data/app/views/super/application/_display_show.html.erb +1 -1
  14. data/app/views/super/application/_filter.html.erb +62 -2
  15. data/app/views/super/application/_form_field.html.erb +5 -0
  16. data/app/views/super/application/_layout.html.erb +1 -1
  17. data/app/views/super/application/_member_header.html.erb +2 -2
  18. data/app/views/super/application/_pagination.html.erb +1 -1
  19. data/app/views/super/application/_site_footer.html.erb +3 -0
  20. data/app/views/super/application/_site_header.html.erb +17 -0
  21. data/app/views/super/application/_sort_expression.html.erb +2 -2
  22. data/app/views/super/feather/README.md +0 -1
  23. data/frontend/super-frontend/dist/application.css +114686 -71486
  24. data/frontend/super-frontend/dist/application.js +5747 -3803
  25. data/lib/generators/super/install/install_generator.rb +0 -16
  26. data/lib/generators/super/install/templates/base_controller.rb.tt +0 -8
  27. data/lib/generators/super/resource/templates/resources_controller.rb.tt +4 -4
  28. data/lib/generators/super/webpacker/webpacker_generator.rb +9 -5
  29. data/lib/super.rb +5 -2
  30. data/lib/super/action_inquirer.rb +18 -3
  31. data/lib/super/assets.rb +44 -23
  32. data/lib/super/badge.rb +60 -0
  33. data/lib/super/cheat.rb +17 -0
  34. data/lib/super/compatibility.rb +19 -0
  35. data/lib/super/display/guesser.rb +3 -1
  36. data/lib/super/display/schema_types.rb +51 -2
  37. data/lib/super/error.rb +2 -0
  38. data/lib/super/filter.rb +1 -1
  39. data/lib/super/filter/form_object.rb +74 -48
  40. data/lib/super/filter/guesser.rb +2 -0
  41. data/lib/super/filter/operator.rb +90 -64
  42. data/lib/super/filter/schema_types.rb +63 -80
  43. data/lib/super/form/builder.rb +110 -27
  44. data/lib/super/form/field_transcript.rb +43 -0
  45. data/lib/super/form/guesser.rb +10 -1
  46. data/lib/super/form/schema_types.rb +73 -16
  47. data/lib/super/link.rb +38 -32
  48. data/lib/super/link_builder.rb +58 -0
  49. data/lib/super/navigation.rb +164 -0
  50. data/lib/super/pagination.rb +2 -44
  51. data/lib/super/reset.rb +22 -0
  52. data/lib/super/schema.rb +4 -0
  53. data/lib/super/useful/builder.rb +4 -4
  54. data/lib/super/version.rb +1 -1
  55. data/lib/tasks/super/cheat.rake +9 -0
  56. metadata +14 -19
  57. data/CONTRIBUTING.md +0 -56
  58. data/Rakefile +0 -36
  59. data/app/views/super/application/_filter_type_select.html.erb +0 -21
  60. data/app/views/super/application/_filter_type_text.html.erb +0 -18
  61. data/app/views/super/application/_filter_type_timestamp.html.erb +0 -24
  62. data/app/views/super/application/_form_field_checkbox.html.erb +0 -1
  63. data/app/views/super/application/_form_field_rich_text_area.html.erb +0 -1
  64. data/app/views/super/application/_form_field_select.html.erb +0 -1
  65. data/app/views/super/application/_form_field_text.html.erb +0 -1
  66. data/app/views/super/feather/_chevron_down.html +0 -1
  67. data/docs/cheat.md +0 -41
  68. data/lib/super/controls.rb +0 -22
  69. data/lib/super/controls/optional.rb +0 -113
  70. data/lib/super/controls/steps.rb +0 -106
  71. data/lib/super/controls/view.rb +0 -55
  72. data/lib/super/navigation/automatic.rb +0 -73
data/CONTRIBUTING.md DELETED
@@ -1,56 +0,0 @@
1
- # Contributing
2
-
3
- Thank you for thinking about contributing to Super!
4
-
5
-
6
- ## General guidelines
7
-
8
- There are a few ground rules that to adhere to:
9
-
10
- * be friendly and patient,
11
- * be welcoming,
12
- * be considerate,
13
- * be respectful,
14
- * be careful in the words that you choose and be kind to others,
15
- * when we disagree, try to understand why.
16
-
17
- This isn't an exhaustive list of things that you can't do. Rather, take it in
18
- the spirit in which it's intended - a guide to make it easier to communicate and
19
- participate in the community.
20
-
21
- This applies to all spaces managed by the Super project.
22
-
23
- If you believe someone is violating the code of conduct, we ask that you report
24
- it by emailing: super+conduct at zachahn.com
25
-
26
- Offenders may be banned, asked to apologize, etc.
27
-
28
- (These guidelines are based on the [FreeBSD CoC][FreeBSD CoC], which in turn is
29
- based on [LLVM Project's draft CoC][LLVM CoC], which in turn is based on the
30
- [Django Project Code of Conduct][Django CoC], which is in turn based on wording
31
- from the Speak Up! project.)
32
-
33
-
34
- ## Bug reports / issues
35
-
36
- 1. Please tell us what version of Super, Ruby, and Rails you are using
37
- 1. Please search the issues before posting your problem
38
- 1. Please ask questions in a public place to benefit all Super users
39
- 1. Please email security-related problems to super+security [at] zachahn.com
40
-
41
-
42
- ## Feature requests / pull requests
43
-
44
- Contributors will need to sign a CLA. This isn't set up yet, so I won't be able
45
- to accept contributions.
46
-
47
- 1. Please note that pull requests may be closed/denied for any reason.
48
- Your feature may be better as its own repository. If so, I will link to your
49
- project from the README!
50
- 1. Please allow Super's contributors to modify your PR before merging.
51
- It might make the process a bit smoother, but this isn't a necessity.
52
-
53
-
54
- [FreeBSD CoC]: https://www.freebsd.org/internal/code-of-conduct.html
55
- [LLVM CoC]: https://llvm.org/docs/CodeOfConduct.html
56
- [Django CoC]: https://www.djangoproject.com/conduct/
data/Rakefile DELETED
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- begin
4
- require "bundler/setup"
5
- rescue LoadError
6
- puts "You must `gem install bundler` and `bundle install` to run rake tasks"
7
- end
8
-
9
- require "rdoc/task"
10
-
11
- RDoc::Task.new(:rdoc) do |rdoc|
12
- rdoc.rdoc_dir = "rdoc"
13
- rdoc.title = "Super"
14
- rdoc.options << "--line-numbers"
15
- rdoc.rdoc_files.include("README.md")
16
- rdoc.rdoc_files.include("lib/**/*.rb")
17
- end
18
-
19
- require_relative "dummy_path"
20
-
21
- APP_RAKEFILE = File.expand_path("#{SUPER_DUMMY_PATH}/Rakefile", __dir__)
22
- load "rails/tasks/engine.rake"
23
-
24
- load "rails/tasks/statistics.rake"
25
-
26
- require "bundler/gem_tasks"
27
-
28
- require "rake/testtask"
29
-
30
- Rake::TestTask.new(:test) do |t|
31
- t.libs << "test"
32
- t.pattern = "test/**/*_test.rb"
33
- t.verbose = false
34
- end
35
-
36
- task default: :test
@@ -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="relative 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>
@@ -1,18 +0,0 @@
1
- <div class="super-field-group" data-controller="clean-filter-param">
2
- <%= form.fields_for(filter_type_text.field_name, filter_type_text) do |form_field| %>
3
- <%= form_field.label(:q, filter_type_text.humanized_field_name) %>
4
- <div class="relative inline-block">
5
- <%= form_field.super.select(
6
- :op,
7
- filter_type_text.operators,
8
- { include_blank: false },
9
- data: { clean_filter_param_target: "candidate" }
10
- ) %>
11
- </div>
12
- <%= form_field.super.text_field(
13
- :q,
14
- class: "mt-3",
15
- data: { clean_filter_param_target: "control candidate" }
16
- ) %>
17
- <% end %>
18
- </div>
@@ -1,24 +0,0 @@
1
- <div class="super-field-group" data-controller="clean-filter-param">
2
- <%= form.fields_for(filter_type_timestamp.field_name, filter_type_timestamp) do |form_field| %>
3
- <%= form_field.label(:q0, filter_type_timestamp.humanized_field_name) %>
4
- <div class="relative inline-block mt-2">
5
- <%= form_field.super.select(
6
- :op,
7
- filter_type_timestamp.operators,
8
- { include_blank: false },
9
- data: { clean_filter_param_target: "candidate" }
10
- ) %>
11
- </div>
12
- <div class="flex items-center mt-3">
13
- <div class="flex-initial">
14
- <%= form_field.super.text_field(:q0, data: { clean_filter_param_target: "control candidate" }) %>
15
- </div>
16
- <div class="flex-initial px-2">
17
- &ndash;
18
- </div>
19
- <div class="flex-initial">
20
- <%= form_field.super.text_field(:q1, data: { clean_filter_param_target: "control candidate" }) %>
21
- </div>
22
- </div>
23
- <% end %>
24
- </div>
@@ -1 +0,0 @@
1
- <%= form.super.check_box!(column) %>
@@ -1 +0,0 @@
1
- <%= form.super.rich_text_area!(column) %>
@@ -1 +0,0 @@
1
- <%= form.super.select!(column, form_field_select[:collection]) %>
@@ -1 +0,0 @@
1
- <%= form.super.text_field!(column) %>
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-down"><polyline points="6 9 12 15 18 9"></polyline></svg>
data/docs/cheat.md DELETED
@@ -1,41 +0,0 @@
1
- <!--
2
- # @title Cheat sheet
3
- -->
4
-
5
- # Cheat sheet
6
-
7
- ## Controls
8
-
9
- You can configure most of your admin page's behavior by editing Controls.
10
- They only work with ActiveRecord models
11
-
12
- Controls have several required and optional methods. Note that all arguments
13
- must be defined, even if they are ignored.
14
-
15
-
16
- ### Required methods
17
-
18
- The following are the methods that must be defined in the `Controls` class.
19
-
20
- * **`#model()`**
21
- The model that your controller is working with
22
-
23
-
24
- ### Optional methods
25
-
26
- The following are the methods that can be defined in the `Controls` class.
27
-
28
- * **`#title()`**
29
- The title to show on the main panel
30
- * **`#collection_actions(action:)`**
31
- The list of collection-level links
32
- * **`#member_actions(action:)`**
33
- The list of member-level links and `#show` pages
34
- * **`#scope(action:)`**
35
- The starting point of the query/relation. Defaults to `#all`
36
- * **`#display_schema(action:)`**
37
- The display schema definition for the `#index` and `#show` pages
38
- * **`#form_schema(action:)`**
39
- The form schema definition for the `#new` and `#edit` pages
40
- * **`#permitted_params(params, action:)`**
41
- The strong parameters definition
@@ -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
@@ -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