[82154] branches/gsoc11-statistics/stats-server/app/controllers/ chart_controller.rb

derek at macports.org derek at macports.org
Mon Aug 8 19:57:27 PDT 2011


Revision: 82154
          http://trac.macports.org/changeset/82154
Author:   derek at macports.org
Date:     2011-08-08 19:57:27 -0700 (Mon, 08 Aug 2011)
Log Message:
-----------
Added ChartController class which provides methods to manage charts.
Controllers that have views which display charts will inherit from this class.

Added Paths:
-----------
    branches/gsoc11-statistics/stats-server/app/controllers/chart_controller.rb

Added: branches/gsoc11-statistics/stats-server/app/controllers/chart_controller.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/controllers/chart_controller.rb	                        (rev 0)
+++ branches/gsoc11-statistics/stats-server/app/controllers/chart_controller.rb	2011-08-09 02:57:27 UTC (rev 82154)
@@ -0,0 +1,54 @@
+# This is a base class for controllers that display charts
+# It contains helpful methods for managing those charts
+
+class ChartController < ApplicationController
+
+  # Associate chart name with a data set
+  def add_chart(chart_name, dataset, populate_code)
+    set_chart_attribute chart_name, :data, dataset
+    set_chart_attribute chart_name, :populate, populate_code
+  end
+  
+  # Set the chart's title
+  def set_chart_title(chart, title)
+    set_chart_attribute chart, :title, title
+  end
+  
+  # Set the chart's type
+  def set_chart_type(chart, type)
+    set_chart_attribute chart, :type, type
+  end
+    
+  # Call a chart's populate_code to populate it with its associated dataset
+  def populate_chart(chart_name, chart)
+    populate = @charts[chart_name][:populate]
+    populate.call(chart_name, chart)
+  end
+  
+  def chart_dataset(chart_name)
+    @charts[chart_name][:data]
+  end
+  
+  def chart_title(chart_name)
+    @charts[chart_name][:title]
+  end
+  
+  def chart_type(chart_name)
+    @charts[chart_name][:type]
+  end
+  
+  private 
+  
+  # Associate an attribute with the given chart
+  def set_chart_attribute(chart, attribute, value)
+    attrs = @charts[chart]
+    
+    if attrs.nil?
+      attrs = Hash.new
+    end
+    
+    attrs[attribute] = value
+    @charts[chart] = attrs
+  end
+  
+end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20110808/0b781f07/attachment-0001.html>


More information about the macports-changes mailing list