prawn_report 1.9.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/app/controllers/ac_filter_defs_controller.rb +17 -0
  3. data/app/controllers/custom_generate_report_controller.rb +18 -0
  4. data/app/controllers/generate_report_controller.rb +24 -0
  5. data/app/controllers/report_templates_controller.rb +40 -0
  6. data/app/models/ac_filter.rb +15 -0
  7. data/app/models/ac_filter_def.rb +38 -0
  8. data/app/models/ac_filter_option.rb +5 -0
  9. data/app/models/report_template.rb +22 -0
  10. data/lib/ac_filters_utils.rb +187 -0
  11. data/lib/active_record_helpers.rb +218 -0
  12. data/lib/bands/band.rb +23 -0
  13. data/lib/bands/footer_band.rb +7 -0
  14. data/lib/bands/header_band.rb +9 -0
  15. data/lib/bands/summary_band.rb +7 -0
  16. data/lib/custom_report_controller.rb +48 -0
  17. data/lib/generators/prawn_report/install/install_generator.rb +16 -0
  18. data/lib/generators/prawn_report/install/templates/20120108210141_create_prawn_report_catalogs.rb +14 -0
  19. data/lib/generators/prawn_report/install/templates/20120124012653_add_filter_defs.rb +35 -0
  20. data/lib/generators/prawn_report/install/templates/20120209231821_add_filters_to_reports.rb +13 -0
  21. data/lib/generators/prawn_report/install/templates/20120222021437_add_order_to_filter_def.rb +9 -0
  22. data/lib/generators/prawn_report/install/templates/20120222025632_add_select_sql.rb +9 -0
  23. data/lib/generators/prawn_report/install/templates/20120222030526_create_ac_filter_joins.rb +12 -0
  24. data/lib/generators/prawn_report/install/templates/20120222122507_add_serialization_params_to_report.rb +9 -0
  25. data/lib/generators/prawn_report/install/templates/20120222134101_create_ac_filter_includes.rb +12 -0
  26. data/lib/generators/prawn_report/install/templates/20120222150029_change_includes_and_joins_to_hash.rb +21 -0
  27. data/lib/generators/prawn_report/install/templates/20120229134810_add_group_to_filter_def.rb +9 -0
  28. data/lib/generators/prawn_report/install/templates/20120229194434_add_system_criteria_to_ac_filter.rb +9 -0
  29. data/lib/generators/prawn_report/install/templates/20120301063031_change_select_sql.rb +11 -0
  30. data/lib/generators/prawn_report/install/templates/20120303104431_change_filled_criteria_unfilled_criteria.rb +15 -0
  31. data/lib/generators/prawn_report/install/templates/20120316162712_add_filled_criteria_to_options.rb +9 -0
  32. data/lib/generators/prawn_report/install/templates/20120323124446_add_fields_to_filter.rb +17 -0
  33. data/lib/generators/prawn_report/install/templates/20130122101313_add_sql_query_to_ac_filter_def.rb +5 -0
  34. data/lib/generators/prawn_report/install/templates/20131107172133_add_excluir_to_report_template.rb +9 -0
  35. data/lib/prawn_report.rb +21 -0
  36. data/lib/prawn_report/engine.rb +9 -0
  37. data/lib/prawn_report/version.rb +3 -0
  38. data/lib/prawn_report_seeds.rb +46 -0
  39. data/lib/report.rb +190 -0
  40. data/lib/report_helpers.rb +82 -0
  41. data/lib/report_info.rb +27 -0
  42. data/repo/bands/footers/footer_001.rb +20 -0
  43. data/repo/bands/headers/header_001.rb +61 -0
  44. data/repo/bands/headers/header_002.rb +31 -0
  45. data/repo/reports/column_group.rb +58 -0
  46. data/repo/reports/listing.rb +144 -0
  47. data/repo/reports/simple_listing.rb +130 -0
  48. metadata +93 -0
