Permalink
Browse files

Merge conflict resolution.

  • Loading branch information...
2 parents 1b4cf33 + 59f6efe commit 689893ef513175850ba27c5721f857dc3a1a83ee @wayneeseguin committed Jul 16, 2009
View
@@ -1 +1,2 @@
doc/*
+*.gem
View
102 README.rdoc 100644 → 100755
@@ -1,7 +1,7 @@
= Dynamic Reports
A dynamic reporting engine for Ruby / Rails
-
+
== Reports
The dynamic reports gem was created to fill a HUGE hole that we felt existed in the
@@ -114,32 +114,90 @@
label_column "created_at"
end
-== Stylizing
-
- The reports are, by default, stylized with an inline style sheet. The styles produce a nicely formatted grid with
- a white on black header row and black on white columns with a gray border througout.
+== External Links
- You can create your own styles by simply adding a class_name object to the report definition as such:
-
- class OrdersReport < DynamicReports::Report
- title "Orders Report"
- subtitle "All orders recorded in database"
- columns :total, :created_at
+ Dynamic Reports supports linking from any column within your table. To add a link to a column, add the following
+ to a report definition:
+
+ link :column, url
+
+ For example:
+
+ class OrdersReport < DynamicReports::Report
+ title "Orders Report"
+ subtitle "All orders recorded in database"
+ columns :total, :created_at
+
+ link :total, '/report/daily_sales'
+ end
+
+ You can also pass parameters to the URL based on values from the underlying model. To pass a parameter, surround the
+ field name with {}. The parameter does NOT need to be a displayed, column. For example, you might want to pass
+ an external link an ID column but not display this column on the table.
+
+ For example:
+
+ class OrdersReport < DynamicReports::Report
+ title "Orders Report"
+ subtitle "All orders recorded in database"
+ columns :total, :created_at
+
+ link :total, '/report/item_sales?id={id}' # => Will substitute ID for the value of ID associated with that record
+ end
+
+
+== Subreports
- class_name "my_class_name"
- end
+ Dynamic Reports supports the display of a sub-report within any report. This is accomplished using the jQuery library
+ available at http://www.jquery.com.
+
+ Sub-reports are created using the same definition format that you would use to create a standard report. The only
+ difference is that it is displayed INLINE when an associated link is clicked.
+
+ A sub-report is defined using the same format as a LINK above, but is labeled as:
+
+ subreport :column, url
+
+ For example, if you wanted to show all sales and allow a user to click on a specific item to see all historic sales
+ inline for just that item, you would do the following:
+
+ IN CONTROLLER:
+
+ def orders
+ @orders = Order.find(:all, :limit => 25)
+ render :text => OrdersReport.on(@orders).to_html, :layout => "application"
+ end
+
+ def item_sales
+ @item_orders = Order.find_by_id(params[:id])
+ render :text => ItemSales.on(@orders).to_html, :layout => "application"
+ end
+
+ REPORT DEFINITIONS
+
+ class OrdersReport < DynamicReports::Report
+ title "Orders Report"
+ subtitle "All orders recorded in database"
+ columns :total, :created_at
+
+ subreport :total, '/report/item_sales?id={id}' # => Will substitute ID for the value of ID associated with that record
+ end
+
+ class ItemSales < DynamicReports::Report
+ columns :item, :price, :created_at
+ end
+
+ Subreports can also be nested.
+
+== Rails Usage
- This will cause DR to simply not include the inline style. From there you can customer the styles using the
- following sub-classes for your class name, for example:
+ The gem includes a stylesheet and javascript based on jQuery. To add both to your Rails project,
+ simply type "drsetup" from the project root. This will add:
- .my_class_name .report_title {}
- .my_class_name .report_subtitle {}
- .my_class_name table tr th {}
- .my_class_name table tr td {}
- .my_class_name .report_charts {} // all charts are displayed within this div
- .my_class_name .report_chart {} // represents an individual chart
+ public/stylesheets/dynamic_reports.css (controls style of dynamic reports)
+ public/javascripts/dynamic_reports.js (controls display of subreports)
-== Rails Usage
+ You can then modify these files as you see fit.
Inside the initializer block in config/environment.rb
View
7 TODO
@@ -1,5 +1,10 @@
= General
- *
+ * Figure out how to all for the creation of a single report definition file within app/reports instead of one per report
+ * Change report definition from the current to something more like
+ * report :name do
+ * report def options
+ * end
+
= Reports
* Factory Generators (for records data)
* Pdf engine option
View
@@ -0,0 +1,28 @@
+#!/usr/bin/env ruby
+# The dynamic_reports command line utility to copy needed resources
+
+require 'fileutils'
+
+puts "Getting resource and local directories..."
+resource_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'dynamic_reports', 'resources'))
+ss_path = File.join('public', 'stylesheets')
+js_path = File.join('public', 'javascripts')
+
+puts "Copying dynamic_reports.css to public/stylesheets"
+FileUtils.cp("#{resource_path}/dynamic_reports.css", ss_path) unless File.exists?("#{ss_path}/dynamic_reports.css")
+
+puts "Copying dynamic_reports.js to public/javascripts"
+FileUtils.cp("#{resource_path}/dynamic_reports.js", js_path) unless File.exists?("#{js_path}/dynamic_reports.js")
+
+puts ""
+puts "Add the following lines to your application layout:"
+puts "--- ERB:"
+puts "<%= javascript_include_tag 'dynamic_reports.js' %>"
+puts "<%= stylesheet_link_tag 'dynamic_reports.css %>"
+puts ""
+puts "--- HAML:"
+puts "= javascript_include_tag 'dynamic_reports.js'"
+puts "= stylesheet_link_tag 'dynamic_reports.css'"
+puts ""
+puts "See RDoc for usage information"
+
View
Binary file not shown.
@@ -193,6 +193,27 @@ def links(object=nil)
def link(column, url, link_options=nil)
links({:column => column, :url => url, :link_options => link_options})
end
+
+ # Define an inline subreport for the report
+ #
+ # Pass parameters within {}. Parameters are replaced with the row values
+ # from passed records. You do NOT need to include a parameter value as a
+ # report column for it to be used in a link. For example, you might
+ # want to generate a subreport with an ID field in it but not display that id
+ # in the actual report. Just include {id} to do this.
+ #
+ # Example:
+ #
+ # subreport :visits, '/reports/{visit}/details?date={recorded_at}'
+ #
+ # The subreport should be created using the same report definition style
+ # that you use for any other report.
+ #
+ def subreport(column, url, link_options=nil)
+ link_options ||= {}
+ link_options.merge!({:class => 'sub_report_link'})
+ links({:column => column, :url => url, :link_options => link_options})
+ end
# Method for instanciating a report instance on a set of given records.
#
@@ -210,14 +231,6 @@ def link(column, url, link_options=nil)
def on(records)
new(records, @options)
end
-
- #--
- # Methods for definining a sub report
- #def link_column
- #end
- #def link_rows
- #end
-
end
# Instantiate the report on a set of records.
@@ -0,0 +1,54 @@
+/* DYNAMIC_REPORTS.CSS */
+/* Required Stylesheet for dynamic_reports gem formatting */
+
+.dynamic_report .report_title {
+ font-size:16pt;
+ font-weight:bold;
+ margin:10px 0px;
+}
+.dynamic_report .report_subtitle {
+ font-size:14pt;
+ color:black;
+ margin:10px 0px;
+}
+.dynamic_report table tr th {
+ color: white;
+ background: gray;
+ padding:5px;
+}
+.dynamic_report table tr td {
+ border: 1px solid black;
+ padding:3px 15px;
+}
+.dynamic_report .report_charts {
+ width: 100%;
+}
+
+.dynamic_report .report_chart {
+ margin:15px;
+}
+
+.dynamic_report .subreport_row td {
+ padding: 10px 10px 10px 20px;
+ background-color: #FFFFCC;
+ font-size: 95%;
+}
+.dynamic_report .subreport table tr td {
+ border: 1px dotted #CCCC99;
+ padding:3px 5px;
+ background-color: white;
+}
+.dynamic_report .subreport table tr th {
+ color: black;
+ background: #CCCCCC;
+ padding:3px;
+}
+
+.dynamic_report .subreport_close {
+ text-align: right;
+ margin: 5px;
+}
+
+.dynamic_report .close-hover {
+ background-color: yellow;
+}
@@ -0,0 +1,35 @@
+// DYNAMIC_REPORTS.JS
+// Required javascript include file for jQuery supported subreport display
+
+$(function() {
+
+ $('a.sub_report_link').live('click',
+ function() {
+
+ row = $(this).closest('.report_row')
+
+ $(this).closest('table').find('.subreport_row').hide();
+ row.show();
+ $.ajax({
+ url: this.href,
+ success: function(response) {
+ num_cols = row.find('td').size();
+ str = "<tr class='subreport_row'><td colspan='" + num_cols + "' class='subreport'><div class='subreport_close'>[close]</div>" + response + "</td></tr>";
+ row.after(str);
+ }
+ })
+
+ return false;
+ })
+
+ $('.subreport_close').live('click',function() {
+ $(this).closest('.subreport_row').hide();
+ })
+
+ $('.subreport_close').live('mouseover',function(){
+ $(this).addClass('close-hover');
+ }).live('mouseout',function(){
+ $(this).removeClass('close-hover');
+ })
+
+})
@@ -47,7 +47,11 @@ def linkcheck(record, column_object)
val = ''
if column_object.is_a?(Hash)
- column = column_object[:column]
+ if column_object.keys.include?(:column)
+ column = column_object[:column]
+ else
+ column = column_object.keys.first # => Josh shortcut :)
+ end
else
column = column_object
end
@@ -73,15 +77,6 @@ def linkcheck(record, column_object)
val.blank? ? get_record_value(record,column) : val
end
- def get_record_value(record, column)
- if record.is_a?(Hash)
- record[column]
- elsif record.respond_to?(column.to_sym)
- record.send(column.to_sym)
- else
- column
- end
- end
def chart_url(chart,report)
columns = chart.columns ? chart.columns : report.columns
@@ -212,7 +207,15 @@ def require_warn(engine)
require engine.downcase
end
-
+ def get_record_value(record, column)
+ if record.is_a?(Hash)
+ record[column]
+ elsif record.respond_to?(column.to_sym)
+ record.send(column.to_sym)
+ else
+ column
+ end
+ end
end
end
Oops, something went wrong.

0 comments on commit 689893e

Please sign in to comment.