templus_models 1.3.4 → 1.3.6
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 +4 -4
- data/app/controllers/crud_controller.rb +7 -2
- data/app/helpers/crud_helper.rb +5 -1
- data/app/views/crud/_record.html.erb +5 -0
- data/app/views/crud/_records.html.erb +5 -0
- data/app/views/crud/_search.html.erb +5 -0
- data/app/views/crud/_show.html.erb +13 -8
- data/lib/templus_models/version.rb +1 -1
- data/test/dummy/app/models/ability.rb +3 -3
- data/test/dummy/app/raro_crud/usuario_crud.rb +3 -3
- data/test/dummy/db/development.sqlite3 +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3fd9b4ef6ae55f12405a64449d066e8db7d9236
|
4
|
+
data.tar.gz: e6f38b2cbdf2aeb53f9b401628d7c0a1f4f84e10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 569fbc02c2feb33f7b4111f4ec172f640be08975f34b7c3c6611fb05bfb0173b0fe02b671ce0f1ae051ae7856c0091c0e969a0503d04949bb572769ea3ec928d
|
7
|
+
data.tar.gz: 7a1956a5c9e3081cab607e12074ffffb2ec053d5afe4c33af50e5bcf64946f5ec894996139033acdb0a2b979039a987a76b7814d43b82e548ff9705599eda5b4
|
@@ -151,11 +151,11 @@ class CrudController < ApplicationController
|
|
151
151
|
@crud_helper.form_fields.each do |field|
|
152
152
|
if @model.reflect_on_association(field[:attribute])
|
153
153
|
if @model.reflect_on_association(field[:attribute]).macro == :belongs_to
|
154
|
-
fields <<
|
154
|
+
fields << @model.reflect_on_association(field[:attribute]).foreign_key
|
155
155
|
else
|
156
156
|
fields << {"#{field[:attribute].to_s.singularize}_ids".to_sym => []}
|
157
157
|
end
|
158
|
-
elsif
|
158
|
+
elsif @model.columns_hash[field[:attribute].to_s]
|
159
159
|
fields << field[:attribute]
|
160
160
|
end
|
161
161
|
end
|
@@ -176,6 +176,11 @@ class CrudController < ApplicationController
|
|
176
176
|
end
|
177
177
|
fields << group
|
178
178
|
end
|
179
|
+
if @model.respond_to?(:params_permitt)
|
180
|
+
@model.params_permitt.each do |field|
|
181
|
+
fields << field
|
182
|
+
end
|
183
|
+
end
|
179
184
|
fields
|
180
185
|
end
|
181
186
|
end
|
data/app/helpers/crud_helper.rb
CHANGED
@@ -118,11 +118,15 @@ module CrudHelper
|
|
118
118
|
if field[:sf].present? && field[:sf][:if].present?
|
119
119
|
return unless field[:sf][:if].call(f.object)
|
120
120
|
end
|
121
|
+
if field[:sf].present? && field[:sf][:date_format].present? && f.object.send(field[:attribute]).present? && Date <= modelo.columns_hash[field[:attribute].to_s].type.to_s.camelcase.constantize
|
122
|
+
field[:sf][:input_html] ||= {}
|
123
|
+
field[:sf][:input_html][:value] = f.object.send(field[:attribute]).strftime(field[:sf][:date_format])
|
124
|
+
end
|
121
125
|
if !field[:sf][:edit].nil? || !field[:sf][:create].nil?
|
122
126
|
if !field[:sf][:edit].nil? && !field[:sf][:edit] && !record.new_record?
|
123
127
|
elsif !field[:sf][:create].nil? && !field[:sf][:create] && record.new_record?
|
124
128
|
else
|
125
|
-
unless modelo.reflect_on_association(field[:attribute])
|
129
|
+
unless modelo.reflect_on_association(field[:attribute])
|
126
130
|
f.input field[:attribute], field[:sf]
|
127
131
|
else
|
128
132
|
f.association field[:attribute], field[:sf]
|
@@ -1,5 +1,10 @@
|
|
1
1
|
<%= content_tag :tr, id: "record-#{record.id}" do %>
|
2
2
|
<%@crud_helper.index_fields.each do |att| %>
|
3
|
+
<% if !att[:visible_if].nil?%>
|
4
|
+
<% if ((att[:visible_if].class == Proc && !att[:visible_if].call(att)) || (att[:visible_if].class != Proc && !att[:visible_if])) %>
|
5
|
+
<% next %>
|
6
|
+
<% end %>
|
7
|
+
<% end %>
|
3
8
|
<% if record.send(att[:attribute]).present? or record.send(att[:attribute]).to_s == "false"%>
|
4
9
|
<% if @model.columns_hash[att[:attribute].to_s].present? && [:date, :datetime].include?(@model.columns_hash[att[:attribute].to_s].type)%>
|
5
10
|
<% if att[:date_format].present?%>
|
@@ -7,6 +7,11 @@
|
|
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])) %>
|
12
|
+
<% next %>
|
13
|
+
<% end %>
|
14
|
+
<% end %>
|
10
15
|
<th>
|
11
16
|
<% if att[:sort_field].present? %>
|
12
17
|
<%= sort_link @q, att[:sort_field], att[:label], {},data: {push: 'partial', target: "#form"}%>
|
@@ -11,6 +11,11 @@
|
|
11
11
|
<%=raro_search_form(@model, 'records','records',"/crud/#{@model.name.underscore}/query") do%>
|
12
12
|
<%raro_group "#{@model.name}"%>
|
13
13
|
<%@crud_helper.search_fields.each do |att| %>
|
14
|
+
<% if att[:sf].present? && !att[:sf][:visible_if].nil?%>
|
15
|
+
<% if ((att[:sf][:visible_if].class == Proc && !att[:sf][:visible_if].call(att)) || (att[:sf][:visible_if].class != Proc && !att[:sf][:visible_if])) %>
|
16
|
+
<% next %>
|
17
|
+
<% end %>
|
18
|
+
<% end %>
|
14
19
|
<%raro_field att[:attribute],att[:sf]%>
|
15
20
|
<%end%>
|
16
21
|
<%end%>
|
@@ -6,6 +6,11 @@
|
|
6
6
|
<tbody>
|
7
7
|
<% @crud_helper.view_fields.each do |field|%>
|
8
8
|
<tr>
|
9
|
+
<% if field[:sf].present? && !field[:sf][:visible_if].nil?%>
|
10
|
+
<% if ((field[:sf][:visible_if].class == Proc && !field[:sf][:visible_if].call(field)) || (field[:sf][:visible_if].class != Proc && !field[:sf][:visible_if])) %>
|
11
|
+
<% next %>
|
12
|
+
<% end %>
|
13
|
+
<% end %>
|
9
14
|
<% if field[:sf].present? && field[:sf][:label].present? %>
|
10
15
|
<th><%= field[:sf][:label].upcase.to_s %></th>
|
11
16
|
<% else %>
|
@@ -22,16 +27,16 @@
|
|
22
27
|
<% @record.send(field[:attribute]).each do |rec| %>
|
23
28
|
<li>
|
24
29
|
<% if field[:sf].present? && field[:sf][:label_method].present? %>
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
+
<% if rec.send(field[:sf][:label_method]).respond_to?(:url) %>
|
31
|
+
<%= render_field_file(rec.send(field[:sf][:label_method])) %>
|
32
|
+
<% else %>
|
33
|
+
<%= rec.send(field[:sf][:label_method]) %>
|
34
|
+
<% end %>
|
30
35
|
<% else %>
|
31
|
-
|
32
|
-
|
36
|
+
<% if rec.to_s.respond_to?(:url) %>
|
37
|
+
<%= render_field_file(rec.to_s) %>
|
33
38
|
<% else %>
|
34
|
-
|
39
|
+
<%= rec.to_s %>
|
35
40
|
<% end %>
|
36
41
|
<% end %>
|
37
42
|
</li>
|
@@ -15,7 +15,7 @@ class Ability
|
|
15
15
|
# can :read, Teste
|
16
16
|
else
|
17
17
|
#Permissão global
|
18
|
-
can :manage, Dashboard
|
18
|
+
# can :manage, Dashboard
|
19
19
|
|
20
20
|
# #Permissão fixa
|
21
21
|
# case usuario.papel.chave
|
@@ -23,8 +23,8 @@ class Ability
|
|
23
23
|
# end
|
24
24
|
|
25
25
|
#Permissão dinamica
|
26
|
-
if usuario.
|
27
|
-
usuario.
|
26
|
+
if usuario.perfil
|
27
|
+
usuario.perfil.permissoes.each do |permissao|
|
28
28
|
# if usuario.reference_id.present? && permissao.klass.constantize.attribute_method?(:reference_id)
|
29
29
|
can permissao.abilities, permissao.klass.constantize, reference_id: usuario.reference_id
|
30
30
|
# else
|
@@ -8,7 +8,7 @@ class UsuarioCrud < RaroCrud
|
|
8
8
|
ordenar_por :nome
|
9
9
|
edicao Proc.new {|obj| !obj.root? }
|
10
10
|
exclusao Proc.new {|obj| !obj.root? }
|
11
|
-
visualizacao Proc.new {|obj| obj.root? }
|
11
|
+
visualizacao Proc.new {|obj| !obj.root? }
|
12
12
|
|
13
13
|
campo_tabela :nome, label: "Nome"
|
14
14
|
campo_tabela :email, label: "email"
|
@@ -21,10 +21,10 @@ class UsuarioCrud < RaroCrud
|
|
21
21
|
|
22
22
|
campo_visualizacao :nome, label: "Nome"
|
23
23
|
campo_visualizacao :email, label: "email"
|
24
|
-
campo_visualizacao :perfil, label: "Papel"
|
24
|
+
campo_visualizacao :perfil, label: "Papel", visible_if: Proc.new {Usuario.current.root? }
|
25
25
|
|
26
26
|
campo_busca :nome, label: "Nome"
|
27
27
|
campo_busca :email, label: "email"
|
28
|
-
campo_busca :papel_id, label: "Papel"
|
28
|
+
campo_busca :papel_id, label: "Papel", visible_if: Proc.new {Usuario.current.root? }
|
29
29
|
|
30
30
|
end
|
Binary file
|
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: 1.3.
|
4
|
+
version: 1.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Sol
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-07-
|
12
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|