how_are_we_doing 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/app/controllers/reports_controller.rb +1 -52
  2. data/app/helpers/reports_helper.rb +30 -4
  3. data/app/models/print.rb +1 -29
  4. data/app/models/share.rb +3 -29
  5. data/app/models/total.rb +2 -21
  6. data/app/models/view.rb +1 -29
  7. data/app/views/reports/_bar_graph.html.erb +48 -0
  8. data/app/views/reports/_line_graph.html.erb +40 -0
  9. data/app/views/reports/_recent_bar_graph.html.erb +41 -0
  10. data/app/views/reports/index.html.erb +12 -22
  11. data/config/locales/en.yml +16 -0
  12. data/lib/generators/how_are_we_doing/install/install_generator.rb +1 -0
  13. data/lib/generators/how_are_we_doing/install/templates/public/images/hawd/blank.png +0 -0
  14. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/API.txt +85 -68
  15. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/FAQ.txt +0 -0
  16. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/NEWS.txt +12 -32
  17. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/PLUGINS.txt +0 -0
  18. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/README.txt +3 -3
  19. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/excanvas.js +160 -663
  20. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/excanvas.min.js +1 -1
  21. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.crosshair.js +12 -51
  22. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.image.js +0 -0
  23. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.js +509 -155
  24. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.navigate.js +0 -1
  25. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.stack.js +0 -0
  26. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.flot.threshold.js +0 -0
  27. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/flot/jquery.js +0 -0
  28. data/lib/generators/how_are_we_doing/install/templates/public/javascripts/how_are_we_doing.js +50 -8
  29. data/lib/how_are_we_doing/acts_as_analytical.rb +98 -0
  30. data/lib/{acts_as_printable.rb → how_are_we_doing/acts_as_printable.rb} +0 -0
  31. data/lib/{acts_as_shareable.rb → how_are_we_doing/acts_as_shareable.rb} +0 -0
  32. data/lib/{acts_as_totalable.rb → how_are_we_doing/acts_as_totalable.rb} +0 -0
  33. data/lib/{acts_as_viewable.rb → how_are_we_doing/acts_as_viewable.rb} +0 -0
  34. data/lib/how_are_we_doing/controllers/reports_helpers.rb +92 -0
  35. data/lib/how_are_we_doing/version.rb +1 -1
  36. data/lib/how_are_we_doing.rb +16 -8
  37. metadata +13 -6
@@ -1,54 +1,3 @@
1
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
2
+ include HowAreWeDoing::Controllers::ReportsHelpers
54
3
  end
@@ -2,21 +2,46 @@ module ReportsHelper
2
2
  def how_are_we_doing_chart(form_id,graph_container_id,graph_type)
3
3
  <<-END.gsub(/^ {6}/, '')
4
4
  <script>
5
+ $("##{form_id} #analyticals").live('click',function(){
6
+ $(this).attr('size',10);
7
+ });
8
+
9
+ $('##{form_id} #analyticals').live('change',function(){
10
+ $(this).parents('form').find('#analytical_ids').val($(this).val());
11
+ $(this).parents('form').trigger('submit');
12
+ });
13
+
14
+
5
15
  $('##{form_id} input:checkbox').live('change',function(){
6
- $('#'+$(this).attr('id').replace('include_','exclude_')).val($(this).attr("checked") ? "" : true);
16
+ $(this).parents('form').find('#'+$(this).attr('id').replace('include_','exclude_')).val($(this).attr("checked") ? "" : true);
17
+ $(this).parents('form').trigger('submit');
7
18
  });
8
19
 
