spotlight_search 0.2.2 → 0.3.0

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: b8d70a1928ef9bfa68c81817f7ab8ba5bb70848ab5c68223ad52294f2cc0e41b
4
- data.tar.gz: 0e87e9608d99ffb50b6b6239f7af51e01f1b916919062a97b086466b8403caa5
3
+ metadata.gz: db095dee4fcbb232c1f7eddd83dfdfe279243415f3f6e54636740c2abbbe9ac3
4
+ data.tar.gz: c93d9955d07504a7aecca13cca15d1655fa847d0c13b1dc3643414ceeab39cb3
5
5
  SHA512:
6
- metadata.gz: ddd8e03cad7ed5f110c5b9e158f2f40a4efe5551371da46caf92cf3b1c57b6b2b405aee83dabf0050f732e571c7ff891407c5a65906095bddce904771772e63e
7
- data.tar.gz: 4b3b4880334b8b5a55fb0224e4878da2673bbaade2c221194c9e178e3cd2d633dd5275bfb60ce8c353de072003ac5d2999beb92613820112aa1909736e462a2d
6
+ metadata.gz: 67fc0b1c020ee49f59dbf539bf7854fcf65a8d8ce393b6315450c07812bec38020ace65fd29c36d76fb7408ddee3a6296c92ebf94dddc13026bc000660e26651
7
+ data.tar.gz: f4b76130d03a78c7fefdf61feffa8a61712097bd9807b479e3d9f41246fa69ed45bed3071a4df6b59ca94f5a3ea03dc0f1ecbdf74fdc701c6b845b92354b3123
@@ -134,9 +134,7 @@ GEM
134
134
  thread_safe (~> 0.1)
135
135
  websocket-driver (0.7.1)
136
136
  websocket-extensions (>= 0.1.0)
137
- websocket-extensions (0.1.4)
138
- zip-zip (0.3)
139
- rubyzip (>= 1.0.0)
137
+ websocket-extensions (0.1.5)
140
138
 
141
139
  PLATFORMS
142
140
  ruby
data/README.md CHANGED
@@ -42,14 +42,17 @@ The install generator does the following
42
42
  * Adds a line in route for mounting.
43
43
 
44
44
  Generator that installs filter and table files to application
45
+ $ rails g spotlight_search filter orders --filters scope_name:filter_type
46
+ $ rails g spotlight_search filter orders --filters search:input order_status:multi_select status:select
45
47
 
46
- $ rails g spotlight_search:filter orders --filters search:input order_status:multi_select status:select
48
+ scope_name is the model scope name, scope can written after running this generator, it won't throw any error that it has to be present.
47
49
 
48
- The install generator does the following
49
-
50
- * Copies the filter partial and the controller with necessary changes
51
-
52
- Filter arguments can be passed as an array and the format is `filter_scope:type_of_filter_input`
50
+ Following filter type are supported
51
+ * input
52
+ * single-select
53
+ * multi-select
54
+ * datetime
55
+ * daterange
53
56
 
54
57
 
55
58
  ## Usage
@@ -8,6 +8,9 @@ module SpotlightSearch
8
8
 
9
9
  def copy_filter_contents_to_app
10
10
  if @options.filters?
11
+ inject_into_file "app/models/#{model.singularize}.rb", after: "ApplicationRecord" do
12
+ "\n include SpotlightSearch\n"
13
+ end
11
14
  template 'filters.html.erb', "app/views/admin/#{model}/_filters.html.slim"
12
15
  template 'controller.rb.erb', "app/controllers/admin/#{model}_controller.rb"
13
16
  end
@@ -11,19 +11,15 @@ module SpotlightSearch
11
11
  copy_file 'environment.js', 'config/webpack/environment.js'
12
12
  copy_file 'coffee.js', 'config/webpack/loaders/coffee.js'
13
13
  copy_file 'spotlight_search.rb', 'config/initializers/spotlight_search.rb'
14
+ copy_file 'application.css.scss', 'app/assets/stylesheets/application.css.scss'
14
15
  route "mount SpotlightSearch::Engine => '/spotlight_search'"
