how_are_we_doing 0.0.6 → 0.0.7

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.
@@ -1,62 +1,73 @@
1
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} #analyticals").live('click',function(){
6
- $(this).attr('size',10);
7
- });
2
+ def default_recent_analytical_ids(analytical_type,start_date,end_date)
3
+ analytical_type.classify.constantize.limit(params[:analytical_limit]||6).where(:created_at => start_date.beginning_of_day.to_date..(end_date+1.day).beginning_of_day.to_date).map(&:id)
4
+ end
5
+
6
+ def default_comparison_analytical_ids(analytical_type)
7
+ analytical_type.classify.constantize.order('id DESC').limit(1).map(&:id)
8
+ end
9
+
10
+ def how_are_we_doing_chart(form_id,graph_container_id,graph_type,options={})
11
+ content_for :javascripts do
12
+ <<-END.gsub(/^ {6}/, '')
13
+ <script>
14
+ $("##{form_id} #analyticals").live('click',function(){
15
+ $(this).attr('size',10);
16
+ });
8
17
 
9
- $('##{form_id} #analyticals').live('change',function(){
10
- $(this).parents('form').find('#analytical_ids').val($(this).val());
11
- $(this).parents('form').trigger('submit');
12
- });
18
+ $('##{form_id} #analyticals').live('change',function(){
19
+ $(this).parents('form').find('#analytical_ids').val($(this).val());
20
+ $(this).parents('form').trigger('submit');
21
+ });
13
22
 
14
23
 
15
- $('##{form_id} input:checkbox').live('change',function(){
16
- $(this).parents('form').find('#'+$(this).attr('id').replace('include_','exclude_')).val($(this).attr("checked") ? "" : true);
17
- $(this).parents('form').trigger('submit');
18
- });
24
+ $('##{form_id} input:checkbox').live('change',function(){
25
+ $(this).parents('form').find('#'+$(this).attr('id').replace('include_','exclude_')).val($(this).attr("checked") ? "" : true);
26
+ $(this).parents('form').trigger('submit');
27
+ });
19
28
 
20
- $('##{form_id}').live('submit',function(){
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
- };
29
+ $('##{form_id}').live('submit',function(){
30
+ var data = {};
31
+ var allowable_params = {
32
+ exclude_totals:1,
33
+ exclude_prints:1,
34
+ exclude_shares:1,
35
+ exclude_views:1,
36
+ start_date:1,
37
+ end_date:1,
38
+ start_date:1,
39
+ parent_type: 1,
40
+ parent_id: 1,
41
+ analytical_ids: 1,
42
+ analytical_type:1
43
+ };
35
44
 
36
- $(this).find('input,select').each(function(i,element){
37
- if(element.name && allowable_params[element.name] && $(element).val()) {
38
- data[element.name] = $(element).val();
39
- }
40
- });
45
+ $(this).find('input,select').each(function(i,element){
46
+ if(element.name && allowable_params[element.name] && $(element).val()) {
47
+ data[element.name] = $(element).val();
48
+ }
49
+ });
41
50
 
42
51
 
43
- $.ajax({
44
- url: $(this).attr('action')+".json",
45
- method: 'get',
46
- data: $.param(data),
47
- dataType: 'json',
48
- success: function(data) {
49
- #{graph_type}_graph_it(data,'#{graph_container_id}');
50
- }
52
+ $.ajax({
53
+ url: $(this).attr('action')+".json",
54
+ method: 'get',
55
+ data: $.param(data),
56
+ dataType: 'json',
57
+ success: function(data) {
58
+ #{graph_type}_graph_it(data,'#{graph_container_id}');
59
+ }
60
+ });
61
+ return false;
51
62
  });
52
- return false;
53
- });
54
63
 
55
- $(function(){
56
- $('##{form_id}').trigger('submit');
57
- $(".date-selector").datepicker();
58
- });
59
- </script>
60
- END
64
+ $(function(){
65
+ $('##{form_id}').trigger('submit');
66
+ $(".date-selector").datepicker();
67
+ });
68
+ </script>
69
+ END
70
+ end
71
+ render "reports/#{graph_type}_graph", :locals => {:form_id => form_id, :graph_container_id => graph_container_id, analytical_ids => options[:analytical_ids], :include_comparision => options[:include_comparision]}
61
72
  end
62
73
  end
@@ -1,15 +1,10 @@
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 %>
1
+ <%= form_tag(params[:parent_type] && params[:parent_id] ? "/#{params[:parent_type]}/#{params[:parent_id]}/reports" : "/reports", {:method => "get", :id => form_id}) do %>
7
2
  <fieldset class="graph-dates">
8
3
  <%= 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" %>
4
+ <%= text_field_tag 'start_date', "", :class => "date-selector", :placeholder => l(params[:start_date],:format => :analytics), :id => "#{form_id}_start_date" %>
10
5
 
11
6
  <%= 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" %>
7
+ <%= text_field_tag 'end_date', "", :class => "date-selector", :placeholder => l(params[:end_date],:format => :analytics), :id => "#{form_id}_end_date" %>
13
8
  </fieldset>
14
9
 
15
10
  <div class="button-wrapper">
@@ -18,16 +13,20 @@
18
13
  <%= hidden_field_tag 'exclude_views' %>
19
14
  <%= hidden_field_tag 'exclude_shares' %>
20
15
  <%= hidden_field_tag 'analytical_type', (params[:analytical_type]||params[:default_analytical_type]) %>
21
- <%= hidden_field_tag 'analytical_ids', (@analytical_ids||[]) %>
16
+ <% if defined?(analytical_ids) %>
17
+ <%= hidden_field_tag 'analytical_ids', (analytical_ids||[]) %>
18
+ <% end %>
22
19
 
23
20
  <%= submit_tag(t(:submit)) %>
24
21
  <%= image_submit_tag("hawd/blank.png") %>
25
22
  </div>
26
23
 
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>
24
+ <% if defined?(include_comparision) and include_comparision %>
25
+ <fieldset class="graph-compare">
26
+ <%= label_tag 'analyticals', t('hawd.comparision', :analytical => (params[:analytical_type]||params[:default_analytical_type]||"")) %>
27
+ <%= select_tag "analyticals", options_from_collection_for_select(@analyticals, "id", "to_s", {:selected => lambda { |analytical| @analytical_ids.include?(analytical.id) }}), :multiple => true, :size => 1 %>
28
+ </fieldset>
29
+ <% end %>
31
30
 
32
31
  <fieldset class="graph-filters">
33
32
  <%= check_box_tag('include_totals', "1", true) %>
@@ -45,4 +44,4 @@
45
44
 
46
45
  <% end -%>
47
46
 
48
- <div id="bar-graph-container" class="graph-chart"></div>
47
+ <div id="<%= graph_container_id %>" class="graph-chart"></div>
@@ -1,14 +1,10 @@
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 %>
1
+ <%= form_tag(params[:parent_type] && params[:parent_id] ? "/#{params[:parent_type]}/#{params[:parent_id]}/reports" : "/reports", {:method => "get", :id => form_id}) do %>
6
2
  <fieldset class="graph-dates">
7
3
  <%= 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" %>
4
+ <%= text_field_tag 'start_date', "", :class => "date-selector", :placeholder => l(params[:start_date],:format => :analytics), :id => "#{form_id}_start_date" %>
9
5
 
10
6
  <%= 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" %>
7
+ <%= text_field_tag 'end_date', "", :class => "date-selector", :placeholder => l(params[:end_date],:format => :analytics), :id => "#{form_id}_end_date" %>
12
8
  </fieldset>
13
9
 
14
10
  <div class="button-wrapper">
@@ -37,4 +33,4 @@
37
33
  <% end -%>
38
34
 
39
35
 
40
- <div id="line-graph-container" class="graph-chart"></div>
36
+ <div id="<%= graph_container_id %>" class="graph-chart"></div>
@@ -18,6 +18,7 @@
18
18
  <%= hidden_field_tag 'exclude_views' %>
19
19
  <%= hidden_field_tag 'exclude_shares' %>
20
20
  <%= hidden_field_tag 'analytical_type', (params[:analytical_type]||params[:default_analytical_type]) %>
21
+ <%= hidden_field_tag 'analytical_ids', (@analytical_ids||[]) %>
21
22
 
22
23
  <%= submit_tag(t(:submit)) %>
23
24
  <%= image_submit_tag("hawd/blank.png") %>
@@ -38,4 +39,4 @@
38
39
  </fieldset>
39
40
  <% end -%>
40
41
 
41
- <div id="recent-bar-graph-container" class="graph-chart"></div>
42
+ <div id="<%= graph_container_id %>" class="graph-chart"></div>
@@ -11,8 +11,13 @@
11
11
  </style>
12
12
  <% end -%>
13
13
 
14
- <%= render :partial => "line_graph" %>
14
+ <%= raw how_are_we_doing_chart("line-graph-form","line-graph-container","line") %>
15
15
 
16
- <%= render :partial => "recent_bar_graph" %>
16
+ <%= raw how_are_we_doing_chart("recent-bar-graph-form","recent-bar-graph-container","bar",{
17
+ :analytical_ids => (@recent_analytical_ids||[]).empty? ? default_recent_analytical_ids(params[:default_analytical_type],params[:start_date],params[:end_date]) : @recent_analytical_ids
18
+ }) %>
17
19
 
18
- <%= render :partial => "bar_graph" %>
20
+ <%= raw how_are_we_doing_chart("bar-graph-form","bar-graph-container","bar",{
21
+ :analytical_ids => (@comparison_analytical_ids||[]).empty? ? default_comparision_analytical_ids(params[:default_analytical_type]) : @comparison_analytical_ids,
22
+ :include_comparison => true
23
+ }) %>
@@ -7,14 +7,6 @@ module HowAreWeDoing
7
7
  base.before_filter :set_graph_type, :only => :index
8
8
  base.before_filter :set_analyticals, :only => :index
9
9
  end
10
- # extend ActiveSupport::Concern
11
- #
12
- # included do
13
- # respond_to :html, :json, :xml, :js
14
- # before_filter :set_dates, :only => :index
15
- # before_filter :set_graph_type, :only => :index
16
- # before_filter :set_analyticals, :only => :index
17
- # end
18
10
 
19
11
  def index
20
12
  respond_to do |format|
@@ -1,3 +1,3 @@
1
1
  module HowAreWeDoing
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: how_are_we_doing
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.6
5
+ version: 0.0.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Gunner Technology, Cody Swann
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-06 00:00:00 -08:00
13
+ date: 2011-03-07 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency