From: <jh...@us...> - 2010-01-27 23:40:47
|
Revision: 200 http://etch.svn.sourceforge.net/etch/?rev=200&view=rev Author: jheiss Date: 2010-01-27 23:40:40 +0000 (Wed, 27 Jan 2010) Log Message: ----------- Move the two dashboard charts to partials so that they can be accessed by themselves (for possible inclusion in an Architecture dashboard). Move the chart generation logic into a separate method in the dashboard controller so that we don't compute the client status counts when generating the client count chart. We need the client status counts when generating the dashboard itself, and when generating the client status chart. It's bad enough computing them twice, computing them a third time unnecessarily bugged me (and the dashboard loads rather slowly in production, so this should help a bit). Clean up the loop when computing the month-by-month client counts, the old code worked fine but was ugly. Simplify the formatting of the months on the month-by-month client count chart, the fancier formatting I had cut-n-pasted from somewhere didn't look very good. Add a style to the chart titles to make them stand out more. Wrap the charts in <div> and apply formatting in the stylesheet to center them. Makes the dashboard look a bit better, although there's still some non-optimal formatting going on. (The status chart moves off-center sooner than it seems like it should when narrowing the browser window.) Modified Paths: -------------- trunk/server/app/controllers/dashboard_controller.rb trunk/server/app/views/dashboard/index.html.erb trunk/server/public/stylesheets/design.css Added Paths: ----------- trunk/server/app/views/dashboard/_client_chart.html.erb trunk/server/app/views/dashboard/_status_chart.html.erb Modified: trunk/server/app/controllers/dashboard_controller.rb =================================================================== --- trunk/server/app/controllers/dashboard_controller.rb 2010-01-21 04:12:08 UTC (rev 199) +++ trunk/server/app/controllers/dashboard_controller.rb 2010-01-27 23:40:40 UTC (rev 200) @@ -1,30 +1,52 @@ +require 'date' + class DashboardController < ApplicationController - def index + def set_counts @total_count = Client.count @healthy_count = Client.count(:conditions => ["status = 0 AND updated_at > ?", 24.hours.ago]) @broken_count = Client.count(:conditions => ["status != 0 AND status != 200 AND updated_at > ?", 24.hours.ago]) @disabled_count = Client.count(:conditions => ["status = 200 AND updated_at > ?", 24.hours.ago]) @stale_count = Client.count(:conditions => ["updated_at <= ?", 24.hours.ago]) - + end + def set_charts + @status_chart = open_flash_chart_object(300, 300, url_for( :action => 'chart', :chart => 'status', :format => :json )) + @client_chart = open_flash_chart_object(500, 300, url_for( :action => 'chart', :chart => 'client', :format => :json )) + end + + def index + set_counts + set_charts + end + + def chart respond_to do |format| format.html { - @status_graph = open_flash_chart_object(300, 300, url_for( :action => 'index', :graph => 'status', :format => :json )) - @client_graph = open_flash_chart_object(500, 300, url_for( :action => 'index', :graph => 'client', :format => :json )) + set_charts + case params[:chart] + when 'status' + render :partial => 'status_chart', :layout => false + return + when 'client' + render :partial => 'client_chart', :layout => false + return + end } format.json { - case params[:graph] + case params[:chart] when 'status' pie = Pie.new pie.start_angle = 0 pie.animate = true pie.tooltip = '#label# of #total#' pie.colours = ['#36E728', '#D01F1F', '#E9F11D', '#741FD0'] + set_counts pie.values = [PieValue.new(@healthy_count, @healthy_count == 0 ? '' : "Healthy: #{@healthy_count}"), PieValue.new(@broken_count, @broken_count == 0 ? '' : "Broken: #{@broken_count}"), PieValue.new(@disabled_count, @disabled_count == 0 ? '' : "Disabled: #{@disabled_count}"), PieValue.new(@stale_count, @stale_count == 0 ? '' : "Stale: #{@stale_count}")] title = Title.new("Client Status") + title.set_style('{font-size: 20px; color: #778877}') chart = OpenFlashChart.new chart.title = title @@ -34,37 +56,21 @@ chart.x_axis = nil render :text => chart, :layout => false + return when 'client' clients = [] months = [] - # Find the oldest client oldest = Client.find(:first, :order => 'created_at') if oldest - # Get the month and year of that date - month = oldest.created_at.mon - year = oldest.created_at.year - # Iterate months to present - (year..Time.now.year).each do |y| - start_month = 1 - end_month = 12 - if y == year - start_month = month - end - if y == Time.now.year - end_month = Time.now.month - end - (start_month..end_month).each do |m| - end_time = nil - if m == 12 - end_time = Time.local(y+1, 1) - else - end_time = Time.local(y, m+1) - end - # This should get us the last second of the desired month - end_time - 1 - clients << Client.count(:conditions => ["created_at <= ?", end_time]) - months << end_time.strftime('%b %Y') - end + start = Date.new(oldest.created_at.year, oldest.created_at.month, 1) + next_month = Date.new(Time.now.year, Time.now.month, 1).next_month + month = start + while month != next_month + # Combination of next_month and -1 gets us the last second of the month + monthtime = Time.local(month.next_month.year, month.next_month.month) - 1 + clients << Client.count(:conditions => ["created_at <= ?", monthtime]) + months << "#{monthtime.strftime('%b')}\n#{monthtime.year}" + month = month.next_month end end @@ -75,15 +81,8 @@ line_dot.dot_size = 5 line_dot.values = clients - tmp = [] - x_labels = XAxisLabels.new - x_labels.set_vertical() - months.each do |text| - tmp << XAxisLabel.new(text, '#0000ff', 12, 'diagonal') - end - x_labels.labels = tmp x = XAxis.new - x.set_labels(x_labels) + x.set_labels(months) y = YAxis.new # Set the top of the y scale to be the largest number of clients @@ -95,6 +94,8 @@ y.set_range(0, ymax, ydiv) title = Title.new("Number of Clients") + title.set_style('{font-size: 20px; color: #778877}') + chart = OpenFlashChart.new chart.set_title(title) chart.x_axis = x @@ -104,6 +105,7 @@ chart.add_element(line_dot) render :text => chart.to_s + return end } end Added: trunk/server/app/views/dashboard/_client_chart.html.erb =================================================================== --- trunk/server/app/views/dashboard/_client_chart.html.erb (rev 0) +++ trunk/server/app/views/dashboard/_client_chart.html.erb 2010-01-27 23:40:40 UTC (rev 200) @@ -0,0 +1,5 @@ +<script type="text/javascript" src="/javascripts/swfobject.js"></script> +<div id="client_chart"> +<%= @client_chart %> +</div> + Added: trunk/server/app/views/dashboard/_status_chart.html.erb =================================================================== --- trunk/server/app/views/dashboard/_status_chart.html.erb (rev 0) +++ trunk/server/app/views/dashboard/_status_chart.html.erb 2010-01-27 23:40:40 UTC (rev 200) @@ -0,0 +1,5 @@ +<script type="text/javascript" src="/javascripts/swfobject.js"></script> +<div id="status_chart"> +<%= @status_chart %> +</div> + Modified: trunk/server/app/views/dashboard/index.html.erb =================================================================== --- trunk/server/app/views/dashboard/index.html.erb 2010-01-21 04:12:08 UTC (rev 199) +++ trunk/server/app/views/dashboard/index.html.erb 2010-01-27 23:40:40 UTC (rev 200) @@ -18,9 +18,8 @@ </tbody> </table> -<script type="text/javascript" src="/javascripts/swfobject.js"></script> -<%= @status_graph %> -<%= @client_graph %> +<%= render :partial => "status_chart" %> +<%= render :partial => "client_chart" %> </div> <!-- end dashboard_body --> Modified: trunk/server/public/stylesheets/design.css =================================================================== --- trunk/server/public/stylesheets/design.css 2010-01-21 04:12:08 UTC (rev 199) +++ trunk/server/public/stylesheets/design.css 2010-01-27 23:40:40 UTC (rev 200) @@ -348,5 +348,20 @@ #loginbox p { text-align: right; } +#status_chart +{ + /* Center this chart */ + margin-left: auto; + margin-right: auto; + /* The chart is defined as 300px wide when created in the dashboard controller */ + width: 300px; +} +#client_chart +{ + margin-left: auto; + margin-right: auto; + width: 500px; +} + /* Hide all HRs, they are only meant for print, or non CSS browsers */ hr { display: none; } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |