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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c89b4b5abbf14d2a5f0bd0b32ebe1f969664d6f15a1546d8da52c5350533dd2
4
- data.tar.gz: 488483330b4d7884daa56e00b276c916eb1e880cedf17930417c94ad35edc5e9
3
+ metadata.gz: ebb484f3b104c1ed0b34ed7e4ba4dac94e2632b36911cf3697fa3f30d23330b3
4
+ data.tar.gz: 6ffabe8806b83e10a7f86bb959fec8d17e508f6f11d2508a93da0be9f4cc49e3
5
5
  SHA512:
6
- metadata.gz: 1774df1335f355630535500a67dbecd62a3291aceeb82bd957ee77fcd47664a078a653a0657cca931a22333aed4683fac9107d4219a4a3ec4a6dc7b4d5d7b689
7
- data.tar.gz: b52de4cc8d6a3a22e2ed8b4fc76e92f4d5c8e1e71c878bb0b84676dd9f3590e64d848e5eadd2ea2d0b3b4030881a1854840a74ef4c820cdc6b7a49549a02d8e3
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
- After installing the gem to the project, there are few places you will have to make changes.
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
- ### Controller
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
- ### HTML
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 add the following helper
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 file
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
- cattr_accessor :enabled_columns, :export_enabled
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
- @@export_enabled = true
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
- @@enabled_columns = only
40
+ self.enabled_columns = only
41
41
  else
42
- @@enabled_columns = all_columns
42
+ self.enabled_columns = all_columns
43
43
  end
44
44
  if except.present?
45
- unless (valid_columns = except & all_columns).size == only.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
- @@enabled_columns = @@enabled_columns - except
49
+ self.enabled_columns = self.enabled_columns - except
50
50
  end
51
51
  else
52
- @@export_enabled = false
53
- @@enabled_columns = nil
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 (@@enabled_columns & columns.map(&:to_sym)) == columns.size
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
@@ -1,3 +1,3 @@
1
1
  module SpotlightSearch
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -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
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
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anbazhagan Palani