super 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -6
  3. data/app/controllers/super/application_controller.rb +6 -3
  4. data/app/views/super/application/_filter.html.erb +14 -0
  5. data/app/views/super/application/_filter_type_select.html.erb +31 -0
  6. data/app/views/super/application/_filter_type_text.html.erb +22 -0
  7. data/app/views/super/application/_filter_type_timestamp.html.erb +35 -0
  8. data/app/views/super/application/_super_layout.html.erb +5 -5
  9. data/app/views/super/application/_super_pagination.html.erb +16 -0
  10. data/app/views/super/application/_super_panel.html.erb +1 -1
  11. data/app/views/super/application/_super_schema_display_index.html.erb +8 -23
  12. data/app/views/super/application/_super_schema_display_show.html.erb +1 -1
  13. data/app/views/super/application/edit.html.erb +1 -6
  14. data/app/views/super/application/index.html.erb +1 -6
  15. data/app/views/super/application/new.html.erb +1 -6
  16. data/app/views/super/application/show.html.erb +1 -6
  17. data/lib/super.rb +8 -2
  18. data/lib/super/compatibility.rb +13 -1
  19. data/lib/super/configuration.rb +7 -0
  20. data/lib/super/controls/optional.rb +0 -11
  21. data/lib/super/controls/steps.rb +44 -31
  22. data/lib/super/display/schema_types.rb +31 -1
  23. data/lib/super/engine.rb +6 -0
  24. data/lib/super/filter.rb +137 -0
  25. data/lib/super/filter/operator.rb +103 -0
  26. data/lib/super/filter/schema_types.rb +118 -0
  27. data/lib/super/pagination.rb +61 -0
  28. data/lib/super/partial.rb +12 -0
  29. data/lib/super/plugin.rb +34 -63
  30. data/lib/super/schema.rb +1 -0
  31. data/lib/super/version.rb +1 -1
  32. data/lib/super/view_helper.rb +1 -1
  33. metadata +25 -4
  34. data/app/helpers/super/application_helper.rb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfd2be7e756bd5000efcf53557039621d67df3705df3a35c5806256c66ee4e96
4
- data.tar.gz: eccb74df362766a46c1fc951ca327168a4febb06cacd11f3297201e898576053
3
+ metadata.gz: a8e7ba2e6b5845517d94684e487bdfed0779dcade517e3e3e89bff55fee6f258
4
+ data.tar.gz: 62e2a405ed8d99a95de077babfdc9eb3b654d651b1887e8776d1dba609058f8e
5
5
  SHA512:
6
- metadata.gz: 85ab056714996f2030f786e4f9498761b41374614078a7fd27155a1200cce25b583361d5b44f02c7f1bf88b6792e83ea40c9985bd6f5c51f3e117b0950732b7c
7
- data.tar.gz: 5e7dc0e1216c67fb5a24cb392dc5d5f1193dbc4ac8acafc39afadd42809ba7cd15c813b729fef9e3026a87cdfaf69eadfe3ef670b9099b62d75fde1c8d14c058
6
+ metadata.gz: 76bd34e08d34ea8797f0ed197b062a6be056247204a5f6badfea5a82f119c196d37b04a65ad2b1f25535885c013a1ebed7175399090078888cc528b997b57371
7
+ data.tar.gz: 5933d518932ea142b70aa5ac3c844d497a5bea951ee7bd72ad1a128fabc911212e2c09b63857900b2eec881a97f28aff5682b6e5c9457a25f2d0dba431887900
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Super
2
2
 
3
3
  Super is an admin framework for Ruby on Rails applications. Super helps you make
4
- powerful admin pages quickly.
4
+ powerful admin pages quickly so that you can concentrate on the parts of your
5
+ app that make it great.
5
6
 
6
7
  Super strives to let engineers build great admin pages quickly and easily by:
7
8
 
@@ -57,16 +58,21 @@ as ActiveAdmin, but it's nice and feels like developing a normal Rails app.
57
58
  There's no DSL.
58
59
 
59
60
 
60
- ## Professional edition
61
+ ## Paid editions
61
62
 
62
- Super Professional is a paid add-on that provides additional benefits:
63
+ If you have additional requirements, there are some paid editions to consider:
64
+
65
+ **Super Premium** provides:
63
66
 
