administrate_filterable 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/CHANGELOG.md +11 -0
- data/README.md +42 -21
- data/app/assets/stylesheets/administrate_filterable/application.css +1 -1
- data/app/views/admin/application/_index_filter.html.erb +2 -2
- data/app/views/admin/application/_search.html.erb +27 -0
- data/lib/administrate_filterable/filterer.rb +2 -3
- data/lib/administrate_filterable/version.rb +1 -1
- metadata +3 -3
- data/CHANGELOG +0 -5
- data/app/views/admin/application/_index_header.html.erb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3e6008fb9def58abce9a1281766aebb0e55ac7e2dece88377ba09d41f4ec902
|
4
|
+
data.tar.gz: 78b59b43ed159b5c5c184434aedd6eb10258fd7a483a5b7c379152be2a1b19b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f865057d44efb6b5660b097be590d1c5bfba7df1e6caed4df2b53c6cd1bf526dd43e63980d6640c934d0bf15e61fedaadd2ea49bc5eba8e5a1ecc3048d4ca423
|
7
|
+
data.tar.gz: 3a62607e5eb4513a443160b2ec244ef468e9b35617f8f7c7c1a39f98af49aa0e1597f852b8a52b42080b219a24d090917ead63f2b2b6719dd8fbc4f985ce0346
|
data/.gitignore
CHANGED
@@ -10,6 +10,8 @@
|
|
10
10
|
# rspec failure tracking
|
11
11
|
.rspec_status
|
12
12
|
|
13
|
+
# Ignore byebug command history file.
|
14
|
+
.byebug_history
|
13
15
|
|
14
16
|
# Ignore the default SQLite database.
|
15
17
|
spec/dummy/db/*.sqlite3
|
@@ -18,3 +20,6 @@ spec/dummy/db/*.sqlite3-journal
|
|
18
20
|
# Ignore all logfiles and tempfiles.
|
19
21
|
spec/dummy/log/*
|
20
22
|
spec/dummy/tmp/*
|
23
|
+
|
24
|
+
# Ignore gem build artifacts
|
25
|
+
*.gem
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -41,7 +41,8 @@ $ bundle add administrate_filterable
|
|
41
41
|
|
42
42
|
## Usage
|
43
43
|
|
44
|
-
|
44
|
+
### Enable the filter
|
45
|
+
For each resource you want to add custom filter, add the following line to their respective Administrate controller.
|
45
46
|
```ruby
|
46
47
|
include AdministrateFilterable::Filterer
|
47
48
|
```
|
@@ -55,7 +56,8 @@ class UsersController < Administrate::ApplicationController
|
|
55
56
|
end
|
56
57
|
```
|
57
58
|
|
58
|
-
|
59
|
+
### Customizing the filter fields
|
60
|
+
By default all the attributes from `COLLECTION_ATTRIBUTES` will be rendered as the filter fields. You can override this by adding `FILTER_ATTRIBUTES` to your Administrate's dashboard file.
|
59
61
|
|
60
62
|
Example (`app/dashboards/user_dashboard.rb`):
|
61
63
|
```ruby
|
@@ -71,21 +73,12 @@ class UserDashboard < Administrate::BaseDashboard
|
|
71
73
|
end
|
72
74
|
```
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
-
<%= render('index_filter', page: page) %>
|
77
|
-
```
|
78
|
-
|
79
|
-
Example (`app/views/admin/users/_index_header.html.erb`):
|
80
|
-
```erb
|
81
|
-
... other code here ...
|
82
|
-
<header class="main-content__header">
|
83
|
-
... other code here ...
|
76
|
+
### Customizing the filter template
|
77
|
+
It is possible to customize the filter template (e.g. changing the filter button icon, etc). You can do this by overriding the default template in your application, just create a new file called `_index_filter.html.erb` in your desired resource folder.
|
84
78
|
|
85
|
-
|
86
|
-
</header>
|
87
|
-
```
|
79
|
+
For example, if you want to override the filter template for `users` resource, you need to create the file in `app/views/admin/users/_index_filter.html.erb`. Then just copy and paste the content from the default template [here](app/views/admin/application/_index_filter.html.erb) and modify it to suit your needs.
|
88
80
|
|
81
|
+
### Asset Pipeline
|
89
82
|
If you use assets pipeline, you need to include this gem's assets to your `app/assets/config/manifest.js` file:
|
90
83
|
```javascript
|
91
84
|
// ... other code here ...
|
@@ -94,8 +87,34 @@ If you use assets pipeline, you need to include this gem's assets to your `app/a
|
|
94
87
|
//= link administrate_filterable/application.js
|
95
88
|
```
|
96
89
|
|
90
|
+
Run `rails assets:precompile` if the assets are not loaded.
|
91
|
+
|
92
|
+
|
93
|
+
## Troubleshooting
|
94
|
+
### Overridden default search template
|
95
|
+
By default this gem will add a filter button to `views/admin/application/_search.html.erb` partial. But if you have override that partial in your application you can add the button manually by adding the following line:
|
96
|
+
```erb
|
97
|
+
<%= render 'index_filter' %>
|
98
|
+
```
|
99
|
+
|
100
|
+
Example (`app/views/admin/users/_search.html.erb`):
|
101
|
+
```erb
|
102
|
+
<form class="search" role="search">
|
103
|
+
... other code here ...
|
104
|
+
</form>
|
105
|
+
|
106
|
+
<%= render 'index_filter' %>
|
107
|
+
```
|
108
|
+
|
109
|
+
### Filter button not showing
|
110
|
+
Since I use the `_search.html.erb` partial to add the filter button, it may not be showing if you turn all the searchable attributes to false in the model dashboard. So make sure you have at least one searchable attribute to make the filter button show up.
|
111
|
+
|
112
|
+
The reason why I use the partial is because:
|
113
|
+
1. It is rarely overridden by the user, so you won't have to add the button manually in most cases.
|
114
|
+
2. Previously, I use `_index_header.html.erb` partial, but it conflicts with the export button from [administrate_exportable](https://github.com/SourceLabsLLC/administrate_exportable). Using both gems results in one button missing, due to the partial override.
|
115
|
+
|
97
116
|
## To Do
|
98
|
-
There are still a lot of things to do to make this gem better. Here are some of them (sorted highest priority first):
|
117
|
+
There are still a lot of things to do to make this gem better. Here are some of them (sorted by highest priority first):
|
99
118
|
- [ ] Add support for relational filter (e.g. filter by `belongs_to` association, etc)
|
100
119
|
- [ ] Add support to customize the dropdown list (e.g. add `prompt` option, add `include_blank` option, etc)
|
101
120
|
- [ ] Exclude checkbox, radio, or select value from the filter params if no action is performed on them
|
@@ -104,11 +123,13 @@ There are still a lot of things to do to make this gem better. Here are some of
|
|
104
123
|
- [ ] Add capability to customize the filter behavior (e.g. search by exact match, search by partial match, etc just like in the ActiveAdmin filter)
|
105
124
|
- [ ] Improve the toggle button user experience (e.g. add open/close animation, add dynamic open/close title, etc)
|
106
125
|
|
107
|
-
|
126
|
+
If you have any idea or suggestion, please let me know by creating an issue or pull request.
|
108
127
|
|
109
|
-
|
128
|
+
## Contributing
|
129
|
+
You can help me to improve this gem by contributing to this project. Any help is highly appreciated.
|
130
|
+
1. Fork this repo and create a pull request
|
110
131
|
2. Please test your code: `bundle exec rspec`
|
111
|
-
3. Please document your code
|
132
|
+
3. Please document your code if needed
|
112
133
|
|
113
134
|
## License
|
114
135
|
|
@@ -116,5 +137,5 @@ There are still a lot of things to do to make this gem better. Here are some of
|
|
116
137
|
|
117
138
|
## Credits
|
118
139
|
Huge thanks for the following resources that help me a lot in creating this gem:
|
119
|
-
- [
|
120
|
-
- [Off-Canvas Menu](https://web.archive.org/web/20210304195120/https://codepen.io/11bits/pen/jryEGW): I found this
|
140
|
+
- [administrate_exportable](https://github.com/SourceLabsLLC/administrate_exportable): Basically I just copy the code from this gem and modify it to suit my needs, highly recommended if you need to export your data from Administrate.
|
141
|
+
- [Off-Canvas Menu](https://web.archive.org/web/20210304195120/https://codepen.io/11bits/pen/jryEGW): I found this code from Google Images when I was looking for a way to create an off-canvas filter component. I modified it a little bit to suit my needs. But it seems the CodePen is no longer available, so I put the archived version here. If any of you know the original author, please let me know so I can give the proper credit.
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% if @administrate_filterable_attributes.present? %>
|
2
|
-
<% resource_title = display_resource_name(
|
2
|
+
<% resource_title = display_resource_name(resource_name) %>
|
3
3
|
|
4
4
|
<% # TODO: Improve the toggle button user experience (e.g. add open/close animation, add dynamic open/close title, etc) %>
|
5
5
|
<a href="#administrate-filterable" class="administrate-filterable__toggle-button" title="Filter <%= resource_title %>">
|
@@ -13,7 +13,7 @@
|
|
13
13
|
<h2>Filter <%= resource_title %></h2>
|
14
14
|
</header>
|
15
15
|
|
16
|
-
<%= form_with(model: [:admin,
|
16
|
+
<%= form_with(model: [:admin, new_resource], method: :get, html: { class: "form administrate-filterable__form" }) do |f| %>
|
17
17
|
<% @administrate_filterable_attributes.each do |attribute| -%>
|
18
18
|
<% # TODO: Add capability to customize the filter behavior (e.g. search by exact match, search by partial match, etc just like in the ActiveAdmin filter) %>
|
19
19
|
<div class="field-unit field-unit--<%= attribute.html_class %> administrate-filterable__field">
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<form class="search" role="search">
|
2
|
+
<label class="search__label" for="search">
|
3
|
+
<svg class="search__eyeglass-icon" role="img">
|
4
|
+
<title>
|
5
|
+
<%= t("administrate.search.label", resource: resource_name) %>
|
6
|
+
</title>
|
7
|
+
<use xlink:href="#icon-eyeglass" />
|
8
|
+
</svg>
|
9
|
+
</label>
|
10
|
+
|
11
|
+
<input class="search__input"
|
12
|
+
id="search"
|
13
|
+
type="search"
|
14
|
+
name="search"
|
15
|
+
placeholder="<%= t("administrate.search.label",
|
16
|
+
resource: resource_name) %>"
|
17
|
+
value="<%= search_term %>">
|
18
|
+
|
19
|
+
<%= link_to clear_search_params, class: "search__clear-link" do %>
|
20
|
+
<svg class="search__clear-icon" role="img">
|
21
|
+
<title><%= t("administrate.search.clear") %></title>
|
22
|
+
<use xlink:href="#icon-cancel" />
|
23
|
+
</svg>
|
24
|
+
<% end %>
|
25
|
+
</form>
|
26
|
+
|
27
|
+
<%= render 'index_filter' %>
|
@@ -13,10 +13,9 @@ module AdministrateFilterable
|
|
13
13
|
# It would be better to implement this as a separate controller action, but I don't have time to explore that right now
|
14
14
|
define_method(:scoped_resource) do
|
15
15
|
# TODO: Figure out a better way to pass the filter data to the form
|
16
|
-
# This is a hack to get the filter
|
16
|
+
# This is a hack to get the filter attributes to show up in the form, but it's not ideal
|
17
17
|
# So I tried to make the variable name as unique as possible to avoid collisions
|
18
|
-
@
|
19
|
-
@administrate_filterable_attributes = FiltererService.filter_attributes(dashboard, @administrate_filterable_resource)
|
18
|
+
@administrate_filterable_attributes = FiltererService.filter_attributes(dashboard, new_resource)
|
20
19
|
|
21
20
|
data = resource_class.all
|
22
21
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: administrate_filterable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Irvan Fauziansyah
|
@@ -133,7 +133,7 @@ files:
|
|
133
133
|
- ".github/workflows/main.yml"
|
134
134
|
- ".gitignore"
|
135
135
|
- ".rspec"
|
136
|
-
- CHANGELOG
|
136
|
+
- CHANGELOG.md
|
137
137
|
- Gemfile
|
138
138
|
- Gemfile.lock
|
139
139
|
- LICENSE
|
@@ -143,7 +143,7 @@ files:
|
|
143
143
|
- app/assets/javascripts/administrate_filterable/application.js
|
144
144
|
- app/assets/stylesheets/administrate_filterable/application.css
|
145
145
|
- app/views/admin/application/_index_filter.html.erb
|
146
|
-
- app/views/admin/application/
|
146
|
+
- app/views/admin/application/_search.html.erb
|
147
147
|
- bin/console
|
148
148
|
- bin/setup
|
149
149
|
- lib/administrate_filterable.rb
|
data/CHANGELOG
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
<% content_for(:title) do %>
|
2
|
-
<%= display_resource_name(page.resource_name) %>
|
3
|
-
<% end %>
|
4
|
-
|
5
|
-
<header class="main-content__header">
|
6
|
-
<h1 class="main-content__page-title" id="page-title">
|
7
|
-
<%= content_for(:title) %>
|
8
|
-
</h1>
|
9
|
-
|
10
|
-
<% if show_search_bar %>
|
11
|
-
<%= render(
|
12
|
-
"search",
|
13
|
-
search_term: search_term,
|
14
|
-
resource_name: display_resource_name(page.resource_name)
|
15
|
-
) %>
|
16
|
-
<% end %>
|
17
|
-
|
18
|
-
<%= render('index_filter', page: page) %>
|
19
|
-
</header>
|