templus_models 3.0.20 → 3.0.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/crud_controller.rb +29 -31
- data/app/views/crud/_crud_template.html.erb +5 -6
- data/app/views/crud/_default_actions_crud.html.erb +1 -1
- data/app/views/crud/_form_group.html.erb +2 -2
- data/app/views/crud/_record.html.erb +8 -4
- data/app/views/crud/_records.html.erb +2 -2
- data/lib/templus_models/version.rb +1 -1
- metadata +5 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6697b9a9308a28c268cc9a85e8698082cda535509c00312c9b148e4f4522fa59
|
4
|
+
data.tar.gz: 9011b06b986d0fe546925dcc5384f791cd9040c556eccd0e3ee23d406646c659
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42430133a2689bf4f63e84c2c591fee5d0c9234ff5f307640e40f8e5b9f4443b3929418f517f052c291d96993123f790dd53f14ff43ef7266000f11ae003fc01
|
7
|
+
data.tar.gz: 224b86a8479102ad1dd9da7bb8985ea582de93ded79d7cbadeb2b62bd2569176cf65a35d8e7873c4cbe11dadc62dc919f83829a9ef227835c8851419f8241a46
|
@@ -1,7 +1,6 @@
|
|
1
1
|
class CrudController < ApplicationController
|
2
2
|
before_action :setup, except: :autocomplete
|
3
3
|
|
4
|
-
|
5
4
|
def index
|
6
5
|
authorize! :read, @model_permission if respond_to?(:current_usuario)
|
7
6
|
if params[:scope].present? && valid_method?(params[:scope])
|
@@ -10,23 +9,22 @@ class CrudController < ApplicationController
|
|
10
9
|
@q = @model.ransack(params[:q])
|
11
10
|
end
|
12
11
|
if @q.sorts.empty?
|
13
|
-
if @crud_helper.order_field.to_s.include?(
|
12
|
+
if @crud_helper.order_field.to_s.include?('desc') || @crud_helper.order_field.to_s.include?('asc')
|
14
13
|
@q.sorts = @crud_helper.order_field.to_s
|
15
14
|
else
|
16
15
|
@q.sorts = "#{@crud_helper.order_field} asc"
|
17
16
|
end
|
18
17
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
18
|
+
@records = @q.result(distinct: true)
|
19
|
+
@records = @records.includes(@crud_helper.includes).references(@crud_helper.includes) if @crud_helper.includes.present?
|
20
|
+
@records = @records.accessible_by(current_ability, :read) if respond_to?(:current_usuario)
|
21
|
+
@records = @records.page(params[:page]).per(@crud_helper.per_page)
|
24
22
|
@titulo = @model.name.pluralize
|
25
23
|
render partial: 'records' if request.respond_to?(:wiselinks_partial?) && request.wiselinks_partial?
|
26
24
|
end
|
27
25
|
|
28
26
|
def new
|
29
|
-
if params[:render] ==
|
27
|
+
if params[:render] == 'modal'
|
30
28
|
if @model.reflect_on_association(params[:attribute].to_s).present?
|
31
29
|
@model = @model.reflect_on_association(params[:attribute].to_s).class_name.constantize
|
32
30
|
else
|
@@ -56,9 +54,9 @@ class CrudController < ApplicationController
|
|
56
54
|
authorize! :create_or_update, @record if respond_to?(:current_usuario)
|
57
55
|
if valid_instance_method?(params[:acao])
|
58
56
|
if @record.send(params[:acao])
|
59
|
-
flash.now[:success] = I18n.t(
|
57
|
+
flash.now[:success] = I18n.t('mensagem_action', acao: params[:acao])
|
60
58
|
else
|
61
|
-
flash.now[:error] = I18n.t(
|
59
|
+
flash.now[:error] = I18n.t('mensagem_erro_action', acao: params[:acao])
|
62
60
|
end
|
63
61
|
redirect_to @url
|
64
62
|
else
|
@@ -75,22 +73,22 @@ class CrudController < ApplicationController
|
|
75
73
|
authorize! :update, @record if respond_to?(:current_usuario)
|
76
74
|
@saved = @record.update(params_permitt)
|
77
75
|
else
|
78
|
-
@record
|
76
|
+
@record = @model.new(params_permitt)
|
79
77
|
authorize! :create, @model_permission if respond_to?(:current_usuario)
|
80
78
|
@saved = @record.save
|
81
79
|
end
|
82
80
|
|
83
81
|
respond_to do |format|
|
84
82
|
if @saved
|
85
|
-
flash[:success] = params[:id].present? ? I18n.t(
|
83
|
+
flash[:success] = params[:id].present? ? I18n.t('updated', model: I18n.t("model.#{@model.name.underscore}")) : I18n.t("created", model: I18n.t("model.#{@model.name.underscore}"))
|
86
84
|
format.html { redirect_to @url }
|
87
85
|
unless params[:render] == 'modal'
|
88
|
-
format.js { render action: :index}
|
86
|
+
format.js { render action: :index }
|
89
87
|
else
|
90
88
|
format.js
|
91
89
|
end
|
92
90
|
else
|
93
|
-
action =
|
91
|
+
action = params[:id] ? :edit : :new
|
94
92
|
format.html { render action: action }
|
95
93
|
format.js
|
96
94
|
end
|
@@ -102,13 +100,13 @@ class CrudController < ApplicationController
|
|
102
100
|
authorize! :destroy, @record if respond_to?(:current_usuario)
|
103
101
|
if @record.destroy
|
104
102
|
respond_to do |format|
|
105
|
-
flash[:success] = I18n.t(
|
103
|
+
flash[:success] = I18n.t('destroyed', model: I18n.t("model.#{@model.name.underscore}"))
|
106
104
|
format.html { redirect_to @url }
|
107
105
|
format.js { render action: :index }
|
108
106
|
end
|
109
107
|
else
|
110
108
|
respond_to do |format|
|
111
|
-
flash[:error] = @record.errors.full_messages.join(
|
109
|
+
flash[:error] = @record.errors.full_messages.join(', ')
|
112
110
|
format.html { redirect_to @url }
|
113
111
|
format.js { render action: :index }
|
114
112
|
end
|
@@ -131,7 +129,7 @@ class CrudController < ApplicationController
|
|
131
129
|
end
|
132
130
|
instance_variable_set("@#{params[:var]}", results)
|
133
131
|
if request.respond_to?(:wiselinks_partial?) && request.wiselinks_partial?
|
134
|
-
render :
|
132
|
+
render partial: params[:partial]
|
135
133
|
else
|
136
134
|
render :index, controller: request[:controller]
|
137
135
|
end
|
@@ -152,9 +150,9 @@ class CrudController < ApplicationController
|
|
152
150
|
if valid_instance_method?(params[:label])
|
153
151
|
method_label = params[:label]
|
154
152
|
else
|
155
|
-
raise
|
153
|
+
raise 'Ação inválida'
|
156
154
|
end
|
157
|
-
render json: results.map {|result| {id: result.id, label: result.send(method_label), value: result.send(method_label)} }
|
155
|
+
render json: results.map { |result| { id: result.id, label: result.send(method_label), value: result.send(method_label) } }
|
158
156
|
end
|
159
157
|
|
160
158
|
def listing
|
@@ -165,7 +163,7 @@ class CrudController < ApplicationController
|
|
165
163
|
@q = @model.ransack(params[:q])
|
166
164
|
end
|
167
165
|
if @q.sorts.empty?
|
168
|
-
if @crud_helper.order_field.to_s.include?(
|
166
|
+
if @crud_helper.order_field.to_s.include?('desc') || @crud_helper.order_field.to_s.include?('asc')
|
169
167
|
@q.sorts = @crud_helper.order_field.to_s
|
170
168
|
else
|
171
169
|
@q.sorts = "#{@crud_helper.order_field} asc"
|
@@ -178,7 +176,7 @@ class CrudController < ApplicationController
|
|
178
176
|
end
|
179
177
|
report_name = "#{@crud_helper.title}_#{DateTime.now.strftime('%Y%m%d')}"
|
180
178
|
respond_to do |format|
|
181
|
-
format.xls { headers[
|
179
|
+
format.xls { headers['Content-Disposition'] = "attachment; filename=#{report_name}.xls" }
|
182
180
|
format.pdf do
|
183
181
|
pdf = WickedPdf.new.pdf_from_string(
|
184
182
|
render_to_string('crud/listing.pdf.erb'),
|
@@ -187,7 +185,7 @@ class CrudController < ApplicationController
|
|
187
185
|
show_as_html: params[:debug],
|
188
186
|
margin: { top: 20, bottom: 20 }
|
189
187
|
)
|
190
|
-
send_data(pdf, filename: "#{report_name}.pdf", type:
|
188
|
+
send_data(pdf, filename: "#{report_name}.pdf", type: 'application/pdf', disposition: 'inline')
|
191
189
|
end
|
192
190
|
end
|
193
191
|
end
|
@@ -205,7 +203,7 @@ class CrudController < ApplicationController
|
|
205
203
|
show_as_html: params[:debug],
|
206
204
|
margin: { top: 20, bottom: 20 }
|
207
205
|
)
|
208
|
-
send_data(pdf, filename: "#{report_name}.pdf", type:
|
206
|
+
send_data(pdf, filename: "#{report_name}.pdf", type: 'application/pdf', disposition: 'inline')
|
209
207
|
end
|
210
208
|
format.html
|
211
209
|
end
|
@@ -219,7 +217,7 @@ class CrudController < ApplicationController
|
|
219
217
|
if Module.const_get(params[:model].camelize).reflect_on_association(params[:associacao])
|
220
218
|
@model = Module.const_get(params[:model].camelize).find(params[:id]).send(params[:associacao])
|
221
219
|
else
|
222
|
-
raise
|
220
|
+
raise 'Ação inválida'
|
223
221
|
end
|
224
222
|
c_helper = Module.const_get(params[:model].camelize).reflect_on_association(params[:associacao]).class_name
|
225
223
|
@crud_helper = Module.const_get("#{c_helper}Crud") unless params[:render] == "modal" and params[:action] == "new"
|
@@ -238,7 +236,7 @@ class CrudController < ApplicationController
|
|
238
236
|
end
|
239
237
|
|
240
238
|
def params_permitt
|
241
|
-
params.require(@model.name.underscore.gsub('/','_').to_sym).permit(fields_model)
|
239
|
+
params.require(@model.name.underscore.gsub('/', '_').to_sym).permit(fields_model)
|
242
240
|
end
|
243
241
|
|
244
242
|
def fields_model
|
@@ -273,7 +271,7 @@ class CrudController < ApplicationController
|
|
273
271
|
|
274
272
|
def permitt_group(fields, key, groups,mod)
|
275
273
|
chave = "#{key}_attributes"
|
276
|
-
group = {chave => [:id, :_destroy]}
|
274
|
+
group = { chave => [:id, :_destroy] }
|
277
275
|
groups.each do |field|
|
278
276
|
if field[:sf].present? && field[:sf][:grupo].present?
|
279
277
|
group[chave] << permitt_group(fields, field[:attribute], field[:sf][:fields], mod.reflect_on_association(key.to_s).class_name.constantize)
|
@@ -283,7 +281,7 @@ class CrudController < ApplicationController
|
|
283
281
|
if modelo.reflect_on_association(field[:attribute]).macro == :belongs_to
|
284
282
|
group[chave] << "#{field[:attribute]}_id".to_sym
|
285
283
|
else
|
286
|
-
group[chave] << {"#{field[:attribute].to_s.singularize}_ids".to_sym => []}
|
284
|
+
group[chave] << { "#{field[:attribute].to_s.singularize}_ids".to_sym => [] }
|
287
285
|
end
|
288
286
|
elsif (modelo.columns_hash[field[:attribute].to_s] || (modelo.respond_to?(:params_permitt) && modelo.params_permitt.include?(field[:attribute].to_sym)))
|
289
287
|
group[chave] << field[:attribute]
|
@@ -297,7 +295,7 @@ class CrudController < ApplicationController
|
|
297
295
|
list_methods = []
|
298
296
|
@model.ancestors.each do |m|
|
299
297
|
list_methods << m.methods(false).reject{ |m| /^_/ =~ m.to_s }
|
300
|
-
break if [
|
298
|
+
break if ['ApplicationRecord', 'ActiveRecord::Base'].include? m.try(:superclass).to_s
|
301
299
|
end
|
302
300
|
list_methods.flatten.include? method.to_sym
|
303
301
|
end
|
@@ -306,7 +304,7 @@ class CrudController < ApplicationController
|
|
306
304
|
list_methods = []
|
307
305
|
@model.ancestors.each do |m|
|
308
306
|
list_methods << m.instance_methods(false).reject{ |m| /^_/ =~ m.to_s }
|
309
|
-
break if [
|
307
|
+
break if ['ApplicationRecord', 'ActiveRecord::Base'].include? m.try(:superclass).to_s
|
310
308
|
end
|
311
309
|
list_methods.flatten.include? method.to_sym
|
312
310
|
end
|
@@ -314,8 +312,8 @@ class CrudController < ApplicationController
|
|
314
312
|
def convert_params(params)
|
315
313
|
if params.present? && params.class == String
|
316
314
|
hash = {}
|
317
|
-
params.split(
|
318
|
-
result = element.split(
|
315
|
+
params.split('&').each do |element|
|
316
|
+
result = element.split('?')[0].split('=')
|
319
317
|
hash[result[0]] = result[1]
|
320
318
|
end
|
321
319
|
params = ActionController::Parameters.new(hash)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%unless params[:render] == 'modal'%>
|
1
|
+
<% unless params[:render] == 'modal' %>
|
2
2
|
<% content_for :breadcumb do %>
|
3
3
|
<% if @crud_associacao.present? %>
|
4
4
|
<li class=""><%= link_to @crud_associacao.title, crud_models_path(model: @crud_associacao.root_path) %></li>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<li class=""><%= link_to @crud_helper.title, crud_models_path(model: @crud_helper.root_path) %></li>
|
8
8
|
<% end %>
|
9
9
|
<% end %>
|
10
|
-
|
10
|
+
|
11
11
|
|
12
12
|
<% content_for :header do %>
|
13
13
|
<%=@crud_helper.title%>
|
@@ -19,10 +19,9 @@
|
|
19
19
|
|
20
20
|
<% content_for :modal do %>
|
21
21
|
<% if @crud_helper.search_fields.present? %>
|
22
|
-
<%= render
|
22
|
+
<%= render '/crud/search' %>
|
23
23
|
<% end %>
|
24
24
|
<% end %>
|
25
|
-
|
26
|
-
<%end%>
|
25
|
+
<% end%>
|
27
26
|
|
28
|
-
<%= render
|
27
|
+
<%= render 'layouts/template_raro_crud' %>
|
@@ -1,2 +1,2 @@
|
|
1
1
|
<%= submit_tag(I18n.t("save"), class: "btn btn-primary") %>
|
2
|
-
<%= link_to I18n.t("undo"), crud_models_path(model: @model.name.underscore), class: 'btn btn-default', data: {push: 'partial', target: "#form"} %>
|
2
|
+
<%= link_to I18n.t("undo"), crud_models_path(model: @model.name.underscore), class: 'btn btn-default', data: { push: 'partial', target: "#form" } %>
|
@@ -24,7 +24,7 @@
|
|
24
24
|
<% if [:has_many,:has_and_belongs_to_many].include?(f.object.class.reflect_on_association(key).macro) %>
|
25
25
|
<div class="form-group">
|
26
26
|
<div class="col-sm-10 col-sm-offset-2">
|
27
|
-
<%= g.link_to_remove "
|
27
|
+
<%= g.link_to_remove "#{I18n.t('destroy')} #{I18n.t(groups[:sublabel] || groups[:label])}" %>
|
28
28
|
</div>
|
29
29
|
</div>
|
30
30
|
<% end %>
|
@@ -32,7 +32,7 @@
|
|
32
32
|
<% if [:has_many,:has_and_belongs_to_many].include?(f.object.class.reflect_on_association(key).macro) %>
|
33
33
|
<div class="form-group">
|
34
34
|
<div class="col-sm-12">
|
35
|
-
<%= f.link_to_add "
|
35
|
+
<%= f.link_to_add "#{I18n.t('add')} #{I18n.t(groups[:sublabel] || groups[:label])}", key %>
|
36
36
|
</div>
|
37
37
|
</div>
|
38
38
|
<% end %>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<%= content_tag :tr, id: "record-#{record.id}" do %>
|
2
|
-
|
2
|
+
<% @crud_helper.index_fields.each do |att| %>
|
3
3
|
<% if !att[:visible_if].nil?%>
|
4
4
|
<% if ((att[:visible_if].class == Proc && !att[:visible_if].call(record)) || (att[:visible_if].class != Proc && !att[:visible_if])) %>
|
5
5
|
<% next %>
|
@@ -86,8 +86,12 @@
|
|
86
86
|
<% if (action[:proc].present? && action[:proc].call(record)) || !action[:proc].present? %>
|
87
87
|
<% if action[:options].present? && action[:options][:wiselink].present? && action[:options][:wiselink] %>
|
88
88
|
<% data = {push: "partial", target: "#form"} %>
|
89
|
-
|
90
|
-
|
89
|
+
<% end %>
|
90
|
+
<% if @crud_associacao.present? %>
|
91
|
+
<%= link_to I18n.t(action[:desc]), action_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], associacao_id: record.id, acao: action[:method], page: params[:page], q: params[:q].try(:to_unsafe_h)), class: "btn btn-primary btn-xs", data: data || {} %>
|
92
|
+
<% else %>
|
93
|
+
<%= link_to I18n.t(action[:desc]), action_crud_path(model: @model.name.underscore, id: record.id, acao: action[:method], page: params[:page], q: params[:q].try(:to_unsafe_h)), class: "btn btn-primary btn-xs", data: data || {} %>
|
94
|
+
<% end %>
|
91
95
|
<% end %>
|
92
96
|
<% end %>
|
93
97
|
<% @crud_helper.actions_links.each do |name, options| %>
|
@@ -146,4 +150,4 @@
|
|
146
150
|
</div>
|
147
151
|
</td>
|
148
152
|
<% end %>
|
149
|
-
<% end %>
|
153
|
+
<% end %>
|
@@ -17,10 +17,10 @@
|
|
17
17
|
<% if att[:sort_field] == :false %>
|
18
18
|
<%= I18n.t(att[:label], default: I18n.t("shared.#{att[:attribute]}")) %>
|
19
19
|
<% else %>
|
20
|
-
<%= sort_link @q, att[:sort_field], I18n.t(att[:label], default: I18n.t("shared.#{att[:attribute]}")), {},data: {push: 'partial', target: "#form"}%>
|
20
|
+
<%= sort_link @q, att[:sort_field], I18n.t(att[:label], default: I18n.t("shared.#{att[:attribute]}")), {},data: { push: 'partial', target: "#form" } %>
|
21
21
|
<% end %>
|
22
22
|
<% else %>
|
23
|
-
<%= sort_link @q, att[:attribute], I18n.t(att[:label], default: I18n.t("shared.#{att[:attribute]}")), {},data: {push: 'partial', target: "#form"}%>
|
23
|
+
<%= sort_link @q, att[:attribute], I18n.t(att[:label], default: I18n.t("shared.#{att[:attribute]}")), {},data: { push: 'partial', target: "#form" } %>
|
24
24
|
<% end %>
|
25
25
|
</th>
|
26
26
|
<% 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.
|
4
|
+
version: 3.0.21
|
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: 2019-06
|
13
|
+
date: 2019-11-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -74,14 +74,14 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - "~>"
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
77
|
+
version: 5.0.0
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
82
|
- - "~>"
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
84
|
+
version: 5.0.0
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: nested_form
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,20 +124,6 @@ dependencies:
|
|
124
124
|
- - "~>"
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '1'
|
127
|
-
- !ruby/object:Gem::Dependency
|
128
|
-
name: sqlite3
|
129
|
-
requirement: !ruby/object:Gem::Requirement
|
130
|
-
requirements:
|
131
|
-
- - "~>"
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version: '1.3'
|
134
|
-
type: :development
|
135
|
-
prerelease: false
|
136
|
-
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
requirements:
|
138
|
-
- - "~>"
|
139
|
-
- !ruby/object:Gem::Version
|
140
|
-
version: '1.3'
|
141
127
|
description: Easy CRUD generator for Rails Projects
|
142
128
|
email:
|
143
129
|
- rodrigo@rarolabs.com.br
|
@@ -979,8 +965,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
979
965
|
- !ruby/object:Gem::Version
|
980
966
|
version: '0'
|
981
967
|
requirements: []
|
982
|
-
|
983
|
-
rubygems_version: 2.7.9
|
968
|
+
rubygems_version: 3.0.3
|
984
969
|
signing_key:
|
985
970
|
specification_version: 4
|
986
971
|
summary: Easy CRUD generator for Rails Projects
|