templus_models 1.6.4 → 1.6.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6719f4fab497f01fb42e07062edf8458700c10dd
4
- data.tar.gz: 0e4350d21ea8baa7ddc4f78413d34c9951286d13
3
+ metadata.gz: be235e07c0065d4c5a85c2f1aaec34e7e99c4474
4
+ data.tar.gz: 28d9d080353e73cdc00c3f12750c6c64e4edc90f
5
5
  SHA512:
6
- metadata.gz: 11cd71b326d65e518a3f40ede2e7f57f786145f05b3557b03b46ab28aa7bd7f9ac2b2ba30cba0f6ec56df96cbefccded09415e8e78469108a7b90c22f4d233f5
7
- data.tar.gz: 95c28d849e57844e92121d73ee9cf3a0e5f6b7314b117341dbebf2417b72d7f9ecf784c4ee9711bf5a7a062e17d3622214d4a799e550618db249159dd82ba78b
6
+ metadata.gz: b5f3146b2773659878fb772d6138791840f45114fba3b9fb3007ada4edb1e6d87ca766ec73ccec0f5f109b783b62ad3824179738e56ed0b055f1ce98752af871
7
+ data.tar.gz: b46be38880c155a8853ff77e6d11d9f1dee39544bc4bddf394934987ffed35f0a8050c20fc91025698080870d87f02c821e7677b040fe245e6d937048bc45199
@@ -170,6 +170,31 @@ class CrudController < ApplicationController
170
170
  render json: results.map {|result| {id: result.id, label: result.send(method_label), value: result.send(method_label)} }
171
171
  end
172
172
 
173
+ def listing
174
+ authorize! :read, @model_permission if respond_to?(:current_usuario)
175
+ @q = @model.search(params[:q])
176
+ if respond_to?(:current_usuario)
177
+ @records = @q.result.accessible_by(current_ability)
178
+ else
179
+ @records = @q.result
180
+ end
181
+ report_name = "Listagem de #{@crud_helper.title} #{DateTime.now.strftime('%Y%m%d')}"
182
+ respond_to do |format|
183
+ format.xls {headers["Content-Disposition"] = "attachment; filename=#{report_name}.xls"}
184
+ format.pdf do
185
+ pdf = WickedPdf.new.pdf_from_string(
186
+ render_to_string('crud/listing.pdf.erb'),
187
+ encoding: 'UTF-8',
188
+ page_size: 'A4',
189
+ show_as_html: params[:debug],
190
+ margin: { top: 20, bottom: 20 }
191
+ )
192
+ send_data(pdf, filename: "#{report_name}.pdf", type: "application/pdf", disposition: "inline")
193
+ end
194
+ format.html
195
+ end
196
+ end
197
+
173
198
  private
174
199
  def params_permitt
175
200
  params.require(@model.name.underscore.to_sym).permit(fields_model)
@@ -205,4 +205,10 @@ module CrudHelper
205
205
  return true if crud_helper.condition_destroy_action.nil?
206
206
  crud_helper.condition_destroy_action.call(record)
207
207
  end
208
+
209
+ def should_listing?(crud_helper,model)
210
+ return false unless can?(:read, model)
211
+ return true if crud_helper.condition_listing_action.nil?
212
+ crud_helper.condition_listing_action.call(model)
213
+ end
208
214
  end
@@ -68,6 +68,8 @@ module SearchHelper
68
68
  return raro_date_range(name)
69
69
  when :boolean
70
70
  return raro_radio(name, opts)
71
+ when :monthyear
72
+ return raro_monthyear(name, opts)
71
73
  else
72
74
  return raro_text_field(name, opts)
73
75
  end
@@ -76,13 +78,16 @@ module SearchHelper
76
78
  def raro_input_as(name,type,opts)
77
79
  case opts[:as]
78
80
  when :select
81
+ if opts[:collection_if] and opts[:collection_if].class == Proc
82
+ opts[:collection] = ActionView::Helpers::FormBuilder.instance_eval &opts[:collection_if]
83
+ end
79
84
  raro_select(name,opts,opts[:collection])
80
85
  when :hidden
81
86
  return raro_hidden_field(name,opts[:value],opts)
82
87
  when :string
83
88
  raro_text_field(name, opts)
84
- when :monthyear
85
- raro_monthyear(name, opts)
89
+ when :range
90
+ raro_range(name)
86
91
  end
87
92
  end
88
93
 
@@ -136,8 +141,8 @@ module SearchHelper
136
141
 
137
142
  def raro_monthyear(name, opts)
138
143
  buffer = ""
