super 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/super/application.css +5 -17
  3. data/app/controllers/super/application_controller.rb +9 -10
  4. data/app/views/super/application/_display_index.html.erb +1 -1
  5. data/app/views/super/application/_filter_type_select.html.erb +1 -1
  6. data/app/views/super/application/_filter_type_text.html.erb +1 -1
  7. data/app/views/super/application/_filter_type_timestamp.html.erb +3 -3
  8. data/app/views/super/application/_form_field.html.erb +5 -0
  9. data/app/views/super/feather/README.md +0 -1
  10. data/frontend/super-frontend/dist/application.css +5 -17
  11. data/lib/generators/super/install/install_generator.rb +0 -16
  12. data/lib/super.rb +2 -0
  13. data/lib/super/action_inquirer.rb +11 -3
  14. data/lib/super/badge.rb +61 -0
  15. data/lib/super/controls/optional.rb +9 -0
  16. data/lib/super/controls/steps.rb +27 -0
  17. data/lib/super/display/schema_types.rb +49 -0
  18. data/lib/super/form/builder.rb +27 -39
  19. data/lib/super/form/guesser.rb +3 -3
  20. data/lib/super/form/schema_types.rb +66 -13
  21. data/lib/super/pagination.rb +0 -42
  22. data/lib/super/reset.rb +17 -0
  23. data/lib/super/useful/builder.rb +4 -4
  24. data/lib/super/version.rb +1 -1
  25. metadata +5 -10
  26. data/app/views/super/application/_form_field_checkbox.html.erb +0 -1
  27. data/app/views/super/application/_form_field_flatpickr_date.html.erb +0 -8
  28. data/app/views/super/application/_form_field_flatpickr_datetime.html.erb +0 -8
  29. data/app/views/super/application/_form_field_flatpickr_time.html.erb +0 -8
  30. data/app/views/super/application/_form_field_rich_text_area.html.erb +0 -1
  31. data/app/views/super/application/_form_field_text.html.erb +0 -1
  32. data/app/views/super/feather/_chevron_down.html +0 -1
  33. data/docs/cheat.md +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcc7c1db8a9e8c3a88b6fae8284f086f7e6ec66eb1190ce0164fa7252b4e2719
4
- data.tar.gz: e5f9ab4bb05db043f3872a64c9766183518ff4d065568bdfb9bb31bf88c43359
3
+ metadata.gz: 3b7ba12321fd5d2a62b2aa9d81a832df2741a25adb997fa393c1aaab49d29946
4
+ data.tar.gz: 2251cbc956d77d0e96b6904706c1ec3af8f3ae7edfcc8e5352268554a2296d27
5
5
  SHA512:
