templus_models 2.0.8 → 2.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1676aaa61958cdb536366ee3608d1cf0d9771288
4
- data.tar.gz: 4a33e15646197c32f54067eaa48c39dfbf463bdf
3
+ metadata.gz: 872ddd9090321dc9cb61eb0813bde103169ce3e4
4
+ data.tar.gz: 6fd45c48c159edc1891fc63d9e0249593d0a8f61
5
5
  SHA512:
6
- metadata.gz: 9565970acc7b83e8adfcd7822194ffd9a83d948ac9348ab34370642924fb92c639cac0cc6d09cf273eb6015ec96eafb644275bca3561e7f24e7377faf34b6ad8
7
- data.tar.gz: 44a4d3804c73423d0f7d462265f739075bbf31005ab473bb9d5dd0711570ed0cfe4e2f897271acba33bb4c328f428b8af7defa497b98a47feb1b4cdf169bfcd5
6
+ metadata.gz: 2fe91b7d4f1f96c87787a26c4fedf70a50a1c489d6369d12bdd398664497b65ddd24691217d250982d5429c2573cbdb1d8e33cce7a23b9375d2f27786d484d52
7
+ data.tar.gz: be8bb80479a4ce137a56e28315268e0cad502e3127d4a1eb2cabe7f30c8f488c3d27c9ae0d48cb141d8322e7c204cedad417d76e68766398e268e86562b1bf5d
@@ -165,14 +165,7 @@ class CrudController < ApplicationController
165
165
  respond_to do |format|
166
166
  format.xls { headers["Content-Disposition"] = "attachment; filename=#{report_name}.xls" }
167
167
  format.pdf do
168
- html = render_to_string('crud/listing.pdf.erb')
169
- options = {
170
- encoding: 'UTF-8',
171
- page_size: 'A4',
172
- show_as_html: params[:debug],
173
- margin: { top: 20, bottom: 20 }
174
- }
175
- pdf = WickedPdf.new.pdf_from_string(html, options)
168
+ pdf = generate_pdf_report(@crud_helper.setup_report_listing, 'crud/listing.pdf.erb')
176
169
  send_data(pdf, filename: "#{report_name}.pdf", type: "application/pdf", disposition: "inline")
177
170
  end
178
171
  end
@@ -184,13 +177,7 @@ class CrudController < ApplicationController
184
177
  report_name = "#{@record}_#{DateTime.now.strftime('%Y%m%d')}"
185
178
  respond_to do |format|
186
179
  format.pdf do
187
- pdf = WickedPdf.new.pdf_from_string(
188
- render_to_string('crud/printing.pdf.erb'),
189
- encoding: 'UTF-8',
190
- page_size: 'A4',
191
- show_as_html: params[:debug],
192
- margin: { top: 20, bottom: 20 }
193
- )
180
+ pdf = generate_pdf_report(@crud_helper.setup_report_printing, 'crud/printing.pdf.erb')
194
181
  send_data(pdf, filename: "#{report_name}.pdf", type: "application/pdf", disposition: "inline")
195
182
  end
196
183
  format.html
@@ -199,6 +186,24 @@ class CrudController < ApplicationController
199
186
 
200
187
 
201
188
  private
189
+
190
+ def generate_pdf_report(opts, layout)
191
+ html = render_to_string(layout)
192
+ options = {
193
+ encoding: 'UTF-8',
194
+ orientation: opts[:orientation],
195
+ page_size: 'A4',
196
+ show_as_html: params[:debug],
197
+ margin: { top: opts[:top], bottom: opts[:bottom] }
198
+ }
199
+ if opts[:header].present?
200
+ options[:header] = {content: render_to_string(template: opts[:header], locals: {title: @crud_helper.title})}
201
+ end
202
+ if opts[:footer].present?
203
+ options[:footer] = {content: render_to_string(template: opts[:footer])}
204
+ end
205
+ WickedPdf.new.pdf_from_string(html, options)
206
+ end
202
207
 
203
208
  def setup
204
209
  if params[:associacao]
@@ -225,7 +230,7 @@ class CrudController < ApplicationController
225
230
  end
226
231
 
227
232
  def params_permitt
228
- params.require(@model.name.underscore.to_sym).permit(fields_model)
233
+ params.require(@model.name.underscore.gsub('/','_').to_sym).permit(fields_model)
229
234
  end
230
235
 
231
236
  def fields_model
@@ -279,7 +284,7 @@ class CrudController < ApplicationController
279
284
  end
280
285
  group
281
286
  end
282
-
287
+
283
288
  def valid_method?(method)
284
289
  list_methods = []
285
290
  @model.ancestors.each do |m|
@@ -288,7 +293,7 @@ class CrudController < ApplicationController
288
293
  end
289
294
  list_methods.flatten.include? method.to_sym
290
295
  end
291
-
296
+
292
297
  def valid_instance_method?(method)
293
298
  list_methods = []
294
299
  @model.ancestors.each do |m|
@@ -78,11 +78,11 @@ module SearchHelper
78
78
  end
79
79
 
80
80
  def raro_input_as(name,type,opts)
81
+ if opts[:collection_if] and opts[:collection_if].class == Proc
82
+ opts[:collection] = ActionView::Helpers::FormBuilder.instance_eval(&opts[:collection_if])
83
+ end
81
84
  case opts[:as]
82
85
  when :select
83
- if opts[:collection_if] and opts[:collection_if].class == Proc
84
- opts[:collection] = ActionView::Helpers::FormBuilder.instance_eval(&opts[:collection_if])
85
- end
86
86
  raro_select(name,opts,opts[:collection])
87
87
  when :hidden
88
88
  return raro_hidden_field(name,opts[:value],opts)
@@ -92,6 +92,8 @@ module SearchHelper
92
92
  raro_range(name)
93
93
  when :monthyear
94
94
  raro_monthyear(name, opts)
95
+ when :check_boxes
96
+ raro_check_boxes(name, opts, opts[:collection])
95
97
  end
96
98
  end
97
99
 
@@ -105,6 +107,23 @@ module SearchHelper
105
107
  return raro_select("q[#{model_name}_id_eq]",opts,collection)
106
108
  end
107
109
 
110
+ def raro_check_boxes(name, opts, collection)
111
+ unless opts[:model]
112
+ name = "q[#{name}_eq]"
113
+ end
114
+ buf = "<div class='col-sm-12'>"
115
+ input_class = opts[:input_html].try(:[], :class)
116
+ collection.each do |e|
117
+ buf << "<span class='checkbox' style='display: inline;'>"
118
+ buf << "<label class='control-label'>"
119
+ buf << "<input class='form-control check_boxes optional #{input_class}' type='checkbox' value='#{e[0]}' name='#{name}' style=''> #{e[1]}"
120
+ buf << '</label>'
121
+ buf << '</span>'
122
+ end
123
+ buf << '</div>'
124
+ return buf
125
+ end
126
+
108
127
  def raro_select(name,opts,collection)
109
128
  unless opts[:model]
110
129
  name = "q[#{name}_eq]"
@@ -7,11 +7,9 @@ class RaroCrud
7
7
  @@form_scripts = {}
8
8
  @@view_fields = {}
9
9
  @@listing_fields = {}
10
- @@logo_listing_field = {}
11
- @@titulo_listing_field = {}
10
+ @@setup_report_listing = {}
11
+ @@setup_report_printing = {}
12
12
  @@printing_fields = {}
13
- @@logo_printing_field = {}
14
- @@titulo_printing_field = {}
15
13
  @@search_fields = {}
16
14
  @@test_fields = {}
17
15
  @@top_links = {}
@@ -178,27 +176,19 @@ class RaroCrud
178
176
  def self.listing_fields
179
177
  @@listing_fields[self.to_s.to_sym] || []
180
178
  end
181
-
182
- def self.logo_listing_field
183
- @@logo_listing_field[self.to_s.to_sym]
179
+
180
+ def self.setup_report_listing
181
+ @@setup_report_listing[self.to_s.to_sym] || {}
184
182
  end
185
-
186
- def self.titulo_listing_field
187
- @@titulo_listing_field[self.to_s.to_sym]
183
+
184
+ def self.setup_report_printing
185
+ @@setup_report_printing[self.to_s.to_sym] || {}
188
186
  end
189
187
 
190
188
  def self.printing_fields
191
189
  @@printing_fields[self.to_s.to_sym] || []
192
190
  end
193
191
 
194
- def self.logo_printing_field
195
- @@logo_printing_field[self.to_s.to_sym]
196
- end
197
-
198
- def self.titulo_printing_field
199
- @@titulo_printing_field[self.to_s.to_sym]
200
- end
201
-
202
192
  def self.search_fields
203
193
  @@search_fields[self.to_s.to_sym] || []
204
194
  end
@@ -249,35 +239,23 @@ class RaroCrud
249
239
  })
250
240
  end
251
241
 
252
- def self.relatorio_listagem_logo(proc = nil, options = {})
253
- url = nil
254
- logo_proc = nil
255
- if proc.respond_to?(:call)
256
- logo_proc = proc
257
- else
258
- url = Templus.logo
259
- end
260
-
261
- @@logo_listing_field[self.to_s.to_sym] = {
262
- url: url,
263
- logo_proc: logo_proc,
264
- sf: options
242
+ def self.setup_relatorio_listagem(options = {})
243
+ @@setup_report_listing[self.to_s.to_sym] = {
244
+ top: options[:top] || 20,
245
+ bottom: options[:bottom] || 20,
246
+ orientation: options[:orientation] || 'Portrait',
247
+ header: options[:header],
248
+ footer: options[:footer]
265
249
  }
266
250
  end
267
251
 
268
- def self.relatorio_listagem_titulo(string_or_proc)
269
- titulo_proc = nil
270
- titulo = nil
271
-
272
- if string_or_proc.respond_to?(:call)
273
- titulo_proc = string_or_proc
274
- elsif string_or_proc.is_a?(String)
275
- titulo = string_or_proc
276
- end
277
-
278
- @@titulo_listing_field[self.to_s.to_sym] = {
279
- titulo_proc: titulo_proc,
280
- titulo: titulo
252
+ def self.setup_relatorio_impressao(options = {})
253
+ @@setup_report_printing[self.to_s.to_sym] = {
254
+ top: options[:top] || 20,
255
+ bottom: options[:bottom] || 20,
256
+ orientation: options[:orientation] || 'Portrait',
257
+ header: options[:header],
258
+ footer: options[:footer]
281
259
  }
282
260
  end
283
261
 
@@ -290,39 +268,6 @@ class RaroCrud
290
268
  })
291
269
  end
292
270
 
293
- def self.relatorio_impressao_logo(field_or_url = nil, options = {})
294
- url = nil
295
- field = nil
296
- if field_or_url.blank?
297
- url = Templus.logo
298
- elsif field_or_url.is_a?(String)
299
- url = field_or_url
300
- else
301
- field = field_or_url
302
- end
303
-
304
- @@logo_printing_field[self.to_s.to_sym] = {
305
- url: url,
306
- field: field,
307
- sf: options
308
- }
309
- end
310
-
311
- def self.relatorio_impressao_titulo(field_or_string = nil)
312
- field = nil
313
- titulo = nil
314
- if field_or_string.is_a?(String)
315
- titulo = I18n.t(field_or_string)
316
- elsif field_or_string.present?
317
- field = field_or_string
318
- end
319
-
320
- @@titulo_printing_field[self.to_s.to_sym] = {
321
- field: field,
322
- titulo: titulo
323
- }
324
- end
325
-
326
271
  def self.sem_visualizacao
327
272
  @@view_action[self.to_s.to_sym] = false
328
273
  end
@@ -3,51 +3,16 @@
3
3
  <div class="widget-box" id="relatorio">
4
4
  <div class="widget-body">
5
5
  <div class="widget-main">
6
- <div class="profile-element">
7
6
 