139
- buffer += "<div class='col-sm-12'>"
140
- buffer += "<input id='q_#{name}' type='text' name='q[#{name}_monthyear_eq]' class='form-control monthyearpicker #{opts[:class]}'/>"
144
+ buffer += "<div class='col-sm-8'>"
145
+ buffer += "<input id='q_#{name}' type='text' name='q[#{name}_cont]' class='form-control #{opts[:class]}'/>"
141
146
  buffer += "</div>"
142
147
  buffer
143
148
  end
@@ -166,9 +171,9 @@ module SearchHelper
166
171
  if opts[:collection].present?
167
172
  opts[:collection].each do |opt|
168
173
  buff<<"<label>"
169
- buff<<"<div class='checkbox'>"
170
- buff<<"<input id='q_#{name}' type='radio' name='q[#{name}_eq]' value='#{opt[0]}' class='i-checks'/>"
171
- buff<<"</div>"
174
+ buff<<"<div class='checkbox'>"
175
+ buff<<"<input id='q_#{name}' type='radio' name='q[#{name}_eq]' value='#{opt[0]}' class='i-checks'/>"
176
+ buff<<"</div>"
172
177
  buff<<"<span class='lbl'> #{opt[1]}</span>"
173
178
  buff<<"</label>"
174
179
  end
@@ -201,6 +206,16 @@ module SearchHelper
201
206
  </div></div>"
202
207
  end
203
208
 
209
+ def raro_range(name)
210
+ buffer = "<div class='col-sm-4'>"
211
+ buffer += "<input type='text' name='q[#{name}_gteq]' class='form-control'/>"
212
+ buffer += "</div>"
213
+ buffer += "<div class='col-sm-4 range-separator'>"
214
+ buffer += "<input type='text' name='q[#{name}_lteq]' class='form-control'/>"
215
+ buffer += "</div>"
216
+ buffer
217
+ end
218
+
204
219
  def raro_before_form(model,partial,var,url,sort)
205
220
  buffer = "<div id='search_box'>"+
206
221
  "<form method='get' class=form-horizontal action='#{url}' data-push='partial' data-target='#form'>" +
@@ -245,6 +260,6 @@ module SearchHelper
245
260
  end
246
261
 
247
262
  def raro_group(text)
248
- @buffer << "<div class=\"col-sm-12 label label-primary\" style=\"margin-bottom:10px; font-size:14px;\"><b>#{text}</b></div>"
263
+ @buffer << "<div class=\"col-sm-12 label label-primary\" style=\"margin-bottom:10px; font-size:14px;display: inline-block;\"><b>#{text}</b></div>"
249
264
  end
250
265
  end
@@ -6,9 +6,10 @@ class RaroCrud
6
6
  @@form_group = {}
7
7
  @@form_scripts = {}
8
8
  @@view_fields = {}
9
+ @@listing_fields = {}
9
10
  @@search_fields = {}
10
11
  @@test_fields = {}
11
- @@top_links = {}
12
+ @@top_links = {}
12
13
  @@title = {}
13
14
  @@subtitle_index = {}
14
15
  @@description_index = {}
@@ -20,6 +21,7 @@ class RaroCrud
20
21
  @@condition_destroy_action = {}
21
22
  @@view_action = {}
22
23
  @@condition_view_action = {}
24
+ @@condition_listing_action = {}
23
25
  @@options_link = {}
24
26
  @@scopes = {}
25
27
  @@menus = []
@@ -33,20 +35,20 @@ class RaroCrud
33
35
  return true
34
36
  end
35
37
  end
36
-
38
+
37
39
  def self.layout
38
40
  (@@layout[self.to_s.to_sym]) ? @@layout[self.to_s.to_sym] : []
39
41
  end
40
-
42
+
41
43
  def self.set_layout(desc,proc = nil)
42
44
  @@layout[self.to_s.to_sym] = [] unless @@layout[self.to_s.to_sym]
43
45
  @@layout[self.to_s.to_sym] = [desc,proc]
44
46
  end
45
-
47
+
46
48
  def self.condition_edit_action
47
49
  (@@condition_edit_action[self.to_s.to_sym]) ? @@condition_edit_action[self.to_s.to_sym] : nil
48
50
  end
49
-
51
+
50
52
  def self.destroy_action
51
53
  if @@destroy_action[self.to_s.to_sym] == false
52
54
  return false
@@ -54,7 +56,7 @@ class RaroCrud
54
56
  return true
55
57
  end
56
58
  end
57
-
59
+
58
60
  def self.condition_destroy_action
59
61
  (@@condition_destroy_action[self.to_s.to_sym]) ? @@condition_destroy_action[self.to_s.to_sym] : nil
60
62
  end
@@ -66,11 +68,15 @@ class RaroCrud
66
68
  return true
67
69
  end
68
70
  end
69
-
71
+
70
72
  def self.condition_view_action
71
73
  (@@condition_view_action[self.to_s.to_sym]) ? @@condition_view_action[self.to_s.to_sym] : nil
