spotlight_search 0.1.2 → 0.1.3

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: 191b3e2e1a54c91a8c1b89722ef097af03e9072055b54ba5d8b0fb050bd6ea1d
4
- data.tar.gz: 0bd5fbfe2bde866d094861155e8e2e1ee11282f2f5784165b647855a0696b6ce
3
+ metadata.gz: fcbc12f0614877e2fc4dd201b0885d74c6ae169b4cbb56760ee3db5bc1f11ce4
4
+ data.tar.gz: c5a8e1299b3b4cc5b2ae8113e66e8afb1e6a08b57cadf526c45780b935b808ba
5
5
  SHA512:
6
- metadata.gz: 9c29cb1e8b6d38ea27ea60ca7b8202b68cf586ac6085e0e036538e5dbd61fd0aafda62b57ff42d8e290a4cefc9989bb565fe8f9315e676f1bae4783373e0110d
7
- data.tar.gz: 981982dbdd5dc0f8b4bfd9130543f56317b93334af064f6a5f346201144c6f64c252c2d03234edda8f25453baa3cee4cc75b1960fa12d39537b3bd6bc7453010
6
+ metadata.gz: 90221663054cdbff4fcdc9293998a272aee5926548912fed9ad98441b8e294a18cb24b5dc871d78cf52eb27e90d5f8b57aa43ab7aaa4143928335ba3add7c56f
7
+ data.tar.gz: 126fc9efce631043f391d16f23af181963817648f113d230124e80e56e383fb5b4d9dd98fe3d5fc9c65f2da1d076a98186c9ed1d8cb9989e1c6552cc4989e040
data/README.md CHANGED
@@ -22,7 +22,69 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ After installing the gem to the project, there are few places you will have to make changes.
26
+
27
+ ### Controller
28
+
29
+ **STEP - 1**
30
+
31
+ First step is to add the search method to the index action.
32
+
33
+ ```
34
+ @filtered_result = @workshop.filter_by(params[:page], filter_params.to_h, sort_params.to_h)
35
+ ```
36
+
37
+ `filter_by` is the search method which accepts 3 arguments. `page`, `filter_params`, `sort_params`.
38
+ All 3 params are sent from the JS which is handled by the gem.
39
+
40
+ **STEP - 2**
41
+
42
+ Second Step is to add the permitted params. Since the JS is taking up values from HTML,
43
+ we do not want all params to be accepted. Permit only the scopes that you want to allow.
44
+
45
+ ```
46
+ def filter_params
47
+ params.require(:filters).permit(:search) if params[:filters]
48
+ end
49
+
50
+ def sort_params
51
+ params.require(:sort).permit(:sort_column, :sort_direction) if params[:sort]
52
+ end
53
+ ```
54
+
55
+ ### HTML
56
+ **STEP - 1 Search**
57
+
58
+ First step is to add the input box to search. Here there are few elements that should be placed mandatorily.
59
+
60
+ ```
61
+ .filters.w-100 data-filter-url="/admin/workshops" data-replacement-class="workshops_table"
62
+ .col-md-4.input-group.search
63
+ input#workshop-search-filter.form-control.filter-box name=("search_term_for_workshops ") placeholder=("Search Workshops") type="text" data-behaviour="filter" data-scope="search" data-type="input-filter"
64
+ ```
65
+
66
+ The elements that should be placed mandatorily are
67
+
68
+ * `.filters` All search input / select filter should be nested inside this class name.
69
+ * `data-filter-url` Is mandatory, this is the search URL, Mostly this will hit the index action.
70
+ * `data-replacement-class` After ajax this is the class name where the data will get appended.
71
+ * `data-behaviour="filter"` If the input behaviour is set to filter then this will get added to ajax
72
+ * `data-scope="search"` This is the model scope name, The helper method will call this when filter is applied.
73
+ * `data-type="input-filter"` This is to tell if the element is input or select other value is `data-type="select-filter"`
74
+
75
+ **STEP - 2 Pagination**
76
+
77
+ We will add the paginate helper to the bottom of the partial which gets replaced.
78
+ ```
79
+ = cm_paginate(@filtered_result.facets)
80
+ ```
81
+
82
+ **STEP - 3 Sort**
83
+
84
+ If any of the header needs to be sorted, then we will add the following helper
85
+ ```
86
+ th = sortable "name", "Name", @filtered_result.sort[:sort_column], @filtered_result.sort[:sort_direction]
87
+ ```
26
88
 
27
89
  ## Development
28
90
 
@@ -14,6 +14,8 @@ module SpotlightSearch
14
14
  filtered_result.data = raw_data.page(page).per(30)
15
15
  filtered_result.facets = self.paginate(page, raw_data.size)
16
16
  filtered_result.sort = sort_params
17
+ filtered_result.facets.sort = sort_params
18
+
17
19
  return filtered_result
18
20
  end
19
21
 
@@ -1,3 +1,3 @@
1
1
  module SpotlightSearch
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anbazhagan Palani