spotlight_search 0.3.0 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db095dee4fcbb232c1f7eddd83dfdfe279243415f3f6e54636740c2abbbe9ac3
4
- data.tar.gz: c93d9955d07504a7aecca13cca15d1655fa847d0c13b1dc3643414ceeab39cb3
3
+ metadata.gz: bc7f95a4b32cda3a0fe9572388d9e73ef1bc8d6f539ea2ec63423a59ac051403
4
+ data.tar.gz: 5f2873974e3fc88a2d8693d7dca287d3bb74af3c7538443d3188d78790d81e34
5
5
  SHA512:
6
- metadata.gz: 67fc0b1c020ee49f59dbf539bf7854fcf65a8d8ce393b6315450c07812bec38020ace65fd29c36d76fb7408ddee3a6296c92ebf94dddc13026bc000660e26651
7
- data.tar.gz: f4b76130d03a78c7fefdf61feffa8a61712097bd9807b479e3d9f41246fa69ed45bed3071a4df6b59ca94f5a3ea03dc0f1ecbdf74fdc701c6b845b92354b3123
6
+ metadata.gz: 4063285378cd29f80b0c7a3f67e907bd1f8cf549613754aa54c6633eae2e9037509a3224c83d38128a5119a6627210e7ebd74da591b58e7f9aea253b169fa9db
7
+ data.tar.gz: 85d4eae1e8ca517c454986bc383d57010b52971482b79e1e2285f651f534e57aad1685f8fe8418c8ca263d58897ac5b2fe2e6d4541fe1755a0413f61bfee729d
@@ -74,6 +74,15 @@ $(document).on('keyup', '[data-type="input-filter"]', function() {
74
74
  });
75
75
  });
76
76
 