15
16
  end
16
17
 
17
18
  def add_essentials
18
- system("yarn add jquery")
19
- system("yarn add coffeescript")
20
- system("yarn add select2")
21
- inject_into_file 'app/assets/stylesheets/application.css.scss', before: " */" do
22
- " *= require select2\n"
23
- end
19
+ system("yarn add jquery coffeescript coffee-loader select2 popper.js daterangepicker bootstrap-datepicker")
24
20
  template "application.js", "app/javascript/packs/application.js"
25
21
  template 'scaffolds.coffee', "app/javascript/application/coffee_scripts/scaffolds.coffee"
26
- gem 'kaminari', '~> 1.2.1' unless File.readlines("Gemfile").grep(/kaminari/).size > 0
22
+ gem 'kaminari'
27
23
  end
28
24
 
29
25
  end
@@ -0,0 +1,26 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
6
+ * vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_self
14
+ *= require font-awesome
15
+ *= require 'select2'
16
+ *= require bootstrap/dist/css/bootstrap
17
+ *= require bootstrap-datepicker/dist/css/bootstrap-datepicker3
18
+ *= require daterangepicker
19
+ */
20
+
21
+ $fa-font-path: '@fortawesome/fontawesome-free/webfonts';
22
+ @import '@fortawesome/fontawesome-free/scss/fontawesome';
23
+ @import '@fortawesome/fontawesome-free/scss/solid';
24
+ @import '@fortawesome/fontawesome-free/scss/regular';
25
+ @import '@fortawesome/fontawesome-free/scss/brands';
26
+ @import '@fortawesome/fontawesome-free/scss/v4-shims';
@@ -7,9 +7,13 @@
7
7
  require("@rails/ujs").start()
8
8
  require("turbolinks").start()
9
9
  require("@rails/activestorage").start()
10
- require('spotlight_search')
10
+ require("spotlight_search")
11
+ require("daterangepicker")
11
12
 
12
13
  import jQuery from 'jquery';
13
14
  window.$ = jQuery
14
15
  window.jQuery = jQuery
15
16
  import 'select2';
17
+ import 'bootstrap/dist/js/bootstrap'
18
+ import 'bootstrap-datepicker/dist/js/bootstrap-datepicker.js';
19
+ import '../application/coffee_scripts/scaffolds.coffee';
@@ -1,4 +1,4 @@
1
- class Admin::<%= model.titleize %>Controller < ApplicationController
1
+ class Admin::<%= model.titleize.gsub(' ', '') %>Controller < ApplicationController
2
2
  before_action :set_<%= model.singularize %>, only: [:show, :edit, :update, :destroy]
3
3
 
4
4
  # GET /<%= model %>
@@ -22,7 +22,7 @@ class Admin::<%= model.titleize %>Controller < ApplicationController
22
22
 
23
23
  # GET /<%= model %>/new
24
24
  def new
25
- @<%= model.singularize %> = Profile.new
25
+ @<%= model.singularize %> = <%= model.singularize.titleize.gsub(' ', '') %>.new
26
26
  end
27
27
 
28
28
  # GET /<%= model %>/1/edit
@@ -32,11 +32,11 @@ class Admin::<%= model.titleize %>Controller < ApplicationController
32
32
  # POST /<%= model %>
33
33
  # POST /<%= model %>.json
34
34
  def create
35
- @<%= model.singularize %> = Profile.new(<%= model.singularize %>_params)
35
+ @<%= model.singularize %> = <%= model.singularize.titleize.gsub(' ', '') %>.new(<%= model.singularize %>_params)
36
36
 
37
37
  respond_to do |format|
38
38
  if @<%= model.singularize %>.save
39
- format.html { redirect_to @<%= model.singularize %>, notice: 'Profile was successfully created.' }
39
+ format.html { redirect_to admin_<%= model.singularize %>_path(@<%= model.singularize %>), notice: '<%= model.singularize.titleize.gsub(' ', '') %> was successfully created.' }
40
40
  format.json { render :show, status: :created, location: @<%= model.singularize %> }