9
20
  $('##{form_id}').live('submit',function(){
10
21
  var data = {};
22
+ var allowable_params = {
23
+ exclude_totals:1,
24
+ exclude_prints:1,
25
+ exclude_shares:1,
26
+ exclude_views:1,
27
+ start_date:1,
28
+ end_date:1,
29
+ start_date:1,
30
+ parent_type: 1,
31
+ parent_id: 1,
32
+ analytical_ids: 1,
33
+ analytical_type:1
34
+ };
11
35
 
12
36
  $(this).find('input,select').each(function(i,element){
13
- if(element.id && element.id.match(/exclude_/) && $(element).val()) {
37
+ if(element.name && allowable_params[element.name] && $(element).val()) {
14
38
  data[element.name] = $(element).val();
15
39
  }
16
- })
40
+ });
41
+
17
42
 
18
43
  $.ajax({
19
- url: "#{reports_path(:json)}",
44
+ url: $(this).attr('action')+".json",
20
45
  method: 'get',
21
46
  data: $.param(data),
22
47
  dataType: 'json',
@@ -29,6 +54,7 @@ module ReportsHelper
29
54
 
30
55
  $(function(){
31
56
  $('##{form_id}').trigger('submit');
57
+ $(".date-selector").datepicker();
32
58
  });
33
59
  </script>
34
60
  END
data/app/models/print.rb CHANGED
@@ -1,31 +1,3 @@
1
1
  class Print < ActiveRecord::Base
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
2
+ acts_as_analytical
31
3
  end
data/app/models/share.rb CHANGED
@@ -1,37 +1,11 @@
1
1
  class Share < ActiveRecord::Base
2
- belongs_to :shareable, :polymorphic => true
3
- belongs_to :user
4
-
5
- before_create :set_url_hash
2
+ acts_as_analytical
6
3
 
7
4
  after_create :create_total
5
+
8
6
 
9
- validates :shareable_type, :presence => true, :on => :create
10
- validates :shareable_id, :presence => true, :on => :create
11
-
7
+ protected
12
8
  def set_url_hash
13
9
  self.url_hash = Digest::SHA1.hexdigest("#{shareable_type}#{shareable_id}#{user_id}how_are_we_doing#{service_ident}")
14
10
  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
37
11
  end
data/app/models/total.rb CHANGED
@@ -1,25 +1,6 @@
1
1
  class Total < ActiveRecord::Base
2
- belongs_to :totalable, :polymorphic => true
3
- belongs_to :user
2
+ acts_as_analytical
4
3
 
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]
4
+ def create_total
24
5
  end
25
6
  end
data/app/models/view.rb CHANGED
@@ -1,31 +1,3 @@
1
1
  class View < ActiveRecord::Base
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
2
+ acts_as_analytical
31
3
  end
@@ -0,0 +1,48 @@
1
+ <% content_for :javascripts do -%>
2
+ <%= raw how_are_we_doing_chart("bar-graph-form","bar-graph-container","bar") %>
3
+ <% end -%>
4
+
5
+
6
+ <%= form_tag(params[:parent_type] && params[:parent_id] ? "/#{params[:parent_type]}/#{params[:parent_id]}/reports" : "/reports", {:method => "get", :id => "bar-graph-form"}) do %>
7
+ <fieldset class="graph-dates">
8
+ <%= label_tag 'start_date', t('hawd.start_date') %>
9
+ <%= text_field_tag 'start_date', "", :class => "date-selector", :placeholder => l(params[:start_date],:format => :analytics), :id => "bar-graph-form_start_date" %>
10
+
11
+ <%= label_tag 'start_date', t('hawd.end_date') %>
12
+ <%= text_field_tag 'end_date', "", :class => "date-selector", :placeholder => l(params[:end_date],:format => :analytics), :id => "bar-graph-form_end_date" %>
13
+ </fieldset>
14
+
15
+ <div class="button-wrapper">
16
+ <%= hidden_field_tag 'exclude_prints' %>
17
+ <%= hidden_field_tag 'exclude_totals' %>
18
+ <%= hidden_field_tag 'exclude_views' %>
19
+ <%= hidden_field_tag 'exclude_shares' %>
20
+ <%= hidden_field_tag 'analytical_type', (params[:analytical_type]||params[:default_analytical_type]) %>
21
+ <%= hidden_field_tag 'analytical_ids', (@analytical_ids||[]) %>
22
+
23
+ <%= submit_tag(t(:submit)) %>
24
+ <%= image_submit_tag("hawd/blank.png") %>
25
+ </div>
26
+
27
+ <fieldset class="graph-compare">
28
+ <%= label_tag 'analyticals', t('hawd.comparision', :analytical => (params[:analytical_type]||params[:default_analytical_type]||"")) %>
29
+ <%= select_tag "analyticals", options_from_collection_for_select(@analyticals, "id", "to_s", {:selected => lambda { |analytical| @analytical_ids.include?(analytical.id) }}), :multiple => true, :size => 1 %>
30
+ </fieldset>
31
+
32
+ <fieldset class="graph-filters">
33
+ <%= check_box_tag('include_totals', "1", true) %>
34
+ <%= label_tag 'include_totals', t('hawd.totals') %>
35
+
36
+ <%= check_box_tag('include_views', "1", true) %>
37
+ <%= label_tag 'include_views', t('hawd.views') %>
38
+
39
+ <%= check_box_tag('include_shares', "1", true) %>
40
+ <%= label_tag 'include_shares', t('hawd.shares') %>
41
+
42
+ <%= check_box_tag('include_prints', "1", true) %>
43
+ <%= label_tag 'include_prints', t('hawd.prints') %>
44
+ </fieldset>
45
+
46
+ <% end -%>
47
+
48
+ <div id="bar-graph-container" class="graph-chart"></div>
@@ -0,0 +1,40 @@
1
+ <% content_for :javascripts do -%>
2
+ <%= raw how_are_we_doing_chart("line-graph-form","line-graph-container","line") %>
3
+ <% end -%>
4
+
5
+ <%= form_tag(params[:parent_type] && params[:parent_id] ? "/#{params[:parent_type]}/#{params[:parent_id]}/reports" : "/reports", {:method => "get", :id => "line-graph-form"}) do %>
6
+ <fieldset class="graph-dates">
7
+ <%= label_tag 'start_date', t('hawd.start_date') %>
8
+ <%= text_field_tag 'start_date', "", :class => "date-selector", :placeholder => l(params[:start_date],:format => :analytics), :id => "line-graph-form_start_date" %>
9
+
10
+ <%= label_tag 'start_date', t('hawd.end_date') %>
11
+ <%= text_field_tag 'end_date', "", :class => "date-selector", :placeholder => l(params[:end_date],:format => :analytics), :id => "line-graph-form_end_date" %>
12
+ </fieldset>
13
+
14
+ <div class="button-wrapper">
15
+ <%= hidden_field_tag 'exclude_prints' %>
16
+ <%= hidden_field_tag 'exclude_totals' %>
17
+ <%= hidden_field_tag 'exclude_views' %>
18
+ <%= hidden_field_tag 'exclude_shares' %>
19
+
20
+ <%= submit_tag(t(:submit)) %>
21
+ <%= image_submit_tag("hawd/blank.png") %>
22
+ </div>
23
+
24
+ <fieldset class="graph-filters">
25
+ <%= check_box_tag('include_totals', "1", true) %>
26
+ <%= label_tag 'include_totals', t('hawd.totals') %>
27
+
28
+ <%= check_box_tag('include_views', "1", true) %>
29
+ <%= label_tag 'include_views', t('hawd.views') %>
30
+
31
+ <%= check_box_tag('include_shares', "1", true) %>
32
+ <%= label_tag 'include_shares', t('hawd.shares') %>
33
+
34
+ <%= check_box_tag('include_prints', "1", true) %>
35
+ <%= label_tag 'include_prints', t('hawd.prints') %>
36
+ </fieldset>
37
+ <% end -%>
38
+
39
+
40
+ <div id="line-graph-container" class="graph-chart"></div>
@@ -0,0 +1,41 @@
1
+ <% content_for :javascripts do -%>
2
+ <%= raw how_are_we_doing_chart("recent-bar-graph-form","recent-bar-graph-container","bar") %>
3
+ <% end -%>
4
+
5
+
6
+ <%= form_tag(params[:parent_type] && params[:parent_id] ? "/#{params[:parent_type]}/#{params[:parent_id]}/reports" : "/reports", {:method => "get", :id => "recent-bar-graph-form"}) do %>
7
+ <fieldset class="graph-dates">
8
+ <%= label_tag 'start_date', t('hawd.start_date') %>
9
+ <%= text_field_tag 'start_date', "", :class => "date-selector", :placeholder => l(params[:start_date],:format => :analytics), :id => "recent-bar-graph-form_start_date" %>
10
+
11
+ <%= label_tag 'start_date', t('hawd.end_date') %>
12
+ <%= text_field_tag 'end_date', "", :class => "date-selector", :placeholder => l(params[:end_date],:format => :analytics), :id => "recent-bar-graph-form_end_date" %>
13
+ </fieldset>
14
+
15
+ <div class="button-wrapper">
16
+ <%= hidden_field_tag 'exclude_prints' %>
17
+ <%= hidden_field_tag 'exclude_totals' %>
18
+ <%= hidden_field_tag 'exclude_views' %>
19
+ <%= hidden_field_tag 'exclude_shares' %>
20
+ <%= hidden_field_tag 'analytical_type', (params[:analytical_type]||params[:default_analytical_type]) %>
21
+
22
+ <%= submit_tag(t(:submit)) %>
23
+ <%= image_submit_tag("hawd/blank.png") %>
24
+ </div>
25
+
26
+ <fieldset class="graph-filters">
27
+ <%= check_box_tag('include_totals', "1", true) %>
28
+ <%= label_tag 'include_totals', t('hawd.totals') %>
29
+
30
+ <%= check_box_tag('include_views', "1", true) %>
31
+ <%= label_tag 'include_views', t('hawd.views') %>
32
+
33
+ <%= check_box_tag('include_shares', "1", true) %>
34
+ <%= label_tag 'include_shares', t('hawd.shares') %>
35
+
36
+ <%= check_box_tag('include_prints', "1", true) %>
37
+ <%= label_tag 'include_prints', t('hawd.prints') %>
38
+ </fieldset>
39
+ <% end -%>
40
+
41
+ <div id="recent-bar-graph-container" class="graph-chart"></div>
@@ -1,28 +1,18 @@
1
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") %>
2
+ <%= javascript_include_tag 'flot/excanvas.min.js','flot/jquery.flot.js', 'jquery-ui-1.8.10.custom.min.js', 'how_are_we_doing' %>
4
3
  <% end -%>
5
4
 
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") %>
5
+ <% content_for :stylesheets do -%>
6
+ <%= stylesheet_link_tag "ui-lightness/jquery-ui-1.8.10.custom.css" %>
7
+ <style>
8
+ .graph-chart {
9
+ height: 300px;
10
+ }
11
+ </style>
25
12
  <% end -%>
26
13
 
14
+ <%= render :partial => "line_graph" %>
27
15
 
28
- <div id="line-graph" style="height:900px;"></div>
16
+ <%= render :partial => "recent_bar_graph" %>
17
+
18
+ <%= render :partial => "bar_graph" %>
@@ -0,0 +1,16 @@
1
+ en:
2
+ date:
3
+ formats:
4
+ analytics: "%m/%d/%Y"
5
+ time:
6
+ formats:
7
+ analytics: "%m/%d/%Y"
8
+ hawd:
9
+ totals: Totals
10
+ prints: Prints
11
+ start_date: Start Date
12
+ end_date: End Date
13
+ views: Views
14
+ prints: Prints
15
+ shares: Shares
16
+ comparision: "Select %{analytical} to compare:"
@@ -30,6 +30,7 @@ module HowAreWeDoing
30
30
 
31
31
  def generate_routes
32
32
  route("match '/reports' => 'reports#index'")
33
+ route("match ':parent_type/:parent_id/reports' => 'reports#index'")
33
34
  route("match ':viewable_type/:viewable_id/views' => 'views#create', :via => :post")
34
35
  route("match ':printable_type/:printable_id/prints' => 'prints#create', :via => :post")
35
36
  route("match ':shareable_type/:shareable_id/shares' => 'shares#create', :via => :post")