prawn_report 1.9.18 → 1.9.21

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 (54) hide show
  1. data/app/controllers/ac_filter_defs_controller.rb +0 -0
  2. data/app/controllers/custom_generate_report_controller.rb +0 -0
  3. data/app/controllers/generate_report_controller.rb +0 -0
  4. data/app/controllers/report_templates_controller.rb +17 -9
  5. data/app/models/ac_filter.rb +0 -0
  6. data/app/models/ac_filter_def.rb +7 -5
  7. data/app/models/ac_filter_option.rb +0 -0
  8. data/app/models/report_template.rb +9 -4
  9. data/app/serializers/ac_filter_def_serializer.rb +10 -0
  10. data/app/serializers/ac_filter_option_serializer.rb +7 -0
  11. data/app/serializers/ac_filter_serializer.rb +9 -0
  12. data/app/serializers/report_template_basic_serializer.rb +4 -0
  13. data/app/serializers/report_template_serializer.rb +9 -0
  14. data/lib/ac_filters_utils.rb +12 -10
  15. data/lib/active_record_helpers.rb +3 -2
  16. data/lib/bands/band.rb +0 -0
  17. data/lib/bands/footer_band.rb +0 -0
  18. data/lib/bands/header_band.rb +0 -0
  19. data/lib/bands/summary_band.rb +0 -0
  20. data/lib/custom_report_controller.rb +28 -16
  21. data/lib/generators/prawn_report/install/install_generator.rb +15 -15
  22. data/lib/generators/prawn_report/install/templates/20120108210141_create_prawn_report_catalogs.rb +14 -14
  23. data/lib/generators/prawn_report/install/templates/20120124012653_add_filter_defs.rb +35 -35
  24. data/lib/generators/prawn_report/install/templates/20120209231821_add_filters_to_reports.rb +13 -13
  25. data/lib/generators/prawn_report/install/templates/20120222021437_add_order_to_filter_def.rb +9 -9
  26. data/lib/generators/prawn_report/install/templates/20120222025632_add_select_sql.rb +9 -9
  27. data/lib/generators/prawn_report/install/templates/20120222030526_create_ac_filter_joins.rb +12 -12
  28. data/lib/generators/prawn_report/install/templates/20120222122507_add_serialization_params_to_report.rb +9 -9
  29. data/lib/generators/prawn_report/install/templates/20120222134101_create_ac_filter_includes.rb +12 -12
  30. data/lib/generators/prawn_report/install/templates/20120222150029_change_includes_and_joins_to_hash.rb +21 -21
  31. data/lib/generators/prawn_report/install/templates/20120229134810_add_group_to_filter_def.rb +9 -9
  32. data/lib/generators/prawn_report/install/templates/20120229194434_add_system_criteria_to_ac_filter.rb +9 -9
  33. data/lib/generators/prawn_report/install/templates/20120301063031_change_select_sql.rb +11 -11
  34. data/lib/generators/prawn_report/install/templates/20120303104431_change_filled_criteria_unfilled_criteria.rb +15 -15
  35. data/lib/generators/prawn_report/install/templates/20120316162712_add_filled_criteria_to_options.rb +9 -9
  36. data/lib/generators/prawn_report/install/templates/20120323124446_add_fields_to_filter.rb +17 -17
  37. data/lib/generators/prawn_report/install/templates/20130122101313_add_sql_query_to_ac_filter_def.rb +5 -5
  38. data/lib/generators/prawn_report/install/templates/20131107172133_add_excluir_to_report_template.rb +10 -9
  39. data/lib/generators/prawn_report/install/templates/20140529153300_add_description_to_report_template.rb +6 -0
  40. data/lib/prawn_report.rb +0 -0
  41. data/lib/prawn_report/engine.rb +9 -9
  42. data/lib/prawn_report_seeds.rb +13 -0
  43. data/lib/report.rb +6 -1
  44. data/lib/report_helpers.rb +15 -14
  45. data/lib/report_info.rb +0 -0
  46. data/repo/bands/footers/footer_001.rb +0 -0
  47. data/repo/bands/headers/header_001.rb +0 -0
  48. data/repo/bands/headers/header_002.rb +0 -0
  49. data/repo/reports/column_group.rb +3 -4
  50. data/repo/reports/listing.rb +59 -1
  51. data/repo/reports/simple_listing.rb +21 -2
  52. metadata +87 -59
  53. checksums.yaml +0 -7
  54. data/lib/prawn_report/version.rb +0 -3
