spotlight_search 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -1
- data/app/controllers/spotlight_search/export_jobs_controller.rb +1 -3
- data/app/jobs/spotlight_search/export_job.rb +15 -10
- data/lib/spotlight_search/helpers.rb +54 -23
- data/lib/spotlight_search/version.rb +1 -1
- data/spotlight_search.gemspec +1 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc74895f3a5f55970160db1457820b6f00334528d14cfbb7f2bf693afe3ff972
|
4
|
+
data.tar.gz: 71060fb2c54856d67a85a4d2c97b49933c2bacc459bd3d52ecc6105ace9740d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13be0c5c2c695c350f63a16c1c24c73645ad6768993f7afbe6dec22d0be2db58a3d3e1227cbfffa91adc83937caaadee0128b6ed2fd0cae1764452e46354619a
|
7
|
+
data.tar.gz: 70e6cca5f7ccce8297fb72497b6e3f54eeaaa76ea4903ec546ab1dc946b2ef2e62f232845cd7e3ce462a899de465aaea29987ef37dbe59a970b7a95090f2250d
|
data/README.md
CHANGED
@@ -25,6 +25,7 @@ Or install it manually:
|
|
25
25
|
* [View](#view)
|
26
26
|
2. [Export table data to excel](#export-table-data-to-excel)
|
27
27
|
* [Initializer](#initializer)
|
28
|
+
* [Routes](#Routes)
|
28
29
|
* [Model](#model)
|
29
30
|
* [View](#export-view)
|
30
31
|
|
@@ -104,6 +105,13 @@ An initializer will have to be created to extend the functionality to ActiveReco
|
|
104
105
|
ActiveRecord::Base.include SpotlightSearch::ExportableColumns
|
105
106
|
```
|
106
107
|
|
108
|
+
#### Routes
|
109
|
+
A line has to be added to the routes.
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
mount SpotlightSearch::Engine => '/spotlight_search'
|
113
|
+
```
|
114
|
+
|
107
115
|
#### Model
|
108
116
|
Enables or disables export and specifies which all columns can be
|
109
117
|
exported. Export is disabled for all columns by default.
|
@@ -166,7 +174,7 @@ This will first show a popup where an option to select the export enabled column
|
|
166
174
|
|
167
175
|
**Note**
|
168
176
|
|
169
|
-
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.
|
177
|
+
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.
|
170
178
|
|
171
179
|
## Development
|
172
180
|
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module SpotlightSearch
|
2
2
|
class ExportJobsController < ApplicationController
|
3
|
-
include SpotlightSearch::Concerns::Exportable
|
4
|
-
|
5
3
|
def export_job
|
6
4
|
begin
|
7
5
|
klass = params[:klass].constantize
|
8
6
|
if klass.validate_exportable_columns(params[:columns])
|
9
|
-
ExportJob.perform_later(params[:email], klass, params[:columns], params[:filters])
|
7
|
+
ExportJob.perform_later(params[:email], klass.to_s, params[:columns], params[:filters])
|
10
8
|
flash[:success] = 'Successfully queued for export'
|
11
9
|
else
|
12
10
|
flash[:error] = 'Invalid columns found'
|
@@ -1,6 +1,9 @@
|
|
1
|
+
require 'axlsx'
|
2
|
+
|
1
3
|
module SpotlightSearch
|
2
4
|
class ExportJob < ApplicationJob
|
3
|
-
def perform(email, klass, columns =
|
5
|
+
def perform(email, klass, columns = [], filters = {})
|
6
|
+
klass = klass.constantize
|
4
7
|
records = get_records(klass, filters, columns)
|
5
8
|
file_path = create_excel(records, klass.name)
|
6
9
|
subject = "#{klass.name} export at #{Time.now}"
|
@@ -10,17 +13,19 @@ module SpotlightSearch
|
|
10
13
|
|
11
14
|
def get_records(klass, filters, columns)
|
12
15
|
records = klass
|
13
|
-
if filters
|
14
|
-
filters['filters'].
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
if filters
|
17
|
+
if filters['filters'].present?
|
18
|
+
filters['filters'].each do |scope, scope_args|
|
19
|
+
if scope_args.is_a?(Array)
|
20
|
+
records = records.send(scope, *scope_args)
|
21
|
+
else
|
22
|
+
records = records.send(scope, scope_args)
|
23
|
+
end
|
19
24
|
end
|
20
25
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
26
|
+
if filters['sort'].present?
|
27
|
+
records = records.order("#{filters['sort']['sort_column']} #{filters['sort']['sort_direction']}")
|
28
|
+
end
|
24
29
|
end
|
25
30
|
columns = columns.map(&:to_sym)
|
26
31
|
records.select(*columns)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module SpotlightSearch
|
2
2
|
module Helpers
|
3
|
+
include ActionView::Helpers::FormTagHelper
|
4
|
+
include ActionView::Helpers::TagHelper
|
3
5
|
|
4
6
|
def sortable(column, title = nil, sort_column="created_at", sort_direction="asc")
|
5
7
|
title ||= column.titleize
|
@@ -10,36 +12,65 @@ module SpotlightSearch
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def exportable(email, klass)
|
13
|
-
tag.
|
15
|
+
tag.div do
|
16
|
+
concat tag.button "Export as excel", class: "modal-btn", data: {toggle: "modal", target: "#exportmodal"}
|
17
|
+
concat column_pop_up(email, klass)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def column_pop_up(email, klass)
|
14
22
|
tag.div class: "modal fade", id: "exportmodal", tabindex: "-1", role: "dialog", aria: {labelledby: "exportModal"} do
|
15
|
-
tag.div class: "modal-dialog", role: "document" do
|
23
|
+
tag.div class: "modal-dialog modal-lg", role: "document" do
|
16
24
|
tag.div class: "modal-content" do
|
17
|
-
|
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
|
25
|
+
concat pop_ups(email, klass)
|
38
26
|
end
|
39
27
|
end
|
40
28
|
end
|
41
29
|
end
|
42
30
|
|
31
|
+
def pop_ups(email, klass)
|
32
|
+
tag.div do
|
33
|
+
concat pop_up_header
|
34
|
+
concat pop_up_body(email, klass)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def pop_up_header
|
39
|
+
tag.div class: "modal-header" do
|
40
|
+
tag.button type: "button", class: "close", data: {dismiss: "modal"}, aria: {label: "Close"} do
|
41
|
+
tag.span "X", aria: {hidden: "true"}
|
42
|
+
end
|
43
|
+
tag.h4 "Select columns to export", class: "modal-title", id: "exportModal"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def pop_up_body(email, klass)
|
48
|
+
tag.div class: "modal-body" do
|
49
|
+
form_tag '/spotlight_search/export_to_file', id: 'export-to-file-form', style: "width: 100%;" do
|
50
|
+
concat hidden_field_tag 'email', email, id: 'export-to-file-email'
|
51
|
+
concat hidden_field_tag 'filters', nil, id: 'export-to-file-filters'
|
52
|
+
concat hidden_field_tag 'klass', klass.to_s, id: 'export-to-file-klass'
|
53
|
+
concat checkbox_row(klass)
|
54
|
+
concat submit_tag 'Export as excel', class: 'btn btn-bordered export-to-file-btn'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def checkbox_row(klass)
|
60
|
+
tag.div class: "row" do
|
61
|
+
klass.enabled_columns.each do |column_name|
|
62
|
+
concat create_checkbox(column_name)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_checkbox(column_name)
|
68
|
+
tag.div class: "col-md-4" do
|
69
|
+
concat check_box_tag "columns[]", column_name.to_s
|
70
|
+
concat column_name.to_s
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
43
74
|
def cm_paginate(facets)
|
44
75
|
tag.div class: 'text-center' do
|
45
76
|
tag.div class: 'nav navbar navbar-inner' do
|
data/spotlight_search.gemspec
CHANGED
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anbazhagan Palani
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: zip-zip
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: |-
|
84
98
|
This gem should help reduce the efforts in the admin panel.
|
85
99
|
It has search, sort and pagination included
|