templus_models 3.0.7 → 3.0.8

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: 8a7986658883e7bee0507408a87a9941a7c0efee
4
- data.tar.gz: 77d54cfcbf307318b3e2a3b7cfb846abf9350730
3
+ metadata.gz: 81dd9ee79ddc913b0d324a40d8e70df9151c22a5
4
+ data.tar.gz: c6213ab6097d334fd99db91e2441f428c6b644fe
5
5
  SHA512:
6
- metadata.gz: 61b363865c81485b63d11eb0ef0353b302614076a2f28fe7fd84c4bde300f91e60472ce4d40ef8386c8f18578ce4d08c7f9a400085f96cfd94aaf4c8d1d7ae18
7
- data.tar.gz: 9cbfb68fe1561d2040b115158e86065ddbd9244a97b564a3f59d24a02a349f0107acd1b437c68db1b3cf429959c861802ef84a5c888fda73f4349c1be5b6f544
6
+ metadata.gz: 9d82f807bf61673a0bedac2f387a64b4ee45bad043edaa5f41a3521095b4cb3426c9499e323ef0f5e2637255be4e1b5f5a51e442696e12ed6a3ce4a24cb4822a
7
+ data.tar.gz: 8c2c8ca412a8bf279613570396641fb1e3e3e43b98b35387fa44cde5752416164241f9a9079a760be45bd77b9af666f164e1ba789bab2bba04e0cb55396018e1
@@ -0,0 +1,32 @@
1
+ module AttributesHelper
2
+
3
+ def association?(model, attribute)
4
+ !!model.reflect_on_association(attribute)
5
+ end
6
+
7
+ def belongs_to_association?(model, attribute)
8
+ association_type?(model, attribute, :belongs_to)
9
+ end
10
+
11
+ def has_one_association?(model, attribute)
12
+ association_type?(model, attribute, :has_one)
13
+ end
14
+
15
+ def array?(record, attribute)
16
+ attribute_class?(record, attribute, Array)
17
+ end
18
+
19
+ def boolean?(record, attribute)
20
+ ['false', 'true'].include? record.send(attribute).to_s
21
+ end
22
+
23
+ private
24
+
25
+ def association_type?(model, attribute, association_type)
26
+ association?(model, attribute) && model.reflect_on_association(attribute).macro == association_type
27
+ end
28
+
29
+ def attribute_class?(record, attribute, klass)
30
+ record.send(attribute).class == klass
31
+ end
32
+ end
@@ -1,11 +1,11 @@
1
1
  module CrudHelper
2
2
 
3
3
  def is_active_controller(controller_name)
4
- params[:controller] == controller_name ? "active" : nil
4
+ params[:controller] == controller_name ? "active" : nil
5
5
  end
6
6
 
7
7
  def is_active_action(action_name)
8
- params[:action] == action_name ? "active" : nil
8
+ params[:action] == action_name ? "active" : nil
9
9
  end
10
10
 
11
11
  def is_raro_crud(classe)
@@ -174,9 +174,9 @@ module CrudHelper
174
174
  end
175
175
 
176
176
  def render_field_file(field)
177
- if imagem?(field) && field.url(:thumb)
177
+ if imagem?(field) && field.respond_to?(:thumb)
178
178
  if is_active_action("printing")
179
- wicked_pdf_image_tag(field.url(:thumb))
179
+ pdf_image_tag(field)
180
180
  else
181
181
  link_to field.url, target: "_blank" do
182
182
  image_tag(field.url(:thumb))
@@ -233,4 +233,31 @@ module CrudHelper
233
233
  return true if crud_helper.condition_printing_action.nil?
234
234
  crud_helper.condition_printing_action.call(record)
235
235
  end
236
+
237
+
238
+ private
239
+
240
+ def pdf_image_tag(field, options = {})
241
+ if Rails.env.development? || Rails.env.test?
242
+ # Unless running a web server that can process 2 requests at the same
243
+ # time, trying to insert an image in a PDF creates a deadlock: the server
244
+ # can't finish processing the PDF request until it gets the image, but it
245
+ # can't start processing the image request until it has finished
246
+ # processing the PDF request.
247
+ # This will not be a problem in production, but in dev, a workaround is
248
+ # to base64 the image and insert its contents into the HTML
249
+ if field.respond_to?(:thumb)
250
+ image_data = File.read(field.thumb.path)
251
+ else
252
+ image_data = Rails.application.assets[field].to_s
253
+ end
254
+ image_tag("data:image/png;base64,#{::Base64.encode64(image_data)}", options)
255
+ else
256
+ if field.respond_to?(:thumb)
257
+ field = field.thumb.url
258
+ end
259
+ wicked_pdf_image_tag(field, options)
260
+ end
261
+ end
262
+
236
263
  end