8
- <div>
9
- <div class="row">
10
- <% if @crud_helper.logo_listing_field.present? %>
11
- <div class="col-xs-3">
12
- <% if @crud_helper.logo_listing_field[:logo_proc].present? %>
13
- <% proc_result = @crud_helper.logo_listing_field[:logo_proc].call(@records) %>
14
- <% if proc_result.is_a?(String) %>
15
- <%= pdf_image_tag(proc_result, width: '100px') %>
16
- <% else %>
17
- <%= render_field_file(proc_result) %>
18
- <% end %>
19
- <% elsif @crud_helper.logo_listing_field[:url].present? %>
20
- <%= pdf_image_tag(@crud_helper.logo_listing_field[:url], width: '100px') %>
21
- <% end %>
22
- </div>
23
- <% end %>
24
-
25
- <% if @crud_helper.titulo_listing_field.present? %>
26
- <div class="col-xs-9">
27
- <h1>
28
- <% if @crud_helper.titulo_listing_field[:titulo].present? %>
29
- <%= t(@crud_helper.titulo_listing_field[:titulo]) %>
30
- <% elsif @crud_helper.titulo_listing_field[:titulo_proc].present? %>
31
- <%= @crud_helper.titulo_listing_field[:titulo_proc].call(@records) %>
32
- <% else %>
33
- <%= Templus.nome_aplicacao %>
34
- <% end %>
35
- </h1>
36
- </div>
37
- <% end %>
7
+ <% unless @crud_helper.setup_report_listing[:header].present? %>
8
+ <div class="row">
9
+ <div class="col-lg-12">
10
+ <h2>
11
+ <small><%= @crud_helper.title %></small><br />
12
+ </h2>
38
13
  </div>
39
14
  </div>
40
- </div>
41
-
42
- <div style="clear: both;"></div>
43
-
44
- <div class="row">
45
- <div class="col-lg-12">
46
- <h2>
47
- <small><%= @crud_helper.title %></small><br />
48
- </h2>
49
- </div>
50
- </div>
15
+ <% end %>
51
16
 
52
17
 
53
18
  <table class="table table-bordered table-striped">
@@ -3,47 +3,13 @@
3
3
  <div class="widget-box" id="relatorio">
4
4
  <div class="widget-body">
5
5
  <div class="widget-main">
6
- <div class="profile-element">
7
-
8
- <div>
9
- <div class="row">
10
- <% if @crud_helper.logo_printing_field.present? %>
11
- <div class="col-xs-3">
12
- <% if @crud_helper.logo_printing_field[:field].present? %>
13
- <% if @record.send(@crud_helper.logo_printing_field[:field]).present? %>
14
- <%= render_field_file(@record.send(@crud_helper.logo_printing_field[:field])) %>
15
- <% else %>
16
- <%= pdf_image_tag(Templus.logo, width: '100px') %>
17
- <% end %>
18
- <% elsif @crud_helper.logo_printing_field[:url].present? %>
19
- <%= pdf_image_tag(@crud_helper.logo_printing_field[:url], width: '100px') %>
20
- <% end %>
21
- </div>
22
- <% end %>
23
-
24
- <% if @crud_helper.titulo_printing_field.present? %>
25
- <div class="col-xs-9">
26
- <h1>
27
- <% if @crud_helper.titulo_printing_field[:titulo].present? %>
28
- <%= t(@crud_helper.titulo_printing_field[:titulo]) %>
29
- <% elsif @crud_helper.titulo_printing_field[:field].present? %>
30
- <%= @record.send(@crud_helper.titulo_printing_field[:field]) %>
31
- <% else %>
32
- <%= Templus.nome_aplicacao %>
33
- <% end %>
34
- </h1>
35
- </div>
36
- <% end %>
37
- </div>
38
- </div>
39
- </div>
40
-
41
- <div style="clear: both;"></div>
42
6
 
43
7
  <div class="row">
44
8
  <div class="col-lg-12">
45
9
  <h2>
46
- <small><%= @crud_helper.title %></small><br />
10
+ <% unless @crud_helper.setup_report_printing[:header].present? %>
11
+ <small><%= @crud_helper.title %></small><br />
12
+ <% end %>
47
13
  <%= @record.to_s %>
48
14
  </h2>
49
15
  </div>
@@ -1,3 +1,3 @@
1
1
  module TemplusModels
2
- VERSION = "2.0.8"
2
+ VERSION = "2.0.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: templus_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8
4
+ version: 2.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Sol
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-06-27 00:00:00.000000000 Z
13
+ date: 2017-07-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -981,7 +981,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
981
981
  version: '0'
982
982
  requirements: []
983
983
  rubyforge_project:
984
- rubygems_version: 2.5.1
984
+ rubygems_version: 2.6.8
985
985
  signing_key:
986
986
  specification_version: 4
987
987
  summary: Easy CRUD generator for Rails Projects