spotlight_search 0.1.9 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +81 -72
- data/README.md +92 -46
- data/app/assets/javascripts/spotlight_search.js +9 -0
- data/app/controllers/spotlight_search/export_jobs_controller.rb +9 -7
- data/app/jobs/spotlight_search/export_job.rb +19 -20
- data/app/mailers/spotlight_search/export_mailer.rb +6 -0
- data/app/views/spotlight_search/export_mailer/send_error_message.html.erb +7 -0
- data/lib/generators/spotlight_search/filter_generator.rb +21 -0
- data/lib/generators/spotlight_search/install_generator.rb +27 -0
- data/lib/generators/spotlight_search/templates/application.css.scss +26 -0
- data/lib/generators/spotlight_search/templates/application.js +19 -0
- data/lib/generators/spotlight_search/templates/coffee.js +6 -0
- data/lib/generators/spotlight_search/templates/controller.rb.erb +91 -0
- data/lib/generators/spotlight_search/templates/environment.js +20 -0
- data/lib/generators/spotlight_search/templates/filters.html.erb +10 -0
- data/lib/generators/spotlight_search/templates/scaffolds.coffee +11 -0
- data/lib/generators/spotlight_search/templates/spotlight_search.rb +5 -0
- data/lib/generators/spotlight_search/templates/webpacker.yml +102 -0
- data/lib/generators/spotlight_search/templates/webpacker_gem_assets.rb +55 -0
- data/lib/spotlight_search/exportable_columns_v2.rb +2 -14
- data/lib/spotlight_search/helpers.rb +60 -14
- data/lib/spotlight_search/utils.rb +1 -1
- data/lib/spotlight_search/version.rb +1 -1
- data/spotlight_search.gemspec +3 -4
- metadata +25 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 576ead7e9ed602d984a2b141bbd9744df9f8ed760c32a72486f052af271aa6c9
|
4
|
+
data.tar.gz: 18c0360d8fd6fba83ee3bf84ff30f2e6e0eddcd1543a4c6056d1f904d564fefd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17743dcac8dc528fd9f5cfa0713f51e109be3703f6d8ba3f380028b9ad65abd508acba501a7ee844e4e16cba8ba6d0ba4f00f9bac3d9fa8767f3c0bdf66a7772
|
7
|
+
data.tar.gz: 4aba022bdfff558c868077abf3f200e02e540e7392c0953dc71a984f605f22921efff26059408c2b13ec284a818926bb930abdc44c46541b8ffd44deec040383
|
data/Gemfile.lock
CHANGED
@@ -1,103 +1,112 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
spotlight_search (0.1.
|
5
|
-
|
4
|
+
spotlight_search (0.1.9)
|
5
|
+
caxlsx (~> 3.0.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actioncable (5.
|
11
|
-
actionpack (= 5.
|
12
|
-
nio4r (
|
13
|
-
websocket-driver (
|
14
|
-
actionmailer (5.
|
15
|
-
actionpack (= 5.
|
16
|
-
actionview (= 5.
|
17
|
-
activejob (= 5.
|
10
|
+
actioncable (5.2.4.2)
|
11
|
+
actionpack (= 5.2.4.2)
|
12
|
+
nio4r (~> 2.0)
|
13
|
+
websocket-driver (>= 0.6.1)
|
14
|
+
actionmailer (5.2.4.2)
|
15
|
+
actionpack (= 5.2.4.2)
|
16
|
+
actionview (= 5.2.4.2)
|
17
|
+
activejob (= 5.2.4.2)
|
18
18
|
mail (~> 2.5, >= 2.5.4)
|
19
19
|
rails-dom-testing (~> 2.0)
|
20
|
-
actionpack (5.
|
21
|
-
actionview (= 5.
|
22
|
-
activesupport (= 5.
|
23
|
-
rack (~> 2.0)
|
24
|
-
rack-test (
|
20
|
+
actionpack (5.2.4.2)
|
21
|
+
actionview (= 5.2.4.2)
|
22
|
+
activesupport (= 5.2.4.2)
|
23
|
+
rack (~> 2.0, >= 2.0.8)
|
24
|
+
rack-test (>= 0.6.3)
|
25
25
|
rails-dom-testing (~> 2.0)
|
26
26
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
-
actionview (5.
|
28
|
-
activesupport (= 5.
|
27
|
+
actionview (5.2.4.2)
|
28
|
+
activesupport (= 5.2.4.2)
|
29
29
|
builder (~> 3.1)
|
30
|
-
|
30
|
+
erubi (~> 1.4)
|
31
31
|
rails-dom-testing (~> 2.0)
|
32
32
|
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
33
|
-
activejob (5.
|
34
|
-
activesupport (= 5.
|
33
|
+
activejob (5.2.4.2)
|
34
|
+
activesupport (= 5.2.4.2)
|
35
35
|
globalid (>= 0.3.6)
|
36
|
-
activemodel (5.
|
37
|
-
activesupport (= 5.
|
38
|
-
activerecord (5.
|
39
|
-
activemodel (= 5.
|
40
|
-
activesupport (= 5.
|
41
|
-
arel (
|
42
|
-
|
36
|
+
activemodel (5.2.4.2)
|
37
|
+
activesupport (= 5.2.4.2)
|
38
|
+
activerecord (5.2.4.2)
|
39
|
+
activemodel (= 5.2.4.2)
|
40
|
+
activesupport (= 5.2.4.2)
|
41
|
+
arel (>= 9.0)
|
42
|
+
activestorage (5.2.4.2)
|
43
|
+
actionpack (= 5.2.4.2)
|
44
|
+
activerecord (= 5.2.4.2)
|
45
|
+
marcel (~> 0.3.1)
|
46
|
+
activesupport (5.2.4.2)
|
43
47
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
44
48
|
i18n (>= 0.7, < 2)
|
45
49
|
minitest (~> 5.1)
|
46
50
|
tzinfo (~> 1.1)
|
47
|
-
arel (
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
arel (9.0.0)
|
52
|
+
builder (3.2.4)
|
53
|
+
caxlsx (3.0.1)
|
54
|
+
htmlentities (~> 4.3, >= 4.3.4)
|
55
|
+
mimemagic (~> 0.3)
|
56
|
+
nokogiri (~> 1.10, >= 1.10.4)
|
57
|
+
rubyzip (>= 1.3.0, < 3)
|
58
|
+
concurrent-ruby (1.1.6)
|
59
|
+
crass (1.0.6)
|
55
60
|
diff-lcs (1.3)
|
56
|
-
|
61
|
+
erubi (1.9.0)
|
57
62
|
globalid (0.4.2)
|
58
63
|
activesupport (>= 4.2.0)
|
59
64
|
htmlentities (4.3.4)
|
60
|
-
i18n (1.
|
65
|
+
i18n (1.8.2)
|
61
66
|
concurrent-ruby (~> 1.0)
|
62
|
-
loofah (2.
|
67
|
+
loofah (2.4.0)
|
63
68
|
crass (~> 1.0.2)
|
64
69
|
nokogiri (>= 1.5.9)
|
65
70
|
mail (2.7.1)
|
66
71
|
mini_mime (>= 0.1.1)
|
67
|
-
|
68
|
-
|
72
|
+
marcel (0.3.3)
|
73
|
+
mimemagic (~> 0.3.2)
|
74
|
+
method_source (1.0.0)
|
75
|
+
mimemagic (0.3.4)
|
76
|
+
mini_mime (1.0.2)
|
69
77
|
mini_portile2 (2.4.0)
|
70
|
-
minitest (5.
|
71
|
-
nio4r (2.
|
72
|
-
nokogiri (1.10.
|
78
|
+
minitest (5.14.0)
|
79
|
+
nio4r (2.5.2)
|
80
|
+
nokogiri (1.10.9)
|
73
81
|
mini_portile2 (~> 2.4.0)
|
74
|
-
rack (2.
|
75
|
-
rack-test (
|
76
|
-
rack (>= 1.0)
|
77
|
-
rails (5.
|
78
|
-
actioncable (= 5.
|
79
|
-
actionmailer (= 5.
|
80
|
-
actionpack (= 5.
|
81
|
-
actionview (= 5.
|
82
|
-
activejob (= 5.
|
83
|
-
activemodel (= 5.
|
84
|
-
activerecord (= 5.
|
85
|
-
|
82
|
+
rack (2.2.2)
|
83
|
+
rack-test (1.1.0)
|
84
|
+
rack (>= 1.0, < 3)
|
85
|
+
rails (5.2.4.2)
|
86
|
+
actioncable (= 5.2.4.2)
|
87
|
+
actionmailer (= 5.2.4.2)
|
88
|
+
actionpack (= 5.2.4.2)
|
89
|
+
actionview (= 5.2.4.2)
|
90
|
+
activejob (= 5.2.4.2)
|
91
|
+
activemodel (= 5.2.4.2)
|
92
|
+
activerecord (= 5.2.4.2)
|
93
|
+
activestorage (= 5.2.4.2)
|
94
|
+
activesupport (= 5.2.4.2)
|
86
95
|
bundler (>= 1.3.0)
|
87
|
-
railties (= 5.
|
96
|
+
railties (= 5.2.4.2)
|
88
97
|
sprockets-rails (>= 2.0.0)
|
89
98
|
rails-dom-testing (2.0.3)
|
90
99
|
activesupport (>= 4.2.0)
|
91
100
|
nokogiri (>= 1.6)
|
92
|
-
rails-html-sanitizer (1.0
|
93
|
-
loofah (~> 2.
|
94
|
-
railties (5.
|
95
|
-
actionpack (= 5.
|
96
|
-
activesupport (= 5.
|
101
|
+
rails-html-sanitizer (1.3.0)
|
102
|
+
loofah (~> 2.3)
|
103
|
+
railties (5.2.4.2)
|
104
|
+
actionpack (= 5.2.4.2)
|
105
|
+
activesupport (= 5.2.4.2)
|
97
106
|
method_source
|
98
107
|
rake (>= 0.8.7)
|
99
|
-
thor (>= 0.
|
100
|
-
rake (
|
108
|
+
thor (>= 0.19.0, < 2.0)
|
109
|
+
rake (13.0.1)
|
101
110
|
rspec (3.8.0)
|
102
111
|
rspec-core (~> 3.8.0)
|
103
112
|
rspec-expectations (~> 3.8.0)
|
@@ -111,31 +120,31 @@ GEM
|
|
111
120
|
diff-lcs (>= 1.2.0, < 2.0)
|
112
121
|
rspec-support (~> 3.8.0)
|
113
122
|
rspec-support (3.8.0)
|
114
|
-
rubyzip (
|
115
|
-
sprockets (
|
123
|
+
rubyzip (2.3.0)
|
124
|
+
sprockets (4.0.0)
|
116
125
|
concurrent-ruby (~> 1.0)
|
117
126
|
rack (> 1, < 3)
|
118
127
|
sprockets-rails (3.2.1)
|
119
128
|
actionpack (>= 4.0)
|
120
129
|
activesupport (>= 4.0)
|
121
130
|
sprockets (>= 3.0.0)
|
122
|
-
thor (0.
|
131
|
+
thor (1.0.1)
|
123
132
|
thread_safe (0.3.6)
|
124
|
-
tzinfo (1.2.
|
133
|
+
tzinfo (1.2.6)
|
125
134
|
thread_safe (~> 0.1)
|
126
|
-
websocket-driver (0.
|
135
|
+
websocket-driver (0.7.1)
|
127
136
|
websocket-extensions (>= 0.1.0)
|
128
|
-
websocket-extensions (0.1.
|
137
|
+
websocket-extensions (0.1.5)
|
129
138
|
|
130
139
|
PLATFORMS
|
131
140
|
ruby
|
132
141
|
|
133
142
|
DEPENDENCIES
|
134
143
|
bundler (~> 2.0)
|
135
|
-
rails (~> 5.
|
136
|
-
rake (
|
144
|
+
rails (~> 5.2.4.2)
|
145
|
+
rake (>= 12.3.3)
|
137
146
|
rspec (~> 3.0)
|
138
147
|
spotlight_search!
|
139
148
|
|
140
149
|
BUNDLED WITH
|
141
|
-
2.
|
150
|
+
2.1.4
|
data/README.md
CHANGED
@@ -4,6 +4,13 @@
|
|
4
4
|
|
5
5
|
It helps filtering, sorting and exporting tables easier.
|
6
6
|
|
7
|
+
First create a new rails project with the following command. If you are adding to existing project skip this
|
8
|
+
|
9
|
+
```
|
10
|
+
rails new blog -m https://raw.githubusercontent.com/commutatus/cm-rails-template/devise_integration/template.rb
|
11
|
+
```
|
12
|
+
|
13
|
+
|
7
14
|
## Installation
|
8
15
|
|
9
16
|
Add this line to your application's Gemfile:
|
@@ -20,7 +27,33 @@ Or install it manually:
|
|
20
27
|
|
21
28
|
$ gem install spotlight_search
|
22
29
|
|
23
|
-
|
30
|
+
Generator that installs mandatory files and gems to application
|
31
|
+
|
32
|
+
$ rails g spotlight_search:install
|
33
|
+
|
34
|
+
The install generator does the following
|
35
|
+
|
36
|
+
* `require spotlight_search` added to application.js
|
37
|
+
|
38
|
+
* Copies required files for the spotlight_search to work, Such as gemassets.rb, webpacker.yml, environment.js
|
39
|
+
|
40
|
+
* Copies initializer file
|
41
|
+
|
42
|
+
* Adds a line in route for mounting.
|
43
|
+
|
44
|
+
Generator that installs filter and table files to application
|
45
|
+
$ rails g spotlight_search filter orders --filters scope_name:filter_type
|
46
|
+
$ rails g spotlight_search filter orders --filters search:input order_status:multi_select status:select
|
47
|
+
|
48
|
+
scope_name is the model scope name, scope can written after running this generator, it won't throw any error that it has to be present.
|
49
|
+
|
50
|
+
Following filter type are supported
|
51
|
+
* input
|
52
|
+
* single-select
|
53
|
+
* multi-select
|
54
|
+
* datetime
|
55
|
+
* daterange
|
56
|
+
|
24
57
|
|
25
58
|
## Usage
|
26
59
|
|
@@ -66,24 +99,20 @@ end
|
|
66
99
|
#### View
|
67
100
|
Please note that the below code is in haml.
|
68
101
|
|
69
|
-
**STEP - 1
|
102
|
+
**STEP - 1 Filters**
|
70
103
|
|
71
|
-
|
104
|
+
**Filter Wrapper, Select-tags and Inputs**
|
72
105
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
106
|
+
| Generator | *Mandatory(Data Attributes, Select options) | *Optional(Classes, Placeholders) |
|
107
|
+
|----------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|
|
108
|
+
| `= filter_wrapper(data_behaviours, classes=nil)` | `{filter_url: '/users', replacement_class: 'users-table'}` | "filter-classes" |
|
109
|
+
| | | |
|
110
|
+
| `= cm_select_tag(select_options, data_behaviours, classes=nil, placeholder=nil)` | `{behaviour: "filter", scope: "status", type: "select-filter}` , User.all.map {\|user\| [user.name.titleize, user.id]} | `"user-select"`, placeholder = `"Users"` |
|
111
|
+
| | | |
|
112
|
+
| `= cm_textfield_tag(data_behaviours, classes=nil, placeholder=nil)` | `{behaviour: "filter", scope: "search", type: "input-filter}` | `"user-search"`, placeholder = `"Search"` |
|
113
|
+
| | | |
|
114
|
+
| `= clear_filters(clear_path, classes=nil, data_behaviours=nil, clear_text=nil)` | clear_path = `users_path` | `"clear-filter"`, data_behaviours = `{behaviour: 'clear'}`, clear_text = `"Clear all"` |
|
78
115
|
|
79
|
-
The elements that should be placed mandatorily are
|
80
|
-
|
81
|
-
* `.filters` All search input / select filter should be nested inside this class name.
|
82
|
-
* `data-filter-url` Is mandatory, this is the search URL, Mostly this will hit the index action.
|
83
|
-
* `data-replacement-class` After ajax this is the class name where the data will get appended.
|
84
|
-
* `data-behaviour="filter"` If the input behaviour is set to filter then this will get added to ajax
|
85
|
-
* `data-scope="search"` This is the model scope name, The helper method will call this when filter is applied.
|
86
|
-
* `data-type="input-filter"` This is to tell if the element is input or select other value is `data-type="select-filter"`
|
87
116
|
|
88
117
|
**STEP - 2 Pagination**
|
89
118
|
|
@@ -101,22 +130,39 @@ th = sortable "name", "Name", @filtered_result.sort[:sort_column], @filtered_res
|
|
101
130
|
|
102
131
|
### Export table data to excel
|
103
132
|
|
104
|
-
|
105
|
-
An initializer will have to be created to extend the functionality to ActiveRecord.
|
133
|
+
**Note**
|
106
134
|
|
107
|
-
|
108
|
-
# config/initializers/spotlight_search.rb
|
109
|
-
ActiveRecord::Base.include SpotlightSearch::ExportableColumns
|
110
|
-
```
|
135
|
+
You will need to have a background job processor such as `sidekiq`, `resque`, `delayed_job` etc as the file will be generated in the background and will be sent to the email passed. If you need to use any other service for sending emails, you will need to override `ExportMailer` class.
|
111
136
|
|
112
|
-
#### Routes
|
113
|
-
A line has to be added to the routes.
|
114
137
|
|
115
|
-
|
116
|
-
|
138
|
+
#### <a name="export-view"></a>View
|
139
|
+
|
140
|
+
Add `exportable email, model_object` in your view to display the export button.
|
141
|
+
|
142
|
+
```html+erb
|
143
|
+
<table>
|
144
|
+
<tr>
|
145
|
+
<th>Name</th>
|
146
|
+
<th>Email</th>
|
147
|
+
</tr>
|
148
|
+
<td>
|
149
|
+
<% @records.each do |record| %>
|
150
|
+
<tr>
|
151
|
+
<td><%= record.name %></td>
|
152
|
+
<td><%= record.value %></td>
|
153
|
+
<% end %>
|
154
|
+
</td>
|
155
|
+
</table>
|
156
|
+
|
157
|
+
<%= exportable(current_user.email, Person) %>
|
117
158
|
```
|
118
159
|
|
160
|
+
This will first show a popup where an option to select the export enabled columns will be listed. This will also apply any filters that has been selected along with a sorting if applied. It then pushes the export to a background job which will send an excel file of the contents to the specified email. You can edit the style of the button using the class `export-to-file-btn`.
|
161
|
+
|
119
162
|
#### Model
|
163
|
+
|
164
|
+
##### V1
|
165
|
+
|
120
166
|
Enables or disables export and specifies which all columns can be
|
121
167
|
exported. Export is disabled for all columns by default.
|
122
168
|
|
@@ -152,33 +198,33 @@ For excluding only specific columns and allowing all others
|
|
152
198
|
end
|
153
199
|
```
|
154
200
|
|
155
|
-
|
201
|
+
##### V2
|
156
202
|
|
157
|
-
|
203
|
+
To use version two of column export, which supports model methods and nested associations, set it up in the spotlight initializer like this:
|
204
|
+
```ruby
|
205
|
+
# config/initializers/spotlight_search.rb
|
206
|
+
ActiveRecord::Base.include SpotlightSearch::ExportableColumns
|
158
207
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
<th>Email</th>
|
164
|
-
</tr>
|
165
|
-
<td>
|
166
|
-
<% @records.each do |record| %>
|
167
|
-
<tr>
|
168
|
-
<td><%= record.name %></td>
|
169
|
-
<td><%= record.value %></td>
|
170
|
-
<% end %>
|
171
|
-
</td>
|
172
|
-
</table>
|
208
|
+
SpotlightSearch.setup do |config|
|
209
|
+
config.exportable_columns_version = :v2
|
210
|
+
end
|
211
|
+
```
|
173
212
|
|
174
|
-
|
213
|
+
All fields will be disabled by default, so you will need to explicitly enable them by passing them to `export_columns`
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
class Person < ActiveRecord::Base
|
217
|
+
export_columns :created_at, :formatted_amount, :preferred_month, :orderable_type, :payment_type, :status, customer: [:full_name, :email, :mobile_number, :city, :college], orderable: :orderable_display_name, seller: [:full_name]
|
218
|
+
end
|
175
219
|
```
|
176
220
|
|
177
|
-
|
221
|
+
Nested association fields should go at the end of `export_columns`, following Ruby's standard syntax of placing keyword arguments at the end
|
222
|
+
|
223
|
+
**Notes**
|
224
|
+
- You will need to make `filter_params` and `sort_params` in your controller public, or the rendering of the form will fail
|
225
|
+
- Be careful with methods that return a hash, as the algorithm will recursively create one column for every key inside that hash. One example is `Money` fields from the `money-rails` gem
|
178
226
|
|
179
|
-
**Note**
|
180
227
|
|
181
|
-
You will need to have a background job processor such as `sidekiq`, `resque`, `delayed_job` etc as the file will be generated in the background and will be sent to the email passed. If you need to use any other service for sending emails, you will need to override `ExportMailer` class.
|
182
228
|
|
183
229
|
## Development
|
184
230
|
|
@@ -74,6 +74,15 @@ $(document).on('keyup', '[data-type="input-filter"]', function() {
|
|
74
74
|
});
|
75
75
|
});
|
76
76
|
|
77
|
+
$(document).on('change', '[data-type="range-filter"]', function() {
|
78
|
+
var thisObj;
|
79
|
+
thisObj = $(this);
|
80
|
+
return $(function() {
|
81
|
+
return get_paginated_list(1, thisObj);
|
82
|
+
});
|
83
|
+
});
|
84
|
+
|
85
|
+
|
77
86
|
$(document).on('change', '[data-type="select-filter"]', function() {
|
78
87
|
var thisObj;
|
79
88
|
thisObj = $(this);
|
@@ -2,17 +2,19 @@ module SpotlightSearch
|
|
2
2
|
class ExportJobsController < ApplicationController
|
3
3
|
def export_job
|
4
4
|
begin
|
5
|
-
klass = params[:
|
5
|
+
klass = params[:class_name].constantize
|
6
6
|
if klass.validate_exportable_columns(params[:columns])
|
7
|
-
|
8
|
-
|
7
|
+
(filter_params = params[:filters].permit!) if params[:filters].present?
|
8
|
+
(sort_params = params[:sort].permit!) if params[:sort].present?
|
9
|
+
ExportJob.perform_later(klass.name, params[:email], params[:columns], filter_params, sort_params)
|
10
|
+
notice = 'Successfully queued for export'
|
9
11
|
else
|
10
|
-
|
12
|
+
notice = 'Invalid columns found'
|
11
13
|
end
|
12
|
-
rescue
|
13
|
-
|
14
|
+
rescue StandardError => e
|
15
|
+
notice = e.message
|
14
16
|
ensure
|
15
|
-
redirect_back fallback_location: root_path
|
17
|
+
redirect_back fallback_location: root_path, notice: notice
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|