72
74
  end
73
75
 
76
+ def self.condition_listing_action
77
+ (@@condition_listing_action[self.to_s.to_sym]) ? @@condition_listing_action[self.to_s.to_sym] : nil
78
+ end
79
+
74
80
  def self.root_path
75
81
  self.to_s.gsub('Crud', '').underscore
76
82
  end
@@ -78,7 +84,7 @@ class RaroCrud
78
84
  def self.index_path str
79
85
  @@index_path = str
80
86
  end
81
-
87
+
82
88
  def self.get_index_path
83
89
  @@index_path
84
90
  end
@@ -101,7 +107,7 @@ class RaroCrud
101
107
  end
102
108
  end
103
109
 
104
- def self.top_links
110
+ def self.top_links
105
111
  (@@top_links[self.to_s.to_sym]) ? @@top_links[self.to_s.to_sym] : []
106
112
  end
107
113
 
@@ -112,7 +118,7 @@ class RaroCrud
112
118
  def self.order_field
113
119
  (@@order_field[self.to_s.to_sym]).present? ? @@order_field[self.to_s.to_sym] : "id"
114
120
  end
115
-
121
+
116
122
  def self.per_page
117
123
  @@per_page[self.to_s.to_sym]
118
124
  end
@@ -145,6 +151,10 @@ class RaroCrud
145
151
  (@@view_fields[self.to_s.to_sym]) ? @@view_fields[self.to_s.to_sym] : []
146
152
  end
147
153
 
154
+ def self.listing_fields
155
+ (@@listing_fields[self.to_s.to_sym]) ? @@listing_fields[self.to_s.to_sym] : []
156
+ end
157
+
148
158
  def self.search_fields
149
159
  (@@search_fields[self.to_s.to_sym]) ? @@search_fields[self.to_s.to_sym] : []
150
160
  end
@@ -152,7 +162,7 @@ class RaroCrud
152
162
  def self.test_fields
153
163
  (@@test_fields[self.to_s.to_sym]) ? @@test_fields[self.to_s.to_sym] : []
154
164
  end
155
-
165
+
156
166
  def self.scopes
157
167
  (@@scopes[self.to_s.to_sym]) ? @@scopes[self.to_s.to_sym] : []
158
168
  end
@@ -164,14 +174,14 @@ class RaroCrud
164
174
  def self.menus
165
175
  @@menus
166
176
  end
167
-
168
-
177
+
178
+
169
179
  private
170
-
180
+
171
181
  def self.modelo
172
182
  self.to_s.underscore.gsub("_crud", "")
173
183
  end
174
-
184
+
175
185
  def self.titulo str
176
186
  @@title[self.to_s.to_sym] = str
177
187
  end
@@ -205,8 +215,8 @@ class RaroCrud
205
215
  partial: opts[:partial]
206
216
  }
207
217
  )
208
- end
209
-
218
+ end
219
+
210
220
  def self.campo_tabela nome, opts
211
221
  @@index_fields[self.to_s.to_sym] = [] unless @@index_fields[self.to_s.to_sym]
212
222
  @@index_fields[self.to_s.to_sym].push(
@@ -215,15 +225,15 @@ class RaroCrud
215
225
  }.merge(opts)
216
226
  )
217
227
  end
218
-
228
+
219
229
  def self.ordenar_por nome
220
230
  @@order_field[self.to_s.to_sym] = nome
221
231
  end
222
-
232
+
223
233
  def self.itens_por_pagina qtd
224
234
  @@per_page[self.to_s.to_sym] = qtd
225
235
  end
226
-
236
+
227
237
  def self.campo_teste nome, opts
228
238
  @@test_fields[self.to_s.to_sym] = [] unless @@test_fields[self.to_s.to_sym]
229
239
  @@test_fields[self.to_s.to_sym].push(
@@ -231,14 +241,14 @@ class RaroCrud
231
241
  attribute: nome
232
242
  }.merge({sf: opts})
233
243
  )
234
- end
235
-
244
+ end
245
+
236
246
  def self.campo_formulario nome, opts
237
247
  @@form_fields[self.to_s.to_sym] = [] unless @@form_fields[self.to_s.to_sym]
238
248
  if opts.present? && opts[:autocomplete].present?
239
249
  opts[:as] = :autocomplete
240
250
  label_method = opts[:autocomplete][:label_method] || opts[:autocomplete][:campo]
241
- opts[:url] = autocomplete_crud_path(model: opts[:autocomplete][:classe], campo: opts[:autocomplete][:campo], tipo: "start", label: label_method)
251
+ opts[:url] = Rails.application.routes.url_helpers.autocomplete_crud_path(model: opts[:autocomplete][:classe], campo: opts[:autocomplete][:campo], tipo: "start", label: label_method)
242
252
  name = "#{opts[:autocomplete][:campo]}_#{opts[:autocomplete][:classe]}"
243
253
  opts[:input_html] = {name: name, id: name}
244
254
  opts[:id_element] = "##{self.modelo}_#{nome}_id"
@@ -262,8 +272,8 @@ class RaroCrud
262
272
  campo_formulario(nome, {as: :hidden})
263
273
  end
264
274
  end
265
-
266
- private
275
+
276
+ private
267
277
  def self.add_group_formulario(field)
268
278
  field[:fields] = []
269
279
  field[:grupo].each do |f|
@@ -283,7 +293,7 @@ class RaroCrud
283
293
  attribute: nome
284
294
  }.merge({sf: opts})
285
295
  )
286
- end
296
+ end
287
297
 
288
298
  def self.campo_busca nome, opts = nil
289
299
  @@search_fields[self.to_s.to_sym] = [] unless @@search_fields[self.to_s.to_sym]
@@ -292,12 +302,21 @@ class RaroCrud
292
302
  attribute: nome
293
303
  }.merge({sf: opts})
294
304
  )
295
- end
296
-
305
+ end
306
+
307
+ def self.campo_listagem nome, opts = nil
308
+ @@listing_fields[self.to_s.to_sym] = [] unless @@listing_fields[self.to_s.to_sym]
309
+ @@listing_fields[self.to_s.to_sym].push(
310
+ {
311
+ attribute: nome
312
+ }.merge({sf: opts})
313
+ )
314
+ end
315
+
297
316
  def self.sem_visualizacao
298
317
  @@view_action[self.to_s.to_sym] = false
299
318
  end
300
-
319
+
301
320
  def self.visualizacao(condicao)
302
321
  @@condition_view_action[self.to_s.to_sym] = condicao
303
322
  end
@@ -305,7 +324,7 @@ class RaroCrud
305
324
  def self.sem_edicao
306
325
  @@edit_action[self.to_s.to_sym] = false
307
326
  end
308
-
327
+
309
328
  def self.edicao(condicao)
310
329
  @@condition_edit_action[self.to_s.to_sym] = condicao
311
330
  end
@@ -313,30 +332,34 @@ class RaroCrud
313
332
  def self.sem_exclusao
314
333
  @@destroy_action[self.to_s.to_sym] = false
315
334
  end
316
-
335
+
317
336
  def self.exclusao(condicao)
318
337
  @@condition_destroy_action[self.to_s.to_sym] = condicao
319
338
  end
320
-
339
+
340
+ def self.listagem(condicao)
341
+ @@condition_listing_action[self.to_s.to_sym] = condicao
342
+ end
343
+
321
344
  def self.acoes(method,desc,proc = nil)
322
345
  @@actions[self.to_s.to_sym] = [] unless @@actions[self.to_s.to_sym]
323
346
  @@actions[self.to_s.to_sym].push([method,desc,proc])
324
347
  end
325
-
348
+
326
349
  def self.links(name,options)
327
350
  @@links[self.to_s.to_sym] = [] unless @@links[self.to_s.to_sym]
328
351
  @@links[self.to_s.to_sym].push([name,options])
329
352
  end
330
-
353
+
331
354
  def self.opcoes(link,desc,proc = nil)
332
355
  @@options_link[self.to_s.to_sym] = [] unless @@options_link[self.to_s.to_sym]
333
356
  @@options_link[self.to_s.to_sym].push([link,desc,proc])
334
357
  end
335
-
358
+
336
359
  def self.escopos(scopes)
337
360
  @@scopes[self.to_s.to_sym] = scopes
338
361
  end
339
-
362
+
340
363
  def self.grupo_formulario(attribute,name,fields=nil)
341
364
  if fields.nil?
342
365
  fields = name
@@ -357,7 +380,7 @@ class RaroCrud
357
380
  @@form_group[self.to_s.to_sym][attribute][:fields].push({attribute: value[:attribute],sf: value[:sf]})
358
381
  end
359
382
  end
360
-
383
+
361
384
  def self.adicionar_endereco
362
385
  @@form_fields[self.to_s.to_sym] = [] unless @@form_fields[self.to_s.to_sym]
363
386
  opts = {}
@@ -384,10 +407,10 @@ class RaroCrud
384
407
  @@form_scripts[self.to_s.to_sym] ||= []
385
408
  @@form_scripts[self.to_s.to_sym] << "cidade_estado"
386
409
  end
387
-
410
+
388
411
  def self.script_formulario(script)
389
412
  @@form_scripts[self.to_s.to_sym] ||= []
390
413
  @@form_scripts[self.to_s.to_sym] << script.to_s
391
414
  end
392
415
 
393
- end
416
+ end
@@ -1,9 +1,11 @@
1
1
  <%unless params[:render] == 'modal'%>
2
2
  <% content_for :breadcumb do %>
3
3
  <% if @crud_associacao.present? %>
4
- <li class=""><%= link_to @crud_associacao.title, @crud_associacao.root_path %></li>
4
+ <li class=""><%= link_to @crud_associacao.title, crud_models_path(model: @crud_associacao.root_path) %></li>
5
+ <li class=""><%= link_to @crud_helper.title, @clean_url %></li>
6
+ <% else %>
7
+ <li class=""><%= link_to @crud_helper.title, crud_models_path(model: @crud_helper.root_path) %></li>
5
8
  <% end %>
6
- <li class=""><%= link_to @crud_helper.title, crud_models_path(model: @crud_helper.root_path) %></li>
7
9
  <% end %>
8
10
 
9
11
 
@@ -1,7 +1,8 @@
1
1
  <% if @crud_helper.scopes.present? %>
2
2
  <% if @crud_helper.scopes.class == Array %>
3
3
  <% @crud_helper.scopes.each do |escopo| %>
4
- <%= link_to crud_models_path(model: @model.name.underscore, scope: escopo[0]), id: "#{escopo[0]}", data: {push: true, crumb: 'wielka'} do%>
4
+ <% url = params[:associacao].present? ? crud_associacao_models_path(model: params[:model], id: params[:id], associacao: params[:associacao], scope: escopo[0]) : crud_models_path(model: @model.name.underscore, scope: escopo[0])%>
5
+ <%= link_to url, id: "#{escopo[0]}", data: {push: true, crumb: 'wielka'} do%>
5
6
  <div style="float: left; margin-left: 10px; min-width: 100px; position:relative;">
6
7
  <div class="widget style1 gray-bg" style="padding:15px 0px!important;">
7
8
  <div class="row vertical-align text-center" style="margin:0!important;">
@@ -31,6 +31,25 @@
31
31
  <%=render_link(link,@clean_url)%>
32
32
  <% end %>
33
33
  <%end%>
34
+ <% if params[:associacao] %>
35
+ <% if @crud_helper.listing_fields.present? && should_listing?(@crud_helper, @model_permission) %>
36
+ <%= link_to listing_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], q: params[:q], format: :xls), class: "btn btn-success btn-rounded" do %>
37
+ <i class="fa fa-file-excel-o"></i>
38
+ <% end %>
39
+ <%= link_to listing_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], q: params[:q], format: :pdf), class: "btn btn-success btn-rounded" do %>
40
+ <i class="fa fa-file-pdf-o"></i>
41
+ <% end %>
42
+ <% end %>
43
+ <% else %>
44
+ <% if @crud_helper.listing_fields.present? && should_listing?(@crud_helper, @model) %>
45
+ <%= link_to listing_crud_path(model: @model.name.underscore, q: params[:q], format: :xls), class: "btn btn-success btn-rounded" do %>
46
+ <i class="fa fa-file-excel-o"></i>
47
+ <% end %>
48
+ <%= link_to listing_crud_path(model: @model.name.underscore, q: params[:q], format: :pdf), class: "btn btn-success btn-rounded" do %>
49
+ <i class="fa fa-file-pdf-o"></i>
50
+ <% end %>
51
+ <% end %>
52
+ <% end %>
34
53
  <% if @crud_helper.search_fields.present? %>
35
54
  <button id="button_search_<%=@model.name.underscore%>" class="btn btn-warning btn-rounded" data-toggle="modal" data-target="#modal_search">
36
55
  <i class="fa fa-search"></i>
