how_are_we_doing 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/app/controllers/reports_controller.rb +54 -0
  2. data/app/helpers/prints_helper.rb +25 -0
  3. data/app/helpers/reports_helper.rb +36 -0
  4. data/app/helpers/shares_helper.rb +25 -0
  5. data/app/helpers/views_helper.rb +25 -0
  6. data/app/models/print.rb +28 -0
  7. data/app/models/share.rb +29 -0
  8. data/app/models/total.rb +25 -0
  9. data/app/models/view.rb +28 -0
  10. data/app/views/reports/index.html.erb +28 -0
  11. data/how_are_we_doing.gemspec +3 -0
  12. data/lib/acts_as_printable.rb +8 -1
  13. data/lib/acts_as_shareable.rb +9 -2
  14. data/lib/acts_as_totalable.rb +31 -0
  15. data/lib/acts_as_viewable.rb +8 -1
  16. data/lib/generators/how_are_we_doing/install/install_generator.rb +9 -3
  17. data/lib/generators/how_are_we_doing/install/templates/db/migrate/create_totals.rb +16 -0
  18. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/API.txt +1024 -0
  19. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/FAQ.txt +71 -0
  20. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/LICENSE.txt +22 -0
  21. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/Makefile +15 -0
  22. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/NEWS.txt +340 -0
  23. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/PLUGINS.txt +105 -0
  24. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/README.txt +81 -0
  25. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/ajax.html +143 -0
  26. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/annotating.html +75 -0
  27. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/arrow-down.gif +0 -0
  28. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/arrow-left.gif +0 -0
  29. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/arrow-right.gif +0 -0
  30. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/arrow-up.gif +0 -0
  31. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/basic.html +38 -0
  32. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/data-eu-gdp-growth-1.json +4 -0
  33. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/data-eu-gdp-growth-2.json +4 -0
  34. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/data-eu-gdp-growth-3.json +4 -0
  35. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/data-eu-gdp-growth-4.json +4 -0
  36. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/data-eu-gdp-growth-5.json +4 -0
  37. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/data-eu-gdp-growth.json +4 -0
  38. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/data-japan-gdp-growth.json +4 -0
  39. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/data-usa-gdp-growth.json +4 -0
  40. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/dual-axis.html +39 -0
  41. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/graph-types.html +75 -0
  42. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/hs-2004-27-a-large_web.jpg +0 -0
  43. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/image.html +45 -0
  44. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/index.html +43 -0
  45. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/interacting.html +93 -0
  46. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/layout.css +6 -0
  47. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/navigate.html +118 -0
  48. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/selection.html +114 -0
  49. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/setting-options.html +65 -0
  50. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/stacking.html +77 -0
  51. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/thresholding.html +54 -0
  52. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/time.html +71 -0
  53. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/tracking.html +95 -0
  54. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/turning-series.html +98 -0
  55. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/visitors.html +90 -0
  56. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/examples/zooming.html +98 -0
  57. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/excanvas.js +1427 -0
  58. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/excanvas.min.js +1 -0
  59. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.colorhelpers.js +174 -0
  60. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.colorhelpers.min.js +1 -0
  61. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.crosshair.js +156 -0
  62. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.crosshair.min.js +1 -0
  63. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.image.js +237 -0
  64. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.image.min.js +1 -0
  65. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.js +2119 -0
  66. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.min.js +1 -0
  67. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.navigate.js +272 -0
  68. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.navigate.min.js +1 -0
  69. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.selection.js +299 -0
  70. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.selection.min.js +1 -0
  71. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.stack.js +152 -0
  72. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.stack.min.js +1 -0
  73. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.threshold.js +103 -0
  74. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.threshold.min.js +1 -0
  75. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.js +4376 -0
  76. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.min.js +19 -0
  77. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/how_are_we_doing.js +89 -0
  78. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/jquery-ui-1.8.10.custom.min.js +99 -0
  79. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  80. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  81. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  82. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  83. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  84. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  85. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  86. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  87. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  88. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  89. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  90. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  91. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  92. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  93. data/lib/generators/how_are_we_doing/install/templates/public/stylesheets/ui-lightness/jquery-ui-1.8.10.custom.css +362 -0
  94. data/lib/how_are_we_doing/version.rb +1 -1
  95. data/lib/how_are_we_doing.rb +8 -0
  96. metadata +112 -14