64
- * Productivity improvements and quality of life features for admins
65
67
  * Priority email support
66
- * Supporting long term development of Super
68
+ * Ensuring long term development of Super
69
+
70
+ **Super Professional** provides everything in Premium and:
71
+
72
+ * Productivity improvements and quality of life features for admins
67
73
  * An LGPL exemption
68
74
 
69
- It isn't available yet. Contact me if you're interested, or subscribe to the
75
+ They aren't available yet. Contact me if you're interested, or subscribe to the
70
76
  [newsletter][newsletter] to be notified of its availability and for brief,
71
77
  occasional updates to Super.
72
78
 
@@ -2,7 +2,6 @@ module Super
2
2
  # Provides a default implementation for each of the resourceful actions
3
3
  class ApplicationController < ActionController::Base
4
4
  include ClientError::Handling
5
- include Pluggable.new(:super_application_controller)
6
5
 
7
6
  helper_method :action_inquirer
8
7
  helper_method :controls
@@ -10,21 +9,22 @@ module Super
10
9
  # Displays a list of records to the user
11
10
  def index
12
11
  @records = controls.load_records(action: action_inquirer, params: params)
13
- @pagination = controls.initialize_pagination(action: action_inquirer, records: @records, query_params: request.GET)
14
- @records = controls.paginate_records(action: action_inquirer, records: @records, pagination: @pagination)
15
12
  @display = controls.display_schema(action: action_inquirer)
13
+ @view = controls.build_index_view
16
14
  end
17
15
 
18
16
  # Displays a specific record to the user
19
17
  def show
20
18
  @record = controls.load_record(action: action_inquirer, params: params)
21
19
  @display = controls.display_schema(action: action_inquirer)
20
+ @view = controls.build_show_view
22
21
  end
23
22
 
24
23
  # Displays a form to allow the user to create a new record
25
24
  def new
26
25
  @record = controls.build_record(action: action_inquirer)
27
26
  @form = controls.form_schema(action: action_inquirer)
27
+ @view = controls.build_new_view
28
28
  end
29
29
 
30
30
  # Creates a record, or shows the validation errors
@@ -35,6 +35,7 @@ module Super
35
35
  redirect_to polymorphic_path(Super.configuration.path_parts(@record))
36
36
  else
37
37
  @form = controls.form_schema(action: action_inquirer_for("new"))
38
+ @view = controls.build_new_view
38
39
  render :new, status: :bad_request
39
40
  end
40
41
  end
@@ -43,6 +44,7 @@ module Super
43
44
  def edit
44
45
  @record = controls.load_record(action: action_inquirer, params: params)
45
46
  @form = controls.form_schema(action: action_inquirer)
47
+ @view = controls.build_edit_view
46
48
  end
47
49
 
48
50
  # Updates a record, or shows validation errors
@@ -53,6 +55,7 @@ module Super
53
55
  redirect_to polymorphic_path(Super.configuration.path_parts(@record))
54
56
  else
55
57
  @form = controls.form_schema(action: action_inquirer_for("edit"))
58
+ @view = controls.build_edit_view
56
59
  render :edit, status: :bad_request
57
60
  end
58
61
  end
