spree_dash 1.3.0.rc1 → 1.3.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,50 +1,31 @@
1
1
  module Spree
2
2
  class Admin::AnalyticsController < Admin::BaseController
3
3
 
4
- def sign_up
5
- redirect_if_registered and return
6
- @store = {
7
- :first_name => '',
8
- :last_name => '',
9
- :email => try_spree_current_user.email,
10
- :currency => 'USD',
11
- :time_zone => Time.zone,
12
- :name => Spree::Config.site_name,
13
- :url => format_url(Spree::Config.site_url)
14
- }
15
- end
16
-
17
4
  def register
18
5
  redirect_if_registered and return
19
- @store = params[:store]
20
- @store[:url] = format_url(@store[:url])
21
-
22
- unless @store.has_key? :terms_of_service
23
- flash[:error] = t(:agree_to_terms_of_service)
24
- return render :sign_up
25
- end
26
-
27
- unless @store.has_key? :privacy_policy
28
- flash[:error] = t(:agree_to_privacy_policy)
29
- return render :sign_up
30
- end
31
6
 
32
7
  begin
33
- @store = Spree::Dash::Jirafe.register(@store)
34
- Spree::Dash::Config.app_id = @store[:app_id]
35
- Spree::Dash::Config.app_token = @store[:app_token]
36
- Spree::Dash::Config.site_id = @store[:site_id]
37
- Spree::Dash::Config.token = @store[:site_token]
38
- flash[:notice] = t(:successfully_signed_up_for_analytics)
8
+ store = Spree::Dash::Jirafe.register(store_hash)
9
+ Spree::Dash::Config.app_id = store[:app_id]
10
+ Spree::Dash::Config.app_token = store[:app_token]
11
+ Spree::Dash::Config.site_id = store[:site_id]
12
+ Spree::Dash::Config.token = store[:site_token]
39
13
  redirect_to admin_path
40
14
  rescue Spree::Dash::JirafeException => e
41
15
  flash[:error] = e.message
42
- render :sign_up
16
+ redirect_to root_path
43
17
  end
44
18
  end
45
19
 
46
- def edit
47
-
20
+ def sync
21
+ session[:last_jirafe_sync] = DateTime.now
22
+ begin
23
+ store = Spree::Dash::Jirafe.synchronize_resources(store_hash)
24
+ redirect_to admin_path
25
+ rescue Spree::Dash::JirafeException => e
26
+ flash[:error] = e.message
27
+ redirect_to admin_path
28
+ end
48
29
  end
49
30
 
50
31
  def update
@@ -65,9 +46,33 @@ module Spree
65
46
  end
66
47
  end
67
48
 
49
+ def store_hash
50
+ url = Spree::Config.site_url || "http://demo.spreecommerce.com"
51
+ email = "junk@spreecommerce.com"
52
+ name = Spree::Config.site_name || "Spree Store"
53
+ platform_type = Rails.env.production? ? "spree" : "spree-#{Rails.env}"
54
+
55
+ store = {
56
+ :first_name => 'Spree',
57
+ :last_name => 'User',
58
+ :email => email,
59
+ :name => 'Spree Store',
60
+ :url => format_url(url),
61
+ :platform_type => platform_type,
62
+ :currency => 'USD',
63
+ :time_zone => ActiveSupport::TimeZone::MAPPING['Eastern Time (US & Canada)'],
64
+ }
65
+
66
+ if Spree::Dash::Config.configured?
67
+ store[:app_id] = Spree::Dash::Config.app_id
68
+ store[:app_token] = Spree::Dash::Config.app_token
69
+ store[:site_id] = Spree::Dash::Config.site_id
70
+ end
71
+ store
72
+ end
73
+
68
74
  def format_url(url)
69
75
  url =~ /^http/ ? url : "http://#{url}"
70
76
  end
71
-
72
77
  end
73
78
  end
@@ -1,5 +1,6 @@
1
1
  module Spree
2
2
  class Admin::OverviewController < Admin::BaseController
3
+ before_filter :check_last_jirafe_sync_time, :only => :index
3
4
 
4
5
  JIRAFE_LOCALES = { :english => 'en_US',
5
6
  :french => 'fr_FR',
@@ -7,10 +8,22 @@ module Spree
7
8
  :japanese => 'ja_JA' }
8
9
 
9
10
  def index
11
+ redirect_to admin_analytics_register_path unless Spree::Dash::Config.configured?
12
+
10
13
  if JIRAFE_LOCALES.values.include? params[:locale]
11
14
  Spree::Dash::Config.locale = params[:locale]
12
15
  end
13
16
  end
14
17
 
18
+ private
19
+
20
+ def check_last_jirafe_sync_time
21
+ if session[:last_jirafe_sync]
22
+ hours_since_last_sync = ((DateTime.now - session[:last_jirafe_sync]) * 24).to_i
23
+ redirect_to admin_analytics_sync_path if hours_since_last_sync > 24
24
+ else
25
+ redirect_to admin_analytics_sync_path
26
+ end
27
+ end
15
28
  end