@@ -0,0 +1,15 @@
1
+ module ImagensHelper
2
+
3
+ def carrier_wave_uploader?(model, attribute)
4
+ model.new.send(attribute).class.ancestors.include?(CarrierWave::Uploader::Base)
5
+ end
6
+
7
+ def possui_url?(record, attribute)
8
+ record.send(attribute).respond_to?(:url)
9
+ end
10
+
11
+ def deve_renderizar_imagem?(opts)
12
+ opts.has_key?(:render) && !!opts[:render]
13
+ end
14
+
15
+ end
@@ -9,6 +9,8 @@ class RaroCrud
9
9
  @@view_fields = {}
10
10
  @@listing_fields = {}
11
11
  @@printing_fields = {}
12
+ @@logo_printing_field = {}
13
+ @@titulo_printing_field = {}
12
14
  @@search_fields = {}
13
15
  @@test_fields = {}
14
16
  @@top_links = {}
@@ -180,6 +182,14 @@ class RaroCrud
180
182
  @@printing_fields[self.to_s.to_sym] || []
181
183
  end
182
184
 
185
+ def self.logo_printing_field
186
+ @@logo_printing_field[self.to_s.to_sym]
187
+ end
188
+
189
+ def self.titulo_printing_field
190
+ @@titulo_printing_field[self.to_s.to_sym]
191
+ end
192
+
183
193
  def self.search_fields
184
194
  @@search_fields[self.to_s.to_sym] || []
185
195
  end
@@ -238,6 +248,39 @@ class RaroCrud
238
248
  })
239
249
  end
240
250
 
251
+ def self.relatorio_impressao_logo(field_or_url = nil, options = {})
252
+ url = nil
253
+ field = nil
254
+ if field_or_url.blank?
255
+ url = Templus.logo
256
+ elsif field_or_url.is_a?(String)
257
+ url = field_or_url
258
+ else
259
+ field = field_or_url
260
+ end
261
+
262
+ @@logo_printing_field[self.to_s.to_sym] = {
263
+ url: url,
264
+ field: field,
265
+ sf: options
266
+ }
267
+ end
268
+
269
+ def self.relatorio_impressao_titulo(field_or_string = nil)
270
+ field = nil
271
+ titulo = nil
272
+ if field_or_string.is_a?(String)
273
+ titulo = field_or_string
274
+ elsif field_or_string.present?
275
+ field = field_or_string
276
+ end
277
+
278
+ @@titulo_printing_field[self.to_s.to_sym] = {
279
+ field: field,
280
+ titulo: titulo
281
+ }
282
+ end
283
+
241
284
  def self.sem_visualizacao
242
285
  @@view_action[self.to_s.to_sym] = false
243
286
  end
@@ -7,8 +7,8 @@
7
7
  <thead>
8
8
  <tr>
9
9
  <% @crud_helper.index_fields.each do |att| %>
10
- <% if !att[:visible_if].nil?%>
11
- <% if ((att[:visible_if].class == Proc && !att[:visible_if].call(att)) || (att[:visible_if].class != Proc && !att[:visible_if])) %>
10
+ <% if !att[:visible_if].nil? %>
11
+ <% if (att[:visible_if].class == Proc && !att[:visible_if].call(att)) || (att[:visible_if].class != Proc && !att[:visible_if]) %>
12
12
  <% next %>
13
13
  <% end %>
14
14
  <% end %>
@@ -15,13 +15,13 @@
15
15
  <% end %>
16
16
  <%= raro_search_form(@model, 'records','records', url) do %>
17
17
  <% raro_group "#{@crud_helper.title}" %>
18
- <%@crud_helper.search_fields.each do |att| %>
18
+ <% @crud_helper.search_fields.each do |att| %>
19
19
  <% if att[:sf].present? && !att[:sf][:visible_if].nil? %>