6
- metadata.gz: e1b0ec9d2fb309afbc2bc1ee7dc866e1f1f7515005f58d448cd3ee004170cd25a95029f94a17ae1decfb88459fa17d20cea9ca671a059922c5ccf6a53e399039
7
- data.tar.gz: d96daea67a5bc024749a5523ee66375aef9760ff40bf3be8eaf53b4c526f85d94df9ceff529f58526102eb8d3d3e0c4cf4c97433414ebb7f88a3dda8bd468a68
6
+ metadata.gz: b515c1e2f3b9b382eb8244793e453af79303618612f06536b6167aed55bc713807857fd6a0bbed30e45af84b5338b5edd53d84246bf5cc79737e3674d24074aa
7
+ data.tar.gz: 55623dc8472f95d6179073399478f452c3854f7c49791e1adf3e8371676bef3f443f3601ad3786fae36105c9988c160a14bf9c0f83d0ed7dc0dee2af3ecd030e
@@ -1475,28 +1475,16 @@ span.flatpickr-day.selected {
1475
1475
  .super-input:focus {
1476
1476
  --tw-border-opacity: 1;
1477
1477
  border-color: rgba(99, 179, 237, var(--tw-border-opacity));
1478
+ outline: 2px solid transparent;
1479
+ outline-offset: 2px;
1478
1480
  }
1479
1481
 
1480
1482
  .super-input-select {
1481
- position: relative;
1482
- }
1483
-
1484
- .super-input-select-field {
1485
1483
  padding-right: 2rem;
1486
1484
  width: 100%;
1487
- }
1488
-
1489
- .super-input-select-icon {
1490
- pointer-events: none;
1491
- position: absolute;
1492
- top: 0px;
1493
- bottom: 0px;
1494
- right: 0px;
1495
- display: flex;
1496
- align-items: center;
1497
- padding-left: 0.5rem;
1498
- padding-right: 0.5rem;
1499
- fill: currentColor;
1485
+ background-repeat: no-repeat;
1486
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%232b6cb0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E %3Cpolyline points='6 9 12 15 18 9'/%3E %3C/svg%3E");
1487
+ background-position: right 0.5rem center;
1500
1488
  }
1501
1489
 
1502
1490
  .super-button {
@@ -41,7 +41,8 @@ module Super
41
41
  if controls.save_record(action: action_inquirer, record: @record, params: params)
42
42
  redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
43
43
  else
44
- @form = controls.form_schema(action: action_inquirer_for("new"))
44
+ @action_inquirer = ActionInquirer.new!
45
+ @form = controls.form_schema(action: action_inquirer)
45
46
  @view = controls.new_view
46
47
  render :new, status: :bad_request
47
48
  end
@@ -61,7 +62,8 @@ module Super
61
62
  if controls.update_record(action: action_inquirer, record: @record, params: params)
62
63
  redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
63
64
  else
64
- @form = controls.form_schema(action: action_inquirer_for("edit"))
65
+ @action_inquirer = ActionInquirer.edit!
66
+ @form = controls.form_schema(action: action_inquirer)
65
67
  @view = controls.edit_view
66
68
  render :edit, status: :bad_request
67
69
  end
@@ -89,14 +91,11 @@ module Super
89
91
  end
90
92
 
91
93
  def action_inquirer
92
- @action_inquirer ||= action_inquirer_for(params[:action])
93
- end
94
-
95
- def action_inquirer_for(action)
96
- ActionInquirer.new(
97
- ActionInquirer.default_for_resources,
98
- action
99
- )
94
+ @action_inquirer ||=
95
+ ActionInquirer.new(
96
+ ActionInquirer.default_for_resources,
97
+ params[:action]
98
+ )
100
99
  end
101
100
 
102
101
  def navigation
@@ -1,5 +1,5 @@
1
1
  <div class="mt-4 overflow-x-auto">
2
- <table class="w-full border-separate relative" cellspacing="0" cellpadding="0">
2
+ <table class="w-full border-separate" cellspacing="0" cellpadding="0">
3
3
  <thead class="">
4
4
  <tr class="">
5
5
  <% display_index.each_attribute_name do |attribute_name| %>
@@ -1,7 +1,7 @@
1
1
  <div class="super-field-group" data-controller="clean-filter-param">
2
2
  <%= form.fields_for(filter_type_select.field_name, filter_type_select) do |form_field| %>
3
3
  <%= form_field.label(:q, filter_type_select.humanized_field_name) %>
4
- <div class="relative inline-block">
4
+ <div class="inline-block">
5
5
  <%= form_field.super.select(
6
6
  :op,
7
7
  filter_type_select.operators,
@@ -1,7 +1,7 @@
1
1
  <div class="super-field-group" data-controller="clean-filter-param">
2
2
  <%= form.fields_for(filter_type_text.field_name, filter_type_text) do |form_field| %>
3
3
  <%= form_field.label(:q, filter_type_text.humanized_field_name) %>
4
- <div class="relative inline-block">
4
+ <div class="inline-block">
5
5
  <%= form_field.super.select(
6
6
  :op,
7
7
  filter_type_text.operators,
@@ -1,7 +1,7 @@
1
1
  <div class="super-field-group" data-controller="clean-filter-param">
2
2
  <%= form.fields_for(filter_type_timestamp.field_name, filter_type_timestamp) do |form_field| %>
3
3
  <%= form_field.label(:q0, filter_type_timestamp.humanized_field_name) %>
4
- <div class="relative inline-block mt-2">
4
+ <div class="inline-block mt-2">
5
5
  <%= form_field.super.select(
6
6
  :op,
7
7
  filter_type_timestamp.operators,
@@ -11,13 +11,13 @@
11
11
  </div>
12
12
  <div class="flex items-center mt-3">
13
13
  <div class="flex-initial">
14
- <%= form_field.super.flatpickr_datetime(:q0, data: { clean_filter_param_target: "control candidate" }) %>
14
+ <%= form_field.super.datetime_flatpickr(:q0, data: { clean_filter_param_target: "control candidate" }) %>
15
15
  </div>
16
16
  <div class="flex-initial px-2">
17
17
  &ndash;
18
18
  </div>
19
19
  <div class="flex-initial">
20
- <%= form_field.super.flatpickr_datetime(:q1, data: { clean_filter_param_target: "control candidate" }) %>
20
+ <%= form_field.super.datetime_flatpickr(:q1, data: { clean_filter_param_target: "control candidate" }) %>
21
21
  </div>
22
22
  </div>
23
23
  <% end %>
@@ -0,0 +1,5 @@
1
+ <% if form_field.super_builder %>
2
+ <%= form.super.public_send(form_field.method_name, column, *form_field.args, **form_field.kwargs) %>
3
+ <% else %>
4
+ <%= form.public_send(form_field.method_name, column, *form_field.args, **form_field.kwargs) %>
5
+ <% end %>
@@ -2,7 +2,6 @@
2
2
 
3
3
  Vendored from: https://github.com/feathericons/feather
4
4
 
5
- * `icons/chevron-down.svg` @ `3c64e93543fab6befab54c3abd013dd8db52509e`
6
5
  * `icons/x.svg` @ `a718a7e9c39447202f703783336e8ba1c8e32405`
7
6
 
8
7
 
@@ -1475,28 +1475,16 @@ span.flatpickr-day.selected {
1475
1475
  .super-input:focus {
1476
1476
  --tw-border-opacity: 1;
1477
1477
  border-color: rgba(99, 179, 237, var(--tw-border-opacity));
1478
+ outline: 2px solid transparent;
1479
+ outline-offset: 2px;
1478
1480
  }
1479
1481
 
1480
1482
  .super-input-select {
1481
- position: relative;
1482
- }
1483
-
1484
- .super-input-select-field {
1485
1483
  padding-right: 2rem;
1486
1484
  width: 100%;
1487
- }
1488
-
1489
- .super-input-select-icon {
1490
- pointer-events: none;
1491
- position: absolute;
1492
- top: 0px;
1493
- bottom: 0px;
1494
- right: 0px;
1495
- display: flex;
1496
- align-items: center;
1497
- padding-left: 0.5rem;
1498
- padding-right: 0.5rem;
1499
- fill: currentColor;
1485
+ background-repeat: no-repeat;
1486
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%232b6cb0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E %3Cpolyline points='6 9 12 15 18 9'/%3E %3C/svg%3E");
1487
+ background-position: right 0.5rem center;
1500
1488
  }
1501
1489
 
1502
1490
  .super-button {
@@ -36,22 +36,6 @@ module Super
36
36
  create_file("app/controllers/#{controller_namespace}/.keep", "")
37
37
  end
38
38
 
39
- def copy_cheatsheet
40
- super_path = Pathname.new(Gem.loaded_specs["super"].full_gem_path).expand_path
41
- super_cheat_path = super_path.join("docs", "cheat.md")
42
-
43
- path =
44
- if options["controller_namespace"].present?
45
- "app/controllers/#{controller_namespace}/README.md"
46
- else
47
- "app/controllers/README.md"
48
- end
49
-
50
- create_file(path) do
51
- super_cheat_path.read.sub(%r{<!--.*?-->}m, "").strip + "\n"
52
- end
53
- end
54
-
55
39
  def setup_sprockets4_manifest
56
40
  append_to_file "app/assets/config/manifest.js", "//= link super_manifest.js\n"
57
41
  end
data/lib/super.rb CHANGED
@@ -10,6 +10,7 @@ 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"
@@ -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"
@@ -19,12 +19,20 @@ module Super
19
19
  #
20
20
  def self.default_for_resources
21
21
  {
22
- read: %i[index show new edit],
23
- write: %i[create update destroy],
24
- delete: %i[destroy]
22
+ "read" => %w[index show new edit],
23
+ "write" => %w[create update destroy],
24
+ "delete" => %w[destroy],
25
25
  }
26
26
  end
27
27
 
28
+ def self.index!; new(default_for_resources, "index"); end
29
+ def self.show!; new(default_for_resources, "show"); end
30
+ def self.new!; new(default_for_resources, "new"); end
31
+ def self.edit!; new(default_for_resources, "edit"); end
32
+ def self.create!; new(default_for_resources, "create"); end
33
+ def self.update!; new(default_for_resources, "update"); end
34
+ def self.destroy!; new(default_for_resources, "destroy"); end
35
+
28
36
  def initialize(categories_and_their_actions, action)
29
37
  @categories = categories_and_their_actions.keys.map(&:to_s)
30
38
  @actions = categories_and_their_actions.values.flatten.uniq.map(&:to_s)
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ class Badge
5
+ STYLES = {
6
+ light: "bg-gray-100 text-black",
7
+ dark: "bg-gray-900 text-white",
8
+ red: "bg-red-700 text-white",
9
+ orange: "bg-orange-400 text-black",
10
+ yellow: "bg-yellow-400 text-black",
11
+ green: "bg-green-700 text-white",
12
+ blue: "bg-blue-700 text-white",
13
+ purple: "bg-purple-800 text-white",
14
+ }
15
+
16
+ def initialize(text, styles: nil)
17
+ @text = text
18
+ @requested_styles = Array(styles.presence).flatten
19
+ end
20
+
21
+ def styles
22
+ return @styles if instance_variable_defined?(:@styles)
23
+ @styles =
24
+ if requested_styles.delete(:reset)
25
+ []
26
+ else
27
+ COMMON_STYLES
28
+ end
29
+
30
+ if requested_styles.empty?
31
+ @styles += [STYLES[:light]]
32
+ else
33
+ requested_styles.each do |style|
34
+ @styles +=
35
+ if STYLES.key?(style)
36
+ [STYLES[style]]
37
+ else
38
+ [style]
39
+ end
40
+ end
41
+ end
42
+
43
+ @styles
44
+ end
45
+
46
+ def to_s
47
+ ActionController::Base.helpers.content_tag(
48
+ :span,
49
+ @text,
50
+ class: styles.join(" ")
51
+ )
52
+ end
53
+
54
+ private
55
+
56
+ COMMON_STYLES = %w[rounded px-2 py-1 text-xs leading-none font-bold]
57
+ private_constant :COMMON_STYLES
58
+
59
+ attr_reader :requested_styles
60
+ end
61
+ end
@@ -108,6 +108,15 @@ module Super
108
108
  def default_sort
109
109
  { id: :desc }
110
110
  end
111
+
112
+ # Specifies how many records to show per page
113
+ #
114
+ # @param action [ActionInquirer]
115
+ # @param query_params [Hash]
116
+ # @return [ActiveRecord::Relation]
117
+ def records_per_page(action:, query_params:)
118
+ Super.configuration.index_records_per_page
119
+ end
111
120
  end
112
121
  end
113
122
  end
@@ -101,6 +101,33 @@ module Super
101
101
  )
102
102
  end
103
103
  end
104
+
105
+ # Sets up pagination
106
+ #
107
+ # @param action [ActionInquirer]
108
+ # @param records [ActiveRecord::Relation]
109
+ # @param query_params [Hash]
110
+ # @return [Pagination]
111
+ def initialize_pagination(action:, records:, query_params:)
112
+ Pagination.new(
113
+ total_count: records.size,
114
+ limit: records_per_page(action: action, query_params: query_params),
115
+ query_params: query_params,
116
+ page_query_param: :page
117
+ )
118
+ end
119
+
120
+ # Paginates
121
+ #
122
+ # @param action [ActionInquirer]
123
+ # @param records [ActiveRecord::Relation]
124
+ # @param pagination [Pagination]
125
+ # @return [ActiveRecord::Relation]
126
+ def paginate_records(action:, records:, pagination:)
127
+ records
128
+ .limit(pagination.limit)
129
+ .offset(pagination.offset)
130
+ end
104
131
  end
105
132
  end
106
133
  end
@@ -61,6 +61,47 @@ module Super
61
61
  end
62
62
  end
63
63
 
64
+ class Badge
65
+ extend Useful::Builder
66
+
67
+ def initialize(builder)
68
+ @builder = builder
69
+ @whens = {}
70
+ format_for_lookup(&:itself)
71
+ format_for_display(&:itself)
72
+ end
73
+
74
+ builder_with_block def when(*patterns, &block)
75
+ patterns.each do |pattern|
76
+ @whens[pattern] = block
77
+ end
78
+ end
79
+
80
+ builder_with_block def else(&block)
81
+ @else = block
82
+ end
83
+
84
+ builder_with_block def format_for_lookup(&block)
85
+ @format_for_lookup = block
86
+ end
87
+
88
+ builder_with_block def format_for_display(&block)
89
+ @format_for_display = block
90
+ end
91
+
92
+ def build
93
+ @builder.transform do |value|
94
+ lookup_value = @format_for_lookup.call(value)
95
+ block = @whens[lookup_value] || @else
96
+ Super::Badge.new(
97
+ @format_for_display.call(value),
98
+ styles: block&.call
99
+ )
100
+ end
101
+ @builder.build
102
+ end
103
+ end
104
+
64
105
  def initialize(fields:)
65
106
  @actions_called = false
66
107
  @fields = fields
@@ -100,6 +141,14 @@ module Super
100
141
  end
101
142
  end
102
143
 
144
+ def badge(*builder_methods)
145
+ builder_methods = %i[real ignore_nil column] if builder_methods.empty?
146
+ builder = builder_methods.each_with_object(Builder.new) do |builder_method, builder|
147
+ builder.public_send(builder_method)
148
+ end
149
+ Badge.new(builder)
150
+ end
151
+
103
152
  def actions
104
153
  @actions_called = true
105
154
  Builder.new.computed.none.transform do
@@ -58,7 +58,7 @@ module Super
58
58
  @builder.check_box(attribute, options, checked_value, unchecked_value)
59
59
  end
60
60
 
61
- def flatpickr_date(attribute, options = {})
61
+ def date_flatpickr(attribute, options = {})
62
62
  options, defaults = split_defaults(
63
63
  options,
64
64
  class: "super-input w-full",
@@ -71,11 +71,12 @@ module Super
71
71
  )
72
72
  options[:class] = join_classes(defaults[:class], options[:class])
73
73
  options[:data] = defaults[:data].deep_merge(options[:data] || {})
74
+ options[:value] = @builder.object.public_send(attribute).presence&.iso8601
74
75
 
75
76
  @builder.text_field(attribute, options)
76
77
  end
77
78
 
78
- def flatpickr_datetime(attribute, options = {})
79
+ def datetime_flatpickr(attribute, options = {})
79
80
  options, defaults = split_defaults(
80
81
  options,
81
82
  class: "super-input w-full",
@@ -90,11 +91,12 @@ module Super
90
91
  )
91
92
  options[:class] = join_classes(defaults[:class], options[:class])
92
93
  options[:data] = defaults[:data].deep_merge(options[:data] || {})
94
+ options[:value] = @builder.object.public_send(attribute).presence&.iso8601
93
95
 
94
96
  @builder.text_field(attribute, options)
95
97
  end
96
98
 
97
- def flatpickr_time(attribute, options = {})
99
+ def time_flatpickr(attribute, options = {})
98
100
  options, defaults = split_defaults(
99
101
  options,
100
102
  class: "super-input w-full",
@@ -110,6 +112,7 @@ module Super
110
112
  )
111
113
  options[:class] = join_classes(defaults[:class], options[:class])
112
114
  options[:data] = defaults[:data].deep_merge(options[:data] || {})
115
+ options[:value] = @builder.object.public_send(attribute).presence&.strftime("%H:%M:%S")
113
116
 
114
117
  @builder.text_field(attribute, options)
115
118
  end
@@ -131,25 +134,10 @@ module Super
131
134
  def select(attribute, choices, options = {}, html_options = {}, &block)
132
135
  options, defaults = split_defaults(options, include_blank: true)
133
136
  options = defaults.merge(options)
134
- html_options, html_defaults = split_defaults(html_options, class: "super-input super-input-select-field")
137
+ html_options, html_defaults = split_defaults(html_options, class: "super-input super-input-select")
135
138
  html_options[:class] = join_classes(html_defaults[:class], html_options[:class])
136
139
 
137
- parts = [
138
- %(<div class="super-input-select">).html_safe,
139
- @builder.select(attribute, choices, options, html_options, &block),
140
- <<~HTML.html_safe,
141
- <div class="super-input-select-icon text-blue-700">
142
- <span class="h-4 w-4">
143
- HTML
144
- @template.render("super/feather/chevron_down"),
145
- <<~HTML.html_safe,
146
- </span>
147
- </div>
148
- HTML
149
- %(</div>).html_safe,
150
- ]
151
-
152
- @template.safe_join(parts)
140
+ @builder.select(attribute, choices, options, html_options, &block)
153
141
  end
154
142
 
155
143
  def submit(value = nil, options = {})
@@ -171,60 +159,60 @@ module Super
171
159
  @template.content_tag(:div, class: "super-field-group", &block)
172
160
  end
173
161
 
174
- def check_box!(attribute, checked_value = "1", unchecked_value = "0", label: {}, field: {}, show_errors: true)
162
+ def check_box!(attribute, checked_value: "1", unchecked_value: "0", label_text: nil, label: {}, field: {}, show_errors: true)
175
163
  label[:super] ||= {}
176
164
  label[:super] = { class: "select-none ml-1" }.merge(label[:super])
177
165
  container do
178
166
  compact_join([
179
167
  "<div>".html_safe,
180
168
  public_send(:check_box, attribute, field, checked_value, unchecked_value),
181
- public_send(:label, attribute, nil, label),
169
+ public_send(:label, attribute, label_text, label),
182
170
  "</div>".html_safe,
183
171
  show_errors && inline_errors(attribute),
184
172
  ])
185
173
  end
186
174
  end
187
175
 
188
- def flatpickr_date!(attribute, label: {}, field: {}, show_errors: true)
176
+ def date_flatpickr!(attribute, label_text: nil, label: {}, field: {}, show_errors: true)
189
177
  container do
190
178
  compact_join([
191
- public_send(:label, attribute, label),
179
+ public_send(:label, attribute, label_text, label),
192
180
  %(<div class="mt-1">).html_safe,
193
- public_send(:flatpickr_date, attribute, field),
181
+ public_send(:date_flatpickr, attribute, field),
194
182
  show_errors && inline_errors(attribute),
195
183
  %(</div>).html_safe,
196
184
  ])
197
185
  end
198
186
  end
199
187
 
200
- def flatpickr_datetime!(attribute, label: {}, field: {}, show_errors: true)
188
+ def datetime_flatpickr!(attribute, label_text: nil, label: {}, field: {}, show_errors: true)
201
189
  container do
202
190
  compact_join([
203
- public_send(:label, attribute, label),
191
+ public_send(:label, attribute, label_text, label),
204
192
  %(<div class="mt-1">).html_safe,
205
- public_send(:flatpickr_datetime, attribute, field),
193
+ public_send(:datetime_flatpickr, attribute, field),
206
194
  show_errors && inline_errors(attribute),
207
195
  %(</div>).html_safe,
208
196
  ])
209
197
  end
210
198
  end
211
199
 
212
- def flatpickr_time!(attribute, label: {}, field: {}, show_errors: true)
200
+ def time_flatpickr!(attribute, label_text: nil, label: {}, field: {}, show_errors: true)
213
201
  container do
214
202
  compact_join([
215
- public_send(:label, attribute, label),
203
+ public_send(:label, attribute, label_text, label),
216
204
  %(<div class="mt-1">).html_safe,
217
- public_send(:flatpickr_time, attribute, field),
205
+ public_send(:time_flatpickr, attribute, field),
218
206
  show_errors && inline_errors(attribute),
219
207
  %(</div>).html_safe,
220
208
  ])
221
209
  end
222
210
  end
223
211
 
224
- def password_field!(attribute, label: {}, field: {}, show_errors: true)
212
+ def password_field!(attribute, label_text: nil, label: {}, field: {}, show_errors: true)
225
213
  container do
226
214
  compact_join([
227
- public_send(:label, attribute, label),
215
+ public_send(:label, attribute, label_text, label),
228
216
  %(<div class="mt-1">).html_safe,
229
217
  public_send(:password_field, attribute, field),
230
218
  show_errors && inline_errors(attribute),
@@ -233,10 +221,10 @@ module Super
233
221
  end
234
222
  end
235
223
 
236
- def rich_text_area!(attribute, label: {}, field: {}, show_errors: true)
224
+ def rich_text_area!(attribute, label_text: nil, label: {}, field: {}, show_errors: true)
237
225
  container do
238
226
  compact_join([
239
- public_send(:label, attribute, label),
227
+ public_send(:label, attribute, label_text, label),
240
228
  %(<div class="mt-1">).html_safe,
241
229
  public_send(:rich_text_area, attribute, field),
242
230
  show_errors && inline_errors(attribute),
@@ -245,10 +233,10 @@ module Super
245
233
  end
246
234
  end
247
235
 
248
- def select!(attribute, collection, label: {}, field: {}, show_errors: true)
236
+ def select!(attribute, collection, label_text: nil, label: {}, field: {}, show_errors: true)
249
237
  container do
250
238
  compact_join([
251
- public_send(:label, attribute, label),
239
+ public_send(:label, attribute, label_text, label),
252
240
  %(<div class="mt-1">).html_safe,
253
241
  public_send(:select, attribute, collection, field),
254
242
  show_errors && inline_errors(attribute),
@@ -257,10 +245,10 @@ module Super
257
245
  end
258
246
  end
259
247
 
260
- def text_field!(attribute, label: {}, field: {}, show_errors: true)
248
+ def text_field!(attribute, label_text: nil, label: {}, field: {}, show_errors: true)
261
249
  container do
262
250
  compact_join([
263
- public_send(:label, attribute, label),
251
+ public_send(:label, attribute, label_text, label),
264
252
  %(<div class="mt-1">).html_safe,
265
253
  public_send(:text_field, attribute, field),
266
254
  show_errors && inline_errors(attribute),
@@ -24,11 +24,11 @@ module Super
24
24
  def attribute_type_for(attribute_name)
25
25
  case @model.type_for_attribute(attribute_name).type
26
26
  when :datetime
27
- @type.flatpickr_datetime
27
+ @type.datetime_flatpickr
28
28
  when :time
29
- @type.flatpickr_time
29
+ @type.time_flatpickr
30
30
  when :date
31
- @type.flatpickr_date
31
+ @type.date_flatpickr
32
32
  else
33
33
  @type.string
34
34
  end
@@ -3,6 +3,38 @@
3
3
  module Super
4
4
  class Form
5
5
  class SchemaTypes
6
+ class Direct
7
+ def initialize(super_builder:, method_name:, args:, kwargs:)
8
+ @super_builder = super_builder
9
+ @method_name = method_name
10
+ @args = args
11
+ @kwargs = kwargs
12
+ end
13
+
14
+ attr_reader :super_builder
15
+ attr_reader :method_name
16
+ attr_reader :args
17
+ attr_reader :kwargs
18
+
19
+ def nested_fields
20
+ {}
21
+ end
22
+
23
+ def to_partial_path
24
+ "form_field"
25
+ end
26
+
27
+ def ==(other)
28
+ return false if other.class != self.class
29
+ return false if other.super_builder != super_builder
30
+ return false if other.method_name != method_name
31
+ return false if other.args != args
32
+ return false if other.kwargs != kwargs
33
+
34
+ true
35
+ end
36
+ end
37
+
6
38
  class Generic
7
39
  def initialize(partial_path:, extras:, nested:)
8
40
  @partial_path = partial_path
@@ -69,36 +101,57 @@ module Super
69
101
  Generic.new(partial_path: partial_path, extras: extras, nested: {})
70
102
  end
71
103
 
104
+ def direct(method_name, *args, super_builder: true, **kwargs)
105
+ Direct.new(super_builder: super_builder, method_name: method_name, args: args, kwargs: kwargs)
106
+ end
107
+
72
108
  def select(**extras)
73
109
  Generic.new(partial_path: "form_field_select", extras: extras, nested: {})
74
110
  end
75
111
 
76
- def string(**extras)
77
- Generic.new(partial_path: "form_field_text", extras: extras, nested: {})
112
+ def text_field(*args, **kwargs)
113
+ Direct.new(super_builder: true, method_name: :text_field!, args: args, kwargs: kwargs)
114
+ end
115
+
116
+ alias string text_field
117
+ alias text text_field
118
+
119
+ def rich_text_area(*args, **kwargs)
120
+ Direct.new(super_builder: true, method_name: :rich_text_area!, args: args, kwargs: kwargs)
121
+ end
122
+
123
+ def check_box(*args, **kwargs)
124
+ Direct.new(super_builder: true, method_name: :check_box!, args: args, kwargs: kwargs)
78
125
  end
79
126
 
80
- alias text string
127
+ alias checkbox check_box
81
128
 
82
- def rich_text_area(**extras)
83
- Generic.new(partial_path: "form_field_rich_text_area", extras: extras, nested: {})
129
+ def date_flatpickr(*args, **kwargs)
130
+ Direct.new(super_builder: true, method_name: :date_flatpickr!, args: args, kwargs: kwargs)
84
131
  end
85
132
 
86
- def checkbox(**extras)
87
- Generic.new(partial_path: "form_field_checkbox", extras: extras, nested: {})
133
+ alias flatpickr_date date_flatpickr
134
+
135
+ def datetime_flatpickr(*args, **kwargs)
136
+ Direct.new(super_builder: true, method_name: :datetime_flatpickr!, args: args, kwargs: kwargs)
88
137
  end
89
138
 
90
- def flatpickr_date(**extras)
91
- Generic.new(partial_path: "form_field_flatpickr_date", extras: extras, nested: {})
139
+ alias flatpickr_datetime datetime_flatpickr
140
+
141
+ def hidden_field(*args, **kwargs)
142
+ Direct.new(super_builder: false, method_name: :hidden_field, args: args, kwargs: kwargs)
92
143
  end
93
144
 
94
- def flatpickr_datetime(**extras)
95
- Generic.new(partial_path: "form_field_flatpickr_datetime", extras: extras, nested: {})
145
+ def password_field(*args, **kwargs)
146
+ Direct.new(super_builder: true, method_name: :password_field!, args: args, kwargs: kwargs)
96
147
  end
97
148
 
98
- def flatpickr_time(**extras)
99
- Generic.new(partial_path: "form_field_flatpickr_time", extras: extras, nested: {})
149
+ def time_flatpickr(*args, **kwargs)
150
+ Direct.new(super_builder: true, method_name: :time_flatpickr!, args: args, kwargs: kwargs)
100
151
  end
101
152
 
153
+ alias flatpickr_time time_flatpickr
154
+
102
155
  def has_many(reader, **extras)
103
156
  nested = @fields.nested do
104
157
  yield
@@ -82,46 +82,4 @@ module Super
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,17 @@
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
+ end
16
+ end
17
+ 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.0.15"
5
5
  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.0.15
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-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -239,14 +239,9 @@ files:
239
239
  - app/views/super/application/_filter_type_timestamp.html.erb
240
240
  - app/views/super/application/_flash.html.erb
241
241
  - app/views/super/application/_form.html.erb
242
+ - app/views/super/application/_form_field.html.erb
242
243
  - 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
244
  - app/views/super/application/_form_field_select.html.erb
249
- - app/views/super/application/_form_field_text.html.erb
250
245
  - app/views/super/application/_form_fieldset.html.erb
251
246
  - app/views/super/application/_form_has_many.html.erb
252
247
  - app/views/super/application/_form_has_one.html.erb
@@ -263,11 +258,9 @@ files:
263
258
  - app/views/super/application/nothing.html.erb
264
259
  - app/views/super/application/show.html.erb
265
260
  - app/views/super/feather/README.md
266
- - app/views/super/feather/_chevron_down.html
267
261
  - app/views/super/feather/_x.html
268
262
  - config/locales/en.yml
269
263
  - config/routes.rb
270
- - docs/cheat.md
271
264
  - frontend/super-frontend/dist/application.css
272
265
  - frontend/super-frontend/dist/application.js
273
266
  - lib/generators/super/action_text/USAGE
@@ -287,6 +280,7 @@ files:
287
280
  - lib/super.rb
288
281
  - lib/super/action_inquirer.rb
289
282
  - lib/super/assets.rb
283
+ - lib/super/badge.rb
290
284
  - lib/super/cheat.rb
291
285
  - lib/super/client_error.rb
292
286
  - lib/super/compatibility.rb
@@ -321,6 +315,7 @@ files:
321
315
  - lib/super/partial/resolving.rb
322
316
  - lib/super/plugin.rb
323
317
  - lib/super/query/form_object.rb
318
+ - lib/super/reset.rb
324
319
  - lib/super/schema.rb
325
320
  - lib/super/schema/common.rb
326
321
  - lib/super/schema/guesser.rb
@@ -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.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