spree_dash 0.70.7 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/LICENSE +2 -2
  2. data/README.md +1 -1
  3. data/app/assets/images/analytics_dashboard_preview.png +0 -0
  4. data/app/controllers/spree/admin/overview_controller.rb +15 -0
  5. data/app/controllers/spree/base_controller_decorator.rb +3 -0
  6. data/app/helpers/spree/analytics_helper.rb +69 -0
  7. data/app/models/spree/dash_configuration.rb +11 -0
  8. data/app/overrides/analytics_header.rb +4 -0
  9. data/app/views/spree/admin/overview/_form.html.erb +23 -0
  10. data/app/views/spree/admin/overview/index.html.erb +37 -0
  11. data/app/views/spree/analytics/_header.html.erb +12 -0
  12. data/config/locales/en.yml +1 -0
  13. data/config/routes.rb +2 -2
  14. data/lib/spree/dash.rb +9 -0
  15. data/lib/spree/dash/engine.rb +24 -0
  16. data/lib/spree_dash.rb +1 -7
  17. metadata +33 -32
  18. data/app/assets/javascripts/admin/dashboard.js +0 -144
  19. data/app/assets/javascripts/admin/spree_dash.js +0 -15
  20. data/app/assets/javascripts/store/spree_dash.js +0 -1
  21. data/app/assets/stylesheets/admin/dashboard.css.erb +0 -143
  22. data/app/assets/stylesheets/admin/spree_dash.css +0 -4
  23. data/app/assets/stylesheets/store/spree_dash.css +0 -3
  24. data/app/controllers/admin/overview_controller.rb +0 -152
  25. data/app/views/admin/overview/index.html.erb +0 -164
  26. data/vendor/assets/javascripts/jqPlot/excanvas.min.js +0 -1
  27. data/vendor/assets/javascripts/jqPlot/jquery.jqplot.min.js +0 -14
  28. data/vendor/assets/javascripts/jqPlot/plugins/jqplot.canvasAxisLabelRenderer.min.js +0 -14
  29. data/vendor/assets/javascripts/jqPlot/plugins/jqplot.canvasAxisTickRenderer.min.js +0 -14
  30. data/vendor/assets/javascripts/jqPlot/plugins/jqplot.canvasTextRenderer.min.js +0 -14
  31. data/vendor/assets/javascripts/jqPlot/plugins/jqplot.categoryAxisRenderer.min.js +0 -14
  32. data/vendor/assets/javascripts/jqPlot/plugins/jqplot.dateAxisRenderer.min.js +0 -14
  33. data/vendor/assets/javascripts/jqPlot/plugins/jqplot.highlighter.min.js +0 -14
  34. data/vendor/assets/javascripts/jqPlot/plugins/jqplot.pieRenderer.min.js +0 -14
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007-2011, Rails Dog LLC and other contributors
1
+ Copyright (c) 2007-2011, Spree Commerce, Inc. and other contributors
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without modification,
@@ -23,4 +23,4 @@ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
23
  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
24
  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
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.
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Overview Dashboard
2
2
  ==================
3
3
 
4
- Core extension to display basic graphs and charts on store activity. Can be deleted if you don't require the dashboard.
4
+ Core extension to display Spree Analytics
5
5
 
6
6
  Testing
7
7
  -------
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ class Admin::OverviewController < Admin::BaseController
3
+
4
+ def index
5
+ end
6
+
7
+ def preferences
8
+ [:app_id, :site_id, :token].each do |key|
9
+ Spree::Dash::Config[key] = params[key]
10
+ end
11
+ redirect_to admin_path
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ Spree::BaseController.class_eval do
2
+ helper 'spree/analytics'
3
+ end
@@ -0,0 +1,69 @@
1
+ module Spree
2
+ module AnalyticsHelper
3
+
4
+ def spree_analytics
5
+ render :partial => '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 { |t| t.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 => 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 @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
+ { :name => variant.name,
60
+ :qty => line_item.quantity,
61
+ :price => variant.price,
62
+ :sku => variant.sku,
63
+ :categories => variant.product.taxons.map { |t| t.permalink }
64
+ }
65
+ end
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ class DashConfiguration < Preferences::Configuration
3
+ preference :app_id, :string
4
+ preference :site_id, :string
5
+ preference :token, :string
6
+
7
+ def configured?
8
+ preferred_app_id.present? and preferred_site_id.present? and preferred_token.present?
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ Deface::Override.new(:virtual_path => "spree/layouts/spree_application",
2
+ :name => "add_analytics_header",
3
+ :insert_bottom => "[data-hook='inside_head']",
4
+ :partial => "spree/analytics/header")
@@ -0,0 +1,23 @@
1
+ <h2><%= t(:spree_analytics_token) %></h2>
2
+
3
+ <%= form_tag admin_dash_preferences_path, :method => :put do %>
4
+ <table data-hook="dash_preferences">
5
+ <tr data-hook="app_id">
6
+ <td><%= t(:analytics_app_id) %>:</td>
7
+ <td><%= text_field_tag :app_id, Spree::Dash::Config.app_id, :size => 50 %></td>
8
+ </tr>
9
+ <tr data-hook="site_id">
10
+ <td><%= t(:analytics_site_id) %>:</td>
11
+ <td><%= text_field_tag :site_id, Spree::Dash::Config.site_id, :size => 50 %></td>
12
+ </tr>
13
+ <tr data-hook="token">
14
+ <td><%= t(:analytics_token) %>:</td>
15
+ <td><%= text_field_tag :token, Spree::Dash::Config.token, :size => 50 %></td>
16
+ </tr>
17
+ </table>
18
+
19
+ <p class="form-buttons" data-hook="buttons">
20
+ <%= button t(:update) %> <%= link_to t(:cancel), admin_path %>
21
+ </p>
22
+
23
+ <% end %>
@@ -0,0 +1,37 @@
1
+ <% content_for :head do %>
2
+ <link type="text/css" rel="stylesheet" href="https://api.jirafe.com/dashboard/css/spree_ui.css" media="all" />
3
+ <script type="text/javascript" src="https://api.jirafe.com/dashboard/js/spree_ui.js"></script>
4
+ <% end %>
5
+
6
+ <h1><%= t(:overview) %></h1>
7
+
8
+ <% if params[:dash_edit] %>
9
+ <%= render 'form' %>
10
+ <% else %>
11
+ <% if Spree::Dash::Config.configured? %>
12
+ <div id="jirafe"></div>
13
+ <script type="text/javascript" defer="defer">
14
+ if (typeof jQuery != 'undefined') {
15
+ (function($) {
16
+ $('#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
+ });
22
+ })(jQuery);
23
+ }
24
+ setTimeout(function() {
25
+ if ($('mod-jirafe') == undefined){
26
+ $('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>");
27
+ }
28
+ }, 10000);
29
+ </script>
30
+ <% else %>
31
+ <%= image_tag 'analytics_dashboard_preview.png' %>
32
+ <% end %>
33
+ <br>
34
+ <%= link_to t(:enter_token), admin_path(:dash_edit => true) %>
35
+ <% end %>
36
+
37
+
@@ -0,0 +1,12 @@
1
+ <% if Spree::Dash::Config.configured? %>
2
+ <script type='text/javascript'>
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 @@
1
+ en:
@@ -1,4 +1,4 @@
1
- Rails.application.routes.draw do
1
+ Spree::Core::Engine.routes.prepend do
2
2
  match '/admin' => 'admin/overview#index', :as => :admin
3
- match '/admin/overview/get_report_data' => 'admin/overview#get_report_data'
3
+ match '/admin/dash_preferences' => 'admin/overview#preferences', :as => :admin_dash_preferences
4
4
  end
@@ -0,0 +1,9 @@
1
+ require 'spree_core'
2
+
3
+ module Spree
4
+ module Dash
5
+
6
+ end
7
+ end
8
+
9
+ require 'spree/dash/engine'
@@ -0,0 +1,24 @@
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
+
16
+ Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/*.rb")) do |c|
17
+ Rails.application.config.cache_classes ? require(c) : load(c)
18
+ end
19
+ end
20
+ config.to_prepare &method(:activate).to_proc
21
+
22
+ end
23
+ end
24
+ end
@@ -1,7 +1 @@
1
- require 'spree_core'
2
-
3
- module SpreeDash
4
- class Engine < Rails::Engine
5
- engine_name 'spree_dash'
6
- end
7
- end
1
+ require 'spree/dash'
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_dash
3
3
  version: !ruby/object:Gem::Version
4
- hash: 265
5
- prerelease:
4
+ hash: 15424055
5
+ prerelease: 6
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 70
9
- - 7
10
- version: 0.70.7
9
+ - 0
10
+ - rc
11
+ - 1
12
+ version: 1.0.0.rc1
11
13
  platform: ruby
12
14
  authors:
13
15
  - Brian Quinn
@@ -15,7 +17,7 @@ autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2012-07-08 00:00:00 Z
20
+ date: 2011-12-23 00:00:00 Z
19
21
  dependencies:
20
22
  - !ruby/object:Gem::Dependency
21
23
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -23,12 +25,14 @@ dependencies:
23
25
  requirements:
24
26
  - - "="
25
27
  - !ruby/object:Gem::Version
26
- hash: 265
28
+ hash: 15424055
27
29
  segments:
30
+ - 1
31
+ - 0
28
32
  - 0
29
- - 70
30
- - 7
31
- version: 0.70.7
33
+ - rc
34
+ - 1
35
+ version: 1.0.0.rc1
32
36
  requirement: *id001
33
37
  type: :runtime
34
38
  prerelease: false
@@ -44,25 +48,20 @@ extra_rdoc_files: []
44
48
  files:
45
49
  - LICENSE
46
50
  - README.md
47
- - app/assets/javascripts/admin/dashboard.js
48
- - app/assets/javascripts/admin/spree_dash.js
49
- - app/assets/javascripts/store/spree_dash.js
50
- - app/assets/stylesheets/admin/dashboard.css.erb
51
- - app/assets/stylesheets/admin/spree_dash.css
52
- - app/assets/stylesheets/store/spree_dash.css
53
- - app/controllers/admin/overview_controller.rb
54
- - app/views/admin/overview/index.html.erb
51
+ - app/assets/images/analytics_dashboard_preview.png
52
+ - app/controllers/spree/admin/overview_controller.rb
53
+ - app/controllers/spree/base_controller_decorator.rb
54
+ - app/helpers/spree/analytics_helper.rb
55
+ - app/models/spree/dash_configuration.rb
56
+ - app/overrides/analytics_header.rb
57
+ - app/views/spree/admin/overview/_form.html.erb
58
+ - app/views/spree/admin/overview/index.html.erb
59
+ - app/views/spree/analytics/_header.html.erb
60
+ - config/locales/en.yml
55
61
  - config/routes.rb
62
+ - lib/spree/dash/engine.rb
63
+ - lib/spree/dash.rb
56
64
  - lib/spree_dash.rb
57
- - vendor/assets/javascripts/jqPlot/excanvas.min.js
58
- - vendor/assets/javascripts/jqPlot/jquery.jqplot.min.js
59
- - vendor/assets/javascripts/jqPlot/plugins/jqplot.canvasAxisLabelRenderer.min.js
60
- - vendor/assets/javascripts/jqPlot/plugins/jqplot.canvasAxisTickRenderer.min.js
61
- - vendor/assets/javascripts/jqPlot/plugins/jqplot.canvasTextRenderer.min.js
62
- - vendor/assets/javascripts/jqPlot/plugins/jqplot.categoryAxisRenderer.min.js
63
- - vendor/assets/javascripts/jqPlot/plugins/jqplot.dateAxisRenderer.min.js
64
- - vendor/assets/javascripts/jqPlot/plugins/jqplot.highlighter.min.js
65
- - vendor/assets/javascripts/jqPlot/plugins/jqplot.pieRenderer.min.js
66
65
  homepage: http://spreecommerce.com
67
66
  licenses: []
68
67
 
@@ -85,15 +84,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
84
  required_rubygems_version: !ruby/object:Gem::Requirement
86
85
  none: false
87
86
  requirements:
88
- - - ">="
87
+ - - ">"
89
88
  - !ruby/object:Gem::Version
90
- hash: 3
89
+ hash: 25
91
90
  segments:
92
- - 0
93
- version: "0"
91
+ - 1
92
+ - 3
93
+ - 1
94
+ version: 1.3.1
94
95
  requirements:
95
96
  - none
96
- rubyforge_project: spree_dash
97
+ rubyforge_project:
97
98
  rubygems_version: 1.8.10
98
99
  signing_key:
99
100
  specification_version: 3
@@ -1,144 +0,0 @@
1
- function number_with_delimiter(number, delimiter, separator) {
2
- try {
3
- var delimiter = delimiter || ",";
4
- var separator = separator || ".";
5
-
6
- var parts = number.toString().split('.');
7
- parts[0] = parts[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + delimiter);
8
- formatted_number = parts.join(separator);
9
-
10
- if(formatted_number.length>=6 && formatted_number.length<=9){
11
- var arr = formatted_number.split(",");
12
- return arr[0] + " k";
13
- }else if(formatted_number.length==10){
14
- var arr = formatted_number.split(",");
15
- return arr[0] + " m";
16
- }else{
17
- return formatted_number
18
- }
19
- } catch(e) {
20
- return number
21
- }
22
- }
23
-
24
- function handle_orders_by_day(r){
25
- var new_points = eval(r);
26
-
27
- if(new_points[0].length>0){
28
- orders_by_day_settings.axes.xaxis.min = new_points[0][0][0].replace(/-/g, "/");
29
- orders_by_day_settings.axes.xaxis.max = new_points[0][new_points[0].length -1][0].replace(/-/g, "/");
30
- }
31
-
32
- orders_by_day_settings.axes.yaxis.label = jQuery("#orders_by_day_value :selected").val();
33
-
34
- jQuery("#order_by_day_title").text(orders + " " + jQuery("#orders_by_day_value :selected").val() + " " + by_day + " (" + jQuery("#orders_by_day_reports :selected").text() + ")");
35
-
36
- jQuery('#orders_by_day').empty();
37
- jQuery.jqplot('orders_by_day', new_points, orders_by_day_settings);
38
-
39
- }
40
-
41
- function handle_orders_total(r){
42
- var values = eval(r);
43
-
44
- jQuery('#orders_total').text(number_with_delimiter(values[0].orders_total));
45
- jQuery('#orders_line_total').text(number_with_delimiter(values[0].orders_line_total));
46
- jQuery('#orders_adjustment_total').text(number_with_delimiter(values[0].orders_adjustment_total));
47
- jQuery('#orders_adjustment_total').text(number_with_delimiter(values[0].orders_adjustment_total));
48
- }
49
-
50
- jQuery(document).ready(function(){
51
-
52
- if(typeof(orders_by_day_points)=="object"){
53
- orders_by_day_settings = {
54
- title: {
55
- textColor: '#476D9B',
56
- fontSize: '12pt',
57
- },
58
- grid: {background:'#fff', gridLineColor:'#fff',borderColor: '#476D9B'},
59
- axes:{
60
- yaxis:{
61
- label:'Order (Count)',
62
- labelRenderer: jQuery.jqplot.CanvasAxisLabelRenderer,
63
- autoscale:true,
64
- tickOptions:{
65
- formatString:'%d',
66
- fontSize: '10pt',
67
- textColor: '#476D9B'
68
- },
69
- min: 0
70
- },
71
- xaxis:{
72
- renderer:jQuery.jqplot.DateAxisRenderer,
73
- rendererOptions:{tickRenderer:jQuery.jqplot.CanvasAxisTickRenderer},
74
- tickOptions:{
75
- formatString:'%b %#d, %y',
76
- angle: -30,
77
- fontSize: '10pt',
78
- textColor: '#476D9B'
79
- },
80
- min: orders_by_day_points[0][0][0].replace(/-/g, "/"),
81
- max: orders_by_day_points[0][orders_by_day_points[0].length -1][0].replace(/-/g, "/")//,
82
- //tickInterval: '1 day'
83
- }
84
- },
85
- series:[{lineWidth:3, color: '#0095DA', fillAndStroke: true, fill: true, fillColor: '#E6F7FF'}],
86
- highlighter: {
87
- formatString: "Date: %s <br />Value: %s ",
88
- sizeAdjust: 7.5
89
- }
90
- };
91
-
92
-
93
- jQuery.jqplot('orders_by_day', orders_by_day_points, orders_by_day_settings);
94
-
95
- jQuery("div#orders_by_day_options select").change(function(){
96
- var report = jQuery("#orders_by_day_reports :selected").val();
97
- var value = jQuery("#orders_by_day_value :selected").val();
98
-
99
- jQuery.ajax({
100
- type: 'GET',
101
- url: 'admin/overview/get_report_data',
102
- data: ({report: 'orders_by_day', name: report, value: value, authenticity_token: AUTH_TOKEN}),
103
- success: handle_orders_by_day
104
- });
105
-
106
- jQuery.ajax({
107
- type: 'GET',
108
- url: 'admin/overview/get_report_data',
109
- data: ({report: 'orders_totals', name: report, authenticity_token: AUTH_TOKEN}),
110
- success: handle_orders_total
111
- });
112
- });
113
-
114
- best_selling_variants = jQuery.jqplot('best_selling_products', [best_selling_variants_points], {
115
- grid: {background:'#fff',borderWidth: 0, borderColor: '#fff', shadow: false},
116
- seriesDefaults:{
117
- renderer:jQuery.jqplot.PieRenderer,
118
- rendererOptions:{padding:6,sliceMargin:0}
119
- },
120
- seriesColors: pie_colors
121
- });
122
-
123
-
124
- top_grossing_variants = jQuery.jqplot('top_grossing_products', [top_grossing_variants_points], {
125
- grid: {background:'#fff',borderWidth: 0, borderColor: '#fff', shadow: false},
126
- seriesDefaults:{
127
- renderer:jQuery.jqplot.PieRenderer,
128
- rendererOptions:{padding:6,sliceMargin:0}
129
- },
130
-
131
- seriesColors: pie_colors
132
- });
133
-
134
- tbest_selling_taxons = jQuery.jqplot('best_selling_taxons', [best_selling_taxons_points], {
135
- grid: {background:'#fff',borderWidth: 0, borderColor: '#fff', shadow: false},
136
- seriesDefaults:{
137
- renderer:jQuery.jqplot.PieRenderer,
138
- rendererOptions:{padding:6,sliceMargin:0}
139
- },
140
-
141
- seriesColors: pie_colors
142
- });
143
- }
144
- });