20
20
  <% if ((att[:sf][:visible_if].class == Proc && !att[:sf][:visible_if].call(att)) || (att[:sf][:visible_if].class != Proc && !att[:sf][:visible_if])) %>
21
21
  <% next %>
22
22
  <% end %>
23
23
  <% end %>
24
- <%raro_field att[:attribute], att[:sf]%>
24
+ <% raro_field att[:attribute], att[:sf] %>
25
25
  <%end%>
26
26
  <%end%>
27
27
  </div>
@@ -49,7 +49,7 @@
49
49
  <% end %>
50
50
  <% end %>
51
51
  <% if @crud_helper.search_fields.present? %>
52
- <button id="button_search_<%=@model.name.underscore%>" class="btn btn-warning btn-rounded" data-toggle="modal" data-target="#modal_search">
52
+ <button id="button_search_<%= @model.name.underscore %>" class="btn btn-warning btn-rounded" data-toggle="modal" data-target="#modal_search">
53
53
  <i class="fa fa-search"></i>
54
54
  </button>
55
55
  <% end %>
@@ -5,44 +5,44 @@ xmlns:x="urn:schemas-microsoft-com:office:excel"
5
5
  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
6
6
  xmlns:html="http://www.w3.org/TR/REC-html40">
7
7
  <Worksheet ss:Name="<%= @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
- <Cell><Data ss:Type="String"><%= I18n.t(att[:sf][:label]) %></Data></Cell>
17
- <% end %>
18
- </Row>
19
- <% @records.each do |record| %>
20
- <Row>
21
- <% @crud_helper.listing_fields.each do |att| %>
22
- <% if record.send(att[:attribute]).present? or record.send(att[:attribute]).to_s == "false"%>
23
- <% if @model.columns_hash[att[:attribute].to_s].present? && [:date, :datetime].include?(@model.columns_hash[att[:attribute].to_s].type)%>
24
- <% if att[:date_format].present?%>
25
- <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).strftime(att[:date_format]) %></Data></Cell>
26
- <% else %>
27
- <Cell><Data ss:Type="String"><%= l record.send(att[:attribute]) %></Data></Cell>
28
- <% end %>
29
- <% 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)%>
30
- <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).map{|rec| rec.to_s}.join(",") %></Data></Cell>
31
- <% else %>
32
- <% if record.send(att[:attribute]).to_s == "false" or record.send(att[:attribute]).to_s == "true" %>
33
- <Cell><Data ss:Type="String"><%= I18n.t(record.send(att[:attribute]) ? "shared.sim" : "shared.nao") %></Data></Cell>
34
- <% elsif att[:sf][:label_method].present? %>
35
- <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).send(att[:sf][:label_method]).to_s %></Data></Cell>
36
- <% else %>
37
- <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).to_s %></Data></Cell>
38
- <% end %>
39
- <% end %>
40
- <% else %>
41
- <Cell><Data ss:Type="String"></Data></Cell>
42
- <% end %>
43
- <% end %>
44
- </Row>
45
- <% end %>
46
- </Table>
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
+ <Cell><Data ss:Type="String"><%= I18n.t(att[:sf][:label]) %></Data></Cell>
17
+ <% end %>
18
+ </Row>
19
+ <% @records.each do |record| %>
20
+ <Row>
21
+ <% @crud_helper.listing_fields.each do |att| %>
22
+ <% if record.send(att[:attribute]).present? or record.send(att[:attribute]).to_s == "false" %>
23
+ <% if @model.columns_hash[att[:attribute].to_s].present? && [:date, :datetime].include?(@model.columns_hash[att[:attribute].to_s].type)%>
24
+ <% if att[:date_format].present?%>
25
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).strftime(att[:date_format]) %></Data></Cell>
26
+ <% else %>
27
+ <Cell><Data ss:Type="String"><%= l record.send(att[:attribute]) %></Data></Cell>
28
+ <% end %>
29
+ <% elsif array?(record, att[:attribute]) || (association?(@model, att[:attribute]) && !belongs_to_association?(@model, att[:attribute]) && !has_one_association?(@model, att[:attribute])) %>
30
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).map{|rec| rec.to_s}.join(",") %></Data></Cell>
31
+ <% elsif boolean?(record, att[:attribute]) %>
32
+ <Cell><Data ss:Type="String"><%= I18n.t(record.send(att[:attribute]) ? "shared.sim" : "shared.nao") %></Data></Cell>
33
+ <% elsif possui_url?(record, att[:attribute]) %>
34
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).url %></Data></Cell>
35
+ <% elsif att[:sf][:label_method].present? %>
36
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).send(att[:sf][:label_method]).to_s %></Data></Cell>
37
+ <% else %>
38
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).to_s %></Data></Cell>
39
+ <% end %>
40
+ <% else %>
41
+ <Cell><Data ss:Type="String"></Data></Cell>
42
+ <% end %>
43
+ <% end %>
44
+ </Row>
45
+ <% end %>
46
+ </Table>
47
47
  </Worksheet>