@@ -0,0 +1,14 @@
1
+ <%= render(Super::Panel.new) do %>
2
+ <h1 class="text-xl">Filters</h1>
3
+ <%= form_for(filter, url: filter.url, method: :get, as: :q, html: { class: "mt-4" }) do |form| %>
4
+ <% filter.each_field do |filter_field| %>
5
+ <div class="mt-4">
6
+ <%= render(filter_field, form: form) %>
7
+ </div>
8
+ <% end %>
9
+
10
+ <div>
11
+ <%= form.submit "Filter", class: "super-button super-button--border-gray mt-6" %>
12
+ </div>
13
+ <% end %>
14
+ <% end %>
@@ -0,0 +1,31 @@
1
+ <div class="super-field-group">
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="super-input-select inline-block">
5
+ <%= form_field.select(
6
+ :op,
7
+ filter_type_select.operators,
8
+ {},
9
+ { class: "super-input super-input-select-field" }
10
+ ) %>
11
+ <div class="super-input-select-icon text-gray-700">
12
+ <span class="h-4 w-4">
13
+ <%= render "super/feather/chevron_down" %>
14
+ </span>
15
+ </div>
16
+ </div>
17
+ <div class="super-input-select mt-3">
18
+ <%= form_field.select(
19
+ :q,
20
+ filter_type_select.field_type.collection,
21
+ { include_blank: true },
22
+ { class: "super-input super-input-select-field" }
23
+ ) %>
24
+ <div class="super-input-select-icon text-gray-700">
25
+ <span class="h-4 w-4">
26
+ <%= render "super/feather/chevron_down" %>
27
+ </span>
28
+ </div>
29
+ </div>
30
+ <% end %>
31
+ </div>
@@ -0,0 +1,22 @@
1
+ <div class="super-field-group">
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.select(
6
+ :op,
7
+ filter_type_text.operators,
8
+ {},
9
+ { class: "super-input super-input-select-field" }
10
+ ) %>
11
+ <div class="super-input-select-icon text-gray-700">
12
+ <span class="h-4 w-4">
13
+ <%= render "super/feather/chevron_down" %>
14
+ </span>
15
+ </div>
16
+ </div>
17
+ <%= form_field.text_field(
18
+ :q,
19
+ class: "super-input w-full mt-3"
20
+ ) %>
21
+ <% end %>
22
+ </div>
@@ -0,0 +1,35 @@
1
+ <div class="super-field-group">
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.select(
6
+ :op,
7
+ filter_type_timestamp.operators,
8
+ {},
9
+ { class: "super-input super-input-select-field" }
10
+ ) %>
11
+ <div class="super-input-select-icon text-gray-700">
12
+ <span class="h-4 w-4">
13
+ <%= render "super/feather/chevron_down" %>
14
+ </span>
15
+ </div>
16
+ </div>
17
+ <div class="flex items-center mt-3">
18
+ <div class="flex-initial">
19
+ <%= form_field.text_field(
20
+ :q0,
21
+ class: "super-input w-full"
22
+ ) %>
23
+ </div>
24
+ <div class="flex-initial px-2">
25
+ &ndash;
26
+ </div>
27
+ <div class="flex-initial">
28
+ <%= form_field.text_field(
29
+ :q1,
30
+ class: "super-input w-full"
31
+ ) %>
32
+ </div>
33
+ </div>
34
+ <% end %>
35
+ </div>
@@ -1,29 +1,29 @@
1
1
  <% super_layout.resolve(self) %>
2
2
 
3
3
  <% super_layout.resolved_headers.each do |partial| %>
4
- <%= super_render_partialish(partial) %>
4
+ <%= Super::Partial.render(partial, template: self) %>
5
5
  <% end %>
6
6
 
7
7
  <% if super_layout.resolved_asides.empty? %>
8
8
  <% super_layout.resolved_mains.each do |partial| %>
9
- <%= super_render_partialish(partial) %>
9
+ <%= Super::Partial.render(partial, template: self) %>
10
10
  <% end %>
11
11
  <% else %>
12
12
  <div class="clearfix -mx-2">
13
13
  <div class="md:float-left md:w-9/12 px-2">
14
14
  <% super_layout.resolved_mains.each do |partial| %>
15
- <%= super_render_partialish(partial) %>
15
+ <%= Super::Partial.render(partial, template: self) %>
16
16
  <% end %>
17
17
  </div>
18
18
 
19
19
  <div class="md:float-right md:w-3/12 px-2">
20
20
  <% super_layout.resolved_asides.each do |partial| %>
21
- <%= super_render_partialish(partial) %>
21
+ <%= Super::Partial.render(partial, template: self) %>
22
22
  <% end %>
23
23
  </div>
24
24
  </div>
25
25
  <% end %>
26
26
 
27
27
  <% super_layout.resolved_footers.each do |partial| %>
28
- <%= super_render_partialish(partial) %>
28
+ <%= Super::Partial.render(partial, template: self) %>
29
29
  <% end %>