77
+ $(document).on('change', '[data-type="range-filter"]', function() {
78
+ var thisObj;
79
+ thisObj = $(this);
80
+ return $(function() {
81
+ return get_paginated_list(1, thisObj);
82
+ });
83
+ });
84
+
85
+
77
86
  $(document).on('change', '[data-type="select-filter"]', function() {
78
87
  var thisObj;
79
88
  thisObj = $(this);
@@ -4,7 +4,9 @@ module SpotlightSearch
4
4
  begin
5
5
  klass = params[:class_name].constantize
6
6
  if klass.validate_exportable_columns(params[:columns])
7
- ExportJob.perform_later(klass.name, params[:email], params[:columns], params[:filters], params[:sort])
7
+ (filter_params = params[:filters].permit!) if params[:filters].present?
8
+ (sort_params = params[:sort].permit!) if params[:sort].present?
9
+ ExportJob.perform_later(klass.name, params[:email], params[:columns], filter_params, sort_params)
8
10
  notice = 'Successfully queued for export'
9
11
  else
10
12
  notice = 'Invalid columns found'
@@ -26,6 +26,11 @@ module SpotlightSearch
26
26
  records = records.send(scope, scope_args)
27
27
  end
28
28
  end
29
+ if klass.default_filters.present?
30
+ klass.default_filters.each do |scope|
31
+ records = records.send(scope)
32
+ end
33
+ end
29
34
  if sort.present?
30
35
  records = records.order("#{sort['sort_column']} #{sort['sort_direction']}")
31
36
  end
@@ -63,12 +68,12 @@ module SpotlightSearch
63
68
 
64
69
  def create_excel_v2(records, class_name)
65
70
  flattened_records = records.map { |record| SpotlightSearch::Utils.flatten_hash(record) }
66
- columns = flattened_records[0].keys
71
+ columns = flattened_records.map{|x| x.keys}.flatten.uniq.sort
67
72
  size_arr = []
68
73
  columns.size.times { size_arr << 22 }
69
74
  xl = Axlsx::Package.new
70
75
  xl.workbook.add_worksheet do |sheet|
71
- sheet.add_row columns, b: true
76
+ sheet.add_row columns&.map(&:titleize), b: true
72
77
  flattened_records.each do |record|
73
78
  sheet.add_row(columns.map { |column| record[column] })
74
79
  end
@@ -32,6 +32,10 @@ module SpotlightSearch
32
32
  self.enabled_columns = [*record_fields, **associated_fields]
33
33
  end
34
34
 
35
+ def default_scopes_for_export(*filter_scopes)
36
+ self.default_filters = filter_scopes
37
+ end
38
+
35
39
  def _model_exportable_columns(klass, *record_fields, **associated_fields)
36
40
  # Gets all the valid columns of a model
37
41
  # If any column is invalid, it also returns it
@@ -85,6 +89,7 @@ module SpotlightSearch
85
89
 
86
90
  included do
87
91
  class_attribute :enabled_columns, instance_accessor: false, default: nil
92
+ class_attribute :default_filters, instance_accessor: false, default: nil
88
93
  end
89
94
  end
90
95
  end
@@ -18,20 +18,20 @@ module SpotlightSearch
18
18
  end
19
19
  end
20
20
 
21
- def column_pop_up(email, klass)
21
+ def column_pop_up(email, klass, required_filters = nil)
22
22
  tag.div class: "modal fade", id: "exportmodal", tabindex: "-1", role: "dialog", aria: {labelledby: "exportModal"} do
23
23
  tag.div class: "modal-dialog modal-lg", role: "document" do
24
24
  tag.div class: "modal-content" do
25
- concat pop_ups(email, klass)
25
+ concat pop_ups(email, klass, required_filters)
26
26
  end
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
- def pop_ups(email, klass)
31
+ def pop_ups(email, klass, required_filters)
32
32
  tag.div do
33
33
  concat pop_up_header
34
- concat pop_up_body(email, klass)
34
+ concat pop_up_body(email, klass, required_filters)
35
35
  end
36
36
  end
37
37
 
@@ -44,11 +44,12 @@ module SpotlightSearch
44
44
  end
45
45
  end
46
46
 
47
- def pop_up_body(email, klass)
47
+ def pop_up_body(email, klass, required_filters)
48
48
  tag.div class: "modal-body" do
49
49
  form_tag '/spotlight_search/export_to_file', id: 'export-to-file-form', style: "width: 100%;", class:"spotlight-csv-export-form" do
50
50
  concat hidden_field_tag 'email', email, id: 'export-to-file-email'
51
51
  concat hidden_field_tag 'class_name', klass.to_s, id: 'export-to-file-klass'
52
+ filters_to_post_helper(required_filters) if required_filters
52
53
  params_to_post_helper(filters: controller.filter_params) if controller.filter_params
53
54
  params_to_post_helper(sort: controller.sort_params) if controller.sort_params
54
55
  case SpotlightSearch.exportable_columns_version
@@ -63,6 +64,12 @@ module SpotlightSearch
63
64
  end
64
65
  end
65
66
 
67
+ def filters_to_post_helper(required_filters)
68
+ URI.decode_www_form(required_filters.to_param).each do |param|
69
+ concat hidden_field_tag "filters[#{param[0]}]", param[1]
70
+ end
71
+ end
72
+
66
73
  def params_to_post_helper(params)
67
74
  URI.decode_www_form(params.to_param).each do |param|
68
75
  concat hidden_field_tag param[0], param[1]
@@ -112,7 +119,7 @@ module SpotlightSearch
112
119
  end
113
120
  when 'daterange'
114
121
  tag.div class: 'filter-field' do
115
- concat text_field_tag scope_name, '', class: "#{classes} filter-rangepicker", data: {behaviour: "filter", scope: scope_name, type: "input-filter"}, placeholder: "#{placeholder}"
122
+ concat text_field_tag scope_name, '', class: "#{classes} filter-rangepicker", data: {behaviour: "filter", scope: scope_name, type: "range-filter"}, placeholder: "#{placeholder}"
116
123
  concat tag.span class: 'fa fa-search search-icon'
117
124
  end
118
125
  end
@@ -2,11 +2,13 @@
2
2
 
3
3
  module SpotlightSearch::Utils
4
4
  class << self
5
- def serialize_csv_columns(*columns, **hashes)
5
+ def serialize_csv_columns(*columns)
6
+ association_hash = columns.select{|columnable| columnable.class.eql?(Hash)}.last || {}
7
+ parent_table_columns = columns.select{|columnable| columnable.class.eql?(Symbol)}
6
8
  # Turns an arbitrary list of args and kwargs into a list of params to be used in a form
7
9
  # For example, turns SpotlightSearch::Utils.serialize_csv_columns(:a, :b, c: [:d, e: :h], f: :g)
8
10
  # into [:a, :b, "c/d", "c/e/h", "f/g"]
9
- columns.map(&:to_s) + hashes.map do |key, value|
11
+ parent_table_columns.map(&:to_s) + association_hash.map do |key, value|
10
12
  serialize_csv_columns(*value).map do |column|
11
13
  "#{key}/#{column}"
12
14
  end
@@ -1,3 +1,3 @@
1
1
  module SpotlightSearch
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.4"
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.3.0
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anbazhagan Palani