@@ -0,0 +1,74 @@
1
+ <div class="profile-element">
2
+ <div class="header">
3
+ <h1>Listagem de <%= @crud_helper.title %></h1>
4
+ </div>
5
+ </div>
6
+ <div class="widget-box" id="relatorio">
7
+ <div class="widget-body">
8
+ <div class="widget-main">
9
+ <table class="table table-bordered table-striped" style="border: 1px solid black;">
10
+ <thead>
11
+ <tr>
12
+ <% @crud_helper.listing_fields.each do |att|%>
13
+ <% if !att[:visible_if].nil?%>
14
+ <% if ((att[:visible_if].class == Proc && !att[:visible_if].call(att)) || (att[:visible_if].class != Proc && !att[:visible_if])) %>
15
+ <% next %>
16
+ <% end %>
17
+ <% end %>
18
+ <% if att[:sf].present? && att[:sf][:label].present? %>
19
+ <th><%= att[:sf][:label].to_s.mb_chars.upcase.to_s %></th>
20
+ <% else %>
21
+ <th><%= att[:attribute].to_s.mb_chars.upcase.to_s %></th>
22
+ <% end %>
23
+ <% end %>
24
+ </tr>
25
+ </thead>
26
+ <tbody>
27
+ <% @records.each do |record| %>
28
+ <tr>
29
+ <%@crud_helper.listing_fields.each do |att| %>
30
+ <% if record.send(att[:attribute]).present? or record.send(att[:attribute]).to_s == "false"%>
31
+ <% if @model.columns_hash[att[:attribute].to_s].present? && [:date, :datetime].include?(@model.columns_hash[att[:attribute].to_s].type)%>
32
+ <% if att[:date_format].present?%>
33
+ <td><%= record.send(att[:attribute]).strftime(att[:date_format]) %></td>
34
+ <% else %>
35
+ <td><%= l record.send(att[:attribute]) %></td>
36
+ <% end %>
37
+ <% elsif ((@model.reflect_on_association(att[:attribute]) && @model.reflect_on_association(att[:attribute]).macro != :belongs_to && @model.reflect_on_association(att[:attribute]).macro != :has_one) || record.send(att[:attribute]).class == Array)%>
38
+ <td><%= record.send(att[:attribute]).map{|rec| rec.to_s}.join(",") %></td>
39
+ <% else %>
40
+ <% if record.send(att[:attribute]).to_s == "false" or record.send(att[:attribute]).to_s == "true" %>
41
+ <td><%= record.send(att[:attribute]) ? "Sim" : "Não" %></td>
42
+ <% elsif att[:sf][:label_method].present? %>
43
+ <td><%= record.send(att[:attribute]).send(att[:sf][:label_method]).to_s %></td>
44
+ <% else %>
45
+ <td><%= record.send(att[:attribute]).to_s %></td>
46
+ <% end %>
47
+ <% end %>
48
+ <% else %>
49
+ <td></td>
50
+ <% end %>
51
+ <% end %>
52
+ </tr>
53
+ <% end %>
54
+ </tbody>
55
+ </table>
56
+ </div>
57
+ </div>
58
+ </div>
59
+ <style>
60
+ table, tr, td, th, tbody, thead, tfoot {
61
+ page-break-inside: avoid !important;
62
+ }
63
+ table, th, td {
64
+ border-collapse: collapse;
65
+ border: 1px solid black;
66
+ }
67
+ #relatorio {
68
+ padding-top: 40px;
69
+ clear: both;
70
+ }
71
+ .header {
72
+ float: left;
73
+ }
74
+ </style>
@@ -0,0 +1,52 @@
1
+ <?xml version="1.0"?>
2
+ <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
3
+ xmlns:o="urn:schemas-microsoft-com:office:office"
4
+ xmlns:x="urn:schemas-microsoft-com:office:excel"
5
+ xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
6
+ xmlns:html="http://www.w3.org/TR/REC-html40">
7
+ <Worksheet ss:Name="Listagem de <%= @crud_helper.title %>">
8
+ <Table>
9
+ <Row>
10
+ <% @crud_helper.listing_fields.each do |att|%>
11
+ <% if !att[:visible_if].nil?%>
12
+ <% if ((att[:visible_if].class == Proc && !att[:visible_if].call(att)) || (att[:visible_if].class != Proc && !att[:visible_if])) %>
13
+ <% next %>
14
+ <% end %>
15
+ <% end %>
16
+ <% if att[:sf].present? && att[:sf][:label].present? %>
17
+ <Cell><Data ss:Type="String"><%= att[:sf][:label].to_s.mb_chars.upcase.to_s %></Data></Cell>
18
+ <% else %>
19
+ <Cell><Data ss:Type="String"><%= att[:attribute].to_s.mb_chars.upcase.to_s %></Data></Cell>
20
+ <% end %>
21
+ <% end %>
22
+ </Row>
23
+ <% @records.each do |record| %>
24
+ <Row>
25
+ <%@crud_helper.listing_fields.each do |att| %>
26
+ <% if record.send(att[:attribute]).present? or record.send(att[:attribute]).to_s == "false"%>
27
+ <% if @model.columns_hash[att[:attribute].to_s].present? && [:date, :datetime].include?(@model.columns_hash[att[:attribute].to_s].type)%>
28
+ <% if att[:date_format].present?%>
29
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).strftime(att[:date_format]) %></Data></Cell>
30
+ <% else %>
31
+ <Cell><Data ss:Type="String"><%= l record.send(att[:attribute]) %></Data></Cell>
32
+ <% end %>
33
+ <% elsif ((@model.reflect_on_association(att[:attribute]) && @model.reflect_on_association(att[:attribute]).macro != :belongs_to && @model.reflect_on_association(att[:attribute]).macro != :has_one) || record.send(att[:attribute]).class == Array)%>
34
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).map{|rec| rec.to_s}.join(",") %></Data></Cell>
35
+ <% else %>
36
+ <% if record.send(att[:attribute]).to_s == "false" or record.send(att[:attribute]).to_s == "true" %>
37
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]) ? "Sim" : "Não" %></Data></Cell>
38
+ <% elsif att[:sf][:label_method].present? %>
39
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).send(att[:sf][:label_method]).to_s %></Data></Cell>
40
+ <% else %>
41
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).to_s %></Data></Cell>
42
+ <% end %>
43
+ <% end %>
44
+ <% else %>
45
+ <Cell><Data ss:Type="String"></Data></Cell>
46
+ <% end %>
47
+ <% end %>
48
+ </Row>
49
+ <% end %>
50
+ </Table>
51
+ </Worksheet>
52
+ </Workbook>
@@ -0,0 +1,6 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ Mime::Type.register "application/xls", :xls
6
+ Mime::Type.register "application/pdf", :pdf
@@ -0,0 +1,3 @@
1
+ WickedPdf.config = {
2
+ exe_path: '/usr/local/bin/wkhtmltopdf'
3
+ }
data/config/routes.rb CHANGED
@@ -7,6 +7,7 @@ Rails.application.routes.draw do
7
7
  get '/crud/:model/query' => "crud#query", as: :query_crud
