Skip to content
Browse files

Made styles and js resources. Created drsetup executable. Added headi…

…ng shortcut
  • Loading branch information...
1 parent e5c3694 commit 35a07ccca4ecd56f42f1de223dabea1a684ce7d6 Joshua Lippiner committed
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
1 VERSION
@@ -0,0 +1 @@
+0.0.3
View
28 bin/drsetup
@@ -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
BIN dynamic_reports-0.0.0.gem
Binary file not shown.
View
BIN dynamic_reports-0.0.2.gem
Binary file not shown.
View
BIN dynamic_reports-0.0.3.gem
Binary file not shown.
View
62 dynamic_reports.gemspec
@@ -0,0 +1,62 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{dynamic_reports}
+ s.version = "0.0.3"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Wayne E. Seguin", "Joshua Lippiner"]
+ s.date = %q{2009-07-01}
+ s.description = %q{Dynamic Ruby Reporting Engine with support for Charts.}
+ s.email = %q{wayneeseguin@gmail.com, jlippiner@gmail.com}
+ s.extra_rdoc_files = [
+ "README",
+ "README.rdoc"
+ ]
+ s.files = [
+ "HISTORY",
+ "README",
+ "dynamic_reports.gemspec",
+ "lib/dynamic_reports.rb",
+ "lib/dynamic_reports/charts.rb",
+ "lib/dynamic_reports/reports.rb",
+ "lib/dynamic_reports/templates.rb",
+ "lib/dynamic_reports/vendor/google_chart.rb",
+ "lib/dynamic_reports/vendor/google_chart/bar_chart.rb",
+ "lib/dynamic_reports/vendor/google_chart/base.rb",
+ "lib/dynamic_reports/vendor/google_chart/financial_line_chart.rb",
+ "lib/dynamic_reports/vendor/google_chart/line_chart.rb",
+ "lib/dynamic_reports/vendor/google_chart/pie_chart.rb",
+ "lib/dynamic_reports/vendor/google_chart/scatter_chart.rb",
+ "lib/dynamic_reports/vendor/google_chart/venn_diagram.rb",
+ "lib/dynamic_reports/views.rb",
+ "lib/dynamic_reports/views/default_layout.html.erb",
+ "lib/dynamic_reports/views/default_report.html.erb",
+ "lib/dynamic_reports/views/default_report.html.haml"
+ ]
+ s.homepage = %q{http://dynamicreports.rubyforge.org/}
+ s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{dynamicreports}
+ s.rubygems_version = %q{1.3.3}
+ s.summary = %q{Dynamic Ruby Reporting Engine with support for Charts}
+ s.test_files = [
+ "test/dynamic_reports/charts_test.rb",
+ "test/dynamic_reports/reports_test.rb",
+ "test/dynamic_reports/templates_test.rb",
+ "test/dynamic_reports/views_test.rb",
+ "test/dynamic_reports.rb",
+ "test/factories/records.rb",
+ "test/test_helper.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
View
14 lib/dynamic_reports/reports.rb
@@ -183,6 +183,12 @@ def links(object=nil)
def link(column, url, link_options=nil)
links({:column => column, :url => url, :link_options => link_options})
end
+
+ 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.
#
@@ -200,14 +206,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.
View
54 lib/dynamic_reports/resources/dynamic_reports.css
@@ -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;
+}
View
35 lib/dynamic_reports/resources/dynamic_reports.js
@@ -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');
+ })
+
+})
View
25 lib/dynamic_reports/templates.rb
@@ -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
View
51 lib/dynamic_reports/views/default_report.html.erb
@@ -1,51 +1,3 @@
-<% if report.class_name.nil? %>
-<style type="text/css">
-.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;
-}
-
-</style>
-<% end %>
-
<div id="<%= report.class_name %>" class="dynamic_report">
<%= "<div class='report_title'>#{report.title}</div>" if report.title %>
<%= "<div class='report_subtitle'>#{report.sub_title}</div>" if report.sub_title %>
@@ -58,7 +10,7 @@
<% if column.keys.include?(:heading) %>
<%= options[:titleize] ? titleize(column[:heading]) : column[:heading] %>
<% else %>
- <%= options[:titleize] ? titleize(column[:column]) : column[:column] %>
+ <%= options[:titleize] ? titleize(column.values.first) : column.values.first %>
<% end %>
<% else %>
<%= options[:titleize] ? titleize(column) : column %>
@@ -87,5 +39,4 @@
</span>
<% end %>
</div>
-
</div>
View
45 lib/dynamic_reports/views/default_report.html.haml
@@ -1,46 +1,3 @@
-- if report.class_name.nil?
- %style{type => "text/css"}
- \.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: #666666;
- padding:5px;
- }
- \.dynamic_report table tr td {
- border: 1px solid #333333;
- 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{ :id => report.class_name }
- if report.title
%h2.report_title
@@ -59,7 +16,7 @@
- if column.keys.include?(:heading)
= options[:titleize] ? titleize(column[:heading]) : column[:heading]
-else
- = options[:titleize] ? titleize(column[:column]) : column[:column]
+ = options[:titleize] ? titleize(column.values.first) : column.values.first
-else
= options[:titleize] ? titleize(column) : column
%tbody.report_body

0 comments on commit 35a07cc

Please sign in to comment.
Something went wrong with that request. Please try again.