dup_spree_dash 1.3.0.rc1

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.
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2007-2012, Spree Commerce, Inc. and other contributors
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ Overview Dashboard
2
+ ==================
3
+
4
+ Core extension to display Spree Analytics
5
+
6
+ Testing
7
+ -------
8
+
9
+ You need to do a quick one-time creation of a test application and then you can use it to run the tests.
10
+
11
+ bundle exec rake test_app
12
+
13
+ Then run the tests
14
+
15
+ bundle exec rake spec
@@ -0,0 +1,73 @@
1
+ module Spree
2
+ class Admin::AnalyticsController < Admin::BaseController
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
+ def register
18
+ 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
+
32
+ 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)
39
+ redirect_to admin_path
40
+ rescue Spree::Dash::JirafeException => e
41
+ flash[:error] = e.message
42
+ render :sign_up
43
+ end
44
+ end
45
+
46
+ def edit
47
+
48
+ end
49
+
50
+ def update
51
+ Spree::Dash::Config.app_id = params[:app_id]
52
+ Spree::Dash::Config.app_token = params[:app_token]
53
+ Spree::Dash::Config.site_id = params[:site_id]
54
+ Spree::Dash::Config.token = params[:token]
55
+ flash[:success] = t(:jirafe_settings_updated, :scope => "spree.dash")
56
+ redirect_to admin_analytics_path
57
+ end
58
+
59
+ private
60
+
61
+ def redirect_if_registered
62
+ if Spree::Dash::Config.configured?
63
+ flash[:success] = t(:already_signed_up_for_analytics)
64
+ redirect_to admin_path and return true
65
+ end
66
+ end
67
+
68
+ def format_url(url)
69
+ url =~ /^http/ ? url : "http://#{url}"
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,16 @@
1
+ module Spree
2
+ class Admin::OverviewController < Admin::BaseController
3
+
4
+ JIRAFE_LOCALES = { :english => 'en_US',
5
+ :french => 'fr_FR',
6
+ :german => 'de_DE',
7
+ :japanese => 'ja_JA' }
8
+
9
+ def index
10
+ if JIRAFE_LOCALES.values.include? params[:locale]
11
+ Spree::Dash::Config.locale = params[:locale]
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ module Admin
3
+ module OverviewHelper
4
+
5
+ def jirafe_locale_links
6
+ Spree::Admin::OverviewController::JIRAFE_LOCALES.collect do |langage, locale|
7
+ link_to image_tag("flags/#{locale.split('_')[1].downcase}.png", :alt => langage.to_s.titleize), admin_path(:locale => locale), :class => 'with-tip', :title => langage.to_s.titleize, :data => {:'tip-color' => 'green'}
8
+ end
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,236 @@
1
+ module Spree
2
+ module AnalyticsHelper
3
+
4
+ def spree_analytics
5
+ render :partial => 'spree/analytics/header'
6
+ end
7
+
8
+ def analytics_tags
9
+ tags = { :id => Spree::Dash::Config.site_id.to_s }
10
+ tags.merge! product_analytics_tags
11
+ tags.merge! taxon_analytics_tags
12
+ tags.merge! keywords_analytics_tags
13
+ tags.merge! cart_analytics_tags
14
+ tags.merge! completed_analytics_tags
15
+ end
16
+
17
+ def product_analytics_tags
18
+ return {} unless @product
19
+ { :product => { :name => @product.name,
20
+ :price => @product.price,
21
+ :sku => @product.sku,
22
+ :categories => @product.taxons.map(&:permalink)
23
+ }
24
+ }
25
+ end
26
+
27
+ def taxon_analytics_tags
28
+ return {} unless @taxon
29
+ { :category => { :name => @taxon.permalink } }
30
+ end
31
+
32
+ def keywords_analytics_tags
33
+ return {} unless params[:keywords]
34
+ { :search => { :keyword => u(params[:keywords]) } }
35
+ end
36
+
37
+ def cart_analytics_tags
38
+ return {} unless @order and @order.cart?
39
+ { :cart => { :total => @order.total,
40
+ :products => products_for_order }
41
+ }
42
+ end
43
+
44
+ def completed_analytics_tags
45
+ return {} unless flash[:commerce_tracking] and @order and @order.complete?
46
+ { :confirm => { :orderid => @order.number,
47
+ :total => @order.total,
48
+ :shipping => @order.ship_total,
49
+ :tax => @order.tax_total,
50
+ :discount => @order.adjustment_total,
51
+ :subtotal => @order.item_total,
52
+ :products => products_for_order }
53
+ }
54
+ end
55
+
56
+ def products_for_order
57
+ @order.line_items.map do |line_item|
58
+ variant = line_item.variant
59
+ {
60
+ :name => variant.name,
61
+ :qty => line_item.quantity,
62
+ :price => variant.price,
63
+ :sku => variant.sku,
64
+ :categories => variant.product.taxons.map(&:permalink)
65
+ }
66
+ end
67
+ end
68
+
69
+ CURRENCIES = [
70
+ ["Australian Dollar", "AUD"],
71
+ ["New Zealand Dollar", "NZD"],
72
+ ["US Dollar", "USD"],
73
+ ["Euro", "EUR"],
74
+ ["British Pound", "GBP"],
75
+ ["Japanese Yen", "JPY"],
76
+ ["Afghanistan Afghani", "AFA"],
77
+ ["Albanian Lek", "ALL"],
78
+ ["Algerian Dinar", "DZD"],
79
+ ["Andorran Franc", "ADF"],
80
+ ["Andorran Peseta", "ADP"],
81
+ ["Angolan New Kwanza", "AON"],
82
+ ["Argentine Peso", "ARS"],
83
+ ["Aruban Florin", "AWG"],
84
+ ["Austrian Schilling", "ATS"],
85
+ ["Bahamanian Dollar", "BSD"],
86
+ ["Bahraini Dinar", "BHD"],
87
+ ["Bangladeshi Taka", "BDT"],
88
+ ["Barbados Dollar", "BBD"],
89
+ ["Belgian Franc", "BEF"],
90
+ ["Belize Dollar", "BZD"],
91
+ ["Bermudian Dollar", "BMD"],
92
+ ["Bhutan Ngultrum", "BTN"],
93
+ ["Bolivian Boliviano", "BOB"],
94
+ ["Botswana Pula", "BWP"],
95
+ ["Brazilian Real", "BRL"],
96
+ ["Brunei Dollar", "BND"],
97
+ ["Bulgarian Lev", "BGL"],
98
+ ["Burundi Franc", "BIF"],
99
+ ["CFA Franc BCEAO", "XOF"],
100
+ ["CFA Franc BEAC", "XAF"],
101
+ ["Cambodian Riel", "KHR"],
102
+ ["Canadian Dollar", "CAD"],
103
+ ["Cape Verde Escudo", "CVE"],
104
+ ["Cayman Islands Dollar", "KYD"],
105
+ ["Central Pacific Franc", "CFP"],
106
+ ["Chilean Peso", "CLP"],
107
+ ["Chinese Yuan Renminbi", "CNY"],
108
+ ["Colombian Peso", "COP"],
109
+ ["Comoros Franc", "KMF"],
110
+ ["Costa Rican Colon", "CRC"],
111
+ ["Croatian Kuna", "HRK"],
112
+ ["Cuban Peso", "CUP"],
113
+ ["Cyprus Pound", "CYP"],
114
+ ["Czech Koruna", "CSK"],
115
+ ["Danish Krone", "DKK"],
116
+ ["Djibouti Franc", "DJF"],
117
+ ["Dominican R. Peso", "DOP"],
118
+ ["Dutch Guilder", "NLG"],
119
+ ["ECU", "XEU"],
120
+ ["East Caribbean Dollar", "XCD"],
121
+ ["Ecuador Sucre", "ECS"],
122
+ ["Egyptian Pound", "EGP"],
123
+ ["El Salvador Colon", "SVC"],
124
+ ["Estonian Kroon", "EEK"],
125
+ ["Ethiopian Birr", "ETB"],
126
+ ["Falkland Islands Pound", "FKP"],
127
+ ["Fiji Dollar", "FJD"],
128
+ ["Finnish Markka", "FIM"],
129
+ ["French Franc", "FRF"],
130
+ ["Gambian Dalasi", "GMD"],
131
+ ["German Mark", "DEM"],
132
+ ["Ghanaian Cedi", "GHC"],
133
+ ["Gibraltar Pound", "GIP"],
134
+ ["Greek Drachma", "GRD"],
135
+ ["Guatemalan Quetzal", "GTQ"],
136
+ ["Guinea Franc", "GNF"],
137
+ ["Guyanese Dollar", "GYD"],
138
+ ["Haitian Gourde", "HTG"],
139
+ ["Honduran Lempira", "HNL"],
140
+ ["Hong Kong Dollar", "HKD"],
141
+ ["Hungarian Forint", "HUF"],
142
+ ["Iceland Krona", "ISK"],
143
+ ["Indian Rupee", "INR"],
144
+ ["Indonesian Rupiah", "IDR"],
145
+ ["Iranian Rial", "IRR"],
146
+ ["Iraqi Dinar", "IQD"],
147
+ ["Irish Punt", "IEP"],
148
+ ["Israeli New Shekel", "ILS"],
149
+ ["Italian Lira", "ITL"],
150
+ ["Jamaican Dollar", "JMD"],
151
+ ["Jordanian Dinar", "JOD"],
152
+ ["Kazakhstan Tenge", "KZT"],
153
+ ["Kenyan Shilling", "KES"],
154
+ ["Kuwaiti Dinar", "KWD"],
155
+ ["Lao Kip", "LAK"],
156
+ ["Latvian Lats", "LVL"],
157
+ ["Lebanese Pound", "LBP"],
158
+ ["Lesotho Loti", "LSL"],
159
+ ["Liberian Dollar", "LRD"],
160
+ ["Libyan Dinar", "LYD"],
161
+ ["Lithuanian Litas", "LTL"],
162
+ ["Luxembourg Franc", "LUF"],
163
+ ["Macau Pataca", "MOP"],
164
+ ["Malagasy Franc", "MGF"],
165
+ ["Malawi Kwacha", "MWK"],
166
+ ["Malaysian Ringgit", "MYR"],
167
+ ["Maldive Rufiyaa", "MVR"],
168
+ ["Maltese Lira", "MTL"],
169
+ ["Mauritanian Ouguiya", "MRO"],
170
+ ["Mauritius Rupee", "MUR"],
171
+ ["Mexican Peso", "MXP"],
172
+ ["Mongolian Tugrik", "MNT"],
173
+ ["Moroccan Dirham", "MAD"],
174
+ ["Mozambique Metical", "MZM"],
175
+ ["Myanmar Kyat", "MMK"],
176
+ ["NL Antillian Guilder", "ANG"],
177
+ ["Namibia Dollar", "NAD"],
178
+ ["Nepalese Rupee", "NPR"],
179
+ ["Nicaraguan Cordoba Oro", "NIO"],
180
+ ["Nigerian Naira", "NGN"],
181
+ ["North Korean Won", "KPW"],
182
+ ["Norwegian Kroner", "NOK"],
183
+ ["Omani Rial", "OMR"],
184
+ ["Pakistan Rupee", "PKR"],
185
+ ["Panamanian Balboa", "PAB"],
186
+ ["Papua New Guinea Kina", "PGK"],
187
+ ["Paraguay Guarani", "PYG"],
188
+ ["Peruvian Nuevo Sol", "PEN"],
189
+ ["Philippine Peso", "PHP"],
190
+ ["Polish Zloty", "PLZ"],
191
+ ["Portuguese Escudo", "PTE"],
192
+ ["Qatari Rial", "QAR"],
193
+ ["Romanian Leu", "ROL"],
194
+ ["Russian Rouble", "RUB"],
195
+ ["Samoan Tala", "WST"],
196
+ ["Sao Tome/Principe Dobra", "STD"],
197
+ ["Saudi Riyal", "SAR"],
198
+ ["Seychelles Rupee", "SCR"],
199
+ ["Sierra Leone Leone", "SLL"],
200
+ ["Singapore Dollar", "SGD"],
201
+ ["Slovak Koruna", "SKK"],
202
+ ["Slovenian Tolar", "SIT"],
203
+ ["Solomon Islands Dollar", "SBD"],
204
+ ["Somali Shilling", "SOS"],
205
+ ["South African Rand", "ZAR"],
206
+ ["South-Korean Won", "KRW"],
207
+ ["Spanish Peseta", "ESP"],
208
+ ["Sri Lanka Rupee", "LKR"],
209
+ ["St. Helena Pound", "SHP"],
210
+ ["Sudanese Dinar", "SDD"],
211
+ ["Sudanese Pound", "SDP"],
212
+ ["Suriname Guilder", "SRG"],
213
+ ["Swaziland Lilangeni", "SZL"],
214
+ ["Swedish Krona", "SEK"],
215
+ ["Swiss Franc", "CHF"],
216
+ ["Syrian Pound", "SYP"],
217
+ ["Taiwan Dollar", "TWD"],
218
+ ["Tanzanian Shilling", "TZS"],
219
+ ["Thai Baht", "THB"],
220
+ ["Tonga Pa'anga", "TOP"],
221
+ ["Trinidad/Tobago Dollar", "TTD"],
222
+ ["Tunisian Dinar", "TND"],
223
+ ["Turkish Lira", "TRL"],
224
+ ["Uganda Shilling", "UGS"],
225
+ ["Ukraine Hryvnia", "UAH"],
226
+ ["Uruguayan Peso", "UYP"],
227
+ ["Utd. Arab Emir. Dirham", "AED"],
228
+ ["Vanuatu Vatu", "VUV"],
229
+ ["Venezuelan Bolivar", "VEB"],
230
+ ["Vietnamese Dong", "VND"],
231
+ ["Yugoslav Dinar", "YUN"],
232
+ ["Zambian Kwacha", "ZMK"],
233
+ ["ZWD","Zimbabwe Dollar"]
234
+ ]
235
+ end
236
+ end
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ class DashConfiguration < Preferences::Configuration
3
+ preference :app_id, :string
4
+ preference :app_token, :string
5
+ preference :site_id, :string
6
+ preference :token, :string
7
+ preference :locale, :string, :default => 'en_US'
8
+
9
+ def configured?
10
+ preferred_app_id.present? and preferred_site_id.present? and preferred_token.present?
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
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')
@@ -0,0 +1,26 @@
1
+ <h2><%= t(:header, :scope => "spree.dash.jirafe") %></h2>
2
+
3
+ <p><%= t(:explanation, :scope => "spree.dash.jirafe") %></p>
4
+
5
+ <%= form_tag admin_analytics_path, :method => :put do %>
6
+ <div class="field">
7
+ <%= label_tag 'app_id', t(:app_id, :scope => "spree.dash.jirafe") %><br>
8
+ <%= text_field_tag 'app_id', Spree::Dash::Config.app_id %>
9
+ </div>
10
+ <div class="field">
11
+ <%= label_tag 'app_token', t(:app_token, :scope => "spree.dash.jirafe") %><br>
12
+ <%= text_field_tag 'app_token', Spree::Dash::Config.app_token, :size => 40 %>
13
+ </div>
14
+ <div class="field">
15
+ <%= label_tag 'site_id', t(:site_id, :scope => "spree.dash.jirafe") %><br>
16
+ <%= text_field_tag 'site_id', Spree::Dash::Config.site_id %>
17
+ </div>
18
+ <div class="field">
19
+ <%= label_tag 'token', t(:token, :scope => "spree.dash.jirafe") %><br>
20
+ <%= text_field_tag 'token', Spree::Dash::Config.token, :size => 40 %>
21
+ </div>
22
+ <div class="form-buttons" data-hook="buttons">
23
+ <%= submit_tag "Update" %>
24
+ </div>
25
+ <% end %>
26
+
@@ -0,0 +1,61 @@
1
+ <% content_for :page_title do %>
2
+ <%= t(:analytics_sign_up) %>
3
+ <% end %>
4
+
5
+ <% content_for :page_title_classes do %>
6
+ align-center
7
+ <% end %>
8
+
9
+ <%= form_tag admin_analytics_register_path do %>
10
+ <div id="analytics_signup" data-hook class="align-center label-block">
11
+ <div class="field">
12
+ <%= label_tag :first_name %>
13
+ <%= text_field_tag 'store[first_name]', @store[:first_name], :size => 50 %>
14
+ </div>
15
+
16
+ <div class="field">
17
+ <%= label_tag :last_name %>
18
+ <%= text_field_tag 'store[last_name]', @store[:last_name], :size => 50 %>
19
+ </div>
20
+
21
+ <div class="field">
22
+ <%= label_tag :email %>
23
+ <%= email_field_tag 'store[email]', @store[:email], :size => 50 %>
24
+ </div>
25
+
26
+ <div class="field">
27
+ <%= label_tag :store_name %>
28
+ <%= text_field_tag 'store[name]', @store[:name], :size => 50 %>
29
+ </div>
30
+
31
+ <div class="field">
32
+ <%= label_tag :store_url %>
33
+ <%= url_field_tag 'store[url]', @store[:url], :size => 50 %>
34
+ </div>
35
+
36
+ <div class="field">
37
+ <%= label_tag :currency %>
38
+ <%= select_tag 'store[currency]', options_for_select(Spree::AnalyticsHelper::CURRENCIES, @store[:currency]), :class => 'select2' %>
39
+ </div>
40
+
41
+ <div class="field">
42
+ <%= label_tag :time_zone %>
43
+ <%= select_tag 'store[time_zone]', time_zone_options_for_select(@store[:time_zone]), :class => 'select2' %>
44
+ </div>
45
+
46
+ <div class="field">
47
+ <%= check_box_tag 'store[terms_of_service]', @store[:terms_of_service], @store.has_key?(:terms_of_service), :size => 50 %>
48
+ <%= label_tag 'store[terms_of_service]', t(:agree_to_terms_of_service) %> (<a href="http://jirafe.com/about/terms" target="_new"><%= t(:review) %></a>)
49
+ </div>
50
+
51
+ <div class="field">
52
+ <%= check_box_tag 'store[privacy_policy]', @store[:privacy_policy], @store.has_key?(:privacy_policy), :size => 50 %>
53
+ <%= label_tag 'store[privacy_policy]', t(:agree_to_privacy_policy) %> (<a href="http://jirafe.com/about/privacy" target="_new"><%= t(:review) %></a>)
54
+ </div>
55
+ </div>
56
+ <div class="form-buttons" data-hook="buttons">
57
+ <%= button t(:activate), 'icon-ok' %>
58
+ <%= t(:or) %>
59
+ <%= link_to_with_icon 'icon-remove', t(:cancel), admin_path, :class => 'button' %>
60
+ </div>
61
+ <% end %>
@@ -0,0 +1,51 @@
1
+ <% content_for :head do %>
2
+ <%= stylesheet_link_tag 'https://api.jirafe.com/dashboard/css/spree_ui.css', :media => 'all' %>
3
+ <%= javascript_include_tag 'https://jirafe.com/dashboard/js/spree_namespaced_ui.js' %>
4
+ <% end %>
5
+
6
+ <% if Spree::Dash::Config.configured? %>
7
+
8
+ <% content_for :page_actions do %>
9
+ <li id="jirafe_locales">
10
+ <i class="icon-globe"></i> <%= t(:choose_dashboard_locale) %>: <%= raw jirafe_locale_links.join(' ') %>
11
+ </li>
12
+ <% end %>
13
+
14
+ <div id="jirafe"></div>
15
+ <%= javascript_tag :defer => 'defer' do %>
16
+ jirafe.jQuery('#jirafe').jirafe({
17
+ api_url: 'https://api.jirafe.com/v1',
18
+ api_token: '<%= Spree::Dash::Config.token %>',
19
+ app_id: '<%= Spree::Dash::Config.app_id %>',
20
+ version: 'spree-v0.1.0',
21
+ locale: '<%= Spree::Dash::Config.locale %>' });
22
+ setTimeout(function() {
23
+ if ($('mod-jirafe') == undefined) {
24
+ $('messages').insert ("<ul class=\"messages\"><li class=\"error-msg\">We're unable to connect with the Jirafe service for the moment. Please wait a few minutes and refresh this page later.</li></ul>");
25
+ }
26
+ }, 10000);
27
+ <% end %>
28
+ <% else %>
29
+ <div class="no-border-top analytics-description">
30
+ <div class="description-text">
31
+ <hgroup>
32
+ <h1><%= t(:analytics_desc_header_1)%></h1>
33
+ <h6><%= t(:analytics_desc_header_2)%></h6>
34
+ </hgroup>
35
+
36
+ <ul>
37
+ <li><%= t(:analytics_desc_list_1)%></li>
38
+ <li><%= t(:analytics_desc_list_2)%></li>
39
+ <li><%= t(:analytics_desc_list_3)%></li>
40
+ <li><%= t(:analytics_desc_list_4)%></li>
41
+ </ul>
42
+ </div>
43
+ <div class="preview-buttons filter-actions actions">
44
+ <%= link_to_with_icon 'icon-ok', t(:activate), admin_analytics_sign_up_path, :class => 'button' %>
45
+ <span class="or">&nbsp; <%= t(:or) %> &nbsp;</span>
46
+ <%= link_to_with_icon 'icon-info-sign', t(:learn_more), "http://spreecommerce.com/blog/2012/01/31/introducing-spree-analytics/", :class => 'button', :target => '_blank' %>
47
+ </div>
48
+ </div>
49
+
50
+ <div class="analytics_splash"></div>
51
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <% if Spree::Dash::Config.configured? %>
2
+ <script type='text/javascript' id='analytics'>
3
+ var jirafe= <%= raw analytics_tags.to_json %>;
4
+ (function(){
5
+ var d=document,g=d.createElement('script'),s=d.getElementsByTagName('script')[0];
6
+ g.type='text/javascript',g.defer=g.async=true;g.src=d.location.protocol+'//c.jirafe.com/jirafe.js';
7
+ s.parentNode.insertBefore(g, s);
8
+ })();
9
+ </script>
10
+ <% else %>
11
+ <!-- Spree Analytics has not been initialized correctly -->
12
+ <% end %>
@@ -0,0 +1,22 @@
1
+ en:
2
+ agree_to_terms_of_service: Agree to Terms of Service
3
+ agree_to_privacy_policy: Agree to Privacy Policy
4
+ already_signed_up_for_analytics: You have already signed up for Spree Analytics
5
+ successfully_signed_up_for_analytics: Successfully signed up for Spree Analytics
6
+ analytics_desc_header_1: Spree Analytics
7
+ analytics_desc_header_2: Live analytics integrated into your Spree dashboard
8
+ analytics_desc_list_1: Get live sales information as it happens
9
+ analytics_desc_list_2: Requires only a free Spree account to activate
10
+ analytics_desc_list_3: Absolutely no code to install
11
+ analytics_desc_list_4: It's completely free!
12
+
13
+ spree:
14
+ dash:
15
+ jirafe:
16
+ header: Jirafe Analytics Settings
17
+ app_id: App ID
18
+ app_token: App Token
19
+ site_id: Site ID
20
+ token: Token
21
+ explanation: The fields below may already be populated if you chose to register with Jirafe from the admin dashboard.
22
+ jirafe_settings_updated: Jirafe Settings have been updated.
data/config/routes.rb ADDED
@@ -0,0 +1,9 @@
1
+ Spree::Core::Engine.routes.prepend do
2
+ match '/admin' => 'admin/overview#index', :as => :admin
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
6
+
7
+ get '/jirafe' => 'admin/analytics#edit', :as => :admin_analytics
8
+ put '/jirafe' => 'admin/analytics#update', :as => :admin_analytics
9
+ end
@@ -0,0 +1,20 @@
1
+ module Spree
2
+ module Dash
3
+ class Engine < Rails::Engine
4
+ isolate_namespace Spree
5
+ engine_name 'spree_dash'
6
+
7
+ initializer "spree.dash.environment", :before => :load_config_initializers do |app|
8
+ Spree::Dash::Config = Spree::DashConfiguration.new
9
+ end
10
+
11
+ def self.activate
12
+ Dir.glob(File.join(File.dirname(__FILE__), "../../../app/**/*_decorator*.rb")) do |c|
13
+ Rails.configuration.cache_classes ? require(c) : load(c)
14
+ end
15
+ end
16
+ config.to_prepare &method(:activate).to_proc
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,74 @@
1
+ module Spree
2
+ module Dash
3
+ class JirafeException < Exception; end
4
+
5
+ class Jirafe
6
+ include HTTParty
7
+ base_uri 'https://api.jirafe.com/v1'
8
+ format :json
9
+
10
+ class << self
11
+ def register(store)
12
+ validate_required_keys! store
13
+ store[:time_zone] = ActiveSupport::TimeZone::MAPPING[store[:time_zone]] # jirafe expects 'America/New_York'
14
+
15
+ store = register_application(store)
16
+ store = synchronize_resources(store)
17
+ end
18
+
19
+ def validate_required_keys!(store)
20
+ [:first_name, :url, :email, :currency, :time_zone, :name].each do |key|
21
+ unless store[key].present?
22
+ raise JirafeException, "#{key.to_s.titleize} is required"
23
+ end
24
+ end
25
+ end
26
+
27
+ def register_application(store)
28
+ return if store[:app_id].present? && store[:app_token].present?
29
+
30
+ options = {
31
+ :body => {
32
+ :name => store[:name],
33
+ :url => store[:url]
34
+ }
35
+ }
36
+ response = post '/applications', options
37
+ raise JirafeException, 'unable to create jirafe application' unless response.code == 200 &&
38
+ response['app_id'].present? &&
39
+ response['token'].present?
40
+ store[:app_id] = response['app_id']
41
+ store[:app_token] = response['token']
42
+ store
43
+ end
44
+
45
+ def synchronize_resources(store)
46
+ return unless store.has_key?(:app_id) and store.has_key?(:app_token)
47
+
48
+ options = {
49
+ :headers => { 'Content-type' => 'application/json' },
50
+ :query => { :token => store[:app_token] },
51
+ :body => {
52
+ :sites => [{ :description => store[:name],
53
+ :url => store[:url],
54
+ :currency => store[:currency],
55
+ :timezone => store[:time_zone],
56
+ :external_id => 1,
57
+ :site_id => store[:site_id] }],
58
+ :users => [{ :email => store[:email],
59
+ :first_name => store[:first_name],
60
+ :last_name => store[:last_name] }]
61
+ }.to_json
62
+ }
63
+ response = post "/applications/#{store[:app_id]}/resources", options
64
+ raise JirafeException, 'unable to synchronize store' unless response.code == 200 &&
65
+ response['sites'].present? &&
66
+ response['users'].present?
67
+ store[:site_id] = response["sites"].first["site_id"]
68
+ store[:site_token] = response["users"].first["token"]
69
+ store
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
data/lib/spree/dash.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'spree_core'
2
+ require 'httparty'
3
+
4
+ module Spree
5
+ module Dash
6
+
7
+ end
8
+ end
9
+
10
+ require 'spree/dash/engine'
11
+ require 'spree/dash/jirafe'
12
+
13
+ Spree::Dash::Engine.config.to_prepare do
14
+ Spree::BaseController.send :helper, 'spree/analytics'
15
+ end
data/lib/spree_dash.rb ADDED
@@ -0,0 +1 @@
1
+ require 'spree/dash'
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dup_spree_dash
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0.rc1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Brian Quinn
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: spree_core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.3.0.rc1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.3.0.rc1
30
+ - !ruby/object:Gem::Dependency
31
+ name: httparty
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.8.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.1
46
+ description: Required dependency for Spree
47
+ email: brian@spreecommerce.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - LICENSE
53
+ - README.md
54
+ - app/assets/images/analytics_dashboard_preview.jpg
55
+ - app/controllers/spree/admin/analytics_controller.rb
56
+ - app/controllers/spree/admin/overview_controller.rb
57
+ - app/helpers/spree/admin/overview_helper.rb
58
+ - app/helpers/spree/analytics_helper.rb
59
+ - app/models/spree/dash_configuration.rb
60
+ - app/overrides/analytics_header.rb
61
+ - app/overrides/configuration_menu_link.rb
62
+ - app/views/spree/admin/analytics/edit.html.erb
63
+ - app/views/spree/admin/analytics/sign_up.html.erb
64
+ - app/views/spree/admin/overview/index.html.erb
65
+ - app/views/spree/analytics/_header.html.erb
66
+ - config/locales/en.yml
67
+ - config/routes.rb
68
+ - lib/spree/dash/engine.rb
69
+ - lib/spree/dash/jirafe.rb
70
+ - lib/spree/dash.rb
71
+ - lib/spree_dash.rb
72
+ homepage: http://spreecommerce.com
73
+ licenses:
74
+ - BSD-3
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: 1.8.7
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>'
89
+ - !ruby/object:Gem::Version
90
+ version: 1.3.1
91
+ requirements:
92
+ - none
93
+ rubyforge_project:
94
+ rubygems_version: 1.8.24
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Overview dashboard for use with Spree.
98
+ test_files: []