48
48
  </Workbook>
@@ -4,47 +4,80 @@
4
4
  <div class="widget-body">
5
5
  <div class="widget-main">
6
6
  <div class="profile-element">
7
- <div class="header">
8
- <h1>
7
+ <div>
8
+ <div class="row">
9
+ <% if @crud_helper.logo_printing_field.present? %>
10
+ <div class="col-xs-3">
11
+ <% if @crud_helper.logo_printing_field[:field].present? %>
12
+ <%= render_field_file(@record.send(@crud_helper.logo_printing_field[:field])) %>
13
+ <% elsif @crud_helper.logo_printing_field[:url].present? %>
14
+ <%= pdf_image_tag(@crud_helper.logo_printing_field[:url], width: '100px') %>
15
+ <% end %>
16
+ </div>
17
+ <% end %>
18
+
19
+ <% if @crud_helper.titulo_printing_field.present? %>
20
+ <div class="col-xs-9">
21
+ <h1>
22
+ <% if @crud_helper.titulo_printing_field[:titulo].present? %>
23
+ <%= t(@crud_helper.titulo_printing_field[:titulo]) %>
24
+ <% elsif @crud_helper.titulo_printing_field[:field].present? %>
25
+ <%= @record.send(@crud_helper.titulo_printing_field[:field]) %>
26
+ <% else %>
27
+ <%= Templus.nome_aplicacao %>
28
+ <% end %>
29
+ </h1>
30
+ </div>
31
+ <% end %>
32
+ </div>
33
+ </div>
34
+ </div>
35
+
36
+ <div style="clear: both;"></div>
37
+
38
+ <div class="row">
39
+ <div class="col-lg-12">
40
+ <h2>
9
41
  <small><%= @crud_helper.title %></small><br />
10
42
  <%= @record.to_s %>
11
- </h1>
43
+ </h2>
12
44
  </div>
13
45
  </div>
46
+
14
47
  <table class="table table-bordered table-striped">
15
48
  <tbody>
16
49
  <% @crud_helper.printing_fields.each do |field| %>
50
+ <% next if field[:sf].present? && !field[:sf][:visible_if].nil? && ((field[:sf][:visible_if].class == Proc && !field[:sf][:visible_if].call(@record)) || (field[:sf][:visible_if].class != Proc && !field[:sf][:visible_if])) %>
17
51
  <tr>
18
- <% if field[:sf].present? && !field[:sf][:visible_if].nil?%>
19
- <% if ((field[:sf][:visible_if].class == Proc && !field[:sf][:visible_if].call(@record)) || (field[:sf][:visible_if].class != Proc && !field[:sf][:visible_if])) %>
20
- <% next %>
21
- <% end %>
22
- <% end %>
23
52
  <% if field[:sf].present? && field[:sf][:label].present? %>
24
53
  <th><%= field[:sf][:label].to_s.mb_chars.upcase.to_s %></th>
25
54
  <% else %>
26
55
  <th><%= I18n.t("simple_form.labels.#{@model.name.underscore}.#{field[:attribute]}") %></th>
27
56
  <% end %>
28
57
 
29
- <% if @model.columns_hash[field[:attribute].to_s].present? && [:date, :datetime].include?(@model.columns_hash[field[:attribute].to_s].type)%>
58
+ <% if @model.columns_hash[field[:attribute].to_s].present? && [:date, :datetime].include?(@model.columns_hash[field[:attribute].to_s].type) %>
30
59
  <% if field[:date_format].present?%>