41
41
  else
42
42
  format.html { render :new }
@@ -50,7 +50,7 @@ class Admin::<%= model.titleize %>Controller < ApplicationController
50
50
  def update
51
51
  respond_to do |format|
52
52
  if @<%= model.singularize %>.update(<%= model.singularize %>_params)
53
- format.html { redirect_to @<%= model.singularize %>, notice: 'Profile was successfully updated.' }
53
+ format.html { redirect_to admin_<%= model.singularize %>_path(@<%= model.singularize %>), notice: '<%= model.singularize.titleize.gsub(' ', '') %> was successfully updated.' }
54
54
  format.json { render :show, status: :ok, location: @<%= model.singularize %> }
55
55
  else
56
56
  format.html { render :edit }
@@ -64,7 +64,7 @@ class Admin::<%= model.titleize %>Controller < ApplicationController
64
64
  def destroy
65
65
  @<%= model.singularize %>.destroy
66
66
  respond_to do |format|
67
- format.html { redirect_to <%= model.singularize %>s_url, notice: 'Profile was successfully destroyed.' }
67
+ format.html { redirect_to admin_<%= model %>_path, notice: '<%= model.singularize.titleize.gsub(' ', '') %> was successfully destroyed.' }
68
68
  format.json { head :no_content }
69
69
  end
70
70
  end
@@ -73,7 +73,7 @@ class Admin::<%= model.titleize %>Controller < ApplicationController
73
73
 
74
74
  # Use callbacks to share common setup or constraints between actions.
75
75
  def set_<%= model.singularize %>
76
- @<%= model.singularize %> = Profile.find(params[:id])
76
+ @<%= model.singularize %> = <%= model.singularize.titleize.gsub(' ', '') %>.find(params[:id])
77
77
  end
78
78
 
79
79
  # Only allow a list of trusted parameters through.
@@ -83,7 +83,7 @@ class Admin::<%= model.titleize %>Controller < ApplicationController
83
83
 
84
84
  def filter_params
85
85
  params.require(:filters).permit(<%= @options.filters.map{ |f| ':' + f.split(':')[0] }.join(', ') %>) if params[:filters]
86
- end
86
+ end
87
87
 
88
88
  def sort_params
89
89
  params.require(:sort).permit(:sort_column, :sort_direction) if params[:sort]
@@ -5,7 +5,8 @@ const webpack = require('webpack')
5
5
  environment.plugins.prepend('Provide',
6
6
  new webpack.ProvidePlugin({
7
7
  $: require.resolve('jquery'),
8
- jQuery: require.resolve('jquery')
8
+ jQuery: require.resolve('jquery'),
9
+ Popper: ['popper.js', 'default']
9
10
  })
10
11
  )
11
12
 
@@ -1,12 +1,10 @@
1
- = filter_wrapper({filter_url: '/admin/<%= model %>', replacement_class: "<%= model %>-table"})
2
- <%- @options.filters.each do |filter| -%>
3
- <%- filter_arr = filter.split(':') -%>
4
- <%- if filter_arr[1].eql?('input') -%>
5
- = cm_textfield_tag({behaviour: "filter", scope: "<%= filter_arr[0] %>", type: "input-filter"}, nil, "<%= filter_arr[0].titleize %>")
6
- <%- elsif filter_arr[1].eql?('select') -%>
7
- = cm_select_tag([["<%= model.titleize %>", "<%= model %>"]], {behaviour: 'filter', scope: "<%= filter_arr[0] %>", type: 'select-filter', placeholder: ''}, "select2-single")
8
- <%- elsif filter_arr[1].eql?('multi_select') -%>
9
- = cm_multi_select_tag([["<%= model.titleize %>", "<%= model %>"]], {behaviour: 'filter', scope: "<%= filter_arr[0] %>", type: 'select-filter', placeholder: ''}, "select2-multiple")
10
- <%- end -%>
11
- <%- end -%>
12
- = clear_filters(admin_<%= model %>_path, nil, nil, "Clear all")
1
+ .filter-section
2
+ .filter-section__lhs
3
+ = filter_wrapper({filter_url: '/admin/<%= model %>', replacement_class: "<%= model %>-table"})
4
+ <%- @options.filters.each do |filter| -%>
5
+ <%- filter_arr = filter.split(':') -%>
6
+ = cm_filter_tag("<%= filter_arr[1] %>", "<%= filter_arr[0] %>", "", 'field-area', "<%= filter_arr[0].titleize %>")
7
+ <%- end -%>
8
+ = clear_filters(admin_<%= model %>_path, nil, nil, "Clear all")
9
+ .filter-section__rhs
10
+ = link_to 'Add', <%= "new_admin_" + model.singularize + "_path" %>, class: 'filter-btn'
@@ -3,4 +3,9 @@ $(document).on "turbolinks:load", () ->
3
3
  $('.select2-single').select2(
4
4
  allowClear: true
5
5
  )
