templus_models 3.0.10 → 3.0.12

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: 3e33084424f911dea9ac45f2cb2bb30f11fadd74
4
- data.tar.gz: 10c67dd7009704c1c30d597760522a1eb3d51446
3
+ metadata.gz: d86a4d7d8f4b7230ca8d19f69e5962beaa00675c
4
+ data.tar.gz: c62f496d5846326d3e8db95bdcaeb71f26afe34d
5
5
  SHA512:
6
- metadata.gz: ea516b56ab9293307131f201cdd3ed655840790a887de435294d9a924b70034f430552d81bdbc5601ec152ec72ae163b0901cb83ca61ab7f99551f261196e9e8
7
- data.tar.gz: bbf80c081f7d45735a93238abe1d4e50735958d3dc50f3372040a93a4a4db0f0a795a37ea472edbf71a4389c9b1d89f9708b1c64a522dcc12414ec199489927f
6
+ metadata.gz: 3ae34b100de5eaaf1bde33742452f26fcc3213e2221d5ab42210177aeaa06d777c15083652b9da2140852c87f6ea266fcf6e4d3b5639a611cb02eb44cfdda0e1
7
+ data.tar.gz: 2109533cc4c8cc866371fd653fe48c2d0147a40f7b80c751d794da87318ac34060e38d43368e1d78c7d642b7c85030b138ba4893e51f9ba2dc4507255ece860f
@@ -17,9 +17,9 @@ class CrudController < ApplicationController
17
17
  end
18
18
  end
19
19
  if respond_to?(:current_usuario)
20
- @records = @q.result.accessible_by(current_ability, :read).page(params[:page]).per(@crud_helper.per_page)
20
+ @records = @q.result(distinct: true).includes(@crud_helper.includes).accessible_by(current_ability, :read).page(params[:page]).per(@crud_helper.per_page)
21
21
  else
22
- @records = @q.result.page(params[:page]).per(@crud_helper.per_page)
22
+ @records = @q.result(distinct: true).includes(@crud_helper.includes).page(params[:page]).per(@crud_helper.per_page)
23
23
  end
24
24
  @titulo = @model.name.pluralize
25
25
  render partial: 'records' if request.respond_to?(:wiselinks_partial?) && request.wiselinks_partial?
@@ -190,6 +190,7 @@ class CrudController < ApplicationController
190
190
  private
191
191
 
192
192
  def setup
193
+ params[:q] = convert_params(params[:q])
193
194
  if params[:associacao]
194
195
  @crud_associacao = Module.const_get("#{params[:model].to_s.singularize}_crud".camelize)
195
196
  if Module.const_get(params[:model].camelize).reflect_on_association(params[:associacao])
@@ -214,7 +215,7 @@ class CrudController < ApplicationController
214
215
  end
215
216
 
216
217
  def params_permitt
217
- params.require(@model.name.underscore.to_sym).permit(fields_model)
218
+ params.require(@model.name.underscore.gsub('/','_').to_sym).permit(fields_model)
218
219
  end
219
220
 
220
221
  def fields_model
@@ -268,7 +269,7 @@ class CrudController < ApplicationController
268
269
  end
269
270
  group
270
271
  end
271
-
272
+
272
273
  def valid_method?(method)
273
274
  list_methods = []
274
275
  @model.ancestors.each do |m|
@@ -277,7 +278,7 @@ class CrudController < ApplicationController
277
278
  end
278
279
  list_methods.flatten.include? method.to_sym
279
280
  end
280
-
281
+
281
282
  def valid_instance_method?(method)
282
283
  list_methods = []
283
284
  @model.ancestors.each do |m|
@@ -286,4 +287,16 @@ class CrudController < ApplicationController
286
287
  end
287
288
  list_methods.flatten.include? method.to_sym
288
289
  end
290
+
291
+ def convert_params(params)
292
+ if params.present? && params.class == String
293
+ hash = {}
294
+ params.split("&").each do |element|
295
+ result = element.split("?")[0].split("=")
296
+ hash[result[0]] = result[1]
297
+ end
298
+ params = ActionController::Parameters.new(hash)
299
+ end
300
+ params
301
+ end
289
302
  end
@@ -234,6 +234,12 @@ module CrudHelper
234
234
  crud_helper.condition_printing_action.call(record)
235
235
  end
236
236
 
237
+ def add_params_page(url, page)
238
+ if page.present? && !url.include?("&")
239
+ url = url.include?("?") ? "#{url}&page=#{page}" : "#{url}?page=#{page}"
240
+ end
241
+ url
242
+ end
237
243
 
238
244
  private
239
245
 
@@ -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 for='vaga_filtro_vaga_attributes_perfil_executor' 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]"
@@ -33,6 +33,7 @@ class RaroCrud
33
33
  @@scopes = {}
34
34
  @@menus = []
35
35
  @@layout = {}
36
+ @@includes = {}
36
37
  @@index_path = nil
37
38
 
38
39
  def modelo
@@ -210,6 +211,10 @@ class RaroCrud
210
211
  @@menus
211
212
  end
212
213
 
214
+ def self.includes
215
+ @@includes[self.to_s.to_sym] || []
216
+ end
217
+
213
218
  def self.campo_visualizacao(nome, opts = {})
214
219
  @@view_fields[self.to_s.to_sym] ||= []
215
220
  opts = set_default_label nome, opts
@@ -409,6 +414,9 @@ class RaroCrud
409
414
  @@form_scripts[self.to_s.to_sym] << script.to_s
410
415
  end
411
416
 
417
+ def self.add_includes(includes)
418
+ @@includes[self.to_s.to_sym] = includes
419
+ end
412
420
 
413
421
  private
414
422
 
@@ -60,7 +60,7 @@
60
60
  <div class="col-sm-4 col-sm-offset-2">
61
61
  <%= f.submit I18n.t("save"), class: 'btn btn-primary' %>
62
62
  <%unless params[:render] == 'modal'%>
63
- <%= link_to I18n.t("undo"), "#{@url}?page=#{params[:page]}", class: 'btn btn-default', data: {push: 'partial', target: "#form"} %>
63
+ <%= link_to I18n.t("undo"), add_params_page(@url, params[:page]), class: 'btn btn-default', data: {push: 'partial', target: "#form"} %>
64
64
  <% end %>
65
65
  </div>
66
66
  </div>
@@ -79,69 +79,71 @@
79
79
  <td class="row"></td>
80
80
  <% end %>
81
81
  <%end%>
82
- <td class="row">
83
- <div class="col-xs-9">
84
- <% @crud_helper.actions.each do |action| %>
85
- <% if ((action[:proc].present? && action[:proc].call(record)) || !action[:proc].present?) %>
86
- <% if action[:options].present? && action[:options][:wiselink].present? && action[:options][:wiselink] %>
87
- <% data = {push: "partial", target: "#form"} %>
82
+ <% if @crud_helper.view_action || @crud_helper.edit_action || @crud_helper.destroy_action || @crud_helper.actions.present? || @crud_helper.actions_links.present? %>
83
+ <td class="row">
84
+ <div class="col-xs-9">
85
+ <% @crud_helper.actions.each do |action| %>
86
+ <% if (action[:proc].present? && action[:proc].call(record)) || !action[:proc].present? %>
87
+ <% if action[:options].present? && action[:options][:wiselink].present? && action[:options][:wiselink] %>
88
+ <% data = {push: "partial", target: "#form"} %>
89
+ <% end %>
90
+ <%= link_to I18n.t(action[:desc]), action_crud_path(model: @model.name.underscore, id: record.id, acao: action[:method]), class: "btn btn-primary btn-xs", data: data || {} %>
88
91
  <% end %>
89
- <%= link_to I18n.t(action[:desc]), action_crud_path(model: @model.name.underscore, id: record.id, acao: action[:method]), class: "btn btn-primary btn-xs", data: data || {} %>
90
92
  <% end %>
91
- <% end %>
92
- <% @crud_helper.actions_links.each do |name, options| %>
93
- <% unless (options[:can].present? && !record.instance_eval(&options[:can])) %>
94
- <% if options[:url].present? %>
95
- <% url = options[:url] %>
96
- <% if options[:id] %>
97
- <% url += options[:url].include?("?") ? "&id=#{record.id}" : "?id=#{record.id}" %>
98
- <% else url.include?(":id") %>
99
- <% url = url.gsub(":id", "#{record.id}") %>
100
- <% end %>
101
- <% if options[:wiselink].present? && options[:wiselink] %>
102
- <a href="<%= url %>" class="btn btn-success btn-xs" data-push="partial" data-target="#form">
103
- <%= I18n.t(name) %>
104
- </a>
105
- <% else %>
106
- <a href="<%= url %>" class="btn btn-success btn-xs">
107
- <%= I18n.t(name) %>
108
- </a>
109
- <% end %>
110
- <% elsif options[:associacao].present? %>
111
- <% if options[:wiselink].present? && options[:wiselink] %>
112
- <%= link_to I18n.t(name), crud_associacao_models_path(model: @model.name.underscore, id: record.id, associacao: options[:associacao].to_s), class: "btn btn-success btn-xs", data: {push: "partial", target: "#form"} %>
113
- <% else %>
114
- <%= link_to I18n.t(name), crud_associacao_models_path(model: @model.name.underscore, id: record.id, associacao: options[:associacao].to_s), class: "btn btn-success btn-xs" %>
93
+ <% @crud_helper.actions_links.each do |name, options| %>
94
+ <% unless (options[:can].present? && !record.instance_eval(&options[:can])) %>
95
+ <% if options[:url].present? %>
96
+ <% url = options[:url] %>
97
+ <% if options[:id] %>
98
+ <% url += options[:url].include?("?") ? "&id=#{record.id}" : "?id=#{record.id}" %>
99
+ <% else url.include?(":id") %>
100
+ <% url = url.gsub(":id", "#{record.id}") %>
101
+ <% end %>
102
+ <% if options[:wiselink].present? && options[:wiselink] %>
103
+ <a href="<%= url %>" class="btn btn-success btn-xs" data-push="partial" data-target="#form">
104
+ <%= I18n.t(name) %>
105
+ </a>
106
+ <% else %>
107
+ <a href="<%= url %>" class="btn btn-success btn-xs">
108
+ <%= I18n.t(name) %>
109
+ </a>
110
+ <% end %>
111
+ <% elsif options[:associacao].present? %>
112
+ <% if options[:wiselink].present? && options[:wiselink] %>
113
+ <%= link_to I18n.t(name), crud_associacao_models_path(model: @model.name.underscore, id: record.id, associacao: options[:associacao].to_s), class: "btn btn-success btn-xs", data: {push: true, crumb: "wielka"} %>
114
+ <% else %>
115
+ <%= link_to I18n.t(name), crud_associacao_models_path(model: @model.name.underscore, id: record.id, associacao: options[:associacao].to_s), class: "btn btn-success btn-xs" %>
116
+ <% end %>
117
+ <% elsif options[:partial].present? %>
118
+ <%= render options[:partial], record: record, action: :index %>
115
119
  <% end %>
116
- <% elsif options[:partial].present? %>
117
- <%= render options[:partial], record: record, action: :index %>
118
120
  <% end %>
119
121
  <% end %>
120
- <% end %>
121
- <% if @crud_helper.view_action && should_view?(@crud_helper, record) %>
122
- <% link_text = TemplusModels.configuration.usar_icones ? "<i class='fa fa-eye'></i>".html_safe : I18n.t("view") %>
123
- <% if @crud_associacao.present? %>
124
- <%= link_to link_text, crud_associacao_model_path(model: params[:model], id: params[:id], associacao: params[:associacao], associacao_id: record.id, page: params[:page], q: params[:q]), class: 'btn btn-primary btn-xs', data: {push: 'partial', target: '#form'} %>
125
- <% else %>
126
- <%= link_to link_text, crud_model_path(model: @model.name.underscore, id: record.id, page: params[:page], q: params[:q]), class: 'btn btn-primary btn-xs', data: {push: 'partial', target: '#form'} %>
122
+ <% if @crud_helper.view_action && should_view?(@crud_helper, record) %>
123
+ <% link_text = TemplusModels.configuration.usar_icones ? "<i class='fa fa-eye'></i>".html_safe : I18n.t("view") %>
124
+ <% if @crud_associacao.present? %>
125
+ <%= link_to link_text, crud_associacao_model_path(model: params[:model], id: params[:id], associacao: params[:associacao], associacao_id: record.id, page: params[:page], q: params[:q]), class: 'btn btn-primary btn-xs', data: {push: 'partial', target: '#form'} %>
126
+ <% else %>
127
+ <%= link_to link_text, crud_model_path(model: @model.name.underscore, id: record.id, page: params[:page], q: params[:q]), class: 'btn btn-primary btn-xs', data: {push: 'partial', target: '#form'} %>
128
+ <% end %>
127
129
  <% end %>
128
- <% end %>
129
- <% if @crud_helper.edit_action && should_edit?(@crud_helper, record) %>
130
- <% link_text = TemplusModels.configuration.usar_icones ? "<i class='fa fa-edit'></i>".html_safe : I18n.t("edit") %>
131
- <% if @crud_associacao.present? %>
132
- <%= link_to link_text, edit_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], associacao_id: record.id, page: params[:page], q: params[:q]), class: 'btn btn-primary btn-xs', data: {push: 'partial', target: '#form'} %>
133
- <% else %>
134
- <%= link_to link_text, edit_crud_path(model: @model.name.underscore, id: record.id, page: params[:page], q: params[:q]), class: 'btn btn-primary btn-xs', data: {push: 'partial', target: '#form'} %>
130
+ <% if @crud_helper.edit_action && should_edit?(@crud_helper, record) %>
131
+ <% link_text = TemplusModels.configuration.usar_icones ? "<i class='fa fa-edit'></i>".html_safe : I18n.t("edit") %>
132
+ <% if @crud_associacao.present? %>
133
+ <%= link_to link_text, edit_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], associacao_id: record.id, page: params[:page], q: params[:q]), class: 'btn btn-primary btn-xs', data: {push: 'partial', target: '#form'} %>
134
+ <% else %>
135
+ <%= link_to link_text, edit_crud_path(model: @model.name.underscore, id: record.id, page: params[:page], q: params[:q]), class: 'btn btn-primary btn-xs', data: {push: 'partial', target: '#form'} %>
136
+ <% end %>
135
137
  <% end %>
136
- <% end %>
137
- <% if @crud_helper.destroy_action && should_destroy?(@crud_helper, record) %>
138
- <% link_text = TemplusModels.configuration.usar_icones ? "<i class='fa fa-trash'></i>".html_safe : I18n.t("destroy") %>
139
- <% if @crud_associacao.present? %>
140
- <%= link_to link_text, destroy_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], associacao_id: record.id, page: params[:page], q: params[:q]), class: 'btn btn-danger btn-xs', data: {method: 'delete', confirm: I18n.t('mensagem_confirm_destroy')} %>
141
- <% else %>
142
- <%= link_to link_text, destroy_crud_path(model: @model.name.underscore, id: record.id, page: params[:page], q: params[:q]), class: 'btn btn-danger btn-xs', data: {method: 'delete', confirm: I18n.t('mensagem_confirm_destroy')} %>
138
+ <% if @crud_helper.destroy_action && should_destroy?(@crud_helper, record) %>
139
+ <% link_text = TemplusModels.configuration.usar_icones ? "<i class='fa fa-trash'></i>".html_safe : I18n.t("destroy") %>
140
+ <% if @crud_associacao.present? %>
141
+ <%= link_to link_text, destroy_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], associacao_id: record.id, page: params[:page], q: params[:q]), class: 'btn btn-danger btn-xs', data: {method: 'delete', confirm: I18n.t('mensagem_confirm_destroy')} %>
142
+ <% else %>
143
+ <%= link_to link_text, destroy_crud_path(model: @model.name.underscore, id: record.id, page: params[:page], q: params[:q]), class: 'btn btn-danger btn-xs', data: {method: 'delete', confirm: I18n.t('mensagem_confirm_destroy')} %>
144
+ <% end %>
143
145
  <% end %>
144
- <% end %>
145
- </div>
146
- </td>
146
+ </div>
147
+ </td>
148
+ <% end %>
147
149
  <% end %>
@@ -24,7 +24,7 @@
24
24
  <% end %>
25
25
  </th>
26
26
  <% end %>
27
- <% if @crud_helper.view_action || @crud_helper.edit_action || @crud_helper.destroy_action || @crud_helper.actions.present? %>
27
+ <% if @crud_helper.view_action || @crud_helper.edit_action || @crud_helper.destroy_action || @crud_helper.actions.present? || @crud_helper.actions_links.present? %>
28
28
  <td><%= I18n.t("simple_form.index.options", default: I18n.t("options")) %></td>
29
29
  <% end %>
30
30
  </tr>
@@ -1,3 +1,3 @@
1
1
  module TemplusModels
2
- VERSION = "3.0.10"
2
+ VERSION = "3.0.12"
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.10
4
+ version: 3.0.12
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-26 00:00:00.000000000 Z
13
+ date: 2017-09-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails