spotlight_search 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -6
- data/lib/spotlight_search/exportable_columns.rb +14 -11
- data/lib/spotlight_search/version.rb +1 -1
- data/lib/spotlight_search.rb +3 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebb484f3b104c1ed0b34ed7e4ba4dac94e2632b36911cf3697fa3f30d23330b3
|
4
|
+
data.tar.gz: 6ffabe8806b83e10a7f86bb959fec8d17e508f6f11d2508a93da0be9f4cc49e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58e302960d4d8d7ac6ee92f3341f322929cd2a005367fa03f5ae71f8ed6b8516aa59640bfe96618e66bd59504c9ae02347ba58895ec76e6703d2886e1f214785
|
7
|
+
data.tar.gz: 7acb7215272cb8c7aca91d51f80867ae658d95fbed6adba0179768a331bff8e52f87386a6a9a69f7008a2cd3d1c9071cde3bb2acad6da46e5862af8eb13de94e
|
data/README.md
CHANGED
@@ -20,9 +20,17 @@ Or install it manually:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
1. [Filtering, Sorting and Pagination](#filtering-sorting-and-pagination)
|
24
|
+
* [Controller](#controller)
|
25
|
+
* [View](#view)
|
26
|
+
2. [Export table data to excel](#export-table-data-to-excel)
|
27
|
+
* [Initializer](#initializer)
|
28
|
+
* [Model](#model)
|
29
|
+
* [View](#export-view)
|
24
30
|
|
25
|
-
###
|
31
|
+
### Filtering, Sorting and Pagination
|
32
|
+
|
33
|
+
#### Controller
|
26
34
|
|
27
35
|
**STEP - 1**
|
28
36
|
|
@@ -50,7 +58,9 @@ def sort_params
|
|
50
58
|
end
|
51
59
|
```
|
52
60
|
|
53
|
-
|
61
|
+
#### View
|
62
|
+
Please note that the below code is in haml.
|
63
|
+
|
54
64
|
**STEP - 1 Search**
|
55
65
|
|
56
66
|
First step is to add the input box to search. Here there are few elements that should be placed mandatorily.
|
@@ -79,12 +89,20 @@ We will add the paginate helper to the bottom of the partial which gets replaced
|
|
79
89
|
|
80
90
|
**STEP - 3 Sort**
|
81
91
|
|
82
|
-
If any of the header needs to be sorted, then we will
|
92
|
+
If any of the header needs to be sorted, then we will add the following helper
|
83
93
|
```
|
84
94
|
th = sortable "name", "Name", @filtered_result.sort[:sort_column], @filtered_result.sort[:sort_direction]
|
85
95
|
```
|
86
96
|
|
87
|
-
### Export to
|
97
|
+
### Export table data to excel
|
98
|
+
|
99
|
+
#### Initializer
|
100
|
+
An initializer will have to be created to extend the functionality to ActiveRecord.
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
# config/initializers/spotlight_search.rb
|
104
|
+
ActiveRecord::Base.include SpotlightSearch::ExportableColumns
|
105
|
+
```
|
88
106
|
|
89
107
|
#### Model
|
90
108
|
Enables or disables export and specifies which all columns can be
|
@@ -122,7 +140,7 @@ For excluding only specific columns and allowing all others
|
|
122
140
|
end
|
123
141
|
```
|
124
142
|
|
125
|
-
#### View
|
143
|
+
#### <a name="export-view"></a>View
|
126
144
|
|
127
145
|
Add `exportable email, model_object` in your view to display the export button.
|
128
146
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SpotlightSearch
|
2
2
|
module ExportableColumns
|
3
|
-
|
3
|
+
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
module ClassMethods
|
6
6
|
# Enables or disables export and specifies which all columns can be
|
@@ -30,27 +30,27 @@ module SpotlightSearch
|
|
30
30
|
#
|
31
31
|
def export_columns(enabled: false, only: nil, except: nil)
|
32
32
|
if enabled
|
33
|
-
|
33
|
+
self.export_enabled = true
|
34
34
|
all_columns = self.column_names.map(&:to_sym)
|
35
35
|
if only.present?
|
36
36
|
unless (valid_columns = only & all_columns).size == only.size
|
37
37
|
invalid_columns = only - valid_columns
|
38
38
|
raise SpotlightSearch::Exceptions::InvalidColumns.new(nil, invalid_columns)
|
39
39
|
end
|
40
|
-
|
40
|
+
self.enabled_columns = only
|
41
41
|
else
|
42
|
-
|
42
|
+
self.enabled_columns = all_columns
|
43
43
|
end
|
44
44
|
if except.present?
|
45
|
-
unless (valid_columns = except & all_columns).size ==
|
45
|
+
unless (valid_columns = except & all_columns).size == except.size
|
46
46
|
invalid_columns = except - valid_columns
|
47
47
|
raise SpotlightSearch::Exceptions::InvalidColumns.new(nil, invalid_columns)
|
48
48
|
end
|
49
|
-
|
49
|
+
self.enabled_columns = self.enabled_columns - except
|
50
50
|
end
|
51
51
|
else
|
52
|
-
|
53
|
-
|
52
|
+
self.export_enabled = false
|
53
|
+
self.enabled_columns = nil
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -59,13 +59,16 @@ module SpotlightSearch
|
|
59
59
|
unless columns.is_a?(Array)
|
60
60
|
raise SpotlightSearch::Exceptions::InvalidValue.new('Excepted Array. Invalid type received')
|
61
61
|
end
|
62
|
-
unless (
|
62
|
+
unless (self.enabled_columns & columns.map(&:to_sym)) == columns.size
|
63
63
|
return false
|
64
64
|
end
|
65
65
|
return true
|
66
66
|
end
|
67
67
|
end
|
68
|
+
|
69
|
+
included do
|
70
|
+
class_attribute :enabled_columns, instance_accessor: false
|
71
|
+
class_attribute :export_enabled, instance_accessor: false
|
72
|
+
end
|
68
73
|
end
|
69
74
|
end
|
70
|
-
|
71
|
-
ActiveRecord::Base.extend SpotlightSearch::ExportableColumns
|
data/lib/spotlight_search.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'spotlight_search/engine'
|
2
2
|
require 'spotlight_search/version'
|
3
|
+
require 'spotlight_search/exportable_columns'
|
3
4
|
require 'spotlight_search/railtie' if defined?(Rails)
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_support/rails'
|
4
7
|
|
5
8
|
module SpotlightSearch
|
6
9
|
extend ActiveSupport::Concern
|
7
10
|
|
8
11
|
autoload :Exceptions, 'spotlight_search/exceptions'
|
9
|
-
autoload :ExportableColumns, 'spotlight_search/exportable_columns'
|
10
12
|
|
11
13
|
module ClassMethods
|
12
14
|
def filter_by(page, filter_params = {}, sort_params = {})
|
@@ -62,5 +64,4 @@ module SpotlightSearch
|
|
62
64
|
return facets
|
63
65
|
end
|
64
66
|
end
|
65
|
-
|
66
67
|
end
|