6
-
6
+ $('.filter-rangepicker').daterangepicker()
7
+ $('.datepicker').datepicker({
8
+ format: 'dd/mm/yyyy',
9
+ todayHighlight: true,
10
+ autoclose: true,
11
+ })
@@ -1 +1,5 @@
1
- ActiveRecord::Base.include SpotlightSearch::ExportableColumns
1
+ ActiveRecord::Base.include SpotlightSearch::ExportableColumnsV2
2
+
3
+ SpotlightSearch.setup do |config|
4
+ config.exportable_columns_version = :v2
5
+ end
@@ -12,9 +12,9 @@ module SpotlightSearch
12
12
  end
13
13
 
14
14
  def exportable(email, klass, html_class: [])
15
- tag.div do
16
- concat tag.button "Export as excel", class: html_class.append("modal-btn"), data: {toggle: "modal", target: "#exportmodal"}
17
- concat column_pop_up(email, klass)
15
+ tag.a "Export as excel", class: html_class.append("filter-btn modal-btn mr-2"), data: {toggle: "modal", target: "#exportmodal"} do
16
+ concat tag.i class: 'fa fa-download'
17
+ concat tag.span " Excel"
18
18
  end
19
19
  end
20
20
 
@@ -57,7 +57,8 @@ module SpotlightSearch
57
57
  when :v2
58
58
  concat checkbox_row_v2(klass)
59
59
  end
60
- concat submit_tag 'Export as excel', class: 'btn btn-bordered export-to-file-btn'
60
+ concat tag.hr
61
+ concat submit_tag 'Export as excel', class: 'btn btn-primary btn-bordered export-to-file-btn'
61
62
  end
62
63
  end
63
64
  end
@@ -89,16 +90,32 @@ module SpotlightSearch
89
90
  end
90
91
  end
91
92
 
