super 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/README.md +12 -6
- data/app/controllers/super/application_controller.rb +6 -3
- data/app/views/super/application/_filter.html.erb +14 -0
- data/app/views/super/application/_filter_type_select.html.erb +31 -0
- data/app/views/super/application/_filter_type_text.html.erb +22 -0
- data/app/views/super/application/_filter_type_timestamp.html.erb +35 -0
- data/app/views/super/application/_super_layout.html.erb +5 -5
- data/app/views/super/application/_super_pagination.html.erb +16 -0
- data/app/views/super/application/_super_panel.html.erb +1 -1
- data/app/views/super/application/_super_schema_display_index.html.erb +8 -23
- data/app/views/super/application/_super_schema_display_show.html.erb +1 -1
- data/app/views/super/application/edit.html.erb +1 -6
- data/app/views/super/application/index.html.erb +1 -6
- data/app/views/super/application/new.html.erb +1 -6
- data/app/views/super/application/show.html.erb +1 -6
- data/lib/super.rb +8 -2
- data/lib/super/compatibility.rb +13 -1
- data/lib/super/configuration.rb +7 -0
- data/lib/super/controls/optional.rb +0 -11
- data/lib/super/controls/steps.rb +44 -31
- data/lib/super/display/schema_types.rb +31 -1
- data/lib/super/engine.rb +6 -0
- data/lib/super/filter.rb +137 -0
- data/lib/super/filter/operator.rb +103 -0
- data/lib/super/filter/schema_types.rb +118 -0
- data/lib/super/pagination.rb +61 -0
- data/lib/super/partial.rb +12 -0
- data/lib/super/plugin.rb +34 -63
- data/lib/super/schema.rb +1 -0
- data/lib/super/version.rb +1 -1
- data/lib/super/view_helper.rb +1 -1
- metadata +25 -4
- data/app/helpers/super/application_helper.rb +0 -39
data/lib/super/pagination.rb
CHANGED
@@ -52,6 +52,10 @@ module Super
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
def to_partial_path
|
56
|
+
"super_pagination"
|
57
|
+
end
|
58
|
+
|
55
59
|
private
|
56
60
|
|
57
61
|
def pages
|
@@ -66,5 +70,62 @@ module Super
|
|
66
70
|
end
|
67
71
|
end
|
68
72
|
end
|
73
|
+
|
74
|
+
module ControllerMethods
|
75
|
+
def index
|
76
|
+
super
|
77
|
+
@pagination = controls.initialize_pagination(action: action_inquirer, records: @records, query_params: request.GET)
|
78
|
+
@records = controls.paginate_records(action: action_inquirer, records: @records, pagination: @pagination)
|
79
|
+
@view.mains.first.parts.push(:@pagination)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class Controls
|
85
|
+
module Optional
|
86
|
+
# Specifies how many records to show per page
|
87
|
+
#
|
88
|
+
# @param action [ActionInquirer]
|
89
|
+
# @param query_params [Hash]
|
90
|
+
# @return [ActiveRecord::Relation]
|
91
|
+
def records_per_page(action:, query_params:)
|
92
|
+
default_for(:records_per_page, action: action, query_params: query_params) do
|
93
|
+
Super.configuration.index_records_per_page
|
94
|
+
end
|
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
|
+
default_for(:initialize_pagination, action: action, records: records, query_params: query_params) do
|
107
|
+
Pagination.new(
|
108
|
+
total_count: records.size,
|
109
|
+
limit: records_per_page(action: action, query_params: query_params),
|
110
|
+
query_params: query_params,
|
111
|
+
page_query_param: :page
|
112
|
+
)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Paginates
|
117
|
+
#
|
118
|
+
# @param action [ActionInquirer]
|
119
|
+
# @param records [ActiveRecord::Relation]
|
120
|
+
# @param pagination [Pagination]
|
121
|
+
# @return [ActiveRecord::Relation]
|
122
|
+
def paginate_records(action:, records:, pagination:)
|
123
|
+
default_for(:paginate_records, action: action, records: records, pagination: pagination) do
|
124
|
+
records
|
125
|
+
.limit(pagination.limit)
|
126
|
+
.offset(pagination.offset)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
69
130
|
end
|
70
131
|
end
|
data/lib/super/partial.rb
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
module Super
|
2
2
|
class Partial
|
3
|
+
def self.render(partialish, template:)
|
4
|
+
if partialish.respond_to?(:to_partial_path)
|
5
|
+
if partialish.respond_to?(:locals)
|
6
|
+
template.render(partialish, partialish.locals)
|
7
|
+
else
|
8
|
+
template.render(partialish)
|
9
|
+
end
|
10
|
+
else
|
11
|
+
partialish
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
3
15
|
def initialize(path, locals: {})
|
4
16
|
@to_partial_path = path
|
5
17
|
@locals = locals
|
data/lib/super/plugin.rb
CHANGED
@@ -1,88 +1,59 @@
|
|
1
1
|
module Super
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
super
|
9
|
-
|
10
|
-
PluginRegistry.base_set(@registry_name, base)
|
11
|
-
|
12
|
-
plugins = PluginRegistry.plugins_for(@registry_name)
|
13
|
-
|
14
|
-
plugins.each do |klass, method_name|
|
15
|
-
base.public_send(method_name, klass)
|
2
|
+
module Plugin
|
3
|
+
class Registry
|
4
|
+
class << self
|
5
|
+
def controller
|
6
|
+
@controller ||= Registry.new
|
7
|
+
end
|
16
8
|
end
|
17
|
-
end
|
18
|
-
end
|
19
9
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
plugin_push(name.to_sym, :include, klass)
|
10
|
+
def initialize
|
11
|
+
@registry = {}
|
12
|
+
@ordering = Hash.new { |hash, key| hash[key] = [] }
|
24
13
|
end
|
25
14
|
|
26
|
-
def
|
27
|
-
|
15
|
+
def use(include: nil, prepend: nil)
|
16
|
+
register(include: include, prepend: prepend, before: [], after: [])
|
28
17
|
end
|
29
18
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
plugins.fetch(name) { {} }
|
19
|
+
def insert_before(*before, include: nil, prepend: nil)
|
20
|
+
register(include: include, prepend: prepend, before: before, after: [])
|
34
21
|
end
|
35
22
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
if !klass.kind_of?(Class)
|
40
|
-
raise Error::InvalidPluginArgument,
|
41
|
-
"Received `#{klass}` which must be a class"
|
42
|
-
end
|
43
|
-
|
44
|
-
bases[name] = klass
|
45
|
-
|
46
|
-
true
|
23
|
+
def insert_after(*after, include: nil, prepend: nil)
|
24
|
+
register(include: include, prepend: prepend, before: [], after: after)
|
47
25
|
end
|
48
26
|
|
49
|
-
def
|
50
|
-
|
27
|
+
def classes_ordered
|
28
|
+
each_node = -> (&b) { @ordering.each_key(&b) }
|
29
|
+
each_child = -> (cb, &b) { @ordering[cb].each(&b) }
|
51
30
|
|
52
|
-
|
31
|
+
TSort.tsort(each_node, each_child)
|
53
32
|
end
|
54
33
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
if ![:include, :prepend].include?(method_name)
|
59
|
-
raise Error::InvalidPluginArgument,
|
60
|
-
"Received `#{method_name.inspect}`, must be either :include or :prepend"
|
34
|
+
def ordered
|
35
|
+
classes_ordered.each do |class_name|
|
36
|
+
yield class_name, @registry[class_name]
|
61
37
|
end
|
38
|
+
end
|
62
39
|
|
63
|
-
|
64
|
-
raise Error::InvalidPluginArgument,
|
65
|
-
"Received `#{klass}` which must be a module"
|
66
|
-
end
|
40
|
+
private
|
67
41
|
|
68
|
-
|
69
|
-
|
42
|
+
def register(include:, prepend:, before: [], after: [])
|
43
|
+
raise Error::InvalidPluginArgument, "only one of :include or :prepend can be filled out" if include && prepend
|
44
|
+
raise Error::InvalidPluginArgument, "at least one of :include or :prepend must be filled out" if include.nil? && prepend.nil?
|
70
45
|
|
71
|
-
|
46
|
+
klass = include || prepend
|
47
|
+
@registry[klass] = :include if include
|
48
|
+
@registry[klass] = :prepend if prepend
|
72
49
|
|
73
|
-
|
74
|
-
|
50
|
+
before.each do |b|
|
51
|
+
@ordering[b].push(klass)
|
75
52
|
end
|
76
53
|
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
def plugins
|
81
|
-
@plugins ||= {}
|
82
|
-
end
|
54
|
+
@ordering[klass].push(*after)
|
83
55
|
|
84
|
-
|
85
|
-
@bases ||= {}
|
56
|
+
nil
|
86
57
|
end
|
87
58
|
end
|
88
59
|
end
|
data/lib/super/schema.rb
CHANGED
data/lib/super/version.rb
CHANGED
data/lib/super/view_helper.rb
CHANGED
@@ -23,7 +23,7 @@ module Super
|
|
23
23
|
|
24
24
|
def errors_accounting_for_reflections(model_instance, column_or_association)
|
25
25
|
errable_fields(model_instance, column_or_association)
|
26
|
-
.flat_map { |field| Compatability.
|
26
|
+
.flat_map { |field| Compatability.errable_fields(field) }
|
27
27
|
.flat_map { |field| model_instance.errors.full_messages_for(field) }
|
28
28
|
.uniq
|
29
29
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: super
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Ahn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: capybara
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,9 +213,12 @@ files:
|
|
199
213
|
- app/assets/javascripts/super/application.js
|
200
214
|
- app/assets/stylesheets/super/application.css
|
201
215
|
- app/controllers/super/application_controller.rb
|
202
|
-
- app/helpers/super/application_helper.rb
|
203
216
|
- app/views/layouts/super/application.html.erb
|
204
217
|
- app/views/super/application/_collection_header.html.erb
|
218
|
+
- app/views/super/application/_filter.html.erb
|
219
|
+
- app/views/super/application/_filter_type_select.html.erb
|
220
|
+
- app/views/super/application/_filter_type_text.html.erb
|
221
|
+
- app/views/super/application/_filter_type_timestamp.html.erb
|
205
222
|
- app/views/super/application/_flash.html.erb
|
206
223
|
- app/views/super/application/_form_field__destroy.html.erb
|
207
224
|
- app/views/super/application/_form_field_select.html.erb
|
@@ -212,6 +229,7 @@ files:
|
|
212
229
|
- app/views/super/application/_form_inline_errors.html.erb
|
213
230
|
- app/views/super/application/_member_header.html.erb
|
214
231
|
- app/views/super/application/_super_layout.html.erb
|
232
|
+
- app/views/super/application/_super_pagination.html.erb
|
215
233
|
- app/views/super/application/_super_panel.html.erb
|
216
234
|
- app/views/super/application/_super_schema_display_actions.html.erb
|
217
235
|
- app/views/super/application/_super_schema_display_index.html.erb
|
@@ -268,6 +286,9 @@ files:
|
|
268
286
|
- lib/super/display/schema_types.rb
|
269
287
|
- lib/super/engine.rb
|
270
288
|
- lib/super/error.rb
|
289
|
+
- lib/super/filter.rb
|
290
|
+
- lib/super/filter/operator.rb
|
291
|
+
- lib/super/filter/schema_types.rb
|
271
292
|
- lib/super/form.rb
|
272
293
|
- lib/super/form/schema_types.rb
|
273
294
|
- lib/super/layout.rb
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Super
|
2
|
-
# View helpers, available within views
|
3
|
-
module ApplicationHelper
|
4
|
-
def super_render_partialish(partialish)
|
5
|
-
if partialish.respond_to?(:to_partial_path)
|
6
|
-
if partialish.is_a?(Super::Partial)
|
7
|
-
render(partialish, partialish.locals)
|
8
|
-
else
|
9
|
-
render(partialish)
|
10
|
-
end
|
11
|
-
else
|
12
|
-
partialish
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def super_format_for_display(schema, record, column)
|
17
|
-
formatter = schema.fields[column]
|
18
|
-
|
19
|
-
formatted =
|
20
|
-
if formatter.real?
|
21
|
-
value = record.public_send(column)
|
22
|
-
formatter.present(value)
|
23
|
-
else
|
24
|
-
formatter.present
|
25
|
-
end
|
26
|
-
|
27
|
-
if formatted.respond_to?(:to_partial_path)
|
28
|
-
if formatted.respond_to?(:locals)
|
29
|
-
formatted.locals[:record] ||= record
|
30
|
-
render(formatted, formatted.locals)
|
31
|
-
else
|
32
|
-
render(formatted)
|
33
|
-
end
|
34
|
-
else
|
35
|
-
formatted
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|