@@ -0,0 +1,16 @@
1
+ <% if @pagination.necessary? %>
2
+ <div class="flex justify-end mr-2">
3
+ <div class="mt-4">
4
+ <% @pagination.each do |page_query_params, is_current_page, display| %>
5
+ <%= link_to(
6
+ display,
7
+ polymorphic_path(
8
+ Super.configuration.path_parts(controls.model),
9
+ page_query_params
10
+ ),
11
+ class: "inline-block ml-2 text-lg #{is_current_page ? " text-gray-900" : ""}"
12
+ ) %>
13
+ <% end %>
14
+ </div>
15
+ </div>
16
+ <% end %>
@@ -1,7 +1,7 @@
1
1
  <% if super_panel.resolve(self, block_given? ? Proc.new : nil).resolved_parts.any? %>
2
2
  <div class="border rounded shadow border-gray-400 bg-white px-5 pt-4 pb-8 mt-6">
3
3
  <% super_panel.resolved_parts.each do |partial| %>
4
- <%= super_render_partialish(partial) %>
4
+ <%= Super::Partial.render(partial, template: self) %>
5
5
  <% end %>
6
6
  </div>
7
7
  <% end %>
@@ -1,9 +1,11 @@
1
- <div class="mt-4 overflow-x-auto">
2
- <table class="w-full border-separate" cellspacing="0" cellpadding="0">
3
- <thead>
1
+ <div class="mt-4 overflow-x-auto lg:overflow-x-visible">
2
+ <table class="w-full border-separate relative" cellspacing="0" cellpadding="0">
3
+ <thead class="">
4
4
  <tr class="">
5
5
  <% super_schema_display_index.field_keys.each do |column| %>
6
- <th class="p-2 first:pl-6 border-b border-b-2 border-gray-400 text-gray-600 text-left text-sm font-normal"><%= column.to_s.humanize %></th>
6
+ <th class="p-2 first:pl-6 border-b border-b-2 border-gray-400 text-gray-600 text-left text-sm font-normal bg-white sticky top-0 z-10">
7
+ <%= controls.model.human_attribute_name(column) %>
8
+ </th>
7
9
  <% end %>
8
10
  </tr>
9
11
  </thead>
@@ -11,8 +13,8 @@
11
13
  <% @records.each.with_index do |record, row_index| %>
12
14
  <tr id="record-pk-<%= record.id %>" class="group">
13
15
  <% super_schema_display_index.field_keys.each do |column| %>
14
- <td class="py-1 px-2 first:pl-5 border-transparent border-t border-b group-hover:bg-blue-200 first:border-l first:rounded-l-lg last:border-r last:rounded-r-lg <%= Super::ViewHelper.classes(["bg-gray-100", row_index.odd?]) %>">
15
- <%= super_format_for_display(super_schema_display_index, record, column) %>
16
+ <td class="py-1 px-2 first:pl-5 border-transparent border-t border-b group-hover:bg-blue-200 first:border-l first:rounded-l-lg last:border-r last:rounded-r-lg bg-white <%= Super::ViewHelper.classes(["bg-gray-100", row_index.odd?]) %>">
17
+ <%= super_schema_display_index.schema_type.render_field(template: self, record: record, column: column) %>
16
18
  </td>
17
19
  <% end %>
18
20
  </tr>
@@ -20,20 +22,3 @@
20
22
  </tbody>
21
23
  </table>
22
24
  </div>
23
-
24
- <% if @pagination.necessary? %>
25
- <div class="flex justify-end mr-2">
26
- <div class="mt-4">
27
- <% @pagination.each do |page_query_params, is_current_page, display| %>
28
- <%= link_to(
29
- display,
30
- polymorphic_path(
31
- Super.configuration.path_parts(controls.model),
32
- page_query_params
33
- ),
34
- class: "inline-block ml-2 text-lg #{is_current_page ? " text-gray-900" : ""}"
35
- ) %>
36
- <% end %>
37
- </div>
38
- </div>
39
- <% end %>
@@ -2,7 +2,7 @@
2
2
  <% super_schema_display_show.field_keys.each do |column| %>
3
3
  <tr>
4
4
  <th class="text-right px-4"><%= column.to_s.humanize %></th>