@@ -1,14 +1,14 @@
1
1
  class ReportTemplatesController < ApplicationController
2
-
2
+
3
3
  unloadable
4
-
4
+
5
5
  def index
6
6
  conditions = []
7
7
  conditions = ['report_type in (?)', parse_array(params['report_type'])] unless params['report_type'].blank?
8
-
9
- @templates = ReportTemplate.find(:all,
8
+
9
+ @templates = ReportTemplate.find(:all,
10
10
  :conditions => conditions)
11
-
11
+
12
12
  respond_to do |format|
13
13
  format.html # index.html.erb
14
14
  format.xml { render :xml => @templates }
@@ -22,11 +22,19 @@ class ReportTemplatesController < ApplicationController
22
22
  }
23
23
  )
24
24
  end
25
+ format.json { render :json => @templates }
26
+ end
27
+
28
+ end
29
+
30
+ def show
31
+ @report_template = ReportTemplate.find(params[:id])
32
+
33
+ respond_to do |format|
34
+ format.json { render :json => @report_template, :root => 'reports' }
25
35
  end
26
-
27
36
  end
28
-
29
-
37
+
30
38
  private
31
39
 
32
40
  def parse_array(s_array)
@@ -36,5 +44,5 @@ class ReportTemplatesController < ApplicationController
36
44
  }
37
45
  retorno
38
46
  end
39
-
47
+
40
48
  end
File without changes
@@ -1,12 +1,14 @@
1
1
  class AcFilterDef < ActiveRecord::Base
2
-
2
+
3
3
  has_many :ac_filters, :dependent => :destroy
4
4
  accepts_nested_attributes_for :ac_filters
5
5
 
6
+ has_many :report_templates
7
+
6
8
  def joins_param=(value)
7
9
  write_marshal_attribute(:joins_param, value)
8
10
  end
9
-
11
+
10
12
  def joins_param
11
13
  read_marshal_attribute(:joins_param)
12
14
  end
@@ -14,7 +16,7 @@ class AcFilterDef < ActiveRecord::Base
14
16
  def include_param=(value)
15
17
  write_marshal_attribute(:include_param, value)
16
18
  end
17
-
19
+
18
20
  def include_param
19
21
  read_marshal_attribute(:include_param)
20
22
  end
@@ -24,11 +26,11 @@ class AcFilterDef < ActiveRecord::Base
24
26
  end
25
27
 
26
28
  protected
27
-
29
+
28
30
  def write_marshal_attribute(name, value)
29
31
  write_attribute name, Marshal.dump(value)
30
32
  end
31
-
33
+
32
34
  def read_marshal_attribute(name)
33
35
  value = read_attribute name
34
36
  value.nil? ? nil : Marshal.load(value)
File without changes
@@ -2,21 +2,26 @@ require 'yaml'
2
2
 
3
3
  class ReportTemplate < ActiveRecord::Base
4
4
  belongs_to :ac_filter_def
5
-
5
+
6
+ has_many :filters, :through => :ac_filter_def, :source => :ac_filters
7
+
8
+
6
9
  def serialization_params=(value)
7
10
  if value.is_a? Hash
8
11
  value = Marshal.dump(value)
9
12
  end
10
13
  write_attribute :serialization_params, value
11
14
  end
12
-
15
+
13
16
  def serialization_params
14
17
  value = read_attribute :serialization_params
18
+ #value.nil? ? {} : Marshal.load(value)
15
19
  begin
16
20
  value.nil? ? {} : Marshal.load(value)
21
+ #value.nil? ? {} : YAML.load(value)
17
22
  rescue TypeError
18
-
23
+
19
24
  end
20
25
  end
21
-
26
+
22
27
  end