16
29
  end
@@ -42,7 +42,7 @@ module Spree
42
42
  end
43
43
 
44
44
  def completed_analytics_tags
45
- return {} unless @order and @order.complete?
45
+ return {} unless flash[:commerce_tracking] and @order and @order.complete?
46
46
  { :confirm => { :orderid => @order.number,
47
47
  :total => @order.total,
48
48
  :shipping => @order.ship_total,
@@ -1,5 +1,5 @@
1
- Deface::Override.new(:virtual_path => "spree/admin/shared/_configuration_menu",
2
- :name => "add_dashboard_sidebar_link",
3
- :insert_bottom => ".sidebar",
4
- :text => "<%= configurations_sidebar_menu_item t(:jirafe), admin_analytics_path %>",
5
- :original => 'a74f177275dc303c9cd5994b2e24e027434c3cbb')
1
+ Deface::Override.new(:virtual_path => Spree::Config[:layout],
2
+ :name => "add_analytics_header",
3
+ :insert_bottom => "head",
4
+ :partial => "spree/analytics/header",
5
+ :original => '6f23c8af6e863d0499835c00b3f2763cb98e1d75')
@@ -0,0 +1,5 @@
1
+ Deface::Override.new(:virtual_path => "spree/admin/shared/_configuration_menu",
2
+ :name => "add_dashboard_sidebar_link",
3
+ :insert_bottom => ".sidebar",
4
+ :text => "<%= configurations_sidebar_menu_item t(:jirafe), admin_analytics_path %>",
5
+ :original => 'a74f177275dc303c9cd5994b2e24e027434c3cbb')
data/config/routes.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  Spree::Core::Engine.routes.prepend do
2
2
  match '/admin' => 'admin/overview#index', :as => :admin
3
3
 
4
- get '/admin/analytics/sign_up' => 'admin/analytics#sign_up', :as => :admin_analytics_sign_up
5
- post '/admin/analytics/register' => 'admin/analytics#register', :as => :admin_analytics_register
4
+ get '/admin/analytics/register' => 'admin/analytics#register', :as => :admin_analytics_register
5
+ get '/admin/analytics/sync' => 'admin/analytics#sync', :as => :admin_analytics_sync
6
6
 
7
7
  get '/jirafe' => 'admin/analytics#edit', :as => :admin_analytics
8
8
  put '/jirafe' => 'admin/analytics#update', :as => :admin_analytics
@@ -10,8 +10,6 @@ module Spree
10
10
  class << self
11
11
  def register(store)
12
12
  validate_required_keys! store
13
- store[:time_zone] = ActiveSupport::TimeZone::MAPPING[store[:time_zone]] # jirafe expects 'America/New_York'
14
-
15
13
  store = register_application(store)
16
14
  store = synchronize_resources(store)
17
15
  end
@@ -55,9 +53,7 @@ module Spree
55
53
  :timezone => store[:time_zone],
56
54
  :external_id => 1,
57
55
  :site_id => store[:site_id] }],
58
- :users => [{ :email => store[:email],
59
- :first_name => store[:first_name],
60
- :last_name => store[:last_name] }]
56
+ :users => users_hash
61
57
  }.to_json
62
58
  }
63
59
  response = post "/applications/#{store[:app_id]}/resources", options
@@ -68,7 +64,19 @@ module Spree
68
64
  store[:site_token] = response["users"].first["token"]
69
65
  store
70
66
  end
67
+
68
+ def users_hash
69
+ users = []
70
+ Spree.user_class.includes(:spree_roles).where("spree_roles.name = 'admin'").each do |user|
71
+ users << {
72
+ :email => user.email,
73
+ :first_name => 'Spree',
74
+ :last_name => 'User'
75
+ }
76
+ end
77
+ users
78
+ end
71
79
  end
72
80
  end
73
81
  end
74
- end
82
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_dash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0.rc1
4
+ version: 1.3.0.rc2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-04 00:00:00.000000000 Z
12
+ date: 2012-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spree_core
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.3.0.rc1
21
+ version: 1.3.0.rc2
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 1.3.0.rc1
29
+ version: 1.3.0.rc2
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: httparty
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +58,7 @@ files:
58
58
  - app/helpers/spree/analytics_helper.rb
59
59
  - app/models/spree/dash_configuration.rb
60
60
  - app/overrides/analytics_header.rb
61
+ - app/overrides/configuration_menu_link.rb
61
62
  - app/views/spree/admin/analytics/edit.html.erb
62
63
  - app/views/spree/admin/analytics/sign_up.html.erb
63
64
  - app/views/spree/admin/overview/index.html.erb
@@ -69,7 +70,8 @@ files:
69
70
  - lib/spree/dash.rb
70
71
  - lib/spree_dash.rb
71
72
  homepage: http://spreecommerce.com
72
- licenses: []
73
+ licenses:
74
+ - BSD-3
73
75
  post_install_message:
74
76
  rdoc_options: []
75
77
  require_paths: