Skip to content

Commit

Permalink
Merge branch '3-0-stable' of github.com:vinsol/spree_address_auto_com…
Browse files Browse the repository at this point in the history
…plete into 3-0-stable
  • Loading branch information
sawangupta92 committed Nov 23, 2016
2 parents 1b4f019 + e78a396 commit 6e8f365
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ capybara-*.html
/public/system
/coverage/
/spec/tmp
/spec/dummy
**.orig
rerun.txt
pickle-email-*.html
Expand Down
85 changes: 67 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PATH
remote: .
specs:
spree_address_auto_complete (3.0.9)
spree_core (~> 3.0.9)
spree (~> 3.0.9)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -51,11 +51,18 @@ GEM
activerecord (>= 3.0)
addressable (2.4.0)
arel (6.0.3)
autoprefixer-rails (6.5.1.1)
execjs
awesome_nested_set (3.0.3)
activerecord (>= 4.0.0, < 5)
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
builder (3.2.2)
camertron-eprun (1.1.0)
camertron-eprun (1.1.1)
cancancan (1.10.1)
canonical-rails (0.0.11)
rails (>= 3.1, < 5.0)
capybara (2.7.1)
addressable
mime-types (>= 1.16)
Expand All @@ -79,9 +86,9 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.10.0)
colorize (0.7.7)
colorize (0.8.1)
concurrent-ruby (1.0.2)
css_parser (1.4.1)
css_parser (1.4.6)
addressable
database_cleaner (1.5.3)
deface (1.0.2)
Expand All @@ -97,17 +104,23 @@ GEM
activesupport (>= 3.0.0)
ffaker (1.32.1)
ffi (1.9.10)
font-awesome-rails (4.6.3.0)
font-awesome-rails (4.7.0.0)
railties (>= 3.2, < 5.1)
friendly_id (5.1.0)
activerecord (>= 4.0.0)
globalid (0.3.6)
globalid (0.3.7)
activesupport (>= 4.1.0)
highline (1.6.21)
htmlentities (4.3.4)
i18n (0.7.0)
jquery-rails (4.2.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (5.0.5)
railties (>= 3.2.16)
json (1.8.3)
kaminari (0.16.3)
kaminari (0.17.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
loofah (2.0.3)
Expand All @@ -127,23 +140,25 @@ GEM
sixarm_ruby_unaccent (>= 1.1.1, < 2)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
paperclip (4.3.6)
paperclip (4.3.7)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
cocaine (~> 0.5.5)
mime-types
mimemagic (= 0.3.0)
paranoia (2.1.5)
activerecord (~> 4.0)
polyamorous (1.3.0)
polyamorous (1.3.1)
activerecord (>= 3.0)
polyglot (0.3.5)
premailer (1.8.6)
css_parser (>= 1.3.6)
premailer (1.8.7)
css_parser (>= 1.4.5)
htmlentities (>= 4.0.0)
premailer-rails (1.9.2)
premailer-rails (1.9.4)
actionmailer (>= 3, < 6)
premailer (~> 1.7, >= 1.7.9)
rabl (0.11.8)
activesupport (>= 2.3.14)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
Expand Down Expand Up @@ -178,7 +193,7 @@ GEM
activesupport (>= 3.0)
i18n
polyamorous (~> 1.1)
responders (2.2.0)
responders (2.3.0)
railties (>= 4.2.0, < 5.1)
rspec-core (3.4.4)
rspec-support (~> 3.4.0)
Expand All @@ -205,6 +220,8 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
select2-rails (3.5.9.1)
thor (~> 0.14)
selenium-webdriver (2.53.0)
childprocess (~> 0.5)
rubyzip (~> 1.0)
Expand All @@ -215,6 +232,26 @@ GEM
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
sixarm_ruby_unaccent (1.1.1)
spree (3.0.9)
spree_api (= 3.0.9)
spree_backend (= 3.0.9)
spree_cmd (= 3.0.9)
spree_core (= 3.0.9)
spree_frontend (= 3.0.9)
spree_sample (= 3.0.9)
spree_api (3.0.9)
rabl (~> 0.11.6)
spree_core (= 3.0.9)
versioncake (~> 2.3.1)
spree_backend (3.0.9)
bootstrap-sass (~> 3.3)
jquery-rails (~> 4.1)
jquery-ui-rails (~> 5.0)
select2-rails (= 3.5.9.1)
spree_api (= 3.0.9)
spree_core (= 3.0.9)
spree_cmd (3.0.9)
thor (~> 0.14)
spree_core (3.0.9)
activemerchant (~> 1.47.0)
acts_as_list (= 0.7.2)
Expand All @@ -240,6 +277,14 @@ GEM
stringex
truncate_html (= 0.9.2)
twitter_cldr (~> 3.0)
spree_frontend (3.0.9)
bootstrap-sass (>= 3.3.5.1, < 3.4)
canonical-rails (~> 0.0.4)
jquery-rails (~> 4.1)
spree_api (= 3.0.9)
spree_core (= 3.0.9)
spree_sample (3.0.9)
spree_core (= 3.0.9)
sprockets (3.6.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand All @@ -255,18 +300,22 @@ GEM
state_machines-activerecord (0.4.0)
activerecord (>= 4.1, < 5.1)
state_machines-activemodel (>= 0.3.0)
stringex (2.6.0)
stringex (2.6.1)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.4)
truncate_html (0.9.2)
twitter_cldr (3.3.0)
twitter_cldr (3.6.0)
camertron-eprun
cldr-plurals-runtime-rb (~> 1.0.0)
json
cldr-plurals-runtime-rb (~> 1.0)
tzinfo
tzinfo (1.2.2)
thread_safe (~> 0.1)
versioncake (2.3.1)
actionpack (>= 3.2)
activesupport (>= 3.2)
railties (>= 3.2)
tzinfo
websocket (1.2.3)
xpath (2.0.0)
nokogiri (~> 1.3)
Expand All @@ -288,4 +337,4 @@ DEPENDENCIES
sqlite3

BUNDLED WITH
1.12.1
1.12.3
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SpreeAddressAutoComplete
# SpreeAddressAutoComplete

Introduction goes here.
SpreeAddressAutoComplete allows you to use suggested address functionality using google maps api. Once installed the user will be given with a field in the address step of checkout page, using which he can select one of the suggested addresses by google, instead of typing the whole address by himself.

## Installation

Expand All @@ -9,9 +9,6 @@ Introduction goes here.
gem 'spree_address_auto_complete', git: 'https://github.com/vinsol/spree_address_auto_complete', branch: '3-0-stable'
```

The `branch` option is important: it must match the version of Spree you're using.
For example, use `3-1-stable` if you're using Spree `3-1-stable` or any `3.1.x` version.

2. Install the gem using Bundler:
```ruby
bundle install
Expand All @@ -22,23 +19,23 @@ Introduction goes here.
bundle exec rails g spree_address_auto_complete:install
```

4. Add Api-Key

Add `google_maps_api_key` to your secrets.
4. Go to general_setting in admin section to add your google maps api key.

5. Restart your server

If your server was running, restart it so that it can find the assets properly.

## Testing

First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using `rake test_app`.
Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.

```shell
bundle
bundle exec rake
bundle exec rake test_app
bundle exec rspec spec
```

<<<<<<< HEAD
When testing your applications integration with this extension you may use it's factories.
Simply add this require statement to your spec_helper:

Expand Down
16 changes: 6 additions & 10 deletions app/assets/javascripts/spree/backend/address_auto_complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,11 @@ AddressAutoComplete.prototype.setCountry = function(countryISO) {
}

AddressAutoComplete.prototype.setState = function(stateName) {
var _this = this;
$.ajax({
url: '/api/states/' + stateName + '/state_id',
dataType: 'json',
success: function(data) {
_this.formComponents.state.val(data['state_id']).change();
$(_this.searchInput).parents('.panel-body').find('.select2-chosen:last').html(_this.formComponents.state.find(':selected').html());
}
})
var stateId = $('#order_bill_address_attributes_state_id option').filter(function () {
return $(this).html().toLowerCase() == stateName.toLowerCase();
}).val();

this.formComponents.state.val(stateId).change();
}

AddressAutoComplete.prototype.setCity = function(cityName) {
Expand All @@ -85,4 +81,4 @@ $(function() {
billingAddressAutoComplete.init();
shippingAddressAutoComplete = new AddressAutoComplete('shipping_search', 'ship');
shippingAddressAutoComplete.init();
});
});
15 changes: 6 additions & 9 deletions app/assets/javascripts/spree/frontend/address_auto_complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,11 @@ AddressAutoComplete.prototype.setCountry = function(countryISO) {
}

AddressAutoComplete.prototype.setState = function(stateName) {
var _this = this;
$.ajax({
url: '/api/states/' + stateName + '/state_id',
dataType: 'json',
success: function(data) {
_this.formComponents.state.val(data['state_id']).change();
}
})
var stateId = $('#order_bill_address_attributes_state_id option').filter(function () {
return $(this).html().toLowerCase() == stateName.toLowerCase();
}).val();

this.formComponents.state.val(stateId).change();
}

AddressAutoComplete.prototype.setCity = function(cityName) {
Expand All @@ -84,4 +81,4 @@ $(function() {
billingAddressAutoComplete.init();
shippingAddressAutoComplete = new AddressAutoComplete('shipping_search', 'ship');
shippingAddressAutoComplete.init();
});
});
13 changes: 0 additions & 13 deletions app/controllers/spree/api/states_controller_decorator.rb

This file was deleted.

3 changes: 3 additions & 0 deletions app/models/spree/app_configuration_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Spree::AppConfiguration.class_eval do
preference :google_maps_api_key, :string
end
11 changes: 11 additions & 0 deletions app/overrides/add_google_maps_api_key_to_configurations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Deface::Override.new(virtual_path: 'spree/admin/general_settings/edit',
name: 'add_google_maps_places_library',
insert_before: "div.form-actions",
text: "
<div class='row'>
<div class='field col-md-6'>
<%= label_tag(Spree.t('google_maps_api_key')) %>
<%= preference_field_tag('google_maps_api_key', Spree::Config['google_maps_api_key'], type: 'string') %>
</div>
</div>
")
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= add_google_maps_places_library(Rails.application.secrets.google_maps_api_key) %>
<%= add_google_maps_places_library(Spree::Config.google_maps_api_key) %>
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

en:
hello: "Hello world"

spree:
google_maps_api_key: 'Google maps api key'
3 changes: 0 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
Spree::Core::Engine.routes.draw do
namespace :api, defaults: { format: 'json' } do
get '/states/:name/state_id', to: 'states#state_id'
end
end
9 changes: 9 additions & 0 deletions spec/models/spree/app_configuration_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "spec_helper"

describe Spree::AppConfiguration do

it "should set preference google_maps_api_key" do
expect(Spree::Config.google_maps_api_key).to eq('')
end

end
2 changes: 1 addition & 1 deletion spree_address_auto_complete.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

s.add_dependency 'spree_core', '~> 3.0.9'
s.add_dependency 'spree', '~> 3.0.9'

s.add_development_dependency 'capybara', '~> 2.6'
s.add_development_dependency 'coffee-rails'
Expand Down

0 comments on commit 6e8f365

Please sign in to comment.