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
data/lib/super/link.rb CHANGED
@@ -82,7 +82,7 @@ module Super
82
82
 
83
83
  def self.polymorphic_parts(*parts_tail)
84
84
  parts_head = Super.configuration.path.strip.gsub(%r{\A/+}, "").gsub(%r{/+\z}, "").strip.split("/")
85
- parts_head + parts_tail
85
+ parts_head.map { |part| part.is_a?(String) ? part.to_sym : part } + parts_tail
86
86
  end
87
87
 
88
88
  def initialize(text, href, **options)
@@ -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,
@@ -76,52 +76,10 @@ module Super
76
76
  module ControllerMethods
77
77
  def index
78
78
  super
79
- @pagination = controls.initialize_pagination(action: action_inquirer, records: @records, query_params: request.GET)
80
- @records = controls.paginate_records(action: action_inquirer, records: @records, pagination: @pagination)
79
+ @pagination = initialize_pagination
80
+ @records = paginate_records
81
81
  @view.mains.first.parts.push(:@pagination)
82
82
  end
83
83
  end
84
84
  end
85
-
86
- class Controls
87
- module Optional
88
- # Specifies how many records to show per page
89
- #
90
- # @param action [ActionInquirer]
91
- # @param query_params [Hash]
92
- # @return [ActiveRecord::Relation]
93
- def records_per_page(action:, query_params:)
94
- Super.configuration.index_records_per_page
95
- end
96
- end
97
-
98
- module Steps
99
- # Sets up pagination
100
- #
101
- # @param action [ActionInquirer]
102
- # @param records [ActiveRecord::Relation]
103
- # @param query_params [Hash]
104
- # @return [Pagination]
105
- def initialize_pagination(action:, records:, query_params:)
106
- Pagination.new(
107
- total_count: records.size,
108
- limit: records_per_page(action: action, query_params: query_params),
109
- query_params: query_params,
110
- page_query_param: :page
111
- )
112
- end
113
-
114
- # Paginates
115
- #
116
- # @param action [ActionInquirer]
117
- # @param records [ActiveRecord::Relation]
118
- # @param pagination [Pagination]
119
- # @return [ActiveRecord::Relation]
120
- def paginate_records(action:, records:, pagination:)
121
- records
122
- .limit(pagination.limit)
123
- .offset(pagination.offset)
124
- end
125
- end
126
- end
127
85
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ module Reset
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ undef_method :index
9
+ undef_method :show
10
+ undef_method :new
11
+ undef_method :create
12
+ undef_method :edit
13
+ undef_method :update
14
+ undef_method :destroy
15
+
16
+ Super::SubstructureController.private_instance_methods(false).each do |imethod|
17
+ next if imethod == :_layout
18
+ next if imethod == :_generate_paths_by_default
19
+ next if imethod == :navigation
20
+ next if imethod == :page_title
21
+ undef_method imethod
22
+ end
23
+ end
24
+ end
25
+ end
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
@@ -6,8 +6,8 @@ module Super
6
6
  def builder(method_name)
7
7
  alias_method("original_#{method_name}", method_name)
8
8
 
9
- define_method(method_name) do
10
- send("original_#{method_name}")
9
+ define_method(method_name) do |*args|
10
+ send("original_#{method_name}", *args)
11
11
  self
12
12
  end
13
13
  end
@@ -15,8 +15,8 @@ module Super
15
15
  def builder_with_block(method_name)
16
16
  alias_method("original_#{method_name}", method_name)
17
17
 
18
- define_method(method_name) do |&block|
19
- send("original_#{method_name}", &block)
18
+ define_method(method_name) do |*args, &block|
19
+ send("original_#{method_name}", *args, &block)
20
20
  self
21
21
  end
22
22
  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.14"
4
+ VERSION = "0.18.0"
5
5
  end
data/lib/super.rb CHANGED
@@ -10,10 +10,10 @@ require "super/useful/enum"
10
10
 
11
11
  require "super/action_inquirer"
12
12
  require "super/assets"
13
+ require "super/badge"
13
14
  require "super/client_error"
14
15
  require "super/compatibility"
15
16
  require "super/configuration"
16
- require "super/controls"
17
17
  require "super/display"
18
18
  require "super/display/guesser"
19
19
  require "super/display/schema_types"
@@ -25,6 +25,7 @@ require "super/filter/operator"
25
25
  require "super/filter/schema_types"
26
26
  require "super/form"
27
27
  require "super/form/builder"
28
+ require "super/form/field_transcript"
28
29
  require "super/form/guesser"
29
30
  require "super/form/inline_errors"
30
31
  require "super/form/schema_types"
@@ -38,6 +39,7 @@ require "super/panel"
38
39
  require "super/partial"
39
40
  require "super/plugin"
40
41
  require "super/query/form_object"
42
+ require "super/reset"
41
43
  require "super/schema"
42
44
  require "super/schema/guesser"
43
45
  require "super/sort"
@@ -4,6 +4,6 @@ namespace :super do
4
4
  task :cheat do
5
5
  require "super/cheat"
6
6
  cheat = Super::Cheat.new
7
- cheat.controls
7
+ cheat.controller
8
8
  end
9
9
  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.14
4
+ version: 0.18.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-04-23 00:00:00.000000000 Z
11
+ date: 2021-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -115,7 +115,7 @@ dependencies:
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  - !ruby/object:Gem::Dependency
118
- name: pry
118
+ name: pry-rails
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - ">="
@@ -212,6 +212,20 @@ dependencies:
212
212
  - - ">="
213
213
  - !ruby/object:Gem::Version
214
214
  version: '0'
215
+ - !ruby/object:Gem::Dependency
216
+ name: rails_anonymous_controller_testing
217
+ requirement: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ type: :development
223
+ prerelease: false
224
+ version_requirements: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ version: '0'
215
229
  description:
216
230
  email:
217
231
  - engineering@zachahn.com
@@ -226,6 +240,7 @@ files:
226
240
  - app/assets/javascripts/super/application.js
227
241
  - app/assets/stylesheets/super/application.css
228
242
  - app/controllers/super/application_controller.rb
243
+ - app/controllers/super/substructure_controller.rb
229
244
  - app/helpers/super/form_builder_helper.rb
230
245
  - app/views/layouts/super/application.html.erb
231
246
  - app/views/super/application/_collection_header.html.erb
@@ -234,19 +249,10 @@ files:
234
249
  - app/views/super/application/_display_rich_text.html.erb
235
250
  - app/views/super/application/_display_show.html.erb
236
251
  - app/views/super/application/_filter.html.erb
237
- - app/views/super/application/_filter_type_select.html.erb
238
- - app/views/super/application/_filter_type_text.html.erb
239
- - app/views/super/application/_filter_type_timestamp.html.erb
240
252
  - app/views/super/application/_flash.html.erb
241
253
  - app/views/super/application/_form.html.erb
254
+ - app/views/super/application/_form_field.html.erb
242
255
  - app/views/super/application/_form_field__destroy.html.erb
243
- - app/views/super/application/_form_field_checkbox.html.erb
244
- - app/views/super/application/_form_field_flatpickr_date.html.erb
245
- - app/views/super/application/_form_field_flatpickr_datetime.html.erb
246
- - app/views/super/application/_form_field_flatpickr_time.html.erb
247
- - app/views/super/application/_form_field_rich_text_area.html.erb
248
- - app/views/super/application/_form_field_select.html.erb
249
- - app/views/super/application/_form_field_text.html.erb
250
256
  - app/views/super/application/_form_fieldset.html.erb
251
257
  - app/views/super/application/_form_has_many.html.erb
252
258
  - app/views/super/application/_form_has_one.html.erb
@@ -255,19 +261,20 @@ files:
255
261
  - app/views/super/application/_pagination.html.erb
256
262
  - app/views/super/application/_panel.html.erb
257
263
  - app/views/super/application/_query.html.erb
264
+ - app/views/super/application/_site_footer.html.erb
265
+ - app/views/super/application/_site_header.html.erb
258
266
  - app/views/super/application/_sort.html.erb
259
267
  - app/views/super/application/_sort_expression.html.erb
260
268
  - app/views/super/application/edit.html.erb
269
+ - app/views/super/application/index.csv.erb
261
270
  - app/views/super/application/index.html.erb
262
271
  - app/views/super/application/new.html.erb
263
272
  - app/views/super/application/nothing.html.erb
264
273
  - app/views/super/application/show.html.erb
265
274
  - app/views/super/feather/README.md
266
- - app/views/super/feather/_chevron_down.html
267
275
  - app/views/super/feather/_x.html
268
276
  - config/locales/en.yml
269
277
  - config/routes.rb
270
- - docs/cheat.md
271
278
  - frontend/super-frontend/dist/application.css
272
279
  - frontend/super-frontend/dist/application.js
273
280
  - lib/generators/super/action_text/USAGE
@@ -287,14 +294,11 @@ files:
287
294
  - lib/super.rb
288
295
  - lib/super/action_inquirer.rb
289
296
  - lib/super/assets.rb
297
+ - lib/super/badge.rb
290
298
  - lib/super/cheat.rb
291
299
  - lib/super/client_error.rb
292
300
  - lib/super/compatibility.rb
293
301
  - lib/super/configuration.rb
294
- - lib/super/controls.rb
295
- - lib/super/controls/optional.rb
296
- - lib/super/controls/steps.rb
297
- - lib/super/controls/view.rb
298
302
  - lib/super/display.rb
299
303
  - lib/super/display/guesser.rb
300
304
  - lib/super/display/schema_types.rb
@@ -307,6 +311,7 @@ files:
307
311
  - lib/super/filter/schema_types.rb
308
312
  - lib/super/form.rb
309
313
  - lib/super/form/builder.rb
314
+ - lib/super/form/field_transcript.rb
310
315
  - lib/super/form/guesser.rb
311
316
  - lib/super/form/inline_errors.rb
312
317
  - lib/super/form/schema_types.rb
@@ -321,6 +326,7 @@ files:
321
326
  - lib/super/partial/resolving.rb
322
327
  - lib/super/plugin.rb
323
328
  - lib/super/query/form_object.rb
329
+ - lib/super/reset.rb
324
330
  - lib/super/schema.rb
325
331
  - lib/super/schema/common.rb
326
332
  - lib/super/schema/guesser.rb
@@ -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.flatpickr_datetime(: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.flatpickr_datetime(: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,8 +0,0 @@
1
- <%= form.super.flatpickr_date!(
2
- column,
3
- **form_field_flatpickr_date.extras.deep_merge(
4
- field: {
5
- value: form.object.public_send(column)&.iso8601,
6
- }
7
- )
8
- ) %>
@@ -1,8 +0,0 @@
1
- <%= form.super.flatpickr_datetime!(
2
- column,
3
- **form_field_flatpickr_datetime.extras.deep_merge(
4
- field: {
5
- value: form.object.public_send(column)&.iso8601,
6
- }
7
- )
8
- ) %>
@@ -1,8 +0,0 @@
1
- <%= form.super.flatpickr_time!(
2
- column,
3
- **form_field_flatpickr_time.extras.deep_merge(
4
- field: {
5
- value: form.object.public_send(column)&.strftime("%H:%M:%S"),
6
- }
7
- )
8
- ) %>
@@ -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