8
8
  get '/crud/:model/autocomplete' => "crud#autocomplete", as: :autocomplete_crud
9
9
  post '/crud/:model/create' => "crud#create", as: :create_crud
10
+ get '/crud/:model/listing' => "crud#listing", as: :listing_crud
10
11
  patch '/crud/:model/:id/create' => "crud#create", as: :update_crud
11
12
  get '/crud/:model/:id/acao/:acao' => "crud#action", as: :action_crud
12
13
  get '/crud/:model/:id' => "crud#show", as: :crud_model
@@ -19,7 +20,8 @@ Rails.application.routes.draw do
19
20
  get '/crud/:model/:id/:associacao/query' => "crud#query", as: :query_crud_associacao
20
21
  get '/crud/:model/:id/:associacao/autocomplete' => "crud#autocomplete", as: :autocomplete_crud_associacao
21
22
  post '/crud/:model/:id/:associacao/create' => "crud#create", as: :create_crud_associacao
23
+ get '/crud/:model/:id/:associacao/listing' => "crud#listing", as: :listing_crud_associacao
22
24
  patch '/crud/:model/:id/:associacao/:associacao_id/create' => "crud#create", as: :update_crud_associacao
23
25
  get '/crud/:model/:id/:associacao/:associacao_id/acao/:acao' => "crud#action", as: :action_crud_associacao
24
26
  get '/crud/:model/:id/:associacao/:associacao_id' => "crud#show", as: :crud_associacao_model
25
- end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module TemplusModels
2
- VERSION = "1.6.4"
2
+ VERSION = "1.6.5"
3
3
  end
metadata CHANGED
@@ -1,132 +1,148 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: templus_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.4
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Sol
8
8
  - Leonardo Herbert
9
+ - Diego Lima
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2016-06-30 00:00:00.000000000 Z
13
+ date: 2017-02-13 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rails
16
17
  requirement: !ruby/object:Gem::Requirement
17
18
  requirements:
18
- - - ">"
19
+ - - "~>"
19
20
  - !ruby/object:Gem::Version
20
- version: 4.1.0
21
+ version: '4.1'
21
22
  type: :runtime
22
23
  prerelease: false
23
24
  version_requirements: !ruby/object:Gem::Requirement
24
25
  requirements:
25
- - - ">"
26
+ - - "~>"
26
27
  - !ruby/object:Gem::Version
27
- version: 4.1.0
28
+ version: '4.1'
28
29
  - !ruby/object:Gem::Dependency
29
30
  name: cancancan
30
31
  requirement: !ruby/object:Gem::Requirement
31
32
  requirements:
32
- - - ">"
33
+ - - "~>"
33
34
  - !ruby/object:Gem::Version
34
35
  version: '1.10'
35
36
  type: :runtime
36
37
  prerelease: false
37
38
  version_requirements: !ruby/object:Gem::Requirement
38
39
  requirements:
39
- - - ">"
40
+ - - "~>"
40
41
  - !ruby/object:Gem::Version
41
42
  version: '1.10'
42
43
  - !ruby/object:Gem::Dependency
43
44
  name: ransack
44
45
  requirement: !ruby/object:Gem::Requirement
45
46
  requirements:
46
- - - ">"
47
+ - - "~>"
47
48
  - !ruby/object:Gem::Version
48
- version: 1.6.3
49
+ version: '1.6'
49
50
  type: :runtime
50
51
  prerelease: false
51
52
  version_requirements: !ruby/object:Gem::Requirement
52
53
  requirements:
53
- - - ">"
54
+ - - "~>"
54
55
  - !ruby/object:Gem::Version
55
- version: 1.6.3
56
+ version: '1.6'
56
57
  - !ruby/object:Gem::Dependency
57
58
  name: kaminari
58
59
  requirement: !ruby/object:Gem::Requirement
59
60
  requirements:
60
- - - ">"
61
+ - - "~>"
61
62
  - !ruby/object:Gem::Version
62
- version: 0.16.2
63
+ version: '0.16'
63
64
  type: :runtime
64
65
  prerelease: false
65
66
  version_requirements: !ruby/object:Gem::Requirement
66
67
  requirements:
67
- - - ">"
68
+ - - "~>"
68
69
  - !ruby/object:Gem::Version
69
- version: 0.16.2
70
+ version: '0.16'
70
71
  - !ruby/object:Gem::Dependency
71
72
  name: simple_form
72
73
  requirement: !ruby/object:Gem::Requirement
73
74
  requirements:
74
- - - ">"
75
+ - - "~>"
75
76
  - !ruby/object:Gem::Version
76
- version: 3.1.0
77
+ version: '3.1'
77
78
  type: :runtime
78
79
  prerelease: false
79
80
  version_requirements: !ruby/object:Gem::Requirement
80
81
  requirements:
81
- - - ">"
82
+ - - "~>"
82
83
  - !ruby/object:Gem::Version
83
- version: 3.1.0
84
+ version: '3.1'
84
85
  - !ruby/object:Gem::Dependency
85
86
  name: nested_form
86
87
  requirement: !ruby/object:Gem::Requirement
87
88
  requirements:
88
- - - ">="
89
+ - - "~>"
89
90
  - !ruby/object:Gem::Version
90
91
  version: '0'
91
92
  type: :runtime
92
93
  prerelease: false
93
94
  version_requirements: !ruby/object:Gem::Requirement
94
95
  requirements:
95
- - - ">="
96
+ - - "~>"
96
97
  - !ruby/object:Gem::Version
97
98
  version: '0'
98
99
  - !ruby/object:Gem::Dependency
99
100
  name: rails-jquery-autocomplete
100
101
  requirement: !ruby/object:Gem::Requirement
101
102
  requirements:
102
- - - ">="
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '1.0'
106
+ type: :runtime
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '1.0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: wicked_pdf
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
103
118
  - !ruby/object:Gem::Version
104
119
  version: '0'
105
120
  type: :runtime
106
121
  prerelease: false
107
122
  version_requirements: !ruby/object:Gem::Requirement
108
123
  requirements:
109
- - - ">="
124
+ - - "~>"
110
125
  - !ruby/object:Gem::Version
111
126
  version: '0'
112
127
  - !ruby/object:Gem::Dependency
113
128
  name: sqlite3
114
129
  requirement: !ruby/object:Gem::Requirement
115
130
  requirements:
116
- - - ">="
131
+ - - "~>"
117
132
  - !ruby/object:Gem::Version
118
133
  version: '0'
119
134
  type: :development
120
135
  prerelease: false
121
136
  version_requirements: !ruby/object:Gem::Requirement
122
137
  requirements:
123
- - - ">="
138
+ - - "~>"
124
139
  - !ruby/object:Gem::Version
125
140
  version: '0'
126
141
  description: Easy CRUD generator for Rails Projects
127
142
  email:
128
143
  - rodrigo@rarolabs.com.br
129
144
  - leonardo@rarolabs.com.br
145
+ - lima@rarolabs.com.br
130
146
  executables: []
131
147
  extensions: []
132
148
  extra_rdoc_files: []
@@ -158,6 +174,8 @@ files:
158
174
  - app/views/crud/create.js.erb
159
175
  - app/views/crud/edit.html.erb
160
176
  - app/views/crud/index.html.erb
177
+ - app/views/crud/listing.pdf.erb
178
+ - app/views/crud/listing.xls.erb
161
179
  - app/views/crud/mensagens/_avisos.html.erb
162
180
  - app/views/crud/mensagens/_erros_formulario.html.erb
163
181
  - app/views/crud/new.html.erb
@@ -171,8 +189,10 @@ files:
171
189
  - app/views/kaminari/templus/_prev_page.html.erb
172
190
  - app/views/layouts/_menu_crud.html.erb
173
191
  - app/views/layouts/_template_raro_crud.html.erb
192
+ - config/initializers/mime_types.rb
174
193
  - config/initializers/raro_search.rb
175
194
  - config/initializers/simple_form.rb
195
+ - config/initializers/wicked_pdf.rb
176
196
  - config/routes.rb
177
197
  - lib/tasks/templus_models_tasks.rake
178
198
  - lib/templus_models.rb