92
- def cm_single_select_tag(select_options, data_behaviours, classes=nil, placeholder=nil)
93
- select_tag data_behaviours[:scope], options_for_select(select_options), class: "#{classes}", data: data_behaviours, include_blank: "#{placeholder}"
94
- end
95
-
96
- def cm_multi_select_tag(select_options, data_behaviours, classes=nil, placeholder=nil)
97
- select_tag data_behaviours[:scope], options_for_select(select_options), class: "#{classes}", data: data_behaviours, include_blank: "#{placeholder}", multiple: true
98
- end
99
-
100
- def cm_textfield_tag(data_behaviours, classes=nil, placeholder=nil)
101
- text_field_tag data_behaviours[:scope], '', class: "#{classes}", data: data_behaviours, placeholder: "#{placeholder}"
93
+ def cm_filter_tag(input_type, scope_name, value, classes = nil, placeholder = nil)
94
+ case input_type
95
+ when 'input'
96
+ tag.div class: 'filter-field' do
97
+ concat text_field_tag scope_name, '', class: "#{classes}", data: {behaviour: "filter", scope: scope_name, type: "input-filter"}, placeholder: "#{placeholder}"
98
+ concat tag.span class: 'fa fa-search search-icon'
99
+ end
100
+ when 'single-select'
101
+ tag.div class: 'filter-field' do
102
+ select_tag scope_name, options_for_select(value), class: "#{classes} select2-single", data: {behaviour: "filter", scope: scope_name, type: "select-filter"}, include_blank: "#{placeholder}"
103
+ end
104
+ when 'multi-select'
105
+ tag.div class: 'filter-field' do
106
+ select_tag scope_name, options_for_select(value), class: "#{classes} select2-single", data: {behaviour: "filter", scope: scope_name, type: "select-filter"}, include_blank: "#{placeholder}", multiple: true
107
+ end
108
+ when 'datetime'
109
+ tag.div class: 'filter-field' do
110
+ concat text_field_tag scope_name, '', class: "#{classes}", data: {behaviour: "filter", scope: scope_name, type: "input-filter", provide: "datepicker"}, placeholder: "#{placeholder}"
111
+ concat tag.span class: 'fa fa-search search-icon'
112
+ end
113
+ when 'daterange'
114
+ 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}"
116
+ concat tag.span class: 'fa fa-search search-icon'
117
+ end
118
+ end
102
119
  end
103
120
 
104
121
  def clear_filters(clear_path, classes=nil, data_behaviours=nil, clear_text=nil)
@@ -116,30 +133,30 @@ module SpotlightSearch
116
133
  def create_checkbox_v2(column_path)
117
134
  tag.div class: "col-md-4" do
118
135
  concat check_box_tag "columns[]", column_path, id: column_path.to_s.gsub('/', '-')
119
- concat column_path.to_s.gsub('/', '_').humanize
136
+ concat " " + column_path.to_s.gsub('/', '_').humanize
120
137
  end
121
138
  end
122
139
 
123
140
  def cm_paginate(facets)
124
- tag.div class: 'text-center' do
141
+ tag.div class: 'cm-pagination' do
125
142
  tag.div class: 'nav navbar navbar-inner' do
126
143
  tag.ul class: 'pagination' do
127
144
  if facets.previous_page != false
128
145
  previous_page = tag.li do
129
- tag.button class: 'btn btn-bordered', data: { behaviour: 'previous-page'} do
146
+ tag.button class: 'cm-pagination__item', data: { behaviour: 'previous-page'} do
130
147
  tag.span "Previous"
131
148
  end
132
149
  end
133
150
  end
134
151
  current_page = content_tag :li do
135
- tag.a class: 'btn btn-bordered mx-2', data: {sort_column: facets.sort[:sort_column], sort_direction: facets.sort[:sort_direction], page: facets.current_page, behaviour: 'current-page' } do
152
+ tag.button class: 'cm-pagination__item', data: {sort_column: facets.sort[:sort_column], sort_direction: facets.sort[:sort_direction], page: facets.current_page, behaviour: 'current-page' } do
136
153
  "Showing #{facets.current_page} of #{facets.total_pages} pages"
137
154
  end
138
155
  end
139
156
 
140
157
  if facets.next_page != false
141
158
  next_page = tag.li do
142
- tag.button class: 'btn btn-bordered', data: { behaviour: 'next-page'} do
159
+ tag.button class: 'cm-pagination__item', data: { behaviour: 'next-page'} do
143
160
  tag.span "Next"
144
161
  end
145
162
  end
@@ -1,3 +1,3 @@
1
1
  module SpotlightSearch
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
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.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anbazhagan Palani
@@ -108,6 +108,7 @@ files:
108
108
  - config/routes.rb
109
109
  - lib/generators/spotlight_search/filter_generator.rb
110
110
  - lib/generators/spotlight_search/install_generator.rb
111
+ - lib/generators/spotlight_search/templates/application.css.scss
111
112
  - lib/generators/spotlight_search/templates/application.js
112
113
  - lib/generators/spotlight_search/templates/coffee.js
113
114
  - lib/generators/spotlight_search/templates/controller.rb.erb