31
- <td><%= l @record.send(field[:attribute]).strftime(field[:date_format]) if @record.send(field[:attribute]).present?%></td>
60
+ <td><%= l @record.send(field[:attribute]).strftime(field[:date_format]) if @record.send(field[:attribute]).present? %></td>
32
61
  <% else %>
33
- <td><%= l @record.send(field[:attribute]) if @record.send(field[:attribute]).present?%></td>
62
+ <td><%= l @record.send(field[:attribute]) if @record.send(field[:attribute]).present? %></td>
34
63
  <% end %>
35
- <% elsif @model.reflect_on_association(field[:attribute]) && @model.reflect_on_association(field[:attribute]).macro != :belongs_to && @model.reflect_on_association(field[:attribute]).macro != :has_one%>
64
+ <% elsif association?(@model, field[:attribute]) && !belongs_to_association?(@model, field[:attribute]) && !has_one_association?(@model, field[:attribute]) %>
36
65
  <td>
37
66
  <% @record.send(field[:attribute]).each do |rec| %>
38
67
  <li>
39
68
  <% if field[:sf].present? && field[:sf][:label_method].present? %>
40
- <% if rec.send(field[:sf][:label_method]).respond_to?(:url) %>
41
- <%= render_field_file(rec.send(field[:sf][:label_method])) %>
69
+ <% if possui_url?(rec, field[:sf][:label_method]) %>
70
+ <% if deve_renderizar_imagem?(field[:sf]) %>
71
+ <%= render_field_file(rec.send(field[:sf][:label_method])) %>
72
+ <% else %>
73
+ <%= rec.send(field[:sf][:label_method]).url %>
74
+ <% end %>
42
75
  <% else %>
43
76
  <%= rec.send(field[:sf][:label_method]) %>
44
77
  <% end %>
45
78
  <% else %>
46
- <% if rec.to_s.respond_to?(:url) %>
47
- <%= render_field_file(rec.to_s) %>
79
+ <% if possui_url?(rec, :itself) && deve_renderizar_imagem?(field[:sf]) %>
80
+ <%= render_field_file(rec) %>
48
81
  <% else %>
49
82
  <%= rec.to_s %>
50
83
  <% end %>
@@ -52,19 +85,19 @@
52
85
  </li>
53
86
  <% end %>
54
87
  </td>
55
- <% elsif @record.send(field[:attribute]).class == Array %>
88
+ <% elsif array?(@record, field[:attribute]) %>
56
89
  <td>
57
90
  <% @record.send(field[:attribute]).each do |rec| %>
58
- <li>
59
- <%= rec.to_s %>
60
- </li>
91
+ <li><%= rec.to_s %></li>
61
92
  <% end %>
62
93
  </td>
63
- <% elsif @record.send(field[:attribute]).respond_to?(:url) %>
64
- <td>
65
- <%= render_field_file(@record.send(field[:attribute])) %>
66
- </td>
67
- <% elsif ["false","true"].include? @record.send(field[:attribute]).to_s %>
94
+ <% elsif possui_url?(@record, field[:attribute]) %>
95
+ <% if deve_renderizar_imagem?(field[:sf]) %>
96
+ <td><%= render_field_file(@record.send(field[:attribute])) %></td>
97
+ <% else %>
98
+ <td><%= @record.send(field[:attribute]).url %></td>
99
+ <% end %>
100
+ <% elsif boolean?(@record, field[:attribute]) %>
68
101
  <td><%= I18n.t(@record.send(field[:attribute]) ? "shared.sim" : "shared.nao") %></td>
69
102
  <% else %>
70
103
  <td>
@@ -1,3 +1,3 @@
1
1
  module TemplusModels
2
- VERSION = "3.0.7"
2
+ VERSION = "3.0.8"
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: 3.0.7
4
+ version: 3.0.8
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-03-27 00:00:00.000000000 Z
13
+ date: 2017-03-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -153,7 +153,9 @@ files:
153
153
  - app/assets/javascripts/raro_crud.js
154
154
  - app/assets/javascripts/templus_models.js.coffee
155
155
  - app/controllers/crud_controller.rb
156
+ - app/helpers/attributes_helper.rb
156
157
  - app/helpers/crud_helper.rb
158
+ - app/helpers/imagens_helper.rb
157
159
  - app/helpers/mensagens_helper.rb
158
160
  - app/helpers/search_helper.rb
159
161
  - app/raro_crud/raro_crud.rb