@@ -0,0 +1,54 @@
1
+ class ReportsController < ApplicationController
2
+ respond_to :html, :json, :xml, :js
3
+ before_filter :set_dates, :only => :index
4
+
5
+ def index
6
+ respond_to do |format|
7
+ format.html
8
+ format.json do
9
+ render :json => {
10
+ :metrics => {
11
+ :totals => params[:exclude_totals] ? {} : {
12
+ :data => Total.json_data_for_chart(params[:start_date],params[:end_date]),
13
+ :label => "Totals",
14
+ :color => 0,
15
+ :ticks => Total.json_labels_for_chart(params[:start_date],params[:end_date])
16
+ },
17
+ :prints => params[:exclude_prints] ? {} : {
18
+ :data => Print.json_data_for_chart(params[:start_date],params[:end_date]),
19
+ :label => "Prints",
20
+ :color => 1,
21
+ :ticks => Print.json_labels_for_chart(params[:start_date],params[:end_date])
22
+ },
23
+ :views => params[:exclude_views] ? {} : {
24
+ :data => View.json_data_for_chart(params[:start_date],params[:end_date]),
25
+ :label => "Views",
26
+ :color => 2,
27
+ :ticks => View.json_labels_for_chart(params[:start_date],params[:end_date])
28
+ },
29
+ :shares => params[:exclude_shares] ? {} : {
30
+ :data => Share.json_data_for_chart(params[:start_date],params[:end_date]),
31
+ :label => "Shares",
32
+ :color => 3,
33
+ :ticks => Share.json_labels_for_chart(params[:start_date],params[:end_date])
34
+ }
35
+ },
36
+ :format_options => {
37
+ :xaxis => {
38
+ :max => params[:end_date].to_time.to_i,
39
+ :min => params[:start_date].to_time.to_i
40
+ }
41
+ }
42
+ }
43
+ end
44
+ end
45
+ end
46
+
47
+ protected
48
+ def set_dates
49
+ params[:start_date] ||= (Date.today - 1.month)
50
+ params[:end_date] ||= (Date.today + 1.day)#Time.now.end_of_day.to_date
51
+ params[:start_date] = Date.parse(params[:start_date].to_s)
52
+ params[:end_date] = Date.parse(params[:end_date].to_s)
53
+ end
54
+ end
@@ -0,0 +1,25 @@
1
+ module PrintsHelper
2
+ def record_print(printable,options={})
3
+ options.reverse_merge!({
4
+ :remote => true
5
+ })
6
+
7
+ if options[:remote]
8
+ '<script>
9
+ (function(){
10
+ var ua = navigator.userAgent.toLowerCase();
11
+ if (!window.ActiveXObject) {
12
+ request = new XMLHttpRequest();
13
+ } else if (ua.indexOf("msie 5") == -1) {
14
+ request = new ActiveXObject("Msxml2.XMLHTTP");
15
+ } else {
16
+ request = new ActiveXObject("Microsoft.XMLHTTP");
17
+ }
18
+ var params = {};
19
+ request.open("POST", "'+printable.class.name.underscore.pluralize+'/'+printable.id.to_s+'/prints.json");
20
+ request.send(params);
21
+ }());
22
+ </script>'.html_safe
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ module ReportsHelper
2
+ def how_are_we_doing_chart(form_id,graph_container_id,graph_type)
3
+ <<-END.gsub(/^ {6}/, '')
4
+ <script>
5
+ $('##{form_id} input:checkbox').live('change',function(){
6
+ $('#'+$(this).attr('id').replace('include_','exclude_')).val($(this).attr("checked") ? "" : true);
7
+ });
8
+
9
+ $('##{form_id}').live('submit',function(){
10
+ var data = {};
11
+
12
+ $(this).find('input,select').each(function(i,element){
13
+ if(element.id && element.id.match(/exclude_/) && $(element).val()) {
14
+ data[element.name] = $(element).val();
15
+ }
16
+ })
17
+
18
+ $.ajax({
19
+ url: "#{reports_path(:json)}",
20
+ method: 'get',
21
+ data: $.param(data),
22
+ dataType: 'json',
23
+ success: function(data) {
24
+ #{graph_type}_graph_it(data,'#{graph_container_id}');
25
+ }
26
+ });
27
+ return false;
28
+ });
29
+
30
+ $(function(){
31
+ $('##{form_id}').trigger('submit');
32
+ });
33
+ </script>
34
+ END
35
+ end
36
+ end
@@ -0,0 +1,25 @@
1
+ module SharesHelper
2
+ def record_share(shareable,service_ident,options={})
3
+ options.reverse_merge!({
4
+ :remote => true
5
+ })
6
+
7
+ if options[:remote]
8
+ '<script>
9
+ (function(){
10
+ var ua = navigator.userAgent.toLowerCase();
11
+ if (!window.ActiveXObject) {
12
+ request = new XMLHttpRequest();
13
+ } else if (ua.indexOf("msie 5") == -1) {
14
+ request = new ActiveXObject("Msxml2.XMLHTTP");
15
+ } else {
16
+ request = new ActiveXObject("Microsoft.XMLHTTP");
17
+ }
18
+ var params = {"share[service_ident]":\''+service_ident+'\'};
19
+ request.open("POST", "'+shareable.class.name.underscore.pluralize+'/'+shareable.id.to_s+'/shares.json");
20
+ request.send(params);
21
+ }());
22
+ </script>'.html_safe
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module ViewsHelper
2
+ def record_view(viewable,options={})
3
+ options.reverse_merge!({
4
+ :remote => true
5
+ })
6
+
7
+ if options[:remote]
8
+ '<script>
9
+ (function(){
10
+ var ua = navigator.userAgent.toLowerCase();
11
+ if (!window.ActiveXObject) {
12
+ request = new XMLHttpRequest();
13
+ } else if (ua.indexOf("msie 5") == -1) {
14
+ request = new ActiveXObject("Msxml2.XMLHTTP");
15
+ } else {
16
+ request = new ActiveXObject("Microsoft.XMLHTTP");
17
+ }
18
+ var params = {};
19
+ request.open("POST", "'+viewable.class.name.underscore.pluralize+'/'+viewable.id.to_s+'/views.json");
20
+ request.send(params);
21
+ }());
22
+ </script>'.html_safe
23
+ end
24
+ end
25
+ end
data/app/models/print.rb CHANGED
@@ -1,3 +1,31 @@
1
1
  class Print < ActiveRecord::Base
2
2
  belongs_to :printable, :polymorphic => true
3
+ belongs_to :user
4
+
5
+ validates :printable_type, :presence => true, :on => :create
6
+ validates :printable_id, :presence => true, :on => :create
7
+
8
+ after_create :create_total
9
+
10
+ def self.json_data_for_chart(start_date,end_date)
11
+ arr = []
12
+ start_date.beginning_of_day.to_date.upto(end_date.end_of_day.to_date) do |day|
13
+ prints = self.where("created_at between ? and ?",day,day+1.day)
14
+ arr << [day.to_time.to_i,prints.count]
15
+ end
16
+ arr
17
+ end
18
+
19
+ def self.json_labels_for_chart(start_date,end_date)
20
+ prints = self.where("created_at between ? and ?",start_date.beginning_of_day,end_date.end_of_day)
21
+ count = prints.count
22
+ prints = prints.where(:printable_id.not_eq => nil)
23
+ label = prints.first.nil? ? "" : prints.first.printable.to_print_chart_label
24
+
25
+ [count,label]
26
+ end
27
+
28
+ def create_total
29
+ printable.totals.create
30
+ end
3
31
  end
data/app/models/share.rb CHANGED
@@ -1,8 +1,37 @@
1
1
  class Share < ActiveRecord::Base
2
2
  belongs_to :shareable, :polymorphic => true
3
+ belongs_to :user
4
+
3
5
  before_create :set_url_hash
4
6
 
7
+ after_create :create_total
8
+
9
+ validates :shareable_type, :presence => true, :on => :create
10
+ validates :shareable_id, :presence => true, :on => :create
11
+
5
12
  def set_url_hash
6
13
  self.url_hash = Digest::SHA1.hexdigest("#{shareable_type}#{shareable_id}#{user_id}how_are_we_doing#{service_ident}")
7
14
  end
15
+
16
+ def self.json_data_for_chart(start_date,end_date)
17
+ arr = []
18
+ start_date.beginning_of_day.to_date.upto(end_date.end_of_day.to_date) do |day|
19
+ shares = self.where("created_at between ? and ?",day,day+1.day)
20
+ arr << [day.to_time.to_i,shares.count]
21
+ end
22
+ arr
23
+ end
24
+
25
+ def self.json_labels_for_chart(start_date,end_date)
26
+ shares = self.where("created_at between ? and ?",start_date.beginning_of_day,end_date.end_of_day)
27
+ count = shares.count
28
+ shares = shares.where(:shareable_id.not_eq => nil)
29
+ label = shares.first.nil? ? "" : shares.first.shareable.to_share_chart_label
30
+
31
+ [count,label]
32
+ end
33
+
34
+ def create_total
35
+ shareable.totals.create
36
+ end
8
37
  end
@@ -0,0 +1,25 @@
1
+ class Total < ActiveRecord::Base
2
+ belongs_to :totalable, :polymorphic => true
3
+ belongs_to :user
4
+
5
+ validates :totalable_type, :presence => true, :on => :create
6
+ validates :totalable_id, :presence => true, :on => :create
7
+
8
+ def self.json_data_for_chart(start_date,end_date)
9
+ arr = []
10
+ start_date.beginning_of_day.to_date.upto(end_date.end_of_day.to_date) do |day|
11
+ totals = self.where("created_at between ? and ?",day,day+1.day)
12
+ arr << [day.to_time.to_i,totals.count]
13
+ end
14
+ arr
15
+ end
16
+
17
+ def self.json_labels_for_chart(start_date,end_date)
18
+ totals = self.where("created_at between ? and ?",start_date.beginning_of_day,end_date.end_of_day)
19
+ count = totals.count
20
+ totals = totals.where(:totalable_id.not_eq => nil)
21
+ label = totals.first.nil? ? "" : totals.first.totalable.to_total_chart_label
22
+
23
+ [count,label]
24
+ end
25
+ end
data/app/models/view.rb CHANGED
@@ -1,3 +1,31 @@
1
1
  class View < ActiveRecord::Base
2
2
  belongs_to :viewable, :polymorphic => true
3
+ belongs_to :user
4
+
5
+ validates :viewable_type, :presence => true, :on => :create
6
+ validates :viewable_id, :presence => true, :on => :create
7
+
8
+ after_create :create_total
9
+
10
+ def self.json_data_for_chart(start_date,end_date)
11
+ arr = []
12
+ start_date.beginning_of_day.to_date.upto(end_date.end_of_day.to_date) do |day|
13
+ views = self.where("created_at between ? and ?",day,day+1.day)
14
+ arr << [day.to_time.to_i,views.count]
15
+ end
16
+ arr
17
+ end
18
+
19
+ def self.json_labels_for_chart(start_date,end_date)
20
+ views = self.where("created_at between ? and ?",start_date.beginning_of_day,end_date.end_of_day)
21
+ count = views.count
22
+ views = views.where(:viewable_id.not_eq => nil)
23
+ label = views.first.nil? ? "" : views.first.viewable.to_view_chart_label
24
+
25
+ [count,label]
26
+ end
27
+
28
+ def create_total
29
+ viewable.totals.create
30
+ end
3
31
  end
@@ -0,0 +1,28 @@
1
+ <% content_for :javascripts do -%>
2
+ <%= javascript_include_tag 'flot/jquery.flot.js', 'how_are_we_doing' %>
3
+ <%= raw how_are_we_doing_chart("test","line-graph","line") %>
4
+ <% end -%>
5
+
6
+ <%= form_tag("/reports", {:method => "get", :id => "test"}) do %>
7
+ <%= label_tag 'include_totals', 'Totals' %>
8
+ <%= check_box_tag('include_totals', "1", true) %>
9
+
10
+ <%= label_tag 'include_views', 'Views' %>
11
+ <%= check_box_tag('include_views', "1", true) %>
12
+
13
+ <%= label_tag 'include_shares', 'Shares' %>
14
+ <%= check_box_tag('include_shares', "1", true) %>
15
+
16
+ <%= label_tag 'include_prints', 'Prints' %>
17
+ <%= check_box_tag('include_prints', "1", true) %>
18
+
19
+ <%= hidden_field_tag 'exclude_prints' %>
20
+ <%= hidden_field_tag 'exclude_totals' %>
21
+ <%= hidden_field_tag 'exclude_views' %>
22
+ <%= hidden_field_tag 'exclude_shares' %>
23
+
24
+ <%= submit_tag("Submit") %>
25
+ <% end -%>
26
+
27
+
28
+ <div id="line-graph" style="height:900px;"></div>
@@ -18,4 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
+
22
+ s.add_dependency("jquery-rails")
23
+ s.add_dependency("meta_where")
21
24
  end
@@ -7,7 +7,7 @@ module HowAreWeDoing
7
7
 
8
8
  module ClassMethods
9
9
  def acts_as_printable
10
- has_many :prints, :as => :printable
10
+ has_many :prints, :as => :printable, :dependent => :nullify
11
11
 
12
12
  include HowAreWeDoing::ActsAsPrintable::InstanceMethods
13
13
  extend HowAreWeDoing::ActsAsPrintable::SingletonMethods
@@ -18,6 +18,13 @@ module HowAreWeDoing
18
18
  end
19
19
 
20
20
  module InstanceMethods
21
+ def to_print_chart_label(graph_type=nil)
22
+ if respond_to?(:print_chart_label)
23
+ print_chart_label(graph_type)
24
+ else
25
+ to_s
26
+ end
27
+ end
21
28
  end
22
29
  end
23
30
  end
@@ -7,8 +7,8 @@ module HowAreWeDoing
7
7
 
8
8
  module ClassMethods
9
9
  def acts_as_shareable
10
- has_many :shares, :as => :shareable
11
-
10
+ has_many :shares, :as => :shareable, :dependent => :nullify
11
+
12
12
  include HowAreWeDoing::ActsAsShareable::InstanceMethods
13
13
  extend HowAreWeDoing::ActsAsShareable::SingletonMethods
14
14
  end
@@ -18,6 +18,13 @@ module HowAreWeDoing
18
18
  end
19
19
 
20
20
  module InstanceMethods
21
+ def to_share_chart_label(graph_type=nil)
22
+ if respond_to?(:share_chart_label)
23
+ share_chart_label(graph_type)
24
+ else
25
+ to_s
26
+ end
27
+ end
21
28
  end
22
29
  end
23
30
  end
@@ -0,0 +1,31 @@
1
+ module HowAreWeDoing
2
+ module ActsAsTotalable #:nodoc:
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def acts_as_totalable
10
+ has_many :totals, :as => :totalable, :dependent => :nullify
11
+
12
+ include HowAreWeDoing::ActsAsTotalable::InstanceMethods
13
+ extend HowAreWeDoing::ActsAsTotalable::SingletonMethods
14
+ end
15
+ end
16
+
17
+ module SingletonMethods
18
+ end
19
+
20
+ module InstanceMethods
21
+ def to_total_chart_label(graph_type=nil)
22
+ if respond_to?(:total_chart_label)
23
+ total_chart_label(graph_type)
24
+ else
25
+ to_s
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -7,7 +7,7 @@ module HowAreWeDoing
7
7
 
8
8
  module ClassMethods
9
9
  def acts_as_viewable
10
- has_many :views, :as => :viewable
10
+ has_many :views, :as => :viewable, :dependent => :nullify
11
11
 
12
12
  include HowAreWeDoing::ActsAsViewable::InstanceMethods
13
13
  extend HowAreWeDoing::ActsAsViewable::SingletonMethods
@@ -18,6 +18,13 @@ module HowAreWeDoing
18
18
  end
19
19
 
20
20
  module InstanceMethods
21
+ def to_view_chart_label(graph_type=nil)
22
+ if respond_to?(:view_chart_label)
23
+ view_chart_label(graph_type)
24
+ else
25
+ to_s
26
+ end
27
+ end
21
28
  end
22
29
  end
23
30
  end