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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 655e44dca6e45d18592d84ccc20dbc79f47da6f79e5c7995c32cc2553f8d1a29
4
- data.tar.gz: 05d8c8e708c9d6a08a1a917938f5c26b67e49872374b08206e4167de82b17721
3
+ metadata.gz: b3e6008fb9def58abce9a1281766aebb0e55ac7e2dece88377ba09d41f4ec902
4
+ data.tar.gz: 78b59b43ed159b5c5c184434aedd6eb10258fd7a483a5b7c379152be2a1b19b9
5
5
  SHA512:
6
- metadata.gz: d4c07a5076e76713970cdacad3fa7b90a56cefe00a4aa4fa385f20389642c39e284ea72a9528d6f9111b422f45ad197517269d5c4c6ceb6f574c811914ea9a6b
7
- data.tar.gz: 6f2a3adc9344bb6014f9a61b1048f012a87d60418d363df6e9f40a9caa2df2d67fa95f574d6d4af641ecc271fcd762942b18a37075ef8b9c59fccca29e94afe5
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
@@ -0,0 +1,11 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.0.3
4
+ * Move `_index_filter.html.erb` render location to `_search.html.erb`
5
+
6
+ ## 0.0.2
7
+ * Refactor filterer resource to use new_resource instead of resource_name
8
+
9
+ ## 0.0.1
10
+
11
+ * Initial release with basic filter functionality
data/README.md CHANGED
@@ -41,7 +41,8 @@ $ bundle add administrate_filterable
41
41
 
42
42
  ## Usage
43
43
 
44
- For each resource you want to add custom filter, add the following line to the their respective Administrate controller.
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
- 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
+ ### 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
- By default this gem will add a filter button to the partial `views/admin/application/_index_header.html.erb`. But if you have your own Administrate index views or override that partial in your application you can add the button manually by adding the following line:
75
- ```erb
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
- <%= render('index_filter', page: page) %>
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
- ## Contributing
126
+ If you have any idea or suggestion, please let me know by creating an issue or pull request.
108
127
 
109
- 1. Contribution are welcome (codes, suggestions, and bugs)
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
- - [administrate_filterable](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.
120
- - [Off-Canvas Menu](https://web.archive.org/web/20210304195120/https://codepen.io/11bits/pen/jryEGW): I found this CodePen from Google Images when I was looking for a way to create an off-canvas menu. 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.
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.
@@ -2,7 +2,7 @@
2
2
  position: fixed;
3
3
  z-index: 4;
4
4
  top: 38px;
5
- right: 10px;
5
+ right: 0;
6
6
  }
7
7
 
8
8
  .administrate-filterable__overlay {
@@ -1,5 +1,5 @@
1
1
  <% if @administrate_filterable_attributes.present? %>
2
- <% resource_title = display_resource_name(page.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, @administrate_filterable_resource], method: :get, html: { class: "form administrate-filterable__form" }) do |f| %>
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 resource and attributes to show up in the form, but it's not ideal
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
- @administrate_filterable_resource = resource_name.to_s.titleize.constantize.new
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
 
@@ -1,3 +1,3 @@
1
1
  module AdministrateFilterable
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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/_index_header.html.erb
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,5 +0,0 @@
1
- # CHANGELOG
2
-
3
- ## 0.0.1
4
-
5
- * Initial release with basic filter functionality
@@ -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>