5
- <td><%= super_format_for_display(super_schema_display_show, @record, column) %></td>
5
+ <td><%= super_schema_display_show.schema_type.render_field(template: self, record: @record, column: column) %></td>
6
6
  </tr>
7
7
  <% end %>
8
8
  </table>
@@ -1,6 +1 @@
1
- <%= render(
2
- Super::Panel.new(
3
- Super::Partial.new("member_header"),
4
- @form
5
- )
6
- ) %>
1
+ <%= render(@view) %>
@@ -1,6 +1 @@
1
- <%= render(
2
- Super::Panel.new(
3
- Super::Partial.new("collection_header"),
4
- @display
5
- )
6
- ) %>
1
+ <%= render(@view) %>
@@ -1,6 +1 @@
1
- <%= render(
2
- Super::Panel.new(
3
- Super::Partial.new("collection_header"),
4
- @form
5
- )
6
- ) %>
1
+ <%= render(@view) %>
@@ -1,6 +1 @@
1
- <%= render(
2
- Super::Panel.new(
3
- Super::Partial.new("member_header"),
4
- @display
5
- )
6
- ) %>
1
+ <%= render(@view) %>
@@ -1,4 +1,6 @@
1
- require "active_support/concern"
1
+ require "tsort"
2
+
3
+ require "rails/engine"
2
4
 
3
5
  require "super/action_inquirer"
4
6
  require "super/assets"
@@ -7,8 +9,10 @@ require "super/compatibility"
7
9
  require "super/configuration"
8
10
  require "super/controls"
9
11
  require "super/display/schema_types"
10
- require "super/engine"
11
12
  require "super/error"
13
+ require "super/filter"
14
+ require "super/filter/operator"
15
+ require "super/filter/schema_types"
12
16
  require "super/form"
13
17
  require "super/form/schema_types"
14
18
  require "super/layout"
@@ -21,3 +25,5 @@ require "super/plugin"
21
25
  require "super/schema"
22
26
  require "super/version"
23
27
  require "super/view_helper"
28
+
29
+ require "super/engine"
@@ -2,12 +2,24 @@ module Super
2
2
  module Compatability
3
3
  module_function
4
4
 
5
- def rails_50_errable_fields(field)
5
+ # Rails 5.1 and after lets you find field errors using either a string or a
6
+ # symbol.
7
+ def errable_fields(field)
6
8
  if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 0
7
9
  [field.to_s, field.to_sym]
8
10
  else
9
11
  field
10
12
  end
11
13
  end
14
+
15
+ def sanitize_sql_like(query)
16
+ if ActiveRecord::VERSION::MAJOR == 4
17
+ ActiveRecord::Base.send(:sanitize_sql_like, query)
18
+ elsif ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR <= 1
19
+ ActiveRecord::Base.send(:sanitize_sql_like, query)
20
+ else
21
+ ActiveRecord::Base.sanitize_sql_like(query)
22
+ end
23
+ end
12
24
  end
13
25
  end
@@ -32,6 +32,9 @@ module Super
32
32
 
33
33
  public_send("#{key}=", value)
34
34
  end
35
+
36
+ Plugin::Registry.controller.use(prepend: Super::Filter::ControllerMethods)
37
+ Plugin::Registry.controller.use(prepend: Super::Pagination::ControllerMethods)
35
38
  end
36
39
 
37
40
  def configured?(attr)
@@ -95,6 +98,10 @@ module Super
95
98
  # @!attribute [rw]
96
99
  configure :asset_handler, default: -> { Super::Assets.auto }
97
100
 
101
+ def controller_plugins
102
+ Plugin::Registry.controller
103
+ end
104
+
98
105
  # @api private
99
106
  def path_parts(*parts)
100
107
  route_namespace + parts
@@ -49,17 +49,6 @@ module Super
49
49
  end
50
50
  end
51
51
  end
52
-
53
- # Specifies how many records to show per page
54
- #
55
- # @param action [ActionInquirer]
56
- # @param query_params [Hash]
57
- # @return [ActiveRecord::Relation]
58
- def records_per_page(action:, query_params:)
59
- default_for(:records_per_page, action: action, query_params: query_params) do
60
- Super.configuration.index_records_per_page
61
- end
62
- end
63
52
  end
64
53
  end
65
54
  end