@@ -0,0 +1,10 @@
1
+ class AcFilterDefSerializer < ActiveModel::Serializer
2
+ embed :ids, :include => true
3
+
4
+ attributes :id, :name
5
+
6
+ has_many :report_templates, :root => 'report_templates'
7
+ has_many :ac_filters, :root => 'ac_filters'
8
+
9
+ end
10
+
@@ -0,0 +1,7 @@
1
+ class AcFilterOptionSerializer < ActiveModel::Serializer
2
+ embed :ids, :include => true
3
+
4
+ attributes :id, :ac_filter_id, :label, :value
5
+
6
+ end
7
+
@@ -0,0 +1,9 @@
1
+ class AcFilterSerializer < ActiveModel::Serializer
2
+ embed :ids, :include => true
3
+
4
+ attributes :id, :data_type, :label, :target_model, :target_field, :required, :required_from, :required_to, :query_user
5
+
6
+ has_one :ac_filter_def, :root => 'ac_filter_defs'
7
+ has_many :ac_filter_options
8
+ end
9
+
@@ -0,0 +1,4 @@
1
+ class ReportTemplateBasicSerializer < ActiveModel::Serializer
2
+ attributes :id, :name
3
+ end
4
+
@@ -0,0 +1,9 @@
1
+ class ReportTemplateSerializer < ActiveModel::Serializer
2
+ embed :ids, :include => true
3
+
4
+ attributes :id, :name, :description, :allow_csv, :ac_filter_def_id, :controller_name, :report_type
5
+
6
+ has_one :ac_filter_def, :root => 'ac_filter_defs'
7
+
8
+ end
9
+
@@ -3,7 +3,7 @@
3
3
  def parse_ac_filters(params)
4
4
  parsed_filters = {}
5
5
  parsed_filters['filter_def_id'] = params['filter_def_id'].to_i
6
- params.each_pair do |k,v|
6
+ params.each_pair do |k,v|
7
7
  md = /^ac_filter_(\d+)_(.+)/.match(k)
8
8
  if md
9
9
  filter_id = md[1]
@@ -26,14 +26,14 @@ def get_ac_filters_applied(params, ac_filter_def)
26
26
  if ['text', 'options'].include? f.data_type
27
27
  val = pf['filter_value']
28
28
  elsif ['period', 'timezone_period'].include?(f.data_type)
29
- if (!pf['from_date'].empty?) && (!pf['to_date'].empty?)
29
+ if (!pf['from_date'].empty?) && (!pf['to_date'].empty?)
30
30
  val = "#{Date.parse(pf['from_date']).strftime('%d/%m/%Y')} até #{Date.parse(pf['to_date']).strftime('%d/%m/%Y')}"
31
31
  elsif !pf['from_date'].empty?
32
32
  val = "Desde #{Date.parse(pf['from_date']).strftime('%d/%m/%Y')}"
33
33
  elsif
34
34
  val = "Até #{Date.parse(pf['to_date']).strftime('%d/%m/%Y')}"
35
35
  end
36
- elsif f.data_type == 'autocomplete'
36
+ elsif ['autocomplete', 'storecombo'].include?(f.data_type)
37
37
  val = Kernel.const_get(f.target_model).find(pf['filter_value']).send(f.target_field)
38
38
  end
39
39
  r << [f.label, val]
@@ -63,7 +63,7 @@ def parse_conditions(parsed_filter, system_params)
63
63
  filter_def = AcFilterDef.find(parsed_filter['filter_def_id'])
64
64
  conditions = []
65
65
  conditions[0] = ['1=1']
66
-
66
+
67
67
  filter_def.ac_filters.each do |f|
68
68
  if f.query_user?
69
69
  parse_condition(conditions, parsed_filter, f)
@@ -74,14 +74,14 @@ def parse_conditions(parsed_filter, system_params)
74
74
  conditions[0] << f.filled_criteria
75
75
  end
76
76
  end
77
-
77
+
78
78
  conditions[0] = conditions[0].join(' and ')
79
79
  conditions
80
- end
80
+ end
81
81
 
82
82
  def parse_condition(conditions, parsed_filter, filter)
83
83
  filled = parsed_filter[filter.id]['is_filled'] == 'true'
84
-
84
+
85
85
  if filter.data_type == 'checkbox'
86
86
  fill_with_checkbox(conditions, filled, parsed_filter, filter)
87
87
  elsif filter.data_type == 'options'
@@ -161,11 +161,11 @@ def fill_with_others(conditions, filled, parsed_filter, filter)
161
161
  end
162
162
 
163
163
  def get_param_by_label(params, label)
164
- filter = AcFilter.find(:first, :conditions => ['ac_filter_def_id = ? and label = ?',params['filter_def_id'], label])
164
+ filter = AcFilter.find(:first, :conditions => ['ac_filter_def_id = ? and label = ?',params['filter_def_id'], label])
165
165
  'ac_filter_'+filter.id.to_s
166
166
  end
167
167
 
