meta_reports 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Guardfile +15 -0
- data/LICENSE +20 -0
- data/README.md +146 -0
- data/Rakefile +29 -0
- data/app/assets/images/meta_reports/print.png +0 -0
- data/app/assets/images/meta_reports/spreadsheet.png +0 -0
- data/app/assets/javascripts/meta_reports/reports.js +2 -0
- data/app/controllers/meta_reports/application_controller.rb +4 -0
- data/app/controllers/meta_reports/reports_controller.rb +91 -0
- data/app/helpers/meta_reports/reports_helper.rb +140 -0
- data/app/models/meta_reports/base.rb +90 -0
- data/app/models/meta_reports/data.rb +34 -0
- data/app/models/meta_reports/table.rb +80 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20130801071213_create_meta_reports_reports.rb +17 -0
- data/lib/generators/meta_reports/install_generator.rb +40 -0
- data/lib/generators/meta_reports/templates/models/report.rb +30 -0
- data/lib/generators/meta_reports/templates/views/_form.html.erb +45 -0
- data/lib/generators/meta_reports/templates/views/edit.html.erb +6 -0
- data/lib/generators/meta_reports/templates/views/forms/_form_example.html.erb +1 -0
- data/lib/generators/meta_reports/templates/views/forms/form.html.erb +17 -0
- data/lib/generators/meta_reports/templates/views/index.html.erb +36 -0
- data/lib/generators/meta_reports/templates/views/new.html.erb +5 -0
- data/lib/generators/meta_reports/templates/views/templates/_default.html.erb +26 -0
- data/lib/generators/meta_reports/templates/views/templates/_default_footer.pdf.prawn +12 -0
- data/lib/generators/meta_reports/templates/views/templates/_default_header.pdf.prawn +14 -0
- data/lib/generators/meta_reports/templates/views/templates/_default_header.xlsx.axlsx +20 -0
- data/lib/generators/meta_reports/templates/views/templates/_default_table.html.erb +24 -0
- data/lib/generators/meta_reports/templates/views/templates/_default_table.pdf.prawn +29 -0
- data/lib/generators/meta_reports/templates/views/templates/default.html.erb +1 -0
- data/lib/generators/meta_reports/templates/views/templates/default.pdf.prawn +26 -0
- data/lib/generators/meta_reports/templates/views/templates/default.xlsx.axlsx +43 -0
- data/lib/meta_reports.rb +4 -0
- data/lib/meta_reports/engine.rb +15 -0
- data/lib/meta_reports/version.rb +3 -0
- data/lib/tasks/meta_reports_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/home_controller.rb +4 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/meta_reports/report.rb +30 -0
- data/spec/dummy/app/views/home/index.html.erb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +16 -0
- data/spec/dummy/app/views/meta_reports/reports/_form.html.erb +45 -0
- data/spec/dummy/app/views/meta_reports/reports/edit.html.erb +6 -0
- data/spec/dummy/app/views/meta_reports/reports/forms/_form_moo.html.erb +1 -0
- data/spec/dummy/app/views/meta_reports/reports/forms/form.html.erb +17 -0
- data/spec/dummy/app/views/meta_reports/reports/index.html.erb +36 -0
- data/spec/dummy/app/views/meta_reports/reports/new.html.erb +5 -0
- data/spec/dummy/app/views/meta_reports/reports/templates/_default.html.erb +26 -0
- data/spec/dummy/app/views/meta_reports/reports/templates/_default_footer.pdf.prawn +12 -0
- data/spec/dummy/app/views/meta_reports/reports/templates/_default_header.pdf.prawn +14 -0
- data/spec/dummy/app/views/meta_reports/reports/templates/_default_header.xlsx.axlsx +20 -0
- data/spec/dummy/app/views/meta_reports/reports/templates/_default_table.html.erb +24 -0
- data/spec/dummy/app/views/meta_reports/reports/templates/_default_table.pdf.prawn +29 -0
- data/spec/dummy/app/views/meta_reports/reports/templates/default.html.erb +1 -0
- data/spec/dummy/app/views/meta_reports/reports/templates/default.pdf.prawn +26 -0
- data/spec/dummy/app/views/meta_reports/reports/templates/default.xlsx.axlsx +43 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +65 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/routes_empty.rb +3 -0
- data/spec/dummy/config/routes_original.rb +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +31 -0
- data/spec/dummy/log/development.log +22317 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/tmp/cache/assets/C9B/140/sprockets%2F805babf865ce32228222420a522c7b36 +0 -0
- data/spec/dummy/tmp/cache/assets/CBD/2B0/sprockets%2F9e22e937dd267c81a146665f15471b8e +0 -0
- data/spec/dummy/tmp/cache/assets/CD0/810/sprockets%2Fe858c95fa595e319dac0065d49982967 +0 -0
- data/spec/dummy/tmp/cache/assets/CD0/AC0/sprockets%2F1d341d7a2fc1328567d4b23e0809b2e2 +0 -0
- data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/D3D/EB0/sprockets%2F2d47bd3108d9abbb12c0497e36d9674d +0 -0
- data/spec/dummy/tmp/cache/assets/D40/8F0/sprockets%2F290aea2004dfecfc76f42e48970f1484 +0 -0
- data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/D61/310/sprockets%2Fc168b1c9be3e38ac1c8403a3074b5b8c +0 -0
- data/spec/dummy/tmp/cache/assets/D74/AE0/sprockets%2F9ad0425db5cfa16a9426f7b1a7958d7d +0 -0
- data/spec/dummy/tmp/cache/assets/D98/270/sprockets%2F0b7ba158ff62bbbb378d6bea80680c63 +0 -0
- data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/E5A/EF0/sprockets%2Fb0d5af721ea37c98fd4bccd8e1e5c6ab +0 -0
- data/spec/dummy/tmp/pids/server.pid +1 -0
- data/spec/features/dummy_spec.rb +42 -0
- data/spec/generators/install_spec.rb +51 -0
- data/spec/models/data_spec.rb +45 -0
- data/spec/models/table_spec.rb +78 -0
- data/spec/spec_helper.rb +41 -0
- metadata +454 -0
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class MetaReports::Report < MetaReports::Base
|
2
|
+
|
3
|
+
#
|
4
|
+
# Shared colors. The key is the class name, value is RGB in hex format
|
5
|
+
#
|
6
|
+
|
7
|
+
COLORS = {
|
8
|
+
even: 'efefef',
|
9
|
+
odd: 'ffffff',
|
10
|
+
}
|
11
|
+
|
12
|
+
|
13
|
+
#
|
14
|
+
# Reports
|
15
|
+
#
|
16
|
+
|
17
|
+
def self.moo(params)
|
18
|
+
MetaReports::Data.new do |d|
|
19
|
+
d.title = 'Le Moo'
|
20
|
+
d.subtitle = 'Ahem'
|
21
|
+
d.tables["The Big Moo"] = MetaReports::Table.new do |t|
|
22
|
+
t << ['Number', 'Title', 'Hey']
|
23
|
+
t << [1, 'Ode to Moo', 'Ow']
|
24
|
+
t << [2, 'Odious Moo', 'Eww']
|
25
|
+
t << [3, "#{params[:moo_type]} Moo", 'No Way!']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy MetaReports App</title>
|
5
|
+
<%= stylesheet_link_tag "application", :media => "all" %>
|
6
|
+
<%= javascript_include_tag "application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= flash[:notice] %>
|
12
|
+
|
13
|
+
<%= yield %>
|
14
|
+
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<%= form_for(@report) do |f| %>
|
2
|
+
<% if @report.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@report.errors.count, "error") %> prohibited this report from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @report.errors.full_messages.each do |msg| %>
|
8
|
+
<li><%= msg %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.label :name %><br />
|
16
|
+
<%= f.text_field :name %>
|
17
|
+
</div>
|
18
|
+
<div class="field">
|
19
|
+
<%= f.label :description %><br />
|
20
|
+
<%= f.text_area :description %>
|
21
|
+
</div>
|
22
|
+
<div class="field">
|
23
|
+
<%= f.label :title %><br />
|
24
|
+
<%= f.text_field :title %>
|
25
|
+
</div>
|
26
|
+
<div class="field">
|
27
|
+
<%= f.label :group %><br />
|
28
|
+
<%= f.text_field :group %>
|
29
|
+
</div>
|
30
|
+
<div class="field">
|
31
|
+
<%= f.label :direct %><br />
|
32
|
+
<%= f.check_box :direct %>
|
33
|
+
</div>
|
34
|
+
<div class="field">
|
35
|
+
<%= f.label :views %><br />
|
36
|
+
<%= f.number_field :views, disabled: true %>
|
37
|
+
</div>
|
38
|
+
<div class="field">
|
39
|
+
<%= f.label :target %><br />
|
40
|
+
<%= f.text_field :target %>
|
41
|
+
</div>
|
42
|
+
<div class="actions">
|
43
|
+
<%= f.submit %>
|
44
|
+
</div>
|
45
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= select_tag :moo_type, options_for_select(['Vegan','Meat Lover']) %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<h3><%= @report.title %></h3>
|
2
|
+
<%= form_tag(meta_reports.short_show_path(@report), id: 'meta_reports_report_form') do %>
|
3
|
+
<p>
|
4
|
+
<%= render "meta_reports/reports/forms/form_#{@report.name}" %>
|
5
|
+
</p>
|
6
|
+
<p class='form-actions'>
|
7
|
+
<% if @report.format? :html %>
|
8
|
+
<%= submit_tag 'Display', data: {action: "/reports/#{@report.name}"} %>
|
9
|
+
<% end -%>
|
10
|
+
<% if @report.format? :pdf %>
|
11
|
+
<%= image_submit_tag image_path('meta_reports/print.png'), name: 'format_print', align: 'absmiddle', data: {action: "/reports/#{@report.name}.pdf", target: '_blank'} %>
|
12
|
+
<% end -%>
|
13
|
+
<% if @report.format? :xlsx %>
|
14
|
+
<%= image_submit_tag image_path('meta_reports/spreadsheet.png'), name: 'format_xlsx', align: 'absmiddle', data: {action: "/reports/#{@report.name}.xlsx", target: '_blank'} %>
|
15
|
+
<% end -%>
|
16
|
+
</p>
|
17
|
+
<% end %>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<h1>Listing reports</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>Name</th>
|
6
|
+
<th>Description</th>
|
7
|
+
<th>Title</th>
|
8
|
+
<th>Group</th>
|
9
|
+
<th>Direct</th>
|
10
|
+
<th>Views</th>
|
11
|
+
<th>Target</th>
|
12
|
+
<th></th>
|
13
|
+
<th></th>
|
14
|
+
<th></th>
|
15
|
+
</tr>
|
16
|
+
|
17
|
+
<% @reports.each do |report| %>
|
18
|
+
<tr>
|
19
|
+
<td><%= report.name %></td>
|
20
|
+
<td><%= report.description %></td>
|
21
|
+
<td><%= report.title %></td>
|
22
|
+
<td><%= report.group %></td>
|
23
|
+
<td><%= report.direct %></td>
|
24
|
+
<td><%= report.views %></td>
|
25
|
+
<td><%= report.target %></td>
|
26
|
+
<td><%= report_link(report, 'Show') %></td>
|
27
|
+
<td><%= link_to 'Edit', edit_report_path(report) %></td>
|
28
|
+
<td><%= link_to 'Destroy', report, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
29
|
+
</tr>
|
30
|
+
<% end %>
|
31
|
+
</table>
|
32
|
+
|
33
|
+
<br />
|
34
|
+
|
35
|
+
<%= link_to 'New Report', new_report_path %>
|
36
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<%
|
2
|
+
report = @report if defined?(report).nil?
|
3
|
+
%>
|
4
|
+
<%= content_tag(:div, :id => report[:id]) do %>
|
5
|
+
<%
|
6
|
+
title = report[:title]
|
7
|
+
title += '<br>'+content_tag(:span, report[:subtitle], :class => 'small') if report[:subtitle]
|
8
|
+
%>
|
9
|
+
<%= content_tag(:h3, title.html_safe) if title %>
|
10
|
+
<div>
|
11
|
+
<%= report_alt_links(report[:report], params) %>
|
12
|
+
<% if report[:description] %><br><p class='description'><%= report[:description] %></p><% end %>
|
13
|
+
</div>
|
14
|
+
|
15
|
+
<%= content_tag(:div, "No data found", :class => 'textcenter') if report[:tables].blank? %>
|
16
|
+
|
17
|
+
<%
|
18
|
+
table_names = report[:table_order] || report[:tables].keys.sort_by {|k| k.to_s}
|
19
|
+
table_names.each do |table_name| %>
|
20
|
+
<%= render partial: 'meta_reports/reports/templates/default_table', locals: {table_name: table_name, table: report[:tables][table_name]} %>
|
21
|
+
<% end %>
|
22
|
+
<% end %>
|
23
|
+
|
24
|
+
<% unless request.xhr? %>
|
25
|
+
<%= link_to 'Reports', '/meta_reports' %>
|
26
|
+
<% end -%>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
pdf.font_size = 8
|
2
|
+
|
3
|
+
time_string = Time.now.strftime("Generated on %-m/%-d/%y at %l:%M %p")
|
4
|
+
absolute_bottom = pdf.bounds.absolute_bottom
|
5
|
+
time_y = 14 - absolute_bottom
|
6
|
+
pdf.repeat :all do
|
7
|
+
pdf.draw_text time_string, at: [0,time_y]
|
8
|
+
end
|
9
|
+
|
10
|
+
string = "Page <page> of <total>"
|
11
|
+
options = { :at => [pdf.bounds.right - 150, 20-absolute_bottom], :width => 150, :align => :right }
|
12
|
+
pdf.number_pages string, options
|
@@ -0,0 +1,14 @@
|
|
1
|
+
pdf.text 'Company Name', :style => :bold, :size => 9
|
2
|
+
pdf.text '1234 Address', :size => 7
|
3
|
+
pdf.text 'City, ST 12345', :size => 7
|
4
|
+
pdf.text '(123) 456-7890', :size => 8
|
5
|
+
# pdf.image 'image_file', width: 60, position: :right, vposition: 0
|
6
|
+
|
7
|
+
|
8
|
+
pdf.move_up 35
|
9
|
+
pdf.pad_bottom(10) do
|
10
|
+
logger.info "title: #{title.inspect}"
|
11
|
+
pdf.text title, :size => 18, :align => :center if title
|
12
|
+
pdf.text subtitle, :size => 12, :align => :center if subtitle
|
13
|
+
end
|
14
|
+
pdf.move_down 7
|
@@ -0,0 +1,20 @@
|
|
1
|
+
wb = sheet.workbook
|
2
|
+
styles = {} unless defined?(styles)
|
3
|
+
unless styles[:bold]
|
4
|
+
styles[:bold] = wb.styles.add_style :b => true
|
5
|
+
end
|
6
|
+
unless styles[:title]
|
7
|
+
styles[:title] = wb.styles.add_style :sz => 14, :alignment => { :horizontal => :center}, :b => true
|
8
|
+
end
|
9
|
+
unless styles[:subtitle]
|
10
|
+
styles[:subtitle] = wb.styles.add_style :sz => 12, :alignment => { :horizontal => :center}, :b => true
|
11
|
+
end
|
12
|
+
|
13
|
+
columns = columns || 8
|
14
|
+
subtitle = subtitle || ''
|
15
|
+
sheet.add_row ["Company Name, Address"] + ['']*(columns-3) + [Date.today().to_s, Time.now().strftime("%I:%M")], :style => styles[:bold]
|
16
|
+
sheet.add_row [' '] * columns
|
17
|
+
sheet.add_row [title], :style => styles[:title]
|
18
|
+
sheet.add_row [subtitle], :style => styles[:subtitle]
|
19
|
+
sheet.merge_cells("A1:#{to_xls_col(columns-3)}1")
|
20
|
+
(2..4).each {|i| sheet.merge_cells("A#{i}:#{to_xls_col(columns-1)}#{i}") }
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<%
|
2
|
+
row_classes = table.row_classes if !defined?(row_classes) || row_classes.nil?
|
3
|
+
table_class = table.options[:table_class].to_s if !defined?(table_class) || table_class.nil?
|
4
|
+
%>
|
5
|
+
<%= content_tag(:h4, table_name) %>
|
6
|
+
<div class='list_container'>
|
7
|
+
<%= content_tag(:table, :class => "table #{table_class}") do %>
|
8
|
+
<% unless @report[:table_header] == false %>
|
9
|
+
<%= content_tag(:thead, content_tag(:tr, table.to_a.shift.map { |h| html_cell(h, :th)}.join.html_safe ) ) %>
|
10
|
+
<% end %>
|
11
|
+
<tbody>
|
12
|
+
<% table.to_a.each_with_index do |row, i| %>
|
13
|
+
<%
|
14
|
+
row_class = "#{cycle('odd','even')} #{row_classes[i]}".strip
|
15
|
+
%>
|
16
|
+
<%= content_tag(:tr, :class => row_class) do
|
17
|
+
row.each do |cell|
|
18
|
+
%><%= html_cell(cell) %><%
|
19
|
+
end
|
20
|
+
end %>
|
21
|
+
<% end %>
|
22
|
+
</tbody>
|
23
|
+
<% end %>
|
24
|
+
</div>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
if defined?(title)
|
2
|
+
pdf.text title.to_s, :align => :center, :style => :bold, :size => 13
|
3
|
+
end
|
4
|
+
styling = {}
|
5
|
+
column_widths = {} if !defined?(column_widths) || column_widths.blank?
|
6
|
+
font_size = table[:font_size] || 8
|
7
|
+
table_header = table[:table_header] != false
|
8
|
+
pdf.table prep_pdf_table(table, styling), :header => table_header, :row_colors => ["EEEEEE", "FFFFFF"], :width => pdf.bounds.width, :cell_style => {:padding => 2, :size => font_size, :align => :center} do |t|
|
9
|
+
t.cells.borders = []
|
10
|
+
t.style t.row(0), :borders => [:bottom], :background_color => "DDDDDD", :font_style => :bold
|
11
|
+
[:left, :center, :right].each do |style|
|
12
|
+
styling[style].to_a.each do |cell|
|
13
|
+
t.row(cell[0]).column(cell[1]).align = style
|
14
|
+
end
|
15
|
+
end
|
16
|
+
styling[:bold].to_a.each do |cell|
|
17
|
+
t.style t.row(cell[0]).column(cell[1]), :font_style => :bold
|
18
|
+
end
|
19
|
+
styling[:row_colors].each do |row, color|
|
20
|
+
t.style t.row(row), :background_color => color
|
21
|
+
end
|
22
|
+
if styling[:column_widths]
|
23
|
+
t.column_widths = styling[:column_widths]
|
24
|
+
else
|
25
|
+
t.column_widths = column_widths
|
26
|
+
end
|
27
|
+
# if totals row? how specify or check?
|
28
|
+
# t.style t.row(-1), :font_style => :bold
|
29
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render 'meta_reports/reports/templates/default', report: (defined?(report).nil? ? @report : report) %>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
margin = @report[:page_margin] && [*@report[:page_margin]][0,4] || nil
|
2
|
+
prawn_document(page_orientation: @report[:page_orientation] || :portrait, page_size: @report[:page_size] || 'LETTER', margin: margin) do |pdf|
|
3
|
+
|
4
|
+
render :partial => "meta_reports/reports/templates/default_header", :locals => { :pdf => pdf, :title => @report[:title], :subtitle => @report[:subtitle] }
|
5
|
+
pdf.font_size = @report[:font_size] || 8
|
6
|
+
if @report[:description]
|
7
|
+
pdf.move_up 5
|
8
|
+
pdf.text strip_tags(@report[:description]), align: :center
|
9
|
+
pdf.move_down 15
|
10
|
+
end
|
11
|
+
|
12
|
+
table_names = @report[:table_order] || @report[:tables].keys.sort_by {|k| k.to_s}
|
13
|
+
table_names.each do |table_name|
|
14
|
+
table = @report[:tables][table_name]
|
15
|
+
pdf.pad_bottom(25) do
|
16
|
+
# TODO: provide option to 'group' all or one table
|
17
|
+
# this forces a table to stay together on one page. throws an error if a table is larger than a page.
|
18
|
+
# pdf.group do
|
19
|
+
render :partial => 'meta_reports/reports/templates/default_table', :locals => {:pdf => pdf, :title => table_name, :table => table}
|
20
|
+
# end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
render partial: "meta_reports/reports/templates/default_footer", locals: { pdf: pdf }
|
25
|
+
|
26
|
+
end #prawn document
|
@@ -0,0 +1,43 @@
|
|
1
|
+
wb = xlsx_package.workbook
|
2
|
+
|
3
|
+
#styles
|
4
|
+
styles = {}
|
5
|
+
styles[:table_header] = wb.styles.add_style :style => :thick, :bg_color => "EEEEEE"
|
6
|
+
styles[:bold] = wb.styles.add_style :style => :thick
|
7
|
+
styles[:title] = wb.styles.add_style :sz => 14, :alignment => { :horizontal => :center}, :style => :thick
|
8
|
+
styles[:subtitle] = wb.styles.add_style :sz => 12, :alignment => { :horizontal => :center}, :style => :thick
|
9
|
+
|
10
|
+
wb.add_worksheet(name: @report[:title][0,31].gsub(/[:\/]/,'-'), page_margins: convert_margins_to_xlsx(@report[:page_margin])) do |sheet|
|
11
|
+
first_table = @report[:tables].values.first
|
12
|
+
columns = first_table.blank? ? 12 : first_table.first.length
|
13
|
+
last_column = to_xls_col(columns)
|
14
|
+
|
15
|
+
render :partial => "meta_reports/reports/templates/default_header", :locals => { :sheet => sheet, :title => @report[:title], :subtitle => @report[:subtitle], :columns => columns, :styles => styles }
|
16
|
+
if @report[:description]
|
17
|
+
sheet.add_row [@report[:description]]
|
18
|
+
this_rows = sheet.rows.length
|
19
|
+
sheet.merge_cells("A#{this_rows}:#{last_column}#{this_rows}")
|
20
|
+
end
|
21
|
+
|
22
|
+
table_names = @report[:table_order] || @report[:tables].keys.sort_by {|k| k.to_s}
|
23
|
+
table_names.each do |table_name|
|
24
|
+
table = @report[:tables][table_name]
|
25
|
+
opts = table.last.is_a?(Hash) ? table.pop : {}
|
26
|
+
row_classes = opts[:row_classes] || {}
|
27
|
+
sheet.add_row [' '] * columns
|
28
|
+
this_rows = sheet.rows.length
|
29
|
+
sheet.add_row [table_name] + [' ']*(columns-1)
|
30
|
+
sheet.merge_cells("A#{this_rows}:#{last_column}#{this_rows}")
|
31
|
+
styling = {}
|
32
|
+
unless @report[:table_header] == false
|
33
|
+
prep_xlsx_table([table.shift], styling).each do |row|
|
34
|
+
sheet.add_row row, :style => styles[:table_header]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
prep_xlsx_table(table, styling).each do |row|
|
38
|
+
sheet.add_row row
|
39
|
+
#TODO: handle styling
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|