gestart-admino 1.0.0 → 2.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +54 -35
- data/README.md +43 -128
- data/gestart-admino.gemspec +4 -4
- data/lib/gestart-admino.rb +1 -1
- data/lib/{admino → gestart_admino}/action_view_extension.rb +5 -5
- data/lib/{admino → gestart_admino}/query/base.rb +3 -3
- data/lib/{admino → gestart_admino}/query/base_presenter.rb +1 -1
- data/lib/{admino → gestart_admino}/query/builder.rb +1 -1
- data/lib/{admino → gestart_admino}/query/configuration.rb +1 -1
- data/lib/{admino → gestart_admino}/query/dsl.rb +2 -2
- data/lib/{admino → gestart_admino}/query/filter_group.rb +1 -1
- data/lib/{admino → gestart_admino}/query/filter_group_presenter.rb +1 -1
- data/lib/{admino → gestart_admino}/query/scope_presenter.rb +1 -1
- data/lib/{admino → gestart_admino}/query/search_field.rb +1 -1
- data/lib/{admino → gestart_admino}/query/sorting.rb +1 -1
- data/lib/{admino → gestart_admino}/query/sorting_presenter.rb +1 -1
- data/lib/gestart_admino/query.rb +15 -0
- data/lib/{admino → gestart_admino}/table/head_row.rb +2 -2
- data/lib/{admino → gestart_admino}/table/presenter.rb +3 -3
- data/lib/{admino → gestart_admino}/table/resource_row.rb +2 -2
- data/lib/{admino → gestart_admino}/table/row.rb +1 -1
- data/lib/gestart_admino/table.rb +7 -0
- data/lib/gestart_admino/version.rb +3 -0
- data/lib/gestart_admino.rb +14 -0
- data/spec/{admino → gestart_admino}/query/base_presenter_spec.rb +1 -1
- data/spec/{admino → gestart_admino}/query/base_spec.rb +1 -1
- data/spec/{admino → gestart_admino}/query/dsl_spec.rb +1 -1
- data/spec/{admino → gestart_admino}/query/filter_group_presenter_spec.rb +1 -1
- data/spec/{admino → gestart_admino}/query/filter_group_spec.rb +1 -1
- data/spec/{admino → gestart_admino}/query/search_field_spec.rb +1 -1
- data/spec/{admino → gestart_admino}/query/sorting_presenter_spec.rb +1 -1
- data/spec/{admino → gestart_admino}/query/sorting_spec.rb +1 -1
- data/spec/{admino → gestart_admino}/table/head_row_spec.rb +1 -1
- data/spec/{admino → gestart_admino}/table/presenter_spec.rb +1 -1
- data/spec/{admino → gestart_admino}/table/resource_row_spec.rb +1 -1
- data/spec/{admino → gestart_admino}/table/row_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -3
- metadata +49 -49
- data/lib/admino/query.rb +0 -15
- data/lib/admino/table.rb +0 -7
- data/lib/admino/version.rb +0 -3
- data/lib/admino.rb +0 -14
- /data/spec/{admino → gestart_admino}/integration_spec.rb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5889239a6de572e00ac5736a3c1f0b4d46b0a334f4b718318f7385f3e4eb3373
|
|
4
|
+
data.tar.gz: 6307b369bfe7d59df2979db087b199fca023e537fea082213f7f4977a8b5cf59
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0cb4e9fe74ae759707c78c41abe998db72a6548ba55cd4b982f8e168d7429283aac11bb8968ead7368f3c258e2235cc858220e090bc8019cc7868ddc5d1ad038
|
|
7
|
+
data.tar.gz: 9c0cbe21e2db1bfe301ba8f50d4c0af5c3a5a90ca64d32588115ddd881d72d865c648cc8ad2aa0c7c6e6dc0e81288e436da45d491bb18bd520771c4ca8351255
|
data/CHANGELOG.md
CHANGED
|
@@ -1,38 +1,57 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
# v2.0.0 — the namespace
|
|
2
|
+
|
|
3
|
+
**Breaking.** The namespace goes from `Admino::` to `GestartAdmino::`, and the
|
|
4
|
+
files from `lib/admino/` to `lib/gestart_admino/`. No behaviour changes: names
|
|
5
|
+
only.
|
|
6
|
+
|
|
7
|
+
Why: `Admino::Query::Base` inside a file that is ours is a lie somebody
|
|
8
|
+
eventually pays for. Upstream has been dead since 2017, so no fix will ever come
|
|
9
|
+
back from it and the usual "keep the diff against upstream clean" argument does
|
|
10
|
+
not apply.
|
|
11
|
+
|
|
12
|
+
To upgrade, in the application: `Admino::` → `GestartAdmino::`. In Gestart that
|
|
13
|
+
is 6 lines, across `base_query.rb`, `table_presenter.rb` and
|
|
14
|
+
`bemo_table_presenter.rb`.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
# v1.0.0 — the fork
|
|
19
|
+
|
|
20
|
+
Gestart fork of [`admino`](https://github.com/cantierecreativo/admino) 0.0.22,
|
|
21
|
+
the last upstream release, dated 23/06/2017.
|
|
22
|
+
|
|
23
|
+
**Why.** Every index page in Gestart rests on this gem: 26 query objects, 32
|
|
24
|
+
`_index_row` partials, 29 `_query` partials and 28 presenters speak its DSL.
|
|
25
|
+
Upstream has been frozen since 2017 and will get no further fixes. Under frozen
|
|
26
|
+
string literals — the Ruby 4.0 regime — the gem broke the application suite in
|
|
27
|
+
121 places, all rooted in `Admino::Table::HeadRow#column`. Rewriting the surface
|
|
28
|
+
would have meant rewriting that vocabulary across ~115 files; forking and pruning
|
|
29
|
+
costs a day and touches none of them.
|
|
30
|
+
|
|
31
|
+
The full decision, with the alternatives that were dropped, lives in the
|
|
32
|
+
application repo: `docs/decisioni/admino.md`.
|
|
33
|
+
|
|
34
|
+
**What changed from 0.0.22.**
|
|
35
|
+
|
|
36
|
+
* Fixed the two string literals mutated in place (`@columns = ""` → `+""`) in
|
|
37
|
+
`Table::HeadRow` and `Table::ResourceRow`: this was the breakage that stood in
|
|
38
|
+
the way of Ruby 4.
|
|
39
|
+
* Dropped the `coercible` dependency (upstream frozen since 10/12/2013) and with
|
|
40
|
+
it the `coerce:` option of `search_field`. The value reaches the scope exactly
|
|
41
|
+
as it arrived from the params; interpreting it is the application's job.
|
|
42
|
+
* Pruned the API Gestart does not use: the `filters_for`, `sortings_for` and
|
|
43
|
+
`search_form_for` helpers, and `Query::BasePresenter#form`, which depended on
|
|
44
|
+
the last one. `table_for` and `simple_search_form_for` stay.
|
|
45
|
+
* Added the `require` of `active_support/core_ext/class/attribute`, which
|
|
46
|
+
upstream assumed loaded elsewhere: without it the gem does not load in
|
|
47
|
+
isolation.
|
|
48
|
+
* Suite runnable on Ruby 3.4 and Rails 8.1: dropped `appraisal`, `coveralls`,
|
|
49
|
+
`simplecov` and the Rails 4.0/4.2 gemfiles; relaxed the `bundler ~> 1.3`
|
|
50
|
+
constraint.
|
|
51
|
+
|
|
52
|
+
**Maintenance.** This fork gets repaired, not extended: it is fixed when Rails
|
|
53
|
+
breaks it, and nothing more. New features do not go in here — the day they are
|
|
54
|
+
wanted, that is the signal that a new table system is due, not a wider fork.
|
|
36
55
|
|
|
37
56
|
---
|
|
38
57
|
|
data/README.md
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
[](http://badge.fury.io/rb/admino)
|
|
4
|
-
[](https://travis-ci.org/cantierecreativo/admino)
|
|
5
|
-
[](https://coveralls.io/r/cantierecreativo/admino?branch=master)
|
|
6
|
-
[](https://codeclimate.com/github/cantierecreativo/admino)
|
|
1
|
+
# gestart-admino
|
|
7
2
|
|
|
8
3
|
A minimal, object-oriented solution to generate Rails administrative index views. Through query objects and presenters, it features a customizable table generator and search forms with filtering/sorting.
|
|
9
4
|
|
|
5
|
+
> **This is a maintenance fork.** `gestart-admino` is Gestart's fork of
|
|
6
|
+
> [`admino`](https://github.com/cantierecreativo/admino) 0.0.22, whose last
|
|
7
|
+
> upstream release is dated 23/06/2017. It exists because every Gestart index
|
|
8
|
+
> page rests on this DSL, and upstream will get no further fixes.
|
|
9
|
+
>
|
|
10
|
+
> **It gets repaired, not extended.** It is fixed when Rails breaks it, and
|
|
11
|
+
> nothing more. If you find yourself wanting to add a feature here, that is the
|
|
12
|
+
> signal a new table system is due — not a wider fork.
|
|
13
|
+
>
|
|
14
|
+
> Compared to upstream: the namespace is `GestartAdmino::`, the `coercible`
|
|
15
|
+
> dependency and the `coerce:` option are gone, and the unused helpers
|
|
16
|
+
> (`filters_for`, `sortings_for`, `search_form_for`) have been pruned. See
|
|
17
|
+
> [`CHANGELOG.md`](CHANGELOG.md).
|
|
18
|
+
|
|
10
19
|
## The philosophy behind it
|
|
11
20
|
|
|
12
21
|
The Rails ecosystem has many [full-fledged solutions to generate administrative interfaces](https://www.ruby-toolbox.com/categories/rails_admin_interfaces).
|
|
@@ -26,28 +35,24 @@ If a particular controller or view needs something different from the standard C
|
|
|
26
35
|
|
|
27
36
|
So what about Admino? Well, it complements the above-mentioned gems, giving you the the missing ~10%: a fast way to generate administrative index views.
|
|
28
37
|
|
|
29
|
-
## Demo
|
|
30
|
-
|
|
31
|
-
To better illustrate how to create a 100%-custom, super-DRY administrative interface using Admino and the aforementioned gems, we prepared a [repo with a sample Rails project](https://github.com/cantierecreativo/admino-example) you can take a look. The app is browsable at [http://admino-example.herokuapp.com](http://admino-example.herokuapp.com), and features a Bootstrap 3 theme.
|
|
32
|
-
|
|
33
38
|
## Installation
|
|
34
39
|
|
|
35
40
|
Add this line to your application's Gemfile:
|
|
36
41
|
|
|
37
|
-
gem 'admino'
|
|
42
|
+
gem 'gestart-admino'
|
|
38
43
|
|
|
39
44
|
And then execute:
|
|
40
45
|
|
|
41
46
|
$ bundle
|
|
42
47
|
|
|
43
|
-
##
|
|
48
|
+
## GestartAdmino::Query::Base
|
|
44
49
|
|
|
45
|
-
`
|
|
50
|
+
`GestartAdmino::Query::Base` implements the [Query object](http://martinfowler.com/eaaCatalog/queryObject.html) pattern, that is, an object responsible for returning a result set (ie. an `ActiveRecord::Relation`) based on business rules.
|
|
46
51
|
|
|
47
|
-
Given a `Task` model, we can generate a `TasksQuery` query object subclassing `
|
|
52
|
+
Given a `Task` model, we can generate a `TasksQuery` query object subclassing `GestartAdmino::Query::Base`:
|
|
48
53
|
|
|
49
54
|
```ruby
|
|
50
|
-
class TasksQuery <
|
|
55
|
+
class TasksQuery < GestartAdmino::Query::Base
|
|
51
56
|
end
|
|
52
57
|
```
|
|
53
58
|
|
|
@@ -71,7 +76,7 @@ You can specify how a `TaskQuery` must build a result set through a simple DSL.
|
|
|
71
76
|
The `starting_scope` method is in charge of defining the scope that will start the filtering/ordering chain:
|
|
72
77
|
|
|
73
78
|
```ruby
|
|
74
|
-
class TasksQuery <
|
|
79
|
+
class TasksQuery < GestartAdmino::Query::Base
|
|
75
80
|
starting_scope { Task.all }
|
|
76
81
|
end
|
|
77
82
|
|
|
@@ -85,7 +90,7 @@ TaskQuery.new.scope.count # => 1
|
|
|
85
90
|
Once you define the following field:
|
|
86
91
|
|
|
87
92
|
```ruby
|
|
88
|
-
class TasksQuery <
|
|
93
|
+
class TasksQuery < GestartAdmino::Query::Base
|
|
89
94
|
# ...
|
|
90
95
|
search_field :title_matches
|
|
91
96
|
end
|
|
@@ -110,7 +115,7 @@ TaskQuery.new(query: { title_matches: 'ASAP' }).scope.count # => 1
|
|
|
110
115
|
You can provide a default value with the `default` option:
|
|
111
116
|
|
|
112
117
|
```ruby
|
|
113
|
-
class TasksQuery <
|
|
118
|
+
class TasksQuery < GestartAdmino::Query::Base
|
|
114
119
|
# ...
|
|
115
120
|
search_field :title_matches, default: 'TODO'
|
|
116
121
|
end
|
|
@@ -126,7 +131,7 @@ class Task < ActiveRecord::Base
|
|
|
126
131
|
}
|
|
127
132
|
end
|
|
128
133
|
|
|
129
|
-
class TasksQuery <
|
|
134
|
+
class TasksQuery < GestartAdmino::Query::Base
|
|
130
135
|
# ...
|
|
131
136
|
filter_by :status, [:completed, :pending]
|
|
132
137
|
filter_by :deleted, [:with_deleted]
|
|
@@ -155,7 +160,7 @@ TaskQuery.new(query: { status: 'foobar' }).scope.count # => 3
|
|
|
155
160
|
You can include a "reset" scope with the `include_empty_scope` option, and provide a default scope with the `default` option:
|
|
156
161
|
|
|
157
162
|
```ruby
|
|
158
|
-
class TasksQuery <
|
|
163
|
+
class TasksQuery < GestartAdmino::Query::Base
|
|
159
164
|
# ...
|
|
160
165
|
filter_by :time, [:last_month, :last_week],
|
|
161
166
|
include_empty_scope: true,
|
|
@@ -166,7 +171,7 @@ end
|
|
|
166
171
|
#### `sorting`
|
|
167
172
|
|
|
168
173
|
```ruby
|
|
169
|
-
class TasksQuery <
|
|
174
|
+
class TasksQuery < GestartAdmino::Query::Base
|
|
170
175
|
# ...
|
|
171
176
|
sorting :by_due_date, :by_title
|
|
172
177
|
end
|
|
@@ -195,7 +200,7 @@ TaskQuery.new(sorting: 'by_due_date').scope # => [ expired_t
|
|
|
195
200
|
It's very common ie. to paginate a result set. The block declared in the `ending_scope` block will be always appended to the end of the chain:
|
|
196
201
|
|
|
197
202
|
```ruby
|
|
198
|
-
class TasksQuery <
|
|
203
|
+
class TasksQuery < GestartAdmino::Query::Base
|
|
199
204
|
ending_scope { |q| page(q.params[:page]) }
|
|
200
205
|
end
|
|
201
206
|
```
|
|
@@ -208,7 +213,7 @@ If you do not want to pollute your ActiveRecord model with all these scopes, you
|
|
|
208
213
|
class Task < ActiveRecord::Base
|
|
209
214
|
end
|
|
210
215
|
|
|
211
|
-
class TasksQuery <
|
|
216
|
+
class TasksQuery < GestartAdmino::Query::Base
|
|
212
217
|
search_field :title_matches
|
|
213
218
|
|
|
214
219
|
def title_matches_scope(scope, text)
|
|
@@ -223,8 +228,8 @@ A query object supports various methods to inspect the available search fields,
|
|
|
223
228
|
|
|
224
229
|
```ruby
|
|
225
230
|
query = TaskQuery.new
|
|
226
|
-
query.search_fields # => [ #<
|
|
227
|
-
query.filter_groups # => [ #<
|
|
231
|
+
query.search_fields # => [ #<GestartAdmino::Query::SearchField>, ... ]
|
|
232
|
+
query.filter_groups # => [ #<GestartAdmino::Query::FilterGroup>, ... ]
|
|
228
233
|
|
|
229
234
|
search_field = query.search_field_by_name(:title_matches)
|
|
230
235
|
|
|
@@ -239,68 +244,13 @@ filter_group.scopes # => [ :completed, :pending ]
|
|
|
239
244
|
filter_group.active_scope # => :completed
|
|
240
245
|
filter_group.is_scope_active?(:pending) # => false
|
|
241
246
|
|
|
242
|
-
sorting = query.sorting # => #<
|
|
247
|
+
sorting = query.sorting # => #<GestartAdmino::Query::Sorting>
|
|
243
248
|
sorting.scopes # => [ :by_title, :by_due_date ]
|
|
244
249
|
sorting.active_scope # => :by_due_date
|
|
245
250
|
sorting.is_scope_active?(:by_title) # => false
|
|
246
251
|
sorting.ascending? # => true
|
|
247
252
|
```
|
|
248
253
|
|
|
249
|
-
### Presenting search form and filters to the user
|
|
250
|
-
|
|
251
|
-
Admino offers some helpers that make it really easy to generate search forms and filtering links:
|
|
252
|
-
|
|
253
|
-
```erb
|
|
254
|
-
<%# generate the search form %>
|
|
255
|
-
<%= search_form_for(query) do |q| %>
|
|
256
|
-
<%# generate inputs from search_fields %>
|
|
257
|
-
<p>
|
|
258
|
-
<%= q.label :title_matches %>
|
|
259
|
-
<%= q.text_field :title_matches %>
|
|
260
|
-
</p>
|
|
261
|
-
<p>
|
|
262
|
-
<%= q.submit %>
|
|
263
|
-
</p>
|
|
264
|
-
|
|
265
|
-
<%# generate inputs from filter_by %>
|
|
266
|
-
<p>
|
|
267
|
-
<%= q.label :status %>
|
|
268
|
-
<%= q.select :status, Task.statuses.keys %>
|
|
269
|
-
</p>
|
|
270
|
-
|
|
271
|
-
<%# if filter_by has only one scope you can use a checkbox %>
|
|
272
|
-
<p>
|
|
273
|
-
<%= q.check_box :deleted, {}, checked_value: "with_deleted" %>
|
|
274
|
-
<%= q.label :deleted %>
|
|
275
|
-
</p>
|
|
276
|
-
<% end %>
|
|
277
|
-
|
|
278
|
-
<%# generate the filtering links %>
|
|
279
|
-
<% filters_for(query) do |filter_group| %>
|
|
280
|
-
<h6><%= filter_group.name %></h6>
|
|
281
|
-
<ul>
|
|
282
|
-
<% filter_group.each_scope do |scope| %>
|
|
283
|
-
<li><%= scope.link %><li>
|
|
284
|
-
<% end %>
|
|
285
|
-
</ul>
|
|
286
|
-
<% end %>
|
|
287
|
-
|
|
288
|
-
<%# generate the sorting links %>
|
|
289
|
-
<h6>Sort by</h6>
|
|
290
|
-
<ul>
|
|
291
|
-
<% sortings_for(query) do |scope| %>
|
|
292
|
-
<li><%= scope.link %></li>
|
|
293
|
-
<% end %>
|
|
294
|
-
</ul>
|
|
295
|
-
```
|
|
296
|
-
The great thing is that:
|
|
297
|
-
|
|
298
|
-
* the search form gets automatically filled in with the last input the user submitted
|
|
299
|
-
* a `is-active` CSS class gets added to the currently active filter scopes
|
|
300
|
-
* if a particular filter link has been clicked and is now active, it is possible to deactivate it by clicking on the link again
|
|
301
|
-
* a `is-asc`/`is-desc` CSS class gets added to the currently active sorting scope
|
|
302
|
-
* if a particular sorting scope link has been clicked and is now in ascending order, it is possible to make it descending by clicking on the link again
|
|
303
|
-
|
|
304
254
|
### Simple Form support
|
|
305
255
|
|
|
306
256
|
If you prefer using [Simple Form](https://github.com/plataformatec/simple_form), please use the `simple_search_form_for` helper instead.
|
|
@@ -331,47 +281,12 @@ def index
|
|
|
331
281
|
end
|
|
332
282
|
```
|
|
333
283
|
|
|
334
|
-
### Coertions
|
|
335
|
-
|
|
336
|
-
Suppose the presence of a model scope that requires a non-textual argument (ie. a date):
|
|
337
|
-
|
|
338
|
-
```ruby
|
|
339
|
-
class Task < ActiveRecord::Base
|
|
340
|
-
scope :due_date_from, ->(date) { where('due_date >= ?', date) }
|
|
341
|
-
end
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
Admino can perform some automatic coertions to the textual parameter it gets, and pass the coerced value to the scope:
|
|
345
|
-
|
|
346
|
-
```ruby
|
|
347
|
-
class TasksQuery < Admino::Query::Base
|
|
348
|
-
search_field :due_date_from, coerce: :to_date
|
|
349
|
-
end
|
|
350
|
-
|
|
351
|
-
query = TaskQuery.new(query: { due_date_from: '2014-03-01' })
|
|
352
|
-
query.search_field_by_name(:due_date_from).value # => #<Date Sat, 01 Mar 2014>
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
If a specific coercion cannot be performed with the provided input, the scope won't be chained. The following coertions are available:
|
|
356
|
-
|
|
357
|
-
* `:to_boolean`
|
|
358
|
-
* `:to_constant`
|
|
359
|
-
* `:to_date`
|
|
360
|
-
* `:to_datetime`
|
|
361
|
-
* `:to_decimal`
|
|
362
|
-
* `:to_float`
|
|
363
|
-
* `:to_integer`
|
|
364
|
-
* `:to_symbol`
|
|
365
|
-
* `:to_time`
|
|
366
|
-
|
|
367
|
-
Please see the [`Coercible::Coercer::String`](https://github.com/solnic/coercible/blob/master/lib/coercible/coercer/string.rb) class for details.
|
|
368
|
-
|
|
369
284
|
### Default sorting
|
|
370
285
|
|
|
371
286
|
If you need to setup a default sorting, you can pass some optional arguments to the `sorting` declaration:
|
|
372
287
|
|
|
373
288
|
```ruby
|
|
374
|
-
class TasksQuery <
|
|
289
|
+
class TasksQuery < GestartAdmino::Query::Base
|
|
375
290
|
# ...
|
|
376
291
|
sorting :by_due_date, :by_title,
|
|
377
292
|
default_scope: :by_due_date,
|
|
@@ -402,7 +317,7 @@ en:
|
|
|
402
317
|
by_title: 'By title'
|
|
403
318
|
```
|
|
404
319
|
|
|
405
|
-
##
|
|
320
|
+
## GestartAdmino::Table::Presenter
|
|
406
321
|
|
|
407
322
|
Admino offers a `table_for` helper that makes it really easy to generate HTML tables from a set of records:
|
|
408
323
|
|
|
@@ -481,7 +396,7 @@ Often tables need to offer some kind of action associated with the records. The
|
|
|
481
396
|
If you want to make the table headers sortable, then please create an Admino query object class to define the available sorting scopes.
|
|
482
397
|
|
|
483
398
|
```ruby
|
|
484
|
-
class TaskQuery <
|
|
399
|
+
class TaskQuery < GestartAdmino::Query::Base
|
|
485
400
|
sorting :by_title, :by_due_date
|
|
486
401
|
end
|
|
487
402
|
```
|
|
@@ -531,11 +446,11 @@ The `#column` and `#action` methods are very flexible, allowing you to change al
|
|
|
531
446
|
<% end %>
|
|
532
447
|
```
|
|
533
448
|
|
|
534
|
-
If you need more power, you can also subclass `
|
|
535
|
-
Table cells are generated through two collaborator classes: `
|
|
449
|
+
If you need more power, you can also subclass `GestartAdmino::Table::Presenter`. For each HTML element, there's a set of methods you can override to customize it's appeareance.
|
|
450
|
+
Table cells are generated through two collaborator classes: `GestartAdmino::Table::HeadRow` and `GestartAdmino::Table::ResourceRow`. You can easily replace them with a subclass if you want. To grasp the idea here's an example:
|
|
536
451
|
|
|
537
452
|
```ruby
|
|
538
|
-
class CustomTablePresenter <
|
|
453
|
+
class CustomTablePresenter < GestartAdmino::Table::Presenter
|
|
539
454
|
private
|
|
540
455
|
|
|
541
456
|
def table_html_options
|
|
@@ -558,7 +473,7 @@ class CustomTablePresenter < Admino::Table::Presenter
|
|
|
558
473
|
HeadRow.new(collection_klass, query, view_context)
|
|
559
474
|
end
|
|
560
475
|
|
|
561
|
-
class ResourceRow <
|
|
476
|
+
class ResourceRow < GestartAdmino::Table::ResourceRow
|
|
562
477
|
private
|
|
563
478
|
|
|
564
479
|
def action_html_options(action_name)
|
|
@@ -574,7 +489,7 @@ class CustomTablePresenter < Admino::Table::Presenter
|
|
|
574
489
|
end
|
|
575
490
|
end
|
|
576
491
|
|
|
577
|
-
class HeadRow <
|
|
492
|
+
class HeadRow < GestartAdmino::Table::ResourceRow
|
|
578
493
|
def column_html_options(attribute_name)
|
|
579
494
|
{ class: 'column-class' }
|
|
580
495
|
end
|
|
@@ -600,17 +515,17 @@ Please refer to the tests for all the details.
|
|
|
600
515
|
|
|
601
516
|
If your controller actions are generated through [Inherited Resources](https://github.com/josevalim/inherited_resources), then you can always get the URL pointing to the show action with the `resource_path` helper method. Similar helpers [are available for the other REST actions too](https://github.com/josevalim/inherited_resources#url-helpers) (new, edit, destroy).
|
|
602
517
|
|
|
603
|
-
More in general, if you are able to programmatically generate/obtain the URLs of your row actions, you can subclass `
|
|
518
|
+
More in general, if you are able to programmatically generate/obtain the URLs of your row actions, you can subclass `GestartAdmino::Table::Presenter` and declare them:
|
|
604
519
|
|
|
605
520
|
```ruby
|
|
606
|
-
class CustomTablePresenter <
|
|
521
|
+
class CustomTablePresenter < GestartAdmino::Table::Presenter
|
|
607
522
|
private
|
|
608
523
|
|
|
609
524
|
def resource_row(resource, view_context)
|
|
610
525
|
ResourceRow.new(resource, view_context)
|
|
611
526
|
end
|
|
612
527
|
|
|
613
|
-
class ResourceRow <
|
|
528
|
+
class ResourceRow < GestartAdmino::Table::ResourceRow
|
|
614
529
|
def show_action_url
|
|
615
530
|
h.resource_url(resource)
|
|
616
531
|
end
|
|
@@ -658,7 +573,7 @@ end
|
|
|
658
573
|
```erb
|
|
659
574
|
<% tasks = present_collection(@tasks)
|
|
660
575
|
|
|
661
|
-
<%=
|
|
576
|
+
<%= GestartAdmino::Table::Presenter.new(tasks, Task, self).to_html do |row, record| %>
|
|
662
577
|
<%= row.column :truncated_title, 'Title' %>
|
|
663
578
|
<% end %>
|
|
664
579
|
```
|
data/gestart-admino.gemspec
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require '
|
|
4
|
+
require 'gestart_admino/version'
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = 'gestart-admino'
|
|
8
|
-
spec.version =
|
|
8
|
+
spec.version = GestartAdmino::VERSION
|
|
9
9
|
spec.authors = ['Gestart Cloud S.r.l.', 'Stefano Verna']
|
|
10
10
|
spec.email = ['dev@gestart.net']
|
|
11
|
-
spec.description = %q{
|
|
12
|
-
spec.summary = %q{
|
|
11
|
+
spec.description = %q{Gestart fork of admino 0.0.22, pruned of what Gestart does not use}
|
|
12
|
+
spec.summary = %q{Gestart fork of admino: query objects and tables for index pages}
|
|
13
13
|
spec.homepage = 'https://github.com/gestartcloudsrl/gestart-admino'
|
|
14
14
|
spec.license = 'MIT'
|
|
15
15
|
|
data/lib/gestart-admino.rb
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'gestart_admino'
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
require 'active_support/core_ext/hash'
|
|
2
|
-
require '
|
|
3
|
-
require '
|
|
2
|
+
require 'gestart_admino/table/presenter'
|
|
3
|
+
require 'gestart_admino/query/base_presenter'
|
|
4
4
|
|
|
5
|
-
module
|
|
5
|
+
module GestartAdmino
|
|
6
6
|
module ActionViewExtension
|
|
7
7
|
module Internals
|
|
8
8
|
def self.present_query(query, context, options, key = :presenter)
|
|
9
|
-
presenter_klass = options.fetch(key,
|
|
9
|
+
presenter_klass = options.fetch(key, GestartAdmino::Query::BasePresenter)
|
|
10
10
|
presenter_klass.new(query, context)
|
|
11
11
|
end
|
|
12
12
|
end
|
|
@@ -14,7 +14,7 @@ module Admino
|
|
|
14
14
|
def table_for(collection, options = {}, &block)
|
|
15
15
|
options.symbolize_keys!
|
|
16
16
|
options.assert_valid_keys(:presenter, :class, :query, :html)
|
|
17
|
-
presenter_klass = options.fetch(:presenter,
|
|
17
|
+
presenter_klass = options.fetch(:presenter, GestartAdmino::Table::Presenter)
|
|
18
18
|
query = if options[:query]
|
|
19
19
|
Internals.present_query(options[:query], self, options, :query_presenter)
|
|
20
20
|
else
|
|
@@ -6,10 +6,10 @@ require 'active_support/hash_with_indifferent_access'
|
|
|
6
6
|
require 'active_support/core_ext/hash'
|
|
7
7
|
require 'active_support/core_ext/class/attribute'
|
|
8
8
|
|
|
9
|
-
require '
|
|
10
|
-
require '
|
|
9
|
+
require 'gestart_admino/query/dsl'
|
|
10
|
+
require 'gestart_admino/query/builder'
|
|
11
11
|
|
|
12
|
-
module
|
|
12
|
+
module GestartAdmino
|
|
13
13
|
module Query
|
|
14
14
|
class Base
|
|
15
15
|
extend ActiveModel::Naming
|
|
@@ -6,7 +6,7 @@ require 'active_support/core_ext/array/extract_options'
|
|
|
6
6
|
require 'active_support/hash_with_indifferent_access'
|
|
7
7
|
require 'active_support/core_ext/hash'
|
|
8
8
|
|
|
9
|
-
module
|
|
9
|
+
module GestartAdmino
|
|
10
10
|
module Query
|
|
11
11
|
class FilterGroupPresenter < Showcase::Presenter
|
|
12
12
|
def scope_link(scope, *args)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'gestart_admino/query/base'
|
|
2
|
+
require 'gestart_admino/query/base_presenter'
|
|
3
|
+
require 'gestart_admino/query/configuration'
|
|
4
|
+
require 'gestart_admino/query/search_field'
|
|
5
|
+
require 'gestart_admino/query/filter_group'
|
|
6
|
+
require 'gestart_admino/query/filter_group_presenter'
|
|
7
|
+
require 'gestart_admino/query/sorting'
|
|
8
|
+
require 'gestart_admino/query/sorting_presenter'
|
|
9
|
+
require 'gestart_admino/query/scope_presenter'
|
|
10
|
+
|
|
11
|
+
module GestartAdmino
|
|
12
|
+
module Query
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
require 'showcase'
|
|
2
|
-
require '
|
|
3
|
-
require '
|
|
2
|
+
require 'gestart_admino/table/head_row'
|
|
3
|
+
require 'gestart_admino/table/resource_row'
|
|
4
4
|
|
|
5
|
-
module
|
|
5
|
+
module GestartAdmino
|
|
6
6
|
module Table
|
|
7
7
|
class Presenter < Showcase::Presenter
|
|
8
8
|
attr_reader :collection_klass
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'active_support/core_ext/module/delegation'
|
|
2
|
+
|
|
3
|
+
require "gestart_admino/version"
|
|
4
|
+
require "gestart_admino/query"
|
|
5
|
+
require "gestart_admino/table"
|
|
6
|
+
require "gestart_admino/action_view_extension"
|
|
7
|
+
|
|
8
|
+
module GestartAdmino
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
ActiveSupport.on_load(:action_view) do
|
|
12
|
+
include GestartAdmino::ActionViewExtension
|
|
13
|
+
end
|
|
14
|
+
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'gestart_admino'
|
|
2
2
|
require 'rspec-html-matchers'
|
|
3
3
|
require 'ostruct'
|
|
4
4
|
|
|
@@ -19,7 +19,7 @@ class ScopeMock
|
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
class TestQuery <
|
|
22
|
+
class TestQuery < GestartAdmino::Query::Base
|
|
23
23
|
search_field :foo, default: 'bar'
|
|
24
24
|
search_field :starting_from
|
|
25
25
|
|
|
@@ -68,7 +68,7 @@ require 'simple_form'
|
|
|
68
68
|
class RailsViewContext < ActionView::Base
|
|
69
69
|
include ActionView::Helpers::TagHelper
|
|
70
70
|
include SimpleForm::ActionViewExtensions::FormHelper
|
|
71
|
-
include
|
|
71
|
+
include GestartAdmino::ActionViewExtension
|
|
72
72
|
|
|
73
73
|
def initialize(*)
|
|
74
74
|
super(ActionView::LookupContext.new([]), {}, nil)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gestart-admino
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gestart Cloud S.r.l.
|
|
@@ -178,7 +178,7 @@ dependencies:
|
|
|
178
178
|
- - ">="
|
|
179
179
|
- !ruby/object:Gem::Version
|
|
180
180
|
version: '0'
|
|
181
|
-
description:
|
|
181
|
+
description: Gestart fork of admino 0.0.22, pruned of what Gestart does not use
|
|
182
182
|
email:
|
|
183
183
|
- dev@gestart.net
|
|
184
184
|
executables: []
|
|
@@ -194,40 +194,40 @@ files:
|
|
|
194
194
|
- README.md
|
|
195
195
|
- Rakefile
|
|
196
196
|
- gestart-admino.gemspec
|
|
197
|
-
- lib/admino.rb
|
|
198
|
-
- lib/admino/action_view_extension.rb
|
|
199
|
-
- lib/admino/query.rb
|
|
200
|
-
- lib/admino/query/base.rb
|
|
201
|
-
- lib/admino/query/base_presenter.rb
|
|
202
|
-
- lib/admino/query/builder.rb
|
|
203
|
-
- lib/admino/query/configuration.rb
|
|
204
|
-
- lib/admino/query/dsl.rb
|
|
205
|
-
- lib/admino/query/filter_group.rb
|
|
206
|
-
- lib/admino/query/filter_group_presenter.rb
|
|
207
|
-
- lib/admino/query/scope_presenter.rb
|
|
208
|
-
- lib/admino/query/search_field.rb
|
|
209
|
-
- lib/admino/query/sorting.rb
|
|
210
|
-
- lib/admino/query/sorting_presenter.rb
|
|
211
|
-
- lib/admino/table.rb
|
|
212
|
-
- lib/admino/table/head_row.rb
|
|
213
|
-
- lib/admino/table/presenter.rb
|
|
214
|
-
- lib/admino/table/resource_row.rb
|
|
215
|
-
- lib/admino/table/row.rb
|
|
216
|
-
- lib/admino/version.rb
|
|
217
197
|
- lib/gestart-admino.rb
|
|
218
|
-
-
|
|
219
|
-
-
|
|
220
|
-
-
|
|
221
|
-
-
|
|
222
|
-
-
|
|
223
|
-
-
|
|
224
|
-
-
|
|
225
|
-
-
|
|
226
|
-
-
|
|
227
|
-
-
|
|
228
|
-
-
|
|
229
|
-
-
|
|
230
|
-
-
|
|
198
|
+
- lib/gestart_admino.rb
|
|
199
|
+
- lib/gestart_admino/action_view_extension.rb
|
|
200
|
+
- lib/gestart_admino/query.rb
|
|
201
|
+
- lib/gestart_admino/query/base.rb
|
|
202
|
+
- lib/gestart_admino/query/base_presenter.rb
|
|
203
|
+
- lib/gestart_admino/query/builder.rb
|
|
204
|
+
- lib/gestart_admino/query/configuration.rb
|
|
205
|
+
- lib/gestart_admino/query/dsl.rb
|
|
206
|
+
- lib/gestart_admino/query/filter_group.rb
|
|
207
|
+
- lib/gestart_admino/query/filter_group_presenter.rb
|
|
208
|
+
- lib/gestart_admino/query/scope_presenter.rb
|
|
209
|
+
- lib/gestart_admino/query/search_field.rb
|
|
210
|
+
- lib/gestart_admino/query/sorting.rb
|
|
211
|
+
- lib/gestart_admino/query/sorting_presenter.rb
|
|
212
|
+
- lib/gestart_admino/table.rb
|
|
213
|
+
- lib/gestart_admino/table/head_row.rb
|
|
214
|
+
- lib/gestart_admino/table/presenter.rb
|
|
215
|
+
- lib/gestart_admino/table/resource_row.rb
|
|
216
|
+
- lib/gestart_admino/table/row.rb
|
|
217
|
+
- lib/gestart_admino/version.rb
|
|
218
|
+
- spec/gestart_admino/integration_spec.rb
|
|
219
|
+
- spec/gestart_admino/query/base_presenter_spec.rb
|
|
220
|
+
- spec/gestart_admino/query/base_spec.rb
|
|
221
|
+
- spec/gestart_admino/query/dsl_spec.rb
|
|
222
|
+
- spec/gestart_admino/query/filter_group_presenter_spec.rb
|
|
223
|
+
- spec/gestart_admino/query/filter_group_spec.rb
|
|
224
|
+
- spec/gestart_admino/query/search_field_spec.rb
|
|
225
|
+
- spec/gestart_admino/query/sorting_presenter_spec.rb
|
|
226
|
+
- spec/gestart_admino/query/sorting_spec.rb
|
|
227
|
+
- spec/gestart_admino/table/head_row_spec.rb
|
|
228
|
+
- spec/gestart_admino/table/presenter_spec.rb
|
|
229
|
+
- spec/gestart_admino/table/resource_row_spec.rb
|
|
230
|
+
- spec/gestart_admino/table/row_spec.rb
|
|
231
231
|
- spec/spec_helper.rb
|
|
232
232
|
homepage: https://github.com/gestartcloudsrl/gestart-admino
|
|
233
233
|
licenses:
|
|
@@ -249,19 +249,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
249
249
|
requirements: []
|
|
250
250
|
rubygems_version: 3.6.9
|
|
251
251
|
specification_version: 4
|
|
252
|
-
summary: '
|
|
252
|
+
summary: 'Gestart fork of admino: query objects and tables for index pages'
|
|
253
253
|
test_files:
|
|
254
|
-
- spec/
|
|
255
|
-
- spec/
|
|
256
|
-
- spec/
|
|
257
|
-
- spec/
|
|
258
|
-
- spec/
|
|
259
|
-
- spec/
|
|
260
|
-
- spec/
|
|
261
|
-
- spec/
|
|
262
|
-
- spec/
|
|
263
|
-
- spec/
|
|
264
|
-
- spec/
|
|
265
|
-
- spec/
|
|
266
|
-
- spec/
|
|
254
|
+
- spec/gestart_admino/integration_spec.rb
|
|
255
|
+
- spec/gestart_admino/query/base_presenter_spec.rb
|
|
256
|
+
- spec/gestart_admino/query/base_spec.rb
|
|
257
|
+
- spec/gestart_admino/query/dsl_spec.rb
|
|
258
|
+
- spec/gestart_admino/query/filter_group_presenter_spec.rb
|
|
259
|
+
- spec/gestart_admino/query/filter_group_spec.rb
|
|
260
|
+
- spec/gestart_admino/query/search_field_spec.rb
|
|
261
|
+
- spec/gestart_admino/query/sorting_presenter_spec.rb
|
|
262
|
+
- spec/gestart_admino/query/sorting_spec.rb
|
|
263
|
+
- spec/gestart_admino/table/head_row_spec.rb
|
|
264
|
+
- spec/gestart_admino/table/presenter_spec.rb
|
|
265
|
+
- spec/gestart_admino/table/resource_row_spec.rb
|
|
266
|
+
- spec/gestart_admino/table/row_spec.rb
|
|
267
267
|
- spec/spec_helper.rb
|
data/lib/admino/query.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'admino/query/base'
|
|
2
|
-
require 'admino/query/base_presenter'
|
|
3
|
-
require 'admino/query/configuration'
|
|
4
|
-
require 'admino/query/search_field'
|
|
5
|
-
require 'admino/query/filter_group'
|
|
6
|
-
require 'admino/query/filter_group_presenter'
|
|
7
|
-
require 'admino/query/sorting'
|
|
8
|
-
require 'admino/query/sorting_presenter'
|
|
9
|
-
require 'admino/query/scope_presenter'
|
|
10
|
-
|
|
11
|
-
module Admino
|
|
12
|
-
module Query
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
data/lib/admino/table.rb
DELETED
data/lib/admino/version.rb
DELETED
data/lib/admino.rb
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
require 'active_support/core_ext/module/delegation'
|
|
2
|
-
|
|
3
|
-
require "admino/version"
|
|
4
|
-
require "admino/query"
|
|
5
|
-
require "admino/table"
|
|
6
|
-
require "admino/action_view_extension"
|
|
7
|
-
|
|
8
|
-
module Admino
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
ActiveSupport.on_load(:action_view) do
|
|
12
|
-
include Admino::ActionViewExtension
|
|
13
|
-
end
|
|
14
|
-
|
|
File without changes
|