168
- module AcFilters
168
+ module AcFilters
169
169
  def apply_ac_filter(parsed_filter, system_params)
170
170
  conditions = parse_conditions(parsed_filter, system_params)
171
171
  find_params = {:conditions => conditions}
@@ -173,6 +173,8 @@ module AcFilters
173
173
  if filter_def.has_sql_query?
174
174
  sql_to_execute = ActiveRecord::Base.send(:sanitize_sql_array, conditions)
175
175
  r = []
176
+ #ActiveRecord::Base.connection.instance_exec(sql_to_execute).each(:as => :hash) {|i| r << i}
177
+ # Ticket_id: 52283 - Seed não exclui mais relatórios existentes
176
178
  ActiveRecord::Base.connection.instance_exec(sql_to_execute).each(as :hash) {|i| r << i}
177
179
  else
178
180
  find_params[:select] = filter_def.select_sql.to_s unless filter_def.select_sql.nil?
@@ -183,5 +185,5 @@ module AcFilters
183
185
  r = find(:all, find_params)
184
186
  end
185
187
  r
186
- end
188
+ end
187
189
  end
@@ -100,10 +100,10 @@ class ActiveRecordYAMLSerializer
100
100
  r += "|-\n"
101
101
  s.lines.each do |l|
102
102
  r += ' ' * (@indent_level + 1)
103
- r += l
103
+ r += l.to_s.gsub('\\', '\\\\\\').gsub('"', '\"')
104
104
  end
105
105
  else
106
- r += '"' + s.to_s.gsub('"', '\"') + '"'
106
+ r += '"' + s.to_s.gsub('\\', '\\\\\\').gsub('"', '\"') + '"'
107
107
  end
108
108
  r + "\n"
109
109
  end
@@ -129,6 +129,7 @@ class ActiveRecordYAMLSerializer
129
129
 
130
130
  def serialize_belongs_tos(rec, first_line, params)
131
131
  r = ''
132
+ params.symbolize_keys!
132
133
  if params[:include_all_belongs_to] == true
133
134
  rec.class.reflect_on_all_associations(:belongs_to).collect do |a|
134
135
  r += render_indent(first_line)
File without changes
File without changes
File without changes
File without changes
@@ -1,48 +1,60 @@
1
1
  #coding: utf-8
2
2
 
3
3
  module PrawnReportController
4
-
4
+
5
5
  def get_pr_report_data
6
6
  []
7
7
  end
8
-
8
+
9
9
  def get_pr_report_class
10
10
  @pr_report_class
11
11
  end
12
-
12
+
13
13
  def get_pr_suggested_filename; end
14
-
14
+
15
15
  def get_pr_report_params
16
16
  @pr_report_params || {}
17
17
  end
18
-
18
+
19
19
  def get_pr_serialization_params
20
20
  @serialization_params || {}
21
21
  end
22
-
22
+
23
23
  def get_pr_filters
24
24
  @filters
25
25
  end
26
-
26
+
27
27
  def index
28
28
  @filters = []
29
29
  rec = get_pr_report_data
30
30
  if rec.nil? || (rec.is_a?(Array) && rec.count == 0)
31
- render :nothing => true, :status => :no_content
31
+ cookies[:fileDownload] = true
32
+ render :nothing => true, :status => :no_content
32
33
  else
33
34
  report_content = rec.pr_serialize(get_pr_serialization_params)
34
35
  report = get_pr_report_class.new(get_pr_report_params)
35
36
  report.report_params[:filters] = get_pr_filters
36
- report_content = report.draw(report_content.get_yaml)
37
37
 
38
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')
39
+
40
+ respond_to do |format|
41
+ format.pdf do
42
+ cookies[:fileDownload] = true
43
+ report_content = report.draw(report_content.get_yaml)
44
+ if fn
45
+ send_data(report_content, :filename => "#{fn}.pdf")
46
+ else
47
+ send_data(report_content, :disposition => 'inline', :type => 'application/pdf')
48
+ end
49
+ end
50
+ format.csv do
51
+ report_content = report.draw_csv(report_content.get_yaml)
52
+ fn ||= "report"
53
+ send_data(report_content, :filename => "#{fn}.csv")
54
+ end
44
55
  end
56
+
45
57
  end
46
58
  end
47
-
48
- end
59
+
60
+ end
@@ -1,16 +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
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
16
  end
@@ -1,14 +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
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
@@ -1,35 +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
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