Commit 858c8851 by Tran Hoang Viet

VietTH: Allow search with multi category

parent 857001a1
...@@ -55,6 +55,7 @@ end ...@@ -55,6 +55,7 @@ end
gem "haml-rails", "~> 0.9" gem "haml-rails", "~> 0.9"
gem 'twitter-bootstrap-rails', '~> 3.2.0' gem 'twitter-bootstrap-rails', '~> 3.2.0'
gem 'chosen_assets', '~> 1.1.0.2'
gem 'font-awesome-sass' gem 'font-awesome-sass'
gem 'quiet_assets' gem 'quiet_assets'
......
...@@ -38,10 +38,10 @@ GEM ...@@ -38,10 +38,10 @@ GEM
thread_safe (~> 0.3, >= 0.3.4) thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.3.8) addressable (2.3.8)
arel (6.0.0) arel (6.0.2)
ast (2.0.0) ast (2.0.0)
astrolabe (1.3.0) astrolabe (1.3.1)
parser (>= 2.2.0.pre.3, < 3.0) parser (~> 2.2)
bcrypt (3.1.10) bcrypt (3.1.10)
binding_of_caller (0.7.2) binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1) debug_inspector (>= 0.0.1)
...@@ -75,6 +75,8 @@ GEM ...@@ -75,6 +75,8 @@ GEM
redis redis
celluloid (0.16.0) celluloid (0.16.0)
timers (~> 4.0.0) timers (~> 4.0.0)
chosen_assets (1.1.0.2)
railties (>= 3.0)
chronic (0.10.2) chronic (0.10.2)
coderay (1.1.0) coderay (1.1.0)
coffee-rails (4.1.0) coffee-rails (4.1.0)
...@@ -103,7 +105,7 @@ GEM ...@@ -103,7 +105,7 @@ GEM
activesupport (>= 3.0) activesupport (>= 3.0)
request_store (~> 1.0) request_store (~> 1.0)
erubis (2.7.0) erubis (2.7.0)
excon (0.45.3) excon (0.45.4)
execjs (2.5.2) execjs (2.5.2)
factory_girl (4.5.0) factory_girl (4.5.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
...@@ -225,6 +227,7 @@ GEM ...@@ -225,6 +227,7 @@ GEM
haml (>= 4.0.6, < 5.0) haml (>= 4.0.6, < 5.0)
html2haml (>= 1.0.1) html2haml (>= 1.0.1)
railties (>= 4.0.1) railties (>= 4.0.1)
hike (1.2.3)
hitimes (1.2.2) hitimes (1.2.2)
html2haml (2.0.0) html2haml (2.0.0)
erubis (~> 2.7.0) erubis (~> 2.7.0)
...@@ -237,7 +240,7 @@ GEM ...@@ -237,7 +240,7 @@ GEM
jbuilder (2.3.1) jbuilder (2.3.1)
activesupport (>= 3.0.0, < 5) activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2) multi_json (~> 1.2)
jeff (1.3.0) jeff (1.5.0)
excon (>= 0.22.1) excon (>= 0.22.1)
jquery-rails (4.0.4) jquery-rails (4.0.4)
rails-dom-testing (~> 1.0) rails-dom-testing (~> 1.0)
...@@ -322,28 +325,28 @@ GEM ...@@ -322,28 +325,28 @@ GEM
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rainbow (2.0.0) rainbow (2.0.0)
raindrops (0.14.0) raindrops (0.15.0)
rake (10.4.2) rake (10.4.2)
rdoc (4.2.0) rdoc (4.2.0)
json (~> 1.4) json (~> 1.4)
redis (3.2.1) redis (3.2.1)
redis-namespace (1.5.2) redis-namespace (1.5.2)
redis (~> 3.0, >= 3.0.4) redis (~> 3.0, >= 3.0.4)
request_store (1.1.0) request_store (1.2.0)
responders (2.1.0) responders (2.1.0)
railties (>= 4.2.0, < 5) railties (>= 4.2.0, < 5)
rolify (4.0.0) rolify (4.0.0)
rsolr (1.0.12) rsolr (1.0.12)
builder (>= 2.1.2) builder (>= 2.1.2)
rspec-core (3.3.1) rspec-core (3.3.2)
rspec-support (~> 3.3.0) rspec-support (~> 3.3.0)
rspec-expectations (3.3.0) rspec-expectations (3.3.1)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0) rspec-support (~> 3.3.0)
rspec-mocks (3.3.1) rspec-mocks (3.3.2)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0) rspec-support (~> 3.3.0)
rspec-rails (3.3.2) rspec-rails (3.3.3)
actionpack (>= 3.0, < 4.3) actionpack (>= 3.0, < 4.3)
activesupport (>= 3.0, < 4.3) activesupport (>= 3.0, < 4.3)
railties (>= 3.0, < 4.3) railties (>= 3.0, < 4.3)
...@@ -361,8 +364,8 @@ GEM ...@@ -361,8 +364,8 @@ GEM
ruby-progressbar (1.7.5) ruby-progressbar (1.7.5)
ruby_parser (3.7.0) ruby_parser (3.7.0)
sexp_processor (~> 4.1) sexp_processor (~> 4.1)
sass (3.4.15) sass (3.4.16)
sass-rails (5.0.3) sass-rails (5.0.1)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
sass (~> 3.1) sass (~> 3.1)
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
...@@ -376,16 +379,19 @@ GEM ...@@ -376,16 +379,19 @@ GEM
sexp_processor (4.6.0) sexp_processor (4.6.0)
shoulda-matchers (2.8.0) shoulda-matchers (2.8.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
sidekiq (3.4.1) sidekiq (3.4.2)
celluloid (~> 0.16.0) celluloid (~> 0.16.0)
connection_pool (>= 2.1.1) connection_pool (~> 2.2, >= 2.2.0)
json json (~> 1.0)
redis (>= 3.0.6) redis (~> 3.2, >= 3.2.1)
redis-namespace (>= 1.3.1) redis-namespace (~> 1.5, >= 1.5.2)
slop (3.6.0) slop (3.6.0)
spring (1.3.6) spring (1.3.6)
sprockets (3.2.0) sprockets (2.12.4)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0) rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.3.2) sprockets-rails (2.3.2)
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
...@@ -421,7 +427,7 @@ GEM ...@@ -421,7 +427,7 @@ GEM
multi_xml (~> 0.5.0) multi_xml (~> 0.5.0)
warden (1.2.3) warden (1.2.3)
rack (>= 1.0) rack (>= 1.0)
web-console (2.1.3) web-console (2.2.1)
activemodel (>= 4.0) activemodel (>= 4.0)
binding_of_caller (>= 0.7.2) binding_of_caller (>= 0.7.2)
railties (>= 4.0) railties (>= 4.0)
...@@ -440,6 +446,7 @@ DEPENDENCIES ...@@ -440,6 +446,7 @@ DEPENDENCIES
capistrano3-unicorn capistrano3-unicorn
carrierwave (~> 0.10.0) carrierwave (~> 0.10.0)
cartman (~> 2.1.2) cartman (~> 2.1.2)
chosen_assets (~> 1.1.0.2)
coffee-rails (~> 4.1.0) coffee-rails (~> 4.1.0)
database_cleaner (~> 1.4.1) database_cleaner (~> 1.4.1)
devise (~> 3.5.1) devise (~> 3.5.1)
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
//= require jquery.validate.min //= require jquery.validate.min
//= require additional-methods //= require additional-methods
//= require twitter/bootstrap //= require twitter/bootstrap
//= require chosen.jquery
//= require jquery_methods //= require jquery_methods
//= require product //= require product
//= require order //= require order
......
@mainLib = (-> @mainLib = (->
@initChosen = ->
$('.chosen-select').chosen()
$('.chosen-select-deselect').chosen { allow_single_deselect: true }
return @ return @
)() )()
\ No newline at end of file
...@@ -2,3 +2,4 @@ $(document).ready -> ...@@ -2,3 +2,4 @@ $(document).ready ->
window.productLib.validateForm() window.productLib.validateForm()
window.productLib.validateQuantity() window.productLib.validateQuantity()
window.orderLib.validateCheckoutForm() window.orderLib.validateCheckoutForm()
window.mainLib.initChosen()
\ No newline at end of file
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*= require bootstrap_and_overrides *= require bootstrap_and_overrides
*= require font-awesome *= require font-awesome
*= require bootstrap-spinner *= require bootstrap-spinner
*= require chosen
*= require layout *= require layout
*= require product *= require product
*= require cart *= require cart
......
...@@ -194,3 +194,27 @@ footer{ ...@@ -194,3 +194,27 @@ footer{
background-color: #F5F5F5; background-color: #F5F5F5;
padding: 20px; padding: 20px;
} }
.chosen-container-multi .chosen-choices{
display: block;
width: 100%;
min-height: 34px !important;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
-webkit-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
-o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
input{
height: 20px !important;
padding: 0 !important;
}
}
\ No newline at end of file
...@@ -6,14 +6,11 @@ class SearchController < ApplicationController ...@@ -6,14 +6,11 @@ class SearchController < ApplicationController
query.merge!(title: params[:query]) if params[:query].present? query.merge!(title: params[:query]) if params[:query].present?
query.merge!(category_id: params[:category]) if params[:category].present? query.merge!(category_id: params[:category]) if params[:category].present?
unless params[:price_start].to_i.zero? && params[:price_end].to_i.zero? unless params[:price_start].to_i.zero? && params[:price_end].to_i.zero?
query.merge!(price: { query.merge!(price: params[:price_start].to_i..params[:price_end].to_i)
value: params[:price_start].to_i..params[:price_end].to_i,
escape: false
})
end end
@products = Product.search(query, page: params[:page]) @products = Product.search(query, page: params[:page])
@categories = @categories = Category.all.limit(Settings.limit_category) @categories = Category.all.limit(Settings.limit_category)
add_breadcrumb('Search result') add_breadcrumb('Search result')
end end
......
...@@ -6,4 +6,8 @@ module ApplicationHelper ...@@ -6,4 +6,8 @@ module ApplicationHelper
def format_price(price, delimiter = '.', separator = ',') def format_price(price, delimiter = '.', separator = ',')
number_with_delimiter(price.ceil, delimiter: delimiter, separator: separator) number_with_delimiter(price.ceil, delimiter: delimiter, separator: separator)
end end
def active_class?(path)
request.path == path ? 'active' : ''
end
end end
...@@ -52,18 +52,20 @@ module Solr extend ActiveSupport::Concern ...@@ -52,18 +52,20 @@ module Solr extend ActiveSupport::Concern
value = item.last value = item.last
escape = solr_options_data[:escape].present? escape = solr_options_data[:escape].present?
end end
value = solr_handle_value(value) value = solr_handle_value(value, escape)
value = %Q("#{value}") if escape.present?
str << "#{item.first}:#{value}" << ' ' str << "#{item.first}:#{value}" << ' '
end end
query query
end end
def solr_handle_value(value) def solr_handle_value(value, escape = true)
if value.is_a?(Range) case value.class.name
when 'Range'
"[#{value.first} TO #{value.last.zero? ? '*' : value.last}]" "[#{value.first} TO #{value.last.zero? ? '*' : value.last}]"
else # String when 'Array'
value "(#{value.join(' OR ')})"
else
escape.present? ? %Q("#{value}") : value
end end
end end
......
%li %li{class: "#{active_class?(category_path(category))}"}
= link_to category do = link_to category do
= category.decorate.title = category.decorate.title
%span.counter %span.counter
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
.form-group .form-group
= label :query, 'Category: ', class: 'col-sm-2 control-label' = label :query, 'Category: ', class: 'col-sm-2 control-label'
.col-sm-5 .col-sm-5
= select_tag :category, options_from_collection_for_select(@categories.decorate, :id, :title, params[:category]), {include_blank: '-- Select category --', class: 'form-control'} = select_tag :category, options_from_collection_for_select(@categories.decorate, :id, :title, params[:category]), {include_blank: '-- Select category --', class: 'form-control chosen-select', multiple: true}
.form-group .form-group
= label :query, 'Product price: ', class: 'col-sm-2 control-label' = label :query, 'Product price: ', class: 'col-sm-2 control-label'
.col-sm-2 .col-sm-2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment