Skip to content

Commit

Permalink
Add a traffic chart to the page element info
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Youch committed Sep 9, 2010
1 parent 05d6003 commit 6ac3072
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
18 changes: 15 additions & 3 deletions app/controllers/emarketing_controller.rb
Expand Up @@ -234,6 +234,7 @@ def real_time_charts_request
range = (params[:range] || 5).to_i
intervals = (params[:intervals] || 10).to_i
update_only = (params[:update] || 0).to_i == 1
site_node_id = params[:site_node_id]

now = Time.now
now = now.to_i - (now.to_i % range.minutes)
Expand All @@ -243,12 +244,23 @@ def real_time_charts_request
uniques = []
hits = []
labels = []
groups = DomainLogEntry.traffic Time.at(from), range.minutes, intervals
groups = []
if site_node_id
site_node = SiteNode.find_by_id site_node_id
groups = site_node.traffic(Time.at(from), range.minutes, intervals) if site_node
else
groups = DomainLogEntry.traffic Time.at(from), range.minutes, intervals
end

groups.sort { |a,b| b.started_at <=> a.started_at }.each do |group|
stat = group.domain_log_stats[0]
uniques << stat.visits
hits << stat.hits
if stat
uniques << stat.visits
hits << stat.hits
else
uniques << 0
hits << 0
end
labels << group.ended_at.strftime('%I:%M')
break if update_only
end
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/structure_controller.rb
Expand Up @@ -55,6 +55,13 @@ def index
@wizard_list = get_handlers(:structure,:wizard) if myself.has_role?('editor_structure_advanced')
@wizard_list ||= []

require_js 'protovis/protovis-r3.2.js'
require_js 'tipsy/jquery.tipsy.js'
require_js 'protovis/tipsy.js'
require_css 'tipsy/tipsy.css'
require_js 'charts.js'
require_js 'emarketing.js'

cms_page_path [], 'Website'
#'website',myself.has_role?('editor_structure_advanced') ? 'CMSStructure.popup();' : nil
render :action => 'view', :layout => "manage"
Expand Down
22 changes: 22 additions & 0 deletions app/views/structure/_page_element_chart.html.erb
@@ -0,0 +1,22 @@
<%
groups = node.traffic Time.now.at_midnight, 1.day, 1
group = groups[0]
stats = group.target_stats
if stats.size > 0
-%>
<div class='tree_detail_secondary_section'>
<div id="real_time_charts"></div>
</div>

<script type="text/javascript">
function requestRealTimeCharts() {
RealTimeStatsViewer.requestRealTimeCharts(undefined, <%= node.id %>);
}

if( RealTimeStatsViewer && google ) {
RealTimeStatsViewer.chart.intervals = 6;
RealTimeStatsViewer.chart.range = 60;
google.load("visualization", "1", {packages:["corechart"], callback: requestRealTimeCharts});
}
</script>
<% end -%>
2 changes: 2 additions & 0 deletions app/views/structure/_page_element_info.rhtml
Expand Up @@ -21,6 +21,7 @@
<% if @active_revision_info[1] %>
<%= render :partial => 'page_element_content_info' %>
<%= render :partial => 'page_element_chart', :locals => {:node => @node} %>
<%= render :partial => 'page_element_images', :locals => { :revision => @active_revision_info[1] } %>
<% end -%>
<% end -%>
Expand All @@ -35,6 +36,7 @@
<% else -%>
<div class='tree_detail_body'>
<%= render :partial => @active_revision_info[1] ? 'revision_info' : 'create_revision_info' %>
<%= render :partial => 'page_element_chart', :locals => {:node => @node} %>
<%= render :partial => 'page_element_content_info' %>
<%= render :partial => 'page_element_images', :locals => { :revision => @active_revision_info[1] } %>
</div>
Expand Down
11 changes: 6 additions & 5 deletions public/javascripts/emarketing.js
Expand Up @@ -199,18 +199,19 @@ RealTimeStatsViewer = {
RealTimeStatsViewer.chartTimer = setTimeout( 'RealTimeStatsViewer.requestRealTimeCharts(true);', RealTimeStatsViewer.chart.range*60*1000 );
},

realTimeChartsUrl: function(update) {
realTimeChartsUrl: function(update, site_node_id) {
var url = "/website/emarketing/real_time_charts_request";
url += '?range=' + RealTimeStatsViewer.chart.range + '&intervals=' + RealTimeStatsViewer.chart.intervals;

if( typeof(update) != 'undefined' )
url += '&update=1';
if(typeof(update) != 'undefined') { url += '&update=1'; }

if(site_node_id) { url += "&site_node_id=" + site_node_id }

return url;
},

requestRealTimeCharts: function(update) {
new Ajax.Request(RealTimeStatsViewer.realTimeChartsUrl(update),
requestRealTimeCharts: function(update, site_node_id) {
new Ajax.Request(RealTimeStatsViewer.realTimeChartsUrl(update, site_node_id),
{ onComplete: RealTimeStatsViewer.realTimeChartsOnComplete
});
},
Expand Down

0 comments on commit 6ac3072

Please sign in to comment.