spotlight_search 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +108 -8
- data/README.md +70 -6
- data/app/assets/javascripts/spotlight_search.js +20 -2
- data/app/controllers/spotlight_search/export_jobs_controller.rb +21 -0
- data/app/jobs/spotlight_search/export_job.rb +49 -0
- data/app/mailers/spotlight_search/export_mailer.rb +10 -0
- data/app/views/spotlight_search/export_mailer/send_excel_file.html.erb +5 -0
- data/config/routes.rb +3 -0
- data/lib/spotlight_search/engine.rb +2 -2
- data/lib/spotlight_search/exceptions.rb +12 -0
- data/lib/spotlight_search/exportable_columns.rb +71 -0
- data/lib/spotlight_search/helpers.rb +31 -0
- data/lib/spotlight_search/version.rb +1 -1
- data/lib/spotlight_search.rb +4 -0
- data/spotlight_search.gemspec +3 -0
- metadata +36 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c89b4b5abbf14d2a5f0bd0b32ebe1f969664d6f15a1546d8da52c5350533dd2
|
4
|
+
data.tar.gz: 488483330b4d7884daa56e00b276c916eb1e880cedf17930417c94ad35edc5e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1774df1335f355630535500a67dbecd62a3291aceeb82bd957ee77fcd47664a078a653a0657cca931a22333aed4683fac9107d4219a4a3ec4a6dc7b4d5d7b689
|
7
|
+
data.tar.gz: b52de4cc8d6a3a22e2ed8b4fc76e92f4d5c8e1e71c878bb0b84676dd9f3590e64d848e5eadd2ea2d0b3b4030881a1854840a74ef4c820cdc6b7a49549a02d8e3
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,102 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
4
|
+
spotlight_search (0.1.1)
|
5
|
+
axlsx
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
8
9
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
actioncable (5.0.7.2)
|
11
|
+
actionpack (= 5.0.7.2)
|
12
|
+
nio4r (>= 1.2, < 3.0)
|
13
|
+
websocket-driver (~> 0.6.1)
|
14
|
+
actionmailer (5.0.7.2)
|
15
|
+
actionpack (= 5.0.7.2)
|
16
|
+
actionview (= 5.0.7.2)
|
17
|
+
activejob (= 5.0.7.2)
|
18
|
+
mail (~> 2.5, >= 2.5.4)
|
19
|
+
rails-dom-testing (~> 2.0)
|
20
|
+
actionpack (5.0.7.2)
|
21
|
+
actionview (= 5.0.7.2)
|
22
|
+
activesupport (= 5.0.7.2)
|
23
|
+
rack (~> 2.0)
|
24
|
+
rack-test (~> 0.6.3)
|
25
|
+
rails-dom-testing (~> 2.0)
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
+
actionview (5.0.7.2)
|
28
|
+
activesupport (= 5.0.7.2)
|
29
|
+
builder (~> 3.1)
|
30
|
+
erubis (~> 2.7.0)
|
31
|
+
rails-dom-testing (~> 2.0)
|
32
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
33
|
+
activejob (5.0.7.2)
|
34
|
+
activesupport (= 5.0.7.2)
|
35
|
+
globalid (>= 0.3.6)
|
36
|
+
activemodel (5.0.7.2)
|
37
|
+
activesupport (= 5.0.7.2)
|
38
|
+
activerecord (5.0.7.2)
|
39
|
+
activemodel (= 5.0.7.2)
|
40
|
+
activesupport (= 5.0.7.2)
|
41
|
+
arel (~> 7.0)
|
42
|
+
activesupport (5.0.7.2)
|
43
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
44
|
+
i18n (>= 0.7, < 2)
|
45
|
+
minitest (~> 5.1)
|
46
|
+
tzinfo (~> 1.1)
|
47
|
+
arel (7.1.4)
|
48
|
+
axlsx (2.0.1)
|
49
|
+
htmlentities (~> 4.3.1)
|
50
|
+
nokogiri (>= 1.4.1)
|
51
|
+
rubyzip (~> 1.0.0)
|
52
|
+
builder (3.2.3)
|
53
|
+
concurrent-ruby (1.1.5)
|
54
|
+
crass (1.0.4)
|
13
55
|
diff-lcs (1.3)
|
14
|
-
|
56
|
+
erubis (2.7.0)
|
57
|
+
globalid (0.4.2)
|
58
|
+
activesupport (>= 4.2.0)
|
59
|
+
htmlentities (4.3.4)
|
60
|
+
i18n (1.6.0)
|
61
|
+
concurrent-ruby (~> 1.0)
|
62
|
+
loofah (2.2.3)
|
63
|
+
crass (~> 1.0.2)
|
64
|
+
nokogiri (>= 1.5.9)
|
65
|
+
mail (2.7.1)
|
66
|
+
mini_mime (>= 0.1.1)
|
67
|
+
method_source (0.9.2)
|
68
|
+
mini_mime (1.0.1)
|
69
|
+
mini_portile2 (2.4.0)
|
70
|
+
minitest (5.11.3)
|
71
|
+
nio4r (2.3.1)
|
72
|
+
nokogiri (1.10.3)
|
73
|
+
mini_portile2 (~> 2.4.0)
|
74
|
+
rack (2.0.7)
|
75
|
+
rack-test (0.6.3)
|
76
|
+
rack (>= 1.0)
|
77
|
+
rails (5.0.7.2)
|
78
|
+
actioncable (= 5.0.7.2)
|
79
|
+
actionmailer (= 5.0.7.2)
|
80
|
+
actionpack (= 5.0.7.2)
|
81
|
+
actionview (= 5.0.7.2)
|
82
|
+
activejob (= 5.0.7.2)
|
83
|
+
activemodel (= 5.0.7.2)
|
84
|
+
activerecord (= 5.0.7.2)
|
85
|
+
activesupport (= 5.0.7.2)
|
86
|
+
bundler (>= 1.3.0)
|
87
|
+
railties (= 5.0.7.2)
|
88
|
+
sprockets-rails (>= 2.0.0)
|
89
|
+
rails-dom-testing (2.0.3)
|
90
|
+
activesupport (>= 4.2.0)
|
91
|
+
nokogiri (>= 1.6)
|
92
|
+
rails-html-sanitizer (1.0.4)
|
93
|
+
loofah (~> 2.2, >= 2.2.2)
|
94
|
+
railties (5.0.7.2)
|
95
|
+
actionpack (= 5.0.7.2)
|
96
|
+
activesupport (= 5.0.7.2)
|
97
|
+
method_source
|
98
|
+
rake (>= 0.8.7)
|
99
|
+
thor (>= 0.18.1, < 2.0)
|
15
100
|
rake (10.5.0)
|
16
101
|
rspec (3.8.0)
|
17
102
|
rspec-core (~> 3.8.0)
|
@@ -26,16 +111,31 @@ GEM
|
|
26
111
|
diff-lcs (>= 1.2.0, < 2.0)
|
27
112
|
rspec-support (~> 3.8.0)
|
28
113
|
rspec-support (3.8.0)
|
114
|
+
rubyzip (1.0.0)
|
115
|
+
sprockets (3.7.2)
|
116
|
+
concurrent-ruby (~> 1.0)
|
117
|
+
rack (> 1, < 3)
|
118
|
+
sprockets-rails (3.2.1)
|
119
|
+
actionpack (>= 4.0)
|
120
|
+
activesupport (>= 4.0)
|
121
|
+
sprockets (>= 3.0.0)
|
122
|
+
thor (0.20.3)
|
123
|
+
thread_safe (0.3.6)
|
124
|
+
tzinfo (1.2.5)
|
125
|
+
thread_safe (~> 0.1)
|
126
|
+
websocket-driver (0.6.5)
|
127
|
+
websocket-extensions (>= 0.1.0)
|
128
|
+
websocket-extensions (0.1.4)
|
29
129
|
|
30
130
|
PLATFORMS
|
31
131
|
ruby
|
32
132
|
|
33
133
|
DEPENDENCIES
|
34
134
|
bundler (~> 2.0)
|
35
|
-
|
135
|
+
rails (~> 5.0.7)
|
36
136
|
rake (~> 10.0)
|
37
137
|
rspec (~> 3.0)
|
38
|
-
|
138
|
+
spotlight_search!
|
39
139
|
|
40
140
|
BUNDLED WITH
|
41
141
|
2.0.1
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# SpotlightSearch
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
It helps filtering, sorting and exporting tables easier.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -16,7 +14,7 @@ And then execute:
|
|
16
14
|
|
17
15
|
$ bundle
|
18
16
|
|
19
|
-
Or install it
|
17
|
+
Or install it manually:
|
20
18
|
|
21
19
|
$ gem install spotlight_search
|
22
20
|
|
@@ -86,6 +84,72 @@ If any of the header needs to be sorted, then we will add the following helper
|
|
86
84
|
th = sortable "name", "Name", @filtered_result.sort[:sort_column], @filtered_result.sort[:sort_direction]
|
87
85
|
```
|
88
86
|
|
87
|
+
### Export to file
|
88
|
+
|
89
|
+
#### Model
|
90
|
+
Enables or disables export and specifies which all columns can be
|
91
|
+
exported. Export is disabled for all columns by default.
|
92
|
+
|
93
|
+
For enabling export for all columns in all models
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
class ApplicationRecord < ActiveRecord::Base
|
97
|
+
export_columns enabled: true
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
For disabling export for only specific models
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
class Person < ActiveRecord::Base
|
105
|
+
export_columns enabled: false
|
106
|
+
end
|
107
|
+
```
|
108
|
+
|
109
|
+
For allowing export for only specific columns in a model
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
class Person < ActiveRecord::Base
|
113
|
+
export_columns enabled: true, only: [:created_at, :updated_at]
|
114
|
+
end
|
115
|
+
```
|
116
|
+
|
117
|
+
For excluding only specific columns and allowing all others
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
class Person < ActiveRecord::Base
|
121
|
+
export_columns enabled: true, except: [:created_at, :updated_at]
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
#### View
|
126
|
+
|
127
|
+
Add `exportable email, model_object` in your view to display the export button.
|
128
|
+
|
129
|
+
```html+erb
|
130
|
+
<table>
|
131
|
+
<tr>
|
132
|
+
<th>Name</th>
|
133
|
+
<th>Email</th>
|
134
|
+
</tr>
|
135
|
+
<td>
|
136
|
+
<% @records.each do |record| %>
|
137
|
+
<tr>
|
138
|
+
<td><%= record.name %></td>
|
139
|
+
<td><%= record.value %></td>
|
140
|
+
<% end %>
|
141
|
+
</td>
|
142
|
+
</table>
|
143
|
+
|
144
|
+
<%= exportable(current_user.email, current_user.class) %>
|
145
|
+
```
|
146
|
+
|
147
|
+
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`.
|
148
|
+
|
149
|
+
**Note**
|
150
|
+
|
151
|
+
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.
|
152
|
+
|
89
153
|
## Development
|
90
154
|
|
91
155
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -94,7 +158,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
94
158
|
|
95
159
|
## Contributing
|
96
160
|
|
97
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
161
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/commutatus/spotlight_search. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
98
162
|
|
99
163
|
## License
|
100
164
|
|
@@ -102,4 +166,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
102
166
|
|
103
167
|
## Code of Conduct
|
104
168
|
|
105
|
-
Everyone interacting in the SpotlightSearch project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
169
|
+
Everyone interacting in the SpotlightSearch project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/commutatus/spotlight_search/blob/master/CODE_OF_CONDUCT.md).
|
@@ -90,5 +90,23 @@ $(document).on('click', '[data-type="anchor-filter"]', function() {
|
|
90
90
|
});
|
91
91
|
});
|
92
92
|
|
93
|
-
|
94
|
-
|
93
|
+
$(document).on('click', '#export-to-file-btn', function(event) {
|
94
|
+
event.preventDefault();
|
95
|
+
$(this).attr('disabled', true);
|
96
|
+
var filter_params, query_string, sort_column, sort_direction;
|
97
|
+
sort_column = $('[data-behaviour="current-page"]').data('sort-column');
|
98
|
+
sort_direction = $('[data-behaviour="current-page"]').data('sort-direction');
|
99
|
+
filter_params = {};
|
100
|
+
$('[data-behaviour="filter"]').each(function(index) {
|
101
|
+
filter_params[$(this).data('scope')] = $(this).val();
|
102
|
+
});
|
103
|
+
body = {
|
104
|
+
filters: filter_params,
|
105
|
+
sort: {
|
106
|
+
sort_column: sort_column,
|
107
|
+
sort_direction: sort_direction
|
108
|
+
}
|
109
|
+
}
|
110
|
+
$('#export-to-file-filters').value(body);
|
111
|
+
$('#export-to-file-form').submit();
|
112
|
+
});
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SpotlightSearch
|
2
|
+
class ExportJobsController < ApplicationController
|
3
|
+
include SpotlightSearch::Concerns::Exportable
|
4
|
+
|
5
|
+
def export_job
|
6
|
+
begin
|
7
|
+
klass = params[:klass].constantize
|
8
|
+
if klass.validate_exportable_columns(params[:columns])
|
9
|
+
ExportJob.perform_later(params[:email], klass, params[:columns], params[:filters])
|
10
|
+
flash[:success] = 'Successfully queued for export'
|
11
|
+
else
|
12
|
+
flash[:error] = 'Invalid columns found'
|
13
|
+
end
|
14
|
+
rescue
|
15
|
+
flash[:error] = 'No records to import'
|
16
|
+
ensure
|
17
|
+
redirect_back fallback_location: root_path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module SpotlightSearch
|
2
|
+
class ExportJob < ApplicationJob
|
3
|
+
def perform(email, klass, columns = nil, filters = nil)
|
4
|
+
records = get_records(klass, filters, columns)
|
5
|
+
file_path = create_excel(records, klass.name)
|
6
|
+
subject = "#{klass.name} export at #{Time.now}"
|
7
|
+
ExportMailer.send_excel_file(email, file_path, subject).deliver_now
|
8
|
+
File.delete(file_path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_records(klass, filters, columns)
|
12
|
+
records = klass
|
13
|
+
if filters['filters'].present?
|
14
|
+
filters['filters'].each do |scope, scope_args|
|
15
|
+
if scope_args.is_a?(Array)
|
16
|
+
records = records.send(scope, *scope_args)
|
17
|
+
else
|
18
|
+
records = records.send(scope, scope_args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
if filters['sort'].present?
|
23
|
+
records = records.order("#{filters['sort']['sort_column']} #{filters['sort']['sort_direction']}")
|
24
|
+
end
|
25
|
+
columns = columns.map(&:to_sym)
|
26
|
+
records.select(*columns)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Creating excel with the passed records
|
30
|
+
# Keys as headers and values as row
|
31
|
+
def create_excel(records, klass)
|
32
|
+
records = records.as_json
|
33
|
+
headers = records.first.keys
|
34
|
+
size_arr = []
|
35
|
+
headers.size.times { size_arr << 22 }
|
36
|
+
xl = Axlsx::Package.new
|
37
|
+
xl.workbook.add_worksheet do |sheet|
|
38
|
+
sheet.add_row headers, b: true
|
39
|
+
records.each do |record|
|
40
|
+
sheet.add_row record.values
|
41
|
+
end
|
42
|
+
sheet.column_widths *size_arr
|
43
|
+
end
|
44
|
+
file_location = "#{Rails.root}/public/export_#{klass}_#{Time.now.to_s}"
|
45
|
+
xl.serialize(file_location)
|
46
|
+
file_location
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module SpotlightSearch
|
2
|
+
class ExportMailer < ActionMailer::Base
|
3
|
+
default from: "no-reply@#{Rails.application.config.action_mailer.default_url_options[:host]}"
|
4
|
+
|
5
|
+
def send_excel_file(email, file_path, subject)
|
6
|
+
attachments[file_path.split('/').last] = File.read(file_path)
|
7
|
+
mail(to: email, subject: subject)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module SpotlightSearch
|
2
|
+
module Exceptions
|
3
|
+
class InvalidColumns < StandardError
|
4
|
+
def initialize(columns: [])
|
5
|
+
message = 'Invalid columns found: ' + columns.map(&:to_s).join(', ')
|
6
|
+
super(message)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class InvalidValue < StandardError; end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module SpotlightSearch
|
2
|
+
module ExportableColumns
|
3
|
+
cattr_accessor :enabled_columns, :export_enabled
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
# Enables or disables export and specifies which all columns can be
|
7
|
+
# exported. For enabling export for all columns in all models
|
8
|
+
#
|
9
|
+
# class ApplicationRecord < ActiveRecord::Base
|
10
|
+
# export_columns enabled: true
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# For disabling export for only specific models
|
14
|
+
#
|
15
|
+
# class Person < ActiveRecord::Base
|
16
|
+
# export_columns enabled: false
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# For allowing export for only specific columns in a model
|
20
|
+
#
|
21
|
+
# class Person < ActiveRecord::Base
|
22
|
+
# export_columns enabled: true, only: [:created_at, :updated_at]
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# For excluding only specific columns and allowing all others
|
26
|
+
#
|
27
|
+
# class Person < ActiveRecord::Base
|
28
|
+
# export_columns enabled: true, except: [:created_at, :updated_at]
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
def export_columns(enabled: false, only: nil, except: nil)
|
32
|
+
if enabled
|
33
|
+
@@export_enabled = true
|
34
|
+
all_columns = self.column_names.map(&:to_sym)
|
35
|
+
if only.present?
|
36
|
+
unless (valid_columns = only & all_columns).size == only.size
|
37
|
+
invalid_columns = only - valid_columns
|
38
|
+
raise SpotlightSearch::Exceptions::InvalidColumns.new(nil, invalid_columns)
|
39
|
+
end
|
40
|
+
@@enabled_columns = only
|
41
|
+
else
|
42
|
+
@@enabled_columns = all_columns
|
43
|
+
end
|
44
|
+
if except.present?
|
45
|
+
unless (valid_columns = except & all_columns).size == only.size
|
46
|
+
invalid_columns = except - valid_columns
|
47
|
+
raise SpotlightSearch::Exceptions::InvalidColumns.new(nil, invalid_columns)
|
48
|
+
end
|
49
|
+
@@enabled_columns = @@enabled_columns - except
|
50
|
+
end
|
51
|
+
else
|
52
|
+
@@export_enabled = false
|
53
|
+
@@enabled_columns = nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Validates whether the selected columns are allowed for export
|
58
|
+
def validate_exportable_columns(columns)
|
59
|
+
unless columns.is_a?(Array)
|
60
|
+
raise SpotlightSearch::Exceptions::InvalidValue.new('Excepted Array. Invalid type received')
|
61
|
+
end
|
62
|
+
unless (@@enabled_columns & columns.map(&:to_sym)) == columns.size
|
63
|
+
return false
|
64
|
+
end
|
65
|
+
return true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
ActiveRecord::Base.extend SpotlightSearch::ExportableColumns
|
@@ -9,6 +9,37 @@ module SpotlightSearch
|
|
9
9
|
content_tag("a","Title", class: css_class, data: {sort_column: column, sort_direction: direction, behaviour: 'sort', type: 'anchor-filter'})
|
10
10
|
end
|
11
11
|
|
12
|
+
def exportable(email, klass)
|
13
|
+
tag.button "Export as excel", class: "modal-btn", data: {toggle: "modal", target: "#exportmodal"}
|
14
|
+
tag.div class: "modal fade", id: "exportmodal", tabindex: "-1", role: "dialog", aria: {labelledby: "exportModal"} do
|
15
|
+
tag.div class: "modal-dialog", role: "document" do
|
16
|
+
tag.div class: "modal-content" do
|
17
|
+
tag.div class: "modal-header" do
|
18
|
+
tag.button type: "button", class: "close", data: {dismiss: "modal"}, aria: {label: "Close"} do
|
19
|
+
tag.span "X", aria: {hidden: "true"}
|
20
|
+
end
|
21
|
+
tag.h4 "Select columns to export", class: "modal-title", id: "exportModal"
|
22
|
+
end
|
23
|
+
tag.div class: "modal-body" do
|
24
|
+
form_tag '/export_to_file', id: 'export-to-file-form' do
|
25
|
+
hidden_field_tag 'email', email, id: 'export-to-file-email'
|
26
|
+
hidden_field_tag 'filters', nil, id: 'export-to-file-filters'
|
27
|
+
hidden_field_tag 'klass', klass.to_s, id: 'export-to-file-klass'
|
28
|
+
klass.enabled_columns.each do |column_name|
|
29
|
+
tag.div class: "row" do
|
30
|
+
tag.div class: "col-md-4" do
|
31
|
+
check_box_tag "columns[]", column_name
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
submit_tag 'Export as excel', class: 'btn btn-bordered export-to-file-btn'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
12
43
|
def cm_paginate(facets)
|
13
44
|
tag.div class: 'text-center' do
|
14
45
|
tag.div class: 'nav navbar navbar-inner' do
|
data/lib/spotlight_search.rb
CHANGED
@@ -4,6 +4,10 @@ require 'spotlight_search/railtie' if defined?(Rails)
|
|
4
4
|
|
5
5
|
module SpotlightSearch
|
6
6
|
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
autoload :Exceptions, 'spotlight_search/exceptions'
|
9
|
+
autoload :ExportableColumns, 'spotlight_search/exportable_columns'
|
10
|
+
|
7
11
|
module ClassMethods
|
8
12
|
def filter_by(page, filter_params = {}, sort_params = {})
|
9
13
|
filtered_result = OpenStruct.new
|
data/spotlight_search.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
lib = File.expand_path("../lib", __FILE__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
# Dir.glob("./**/**/*.rb").each { |path| require path }
|
3
4
|
require "spotlight_search/version"
|
4
5
|
|
5
6
|
Gem::Specification.new do |s|
|
@@ -24,5 +25,7 @@ Gem::Specification.new do |s|
|
|
24
25
|
|
25
26
|
s.add_development_dependency "bundler", "~> 2.0"
|
26
27
|
s.add_development_dependency "rake", "~> 10.0"
|
28
|
+
s.add_development_dependency "rails", "~> 5.0.7"
|
27
29
|
s.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
s.add_runtime_dependency 'axlsx'
|
28
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spotlight_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anbazhagan Palani
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.0.7
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.0.7
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: axlsx
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description: |-
|
56
84
|
This gem should help reduce the efforts in the admin panel.
|
57
85
|
It has search, sort and pagination included
|
@@ -70,10 +98,17 @@ files:
|
|
70
98
|
- app/.DS_Store
|
71
99
|
- app/assets/javascripts/spotlight_search.js
|
72
100
|
- app/assets/javascripts/spotlight_search_main.js
|
101
|
+
- app/controllers/spotlight_search/export_jobs_controller.rb
|
102
|
+
- app/jobs/spotlight_search/export_job.rb
|
103
|
+
- app/mailers/spotlight_search/export_mailer.rb
|
104
|
+
- app/views/spotlight_search/export_mailer/send_excel_file.html.erb
|
73
105
|
- bin/console
|
74
106
|
- bin/setup
|
107
|
+
- config/routes.rb
|
75
108
|
- lib/spotlight_search.rb
|
76
109
|
- lib/spotlight_search/engine.rb
|
110
|
+
- lib/spotlight_search/exceptions.rb
|
111
|
+
- lib/spotlight_search/exportable_columns.rb
|
77
112
|
- lib/spotlight_search/helpers.rb
|
78
113
|
- lib/spotlight_search/railtie.rb
|
79
114
|
- lib/spotlight_search/version.rb
|