@@ -0,0 +1,23 @@
1
+ module PrawnReport
2
+
3
+ class Band
4
+
5
+ attr_accessor :height, :report
6
+
7
+ def initialize(report, params = {})
8
+ @report = report
9
+ end
10
+
11
+ def draw
12
+ internal_draw
13
+ end
14
+
15
+ def internal_draw; end
16
+
17
+ def self.height
18
+ 20
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,7 @@
1
+ module PrawnReport
2
+
3
+ class FooterBand < Band
4
+
5
+ end
6
+
7
+ end
@@ -0,0 +1,9 @@
1
+ module PrawnReport
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/band")
4
+
5
+ class HeaderBand < Band
6
+
7
+ end
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ module PrawnReport
2
+
3
+ class SummaryBand < Band
4
+
5
+ end
6
+
7
+ end
@@ -0,0 +1,48 @@
1
+ #coding: utf-8
2
+
3
+ module PrawnReportController
4
+
5
+ def get_pr_report_data
6
+ []
7
+ end
8
+
9
+ def get_pr_report_class
10
+ @pr_report_class
11
+ end
12
+
13
+ def get_pr_suggested_filename; end
14
+
15
+ def get_pr_report_params
16
+ @pr_report_params || {}
17
+ end
18
+
19
+ def get_pr_serialization_params
20
+ @serialization_params || {}
21
+ end
22
+
23
+ def get_pr_filters
24
+ @filters
25
+ end
26
+
27
+ def index
28
+ @filters = []
29
+ rec = get_pr_report_data
30
+ if rec.nil? || (rec.is_a?(Array) && rec.count == 0)
31
+ render :nothing => true, :status => :no_content
32
+ else
33
+ report_content = rec.pr_serialize(get_pr_serialization_params)
34
+ report = get_pr_report_class.new(get_pr_report_params)
35
+ report.report_params[:filters] = get_pr_filters
36
+ report_content = report.draw(report_content.get_yaml)
37
+
38
+ fn = get_pr_suggested_filename
39
+
40
+ if fn
41
+ send_data(report_content, :filename => fn)
42
+ else
43
+ send_data(report_content, :disposition => 'inline', :type => 'application/pdf')
44
+ end
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,16 @@
1
+ module PrawnReport
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ desc "Copies migrations to app db/migrate folder"
5
+ dirname = File.expand_path('../templates/', __FILE__)
6
+ Dir.glob(File.join(dirname, '*.rb')).each do |mig|
7
+ destfilename = Rails.root.join('db', 'migrate', Pathname.new(mig).basename)
8
+ unless File.exists?(destfilename)
9
+ puts "Imported migration #{Pathname.new(mig).basename}"
10
+ FileUtils.copy(mig, destfilename)
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ class CreatePrawnReportCatalogs < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :report_templates do |t|
4
+ t.string :name
5
+ t.string :report_type
6
+ t.string :controller_name
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :report_templates
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ class AddFilterDefs < ActiveRecord::Migration
2
+ def self.up
3
+
4
+ create_table :ac_filter_defs do |t|
5
+ t.string :name
6
+ t.text :description
7
+ t.string :model_class
8
+ t.timestamps
9
+ end
10
+
11
+ create_table :ac_filters do |t|
12
+ t.integer :ac_filter_def_id, :name => 'filter_def_in_filter'
13
+ t.boolean :query_user
14
+ t.string :data_type
15
+ t.string :label
16
+ t.string :filled_criteria
17
+ t.string :unfilled_criteria
18
+ t.string :target_model
19
+ t.string :target_field
20
+ end
21
+
22
+ create_table :ac_filter_options do |t|
23
+ t.integer :ac_filter_id, :name => 'filter_in_filter_options'
24
+ t.string :label
25
+ t.string :value
26
+ end
27
+
28
+ end
29
+
30
+ def self.down
31
+ drop_table :ac_filter_options
32
+ drop_table :ac_filters
33
+ drop_table :ac_filter_defs
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ class AddFiltersToReports < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ add_column :report_templates, :ac_filter_def_id, :integer, :name => 'filter_in_report_template'
5
+ add_column :report_templates, :report_class, :string
6
+ end
7
+
8
+ def self.down
9
+ remove_column :report_templates, :ac_filter_def_id
10
+ remove_column :report_templates, :report_class
11
+ end
12
+
13
+ end
@@ -0,0 +1,9 @@
1
+ class AddOrderToFilterDef < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :ac_filter_defs, :order_sql, :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column :ac_filter_defs, :order_sql
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class AddSelectSql < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :ac_filter_defs, :select_sql, :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column :ac_filter_defs, :select_sql
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ class CreateAcFilterJoins < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :ac_filter_joins do |t|
4
+ t.integer :ac_filter_def_id, :name => 'filter_join_in_filter'
5
+ t.string :name
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :ac_filter_joins
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ class AddSerializationParamsToReport < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :report_templates, :serialization_params, :text
4
+ end
5
+
6
+ def self.down
7
+ remove_column :report_templates, :serialization_params
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ class CreateAcFilterIncludes < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :ac_filter_includes do |t|
4
+ t.integer :ac_filter_def_id, :name => 'filter_include_in_filter'
5
+ t.string :name
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :ac_filter_includes
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ class ChangeIncludesAndJoinsToHash < ActiveRecord::Migration
2
+ def self.up
3
+ drop_table :ac_filter_includes
4
+ drop_table :ac_filter_joins
5
+ add_column :ac_filter_defs, :include_param, :text
6
+ add_column :ac_filter_defs, :joins_param, :text
7
+ end
8
+
9
+ def self.down
10
+ create_table :ac_filter_includes do |t|
11
+ t.integer :ac_filter_def_id, :name => 'filter_include_in_filter'
12
+ t.string :name
13
+ end
14
+ create_table :ac_filter_joins do |t|
15
+ t.integer :ac_filter_def_id, :name => 'filter_join_in_filter'
16
+ t.string :name
17
+ end
18
+ remove_column :ac_filter_defs, :include_param
19
+ remove_column :ac_filter_defs, :joins_param
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ class AddGroupToFilterDef < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :ac_filter_defs, :group_param, :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column :ac_filter_defs, :group_param, :string
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class AddSystemCriteriaToAcFilter < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :ac_filters, :system_criteria, :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column :ac_filters, :system_criteria
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class ChangeSelectSql < ActiveRecord::Migration
2
+ def self.up
3
+ remove_column :ac_filter_defs, :select_sql
4
+ add_column :ac_filter_defs, :select_sql, :text
5
+ end
6
+
7
+ def self.down
8
+ remove_column :ac_filter_defs, :select_sql
9
+ add_column :ac_filter_defs, :select_sql, :string
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ class ChangeFilledCriteriaUnfilledCriteria < ActiveRecord::Migration
2
+ def self.up
3
+ remove_column :ac_filters, :filled_criteria
4
+ add_column :ac_filters, :filled_criteria, :text
5
+ remove_column :ac_filters, :unfilled_criteria
6
+ add_column :ac_filters, :unfilled_criteria, :text
7
+ end
8
+
9
+ def self.down
10
+ remove_column :ac_filters, :filled_criteria
11
+ add_column :ac_filters, :filled_criteria, :string
12
+ remove_column :ac_filters, :unfilled_criteria
13
+ add_column :ac_filters, :unfilled_criteria, :string
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ class AddFilledCriteriaToOptions < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :ac_filter_options, :filled_criteria, :text
4
+ end
5
+
6
+ def self.down
7
+ remove_column :ac_filter_options, :filled_criteria, :text
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ class AddFieldsToFilter < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :ac_filters, :filled_criteria_from, :text
4
+ add_column :ac_filters, :filled_criteria_to, :text
5
+ add_column :ac_filters, :required, :boolean, :default => false
6
+ add_column :ac_filters, :required_from, :boolean, :default => false
7
+ add_column :ac_filters, :required_to, :boolean, :default => false
8
+ end
9
+
10
+ def self.down
11
+ remove_column :ac_filters, :filled_criteria_from
12
+ remove_column :ac_filters, :filled_criteria_to
13
+ remove_column :ac_filters, :required
14
+ remove_column :ac_filters, :required_from
15
+ remove_column :ac_filters, :required_to
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ class AddSqlQueryToAcFilterDef < ActiveRecord::Migration
2
+ def change
3
+ add_column 'ac_filter_defs', 'sql_query', :text
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class AddExcluirToReportTemplate < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :report_templates, :excluir, :boolean
4
+ end
5
+
6
+ def self.down
7
+ remove_column :report_templates, :excluir
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+
3
+
4
+ module PrawnReport
5
+ mattr_accessor :parent_controller
6
+ @@parent_controller = "CustomGenerateReportController"
7
+ end
8
+
9
+
10
+ require "report"
11
+ require "bands/band"
12
+ require "bands/summary_band"
13
+ require "active_record_helpers"
14
+ require "ac_filters_utils"
15
+ require File.expand_path(File.dirname(__FILE__) + "/../repo/bands/headers/header_001.rb")
16
+ require File.expand_path(File.dirname(__FILE__) + "/../repo/bands/footers/footer_001.rb")
17
+ require File.expand_path(File.dirname(__FILE__) + "/../repo/reports/simple_listing.rb")
18
+ require File.expand_path(File.dirname(__FILE__) + "/../repo/reports/column_group.rb")
19
+
20
+ # Rails 3 compatibility
21
+ require 'prawn_report/engine' if ((defined? Rails) and (Rails::version >= '3.0.0'))
@@ -0,0 +1,9 @@
1
+ module PrawnReport
2
+ class Engine < ::Rails::Engine
3
+ initializer "application_controller.initialize_prawn_report" do
4
+ ActiveSupport.on_load(:action_controller) do
5
+ #include PrawnReport
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module PrawnReport
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+
3
+ require 'yaml'
4
+
5
+ ReportTemplate.update_all({:ac_filter_def_id => nil, :excluir => true})
6
+ AcFilterOption.delete_all
7
+ AcFilter.delete_all
8
+ AcFilterDef.delete_all
9
+
10
+ puts "Iniciando importação dos filtros"
11
+ Dir.glob("#{Rails.root}/db/filters/*.yml").each do |f|
12
+ params = YAML::load(File.open(f, 'r'))
13
+ AcFilterDef.create(params)
14
+ puts "Criado filtro: " + params["name"]
15
+ end
16
+ puts "FIM"
17
+
18
+ puts "Iniciando importação dos reports"
19
+ Dir.glob("#{Rails.root}/db/reports/*.yml").each do |f|
20
+ params = YAML::load(File.open(f, 'r'))
21
+ r = ReportTemplate.find_by_name(params["name"])
22
+ if r.nil?
23
+ if params["filter_name"]
24
+ f = AcFilterDef.find_by_name(params.delete("filter_name"))
25
+ if f
26
+ params["ac_filter_def_id"] = f.id
27
+ end
28
+ end
29
+ params["excluir"] = false
30
+ ReportTemplate.create(params)
31
+ puts "Criado relatório: " + params["name"]
32
+ else
33
+ if params["filter_name"]
34
+ f = AcFilterDef.find_by_name(params.delete("filter_name"))
35
+ if f
36
+ params["ac_filter_def_id"] = f.id
37
+ end
38
+ end
39
+ params["excluir"] = false
40
+ r.update_attributes(params)
41
+ puts "Atualizado relatório: " + params["name"]
42
+ end
43
+ end
44
+ ReportTemplate.destroy_all(:excluir => true)
45
+ puts "finishing, closing, and going home"
46
+