pg_rails 7.0.1 → 7.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -4
  3. data/pg_associable/app/assets/css/pg_associable.scss +99 -0
  4. data/pg_associable/app/assets/js/asociable_controller.js +59 -0
  5. data/pg_associable/app/assets/js/asociable_inline_controller.js +141 -0
  6. data/pg_associable/app/assets/js/modal_controller.js +130 -0
  7. data/pg_associable/app/helpers/pg_associable/form_builder_methods.rb +31 -0
  8. data/pg_associable/app/helpers/pg_associable/helpers.rb +19 -0
  9. data/pg_associable/app/inputs/pg_associable/pg_associable_inline_input.rb +39 -0
  10. data/pg_associable/app/inputs/pg_associable/pg_associable_input.rb +41 -0
  11. data/pg_associable/app/views/pg_associable/_resultados.html.slim +9 -0
  12. data/pg_associable/app/views/pg_associable/_resultados_inline.html.slim +12 -0
  13. data/pg_associable/app/views/pg_engine/base/_pg_associable_modal.html.slim +39 -0
  14. data/pg_associable/index.js +7 -0
  15. data/pg_associable/lib/pg_associable/engine.rb +12 -0
  16. data/pg_associable/lib/pg_associable/simple_form_initializer.rb +34 -0
  17. data/pg_associable/lib/pg_associable.rb +5 -0
  18. data/{lib/tasks/pg_rails_tasks.rake → pg_associable/lib/tasks/pg_associable_tasks.rake} +1 -2
  19. data/pg_engine/app/assets/stylesheets/pg_rails_b5.scss +74 -0
  20. data/pg_engine/app/controllers/pg_engine/base_controller.rb +365 -0
  21. data/pg_engine/app/controllers/pg_engine/devise_controller.rb +9 -0
  22. data/pg_engine/app/controllers/pg_engine/signed_in_controller.rb +7 -0
  23. data/{app/decorators/pg_rails → pg_engine/app/decorators/pg_engine}/base_decorator.rb +21 -23
  24. data/pg_engine/app/helpers/pg_engine/flash_helper.rb +26 -0
  25. data/pg_engine/app/helpers/pg_engine/form_helper.rb +33 -0
  26. data/pg_engine/app/helpers/pg_engine/index_helper.rb +42 -0
  27. data/{app/helpers/pg_rails → pg_engine/app/helpers/pg_engine}/postgres_helper.rb +1 -1
  28. data/{app/helpers/pg_rails → pg_engine/app/helpers/pg_engine}/print_helper.rb +15 -31
  29. data/pg_engine/app/helpers/pg_engine/route_helper.rb +41 -0
  30. data/pg_engine/app/inputs/pg_engine/fecha_input.rb +20 -0
  31. data/{app/lib/pg_rails → pg_engine/app/lib/pg_engine}/filtros_builder.rb +16 -17
  32. data/pg_engine/app/lib/pg_form_builder.rb +22 -0
  33. data/pg_engine/app/models/pg_engine/base_record.rb +63 -0
  34. data/{app/policies/pg_rails → pg_engine/app/policies/pg_engine}/application_policy.rb +2 -2
  35. data/pg_engine/app/views/pg_engine/base/download.xlsx.axlsx +14 -0
  36. data/pg_engine/app/views/pg_engine/base/index.html.slim +51 -0
  37. data/pg_engine/config/locales/es.yml +48 -0
  38. data/pg_engine/config/simple_form/simple_form.rb +178 -0
  39. data/pg_engine/config/simple_form/simple_form_bootstrap.rb +371 -0
  40. data/{lib/pg_rails → pg_engine/lib/pg_engine}/configuracion.rb +3 -1
  41. data/pg_engine/lib/pg_engine/engine.rb +53 -0
  42. data/{lib/pg_rails → pg_engine/lib/pg_engine}/utils/logueador.rb +8 -1
  43. data/pg_engine/lib/pg_engine.rb +35 -0
  44. data/{lib → pg_engine/lib}/tasks/auto_anotar_modelos.rake +1 -1
  45. data/pg_engine/lib/templates/activeadmin/audits.rb +53 -0
  46. data/pg_engine/lib/templates/activeadmin/users.rb +54 -0
  47. data/pg_layout/app/assets/stylesheets/sidebar.scss +106 -0
  48. data/pg_layout/app/javascript/cookies.js +23 -0
  49. data/pg_layout/app/javascript/navbar_controller.js +10 -0
  50. data/pg_layout/app/lib/navbar.rb +61 -0
  51. data/pg_layout/app/views/devise/confirmations/new.html.erb +20 -0
  52. data/pg_layout/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  53. data/pg_layout/app/views/devise/mailer/email_changed.html.erb +7 -0
  54. data/pg_layout/app/views/devise/mailer/password_change.html.erb +3 -0
  55. data/pg_layout/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  56. data/pg_layout/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  57. data/pg_layout/app/views/devise/passwords/edit.html.erb +27 -0
  58. data/pg_layout/app/views/devise/passwords/new.html.erb +18 -0
  59. data/pg_layout/app/views/devise/registrations/edit.html.erb +35 -0
  60. data/pg_layout/app/views/devise/registrations/new.html.erb +25 -0
  61. data/pg_layout/app/views/devise/sessions/new.html.erb +20 -0
  62. data/pg_layout/app/views/devise/shared/_error_messages.html.erb +15 -0
  63. data/pg_layout/app/views/devise/shared/_links.html.erb +25 -0
  64. data/pg_layout/app/views/devise/unlocks/new.html.erb +19 -0
  65. data/pg_layout/app/views/kaminari/_first_page.html.slim +3 -0
  66. data/pg_layout/app/views/kaminari/_gap.html.slim +2 -0
  67. data/pg_layout/app/views/kaminari/_last_page.html.slim +3 -0
  68. data/pg_layout/app/views/kaminari/_next_page.html.slim +3 -0
  69. data/pg_layout/app/views/kaminari/_page.html.slim +6 -0
  70. data/pg_layout/app/views/kaminari/_paginator.html.slim +12 -0
  71. data/pg_layout/app/views/kaminari/_prev_page.html.slim +3 -0
  72. data/pg_layout/app/views/layouts/pg_layout/devise.html.slim +24 -0
  73. data/pg_layout/app/views/layouts/pg_layout/layout.html.slim +30 -0
  74. data/pg_layout/app/views/pg_layout/_flash.html.slim +10 -0
  75. data/pg_layout/app/views/pg_layout/_navbar.html.erb +43 -0
  76. data/pg_layout/app/views/pg_layout/_sidebar.html.erb +42 -0
  77. data/pg_layout/index.js +35 -0
  78. data/pg_layout/lib/pg_layout/engine.rb +7 -0
  79. data/pg_layout/lib/pg_layout.rb +9 -0
  80. data/pg_rails/js/index.js +2 -0
  81. data/pg_rails/lib/pg_rails.rb +7 -0
  82. data/{lib/pg_rails → pg_rails/lib}/version.rb +1 -1
  83. data/pg_rails/scss/pg_rails.scss +3 -0
  84. data/pg_scaffold/lib/generators/pg_active_record/model/model_generator.rb +34 -0
  85. data/pg_scaffold/lib/generators/pg_active_record/model/templates/admin.rb +19 -0
  86. data/pg_scaffold/lib/generators/pg_active_record/model/templates/create_table_migration.rb.tt +46 -0
  87. data/pg_scaffold/lib/generators/pg_active_record/model/templates/migration.rb.tt +48 -0
  88. data/pg_scaffold/lib/generators/pg_active_record/model/templates/model.rb +47 -0
  89. data/pg_scaffold/lib/generators/pg_active_record/model/templates/module.rb +9 -0
  90. data/pg_scaffold/lib/generators/pg_decorator/USAGE +8 -0
  91. data/pg_scaffold/lib/generators/pg_decorator/pg_decorator_generator.rb +31 -0
  92. data/pg_scaffold/lib/generators/pg_decorator/templates/decorator.rb +22 -0
  93. data/pg_scaffold/lib/generators/pg_factory_bot/model/model_generator.rb +95 -0
  94. data/pg_scaffold/lib/generators/pg_factory_bot/model/templates/factories.erb +14 -0
  95. data/pg_scaffold/lib/generators/pg_pundit/USAGE +8 -0
  96. data/pg_scaffold/lib/generators/pg_pundit/pg_pundit_generator.rb +21 -0
  97. data/pg_scaffold/lib/generators/pg_pundit/templates/policy.rb +37 -0
  98. data/pg_scaffold/lib/generators/pg_rails/instalar/USAGE +8 -0
  99. data/pg_scaffold/lib/generators/pg_rails/instalar/instalar_generator.rb +17 -0
  100. data/pg_scaffold/lib/generators/pg_rails/instalar/templates/pg_rails.rb +10 -0
  101. data/pg_scaffold/lib/generators/pg_resource_route/pg_resource_route_generator.rb +27 -0
  102. data/pg_scaffold/lib/generators/pg_rspec/model/model_generator.rb +30 -0
  103. data/pg_scaffold/lib/generators/pg_rspec/model/templates/model_spec.rb +15 -0
  104. data/pg_scaffold/lib/generators/pg_rspec/scaffold/scaffold_generator.rb +43 -0
  105. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/api_controller_spec.rb +167 -0
  106. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +269 -0
  107. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/edit_spec.rb +34 -0
  108. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/index_spec.rb +28 -0
  109. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/new_spec.rb +34 -0
  110. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/routing_spec.rb +50 -0
  111. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/show_spec.rb +26 -0
  112. data/pg_scaffold/lib/generators/pg_scaffold/USAGE +8 -0
  113. data/pg_scaffold/lib/generators/pg_scaffold/pg_scaffold_generator.rb +87 -0
  114. data/pg_scaffold/lib/generators/pg_scaffold/templates/controller.rb +37 -0
  115. data/pg_scaffold/lib/generators/pg_slim/USAGE +8 -0
  116. data/pg_scaffold/lib/generators/pg_slim/pg_slim_generator.rb +31 -0
  117. data/pg_scaffold/lib/generators/pg_slim/templates/_form.html.slim +12 -0
  118. data/pg_scaffold/lib/generators/pg_slim/templates/download.xlsx.axlsx +14 -0
  119. data/pg_scaffold/lib/generators/pg_slim/templates/edit.html.slim +5 -0
  120. data/pg_scaffold/lib/generators/pg_slim/templates/index.html.slim +51 -0
  121. data/pg_scaffold/lib/generators/pg_slim/templates/new.html.slim +5 -0
  122. data/pg_scaffold/lib/generators/pg_slim/templates/partial.html.slim +1 -0
  123. data/pg_scaffold/lib/generators/pg_slim/templates/show.html.slim +38 -0
  124. data/pg_scaffold/lib/pg_scaffold/monkey_patches/mejoras_a_named_base.rb +37 -0
  125. data/pg_scaffold/lib/pg_scaffold/monkey_patches/mejoras_de_atributos.rb +116 -0
  126. data/pg_scaffold/lib/pg_scaffold/railtie.rb +16 -0
  127. data/pg_scaffold/lib/pg_scaffold.rb +4 -0
  128. metadata +134 -48
  129. data/Rakefile +0 -36
  130. data/app/assets/javascripts/pg_rails/asociacion_creable.js +0 -85
  131. data/app/assets/javascripts/pg_rails/best_in_place_datepicker.js +0 -58
  132. data/app/assets/javascripts/pg_rails/librerias.js +0 -13
  133. data/app/assets/javascripts/pg_rails/librerias_b3.js +0 -14
  134. data/app/assets/javascripts/pg_rails/validaciones.js +0 -44
  135. data/app/assets/javascripts/pg_rails.js +0 -318
  136. data/app/assets/stylesheets/pg_rails/librerias.scss +0 -5
  137. data/app/assets/stylesheets/pg_rails/pg_chosen.scss +0 -29
  138. data/app/assets/stylesheets/pg_rails/pg_rails.scss +0 -199
  139. data/app/assets/stylesheets/pg_rails_b3.scss +0 -10
  140. data/app/assets/stylesheets/pg_rails_b4.scss +0 -12
  141. data/app/assets/stylesheets/pg_rails_b5.scss +0 -1
  142. data/app/controllers/pg_rails/application_controller.rb +0 -316
  143. data/app/controllers/pg_rails/editar_en_lugar_controller.rb +0 -24
  144. data/app/helpers/pg_rails/editar_en_lugar_helper.rb +0 -106
  145. data/app/helpers/pg_rails/form_helper.rb +0 -25
  146. data/app/inputs/pg_rails/asociacion_creable_input.rb +0 -72
  147. data/app/inputs/pg_rails/fecha_input.rb +0 -20
  148. data/app/inputs/pg_rails/selects_dependientes_input.rb +0 -9
  149. data/app/lib/pg_form_builder.rb +0 -31
  150. data/app/models/pg_rails/application_record.rb +0 -51
  151. data/app/views/application/_abrir_modal.js.erb +0 -14
  152. data/app/views/application/_actualizar_smart_listing.html.slim +0 -3
  153. data/app/views/application/_cerrar_modal.js.erb +0 -8
  154. data/app/views/application/_modal_ajax_form.js.erb +0 -7
  155. data/config/brakeman.ignore +0 -42
  156. data/config/locales/es.yml +0 -17
  157. data/config/routes.rb +0 -3
  158. data/config/spring.rb +0 -1
  159. data/lib/pg_rails/engine.rb +0 -42
  160. data/lib/pg_rails/simple_form/initializer.rb +0 -583
  161. data/lib/pg_rails.rb +0 -23
  162. /data/{lib/pg_rails → pg_engine/lib/pg_engine}/core_ext.rb +0 -0
@@ -1,316 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PgRails
4
- class ApplicationController < ActionController::Base
5
- include ApplicationHelper
6
- include Pundit::Authorization
7
- # include SmartListing::Helper::ControllerExtensions
8
- # helper SmartListing::Helper
9
- include PrintHelper
10
- include PostgresHelper
11
-
12
- rescue_from PrintHelper::FechaInvalidaError, with: :fecha_invalida
13
- rescue_from Pundit::NotAuthorizedError, with: :not_authorized
14
-
15
- layout :setear_layout
16
-
17
- def self.inherited(klass)
18
- super
19
- # incluyo los helpers de /app/helpers de la main_app
20
- klass.helper :all
21
- end
22
-
23
- helper_method :mobile_device?
24
-
25
- def mobile_device?
26
- request.user_agent =~ /Mobile|webOS/
27
- end
28
-
29
- helper_method :any_filter?
30
-
31
- def any_filter?
32
- params.keys.reject { |a| a.in? ["controller", "action", "page", "page_size", "order_by", "order_direction"] }.any?
33
- end
34
-
35
-
36
- helper_method :current_page_size
37
-
38
- def current_page_size
39
- if params[:page_size].present?
40
- session[:page_size] = params[:page_size]
41
- params[:page_size].to_i
42
- else
43
- default_page_size
44
- end
45
- end
46
-
47
- def default_page_size
48
- session[:page_size].present? ? session[:page_size].to_i : 10
49
- end
50
-
51
-
52
- protected
53
-
54
- def pg_respond_update(object: nil, extra_js: nil)
55
- object ||= instancia_modelo
56
- respond_to do |format|
57
- if (@saved = object.save)
58
- format.html do
59
- redirect_to object.decorate.target_object
60
- end
61
- format.json { render json: object.decorate }
62
- else
63
- format.turbo_stream do
64
- flash.now[:error] = object.errors.full_messages.join(', ')
65
- render turbo_stream: render_turbo_stream_flash_messages
66
- end
67
- format.html { render :edit, status: :unprocessable_entity }
68
- format.json { render json: object.errors, status: :unprocessable_entity }
69
- end
70
- format.js do
71
- render '_cerrar_modal', locals: {
72
- contenido: 'form', extra_js: ['modal_ajax_form', extra_js]
73
- }
74
- end
75
- end
76
- end
77
-
78
- def pg_respond_create(object: nil, extra_js: nil)
79
- object ||= instancia_modelo
80
- respond_to do |format|
81
- if (@saved = object.save)
82
- format.html do
83
- if params[:save_and_next] == 'true'
84
- new_path = url_for(@clase_modelo) + "/new"
85
- redirect_to new_path, notice: "#{@clase_modelo.nombre_singular} creado."
86
- else
87
- redirect_to object.decorate.target_object
88
- end
89
- end
90
- format.json { render json: object.decorate }
91
- else
92
- format.turbo_stream do
93
- flash.now[:error] = object.errors.full_messages.join(', ')
94
- render turbo_stream: render_turbo_stream_flash_messages
95
- end
96
- format.html { render :new, status: :unprocessable_entity }
97
- format.json { render json: object.errors.full_messages, status: :unprocessable_entity }
98
- end
99
- format.js do
100
- render '_cerrar_modal', locals: {
101
- contenido: 'form', extra_js: ['modal_ajax_form', extra_js]
102
- }
103
- end
104
- end
105
- end
106
-
107
- def pg_respond_index(collection)
108
- respond_to do |format|
109
- format.json { render json: collection }
110
- format.js { render_smart_listing }
111
- format.html { render_smart_listing }
112
- format.xlsx do
113
- render xlsx: 'download',
114
- filename: "#{@clase_modelo.nombre_plural.gsub(' ', '-').downcase}" \
115
- "-#{Time.zone.now.strftime("%Y-%m-%d-%H.%M.%S")}.xlsx"
116
- end
117
- end
118
- end
119
-
120
- def pg_respond_show(object = nil)
121
- respond_to do |format|
122
- format.json { render json: object || instancia_modelo }
123
- format.html
124
- end
125
- end
126
-
127
- def pg_respond_destroy(model, redirect_url = nil)
128
- if destroy_model(model)
129
- respond_to do |format|
130
- format.html do
131
- if redirect_url.present?
132
- redirect_to redirect_url, notice: 'Elemento borrado.', status: 303
133
- else
134
- redirect_back(fallback_location: root_path, notice: 'Elemento borrado.', status: 303)
135
- end
136
- end
137
- format.json { head :no_content }
138
- end
139
- else
140
- respond_to do |format|
141
- format.html do
142
- if model.respond_to?(:associated_elements) && model.associated_elements.present?
143
- @model = model
144
- render destroy_error_details_view
145
- else
146
- flash[:error] = @error_message
147
- # if redirect_url.present?
148
- # redirect_to redirect_url
149
- # else
150
- redirect_back(fallback_location: root_path, status: 303)
151
- # end
152
- end
153
- end
154
- format.json { render json: { error: @error_message }, status: :unprocessable_entity }
155
- end
156
- end
157
- end
158
-
159
- # destroy_and_respond DEPRECADO
160
- alias_method :destroy_and_respond, :pg_respond_destroy
161
-
162
- def destroy_error_details_view
163
- 'destroy_error_details'
164
- end
165
-
166
- def destroy_model(model)
167
- @error_message = 'No se pudo eliminar el registro'
168
- begin
169
- destroy_method = model.respond_to?(:discard) ? :discard : :destroy
170
- return true if model.send(destroy_method)
171
-
172
- @error_message = model.errors.full_messages.join(', ')
173
- false
174
- rescue ActiveRecord::InvalidForeignKey => e
175
- # class_name = /from table \"(?<table_name>[\p{L}_]*)\"/.match(e.message)[:table_name].singularize.camelcase
176
- # # pk_id = /from table \"(?<pk_id>[\p{L}_]*)\"/.match(e.message)[:pk_id].singularize.camelcase
177
- # clazz = Object.const_get class_name
178
- # objects = clazz.where(model.class.table_name.singularize => model)
179
- model_name = t("activerecord.models.#{model.class.name.underscore}")
180
- @error_message = "#{model_name} no se pudo borrar porque tiene elementos asociados."
181
- logger.debug e.message
182
- end
183
- false
184
- end
185
-
186
- def render_smart_listing
187
- raise 'implementar en subclase'
188
- end
189
-
190
- def buscar_instancia
191
- if Object.const_defined?('FriendlyId') && @clase_modelo.is_a?(FriendlyId)
192
- @clase_modelo.friendly.find(params[:id])
193
- else
194
- @clase_modelo.find(params[:id])
195
- end
196
- end
197
-
198
- def set_instancia_modelo
199
- if action_name.in? %w[new create]
200
- self.instancia_modelo = @clase_modelo.new(modelo_params)
201
- else
202
- self.instancia_modelo = buscar_instancia
203
-
204
- instancia_modelo.assign_attributes(modelo_params) if action_name.in? %w[update]
205
- end
206
-
207
- instancia_modelo.current_user = send(PgRails.configuracion.current_user_method)
208
-
209
- authorize instancia_modelo
210
-
211
- self.instancia_modelo = instancia_modelo.decorate if action_name.in? %w[show edit new]
212
- end
213
-
214
- def instancia_modelo=(val)
215
- instance_variable_set("@#{nombre_modelo}".to_sym, val)
216
- end
217
-
218
- def instancia_modelo
219
- instance_variable_get("@#{nombre_modelo}".to_sym)
220
- end
221
-
222
- def modelo_params
223
- if action_name == 'new'
224
- params.permit(atributos_permitidos)
225
- else
226
- params.require(nombre_modelo).permit(atributos_permitidos)
227
- end
228
- end
229
-
230
- def nombre_modelo
231
- @clase_modelo.name.underscore
232
- end
233
-
234
- def default_url_options(options = {})
235
- if Rails.env.production?
236
- options.merge(protocol: 'https')
237
- else
238
- options
239
- end
240
- end
241
-
242
- def setear_layout
243
- if params[:sin_layout] == 'true'
244
- false
245
- else
246
- 'application'
247
- end
248
- end
249
-
250
- def clase_modelo
251
- # agarro la variable o intento con el nombre del controller
252
- @clase_modelo ||= self.class.name.singularize.gsub('Controller', '').constantize
253
- end
254
-
255
- def filtros_y_policy(campos)
256
- @filtros = PgRails::FiltrosBuilder.new(
257
- self, clase_modelo, campos
258
- )
259
- scope = policy_scope(clase_modelo)
260
-
261
- @filtros.filtrar(scope)
262
- end
263
-
264
- def do_sort(scope, field, direction)
265
- unless scope.model.column_names.include? field.to_s
266
- return scope
267
- end
268
- scope = scope.order(field => direction)
269
- instance_variable_set(:"@field", field)
270
- instance_variable_set(:"@direction", direction)
271
- scope
272
- rescue ArgumentError => e
273
- Utils::Logueador.warning(e.to_s)
274
- scope
275
- end
276
-
277
- def sort_collection(scope, options = {})
278
- if params[:order_by].present?
279
- field = params[:order_by]
280
- direction = params[:order_direction]
281
- do_sort(scope, field, direction)
282
- elsif options[:default].present?
283
- field = options[:default].first[0]
284
- direction = options[:default].first[1]
285
- do_sort(scope, field, direction)
286
- else
287
- scope
288
- end
289
- end
290
-
291
- def fecha_invalida
292
- respond_to do |format|
293
- format.json do
294
- render json: { error: 'Formato de fecha inválido' }, status: :unprocessable_entity
295
- end
296
- format.js { render inline: 'showToast("error", "Formato de fecha inválido")' }
297
- format.html { go_back('Formato de fecha inválido') }
298
- end
299
- end
300
-
301
- def not_authorized
302
- respond_to do |format|
303
- format.json do
304
- render json: { error: 'Not authorized' }, status: :unprocessable_entity
305
- end
306
- # format.js { render inline: 'showToast("error", "Formato de fecha inválido")' }
307
- format.html { go_back('Not authorized') }
308
- end
309
- end
310
-
311
- def go_back(message)
312
- flash[:error] = message
313
- redirect_back fallback_location: root_path
314
- end
315
- end
316
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PgRails
4
- class EditarEnLugarController < ::ApplicationController
5
- def actualizar
6
- key_modelo = params.keys[1]
7
- modelo = Kernel.const_get(key_modelo)
8
- objeto = modelo.find params[:id]
9
- authorize objeto, :editar_en_lugar?
10
- object_params = request.parameters[key_modelo]
11
- objeto.current_user = current_user
12
- objeto.update(object_params)
13
- respond_with_bip(objeto, param: key_modelo)
14
- rescue Pundit::NotAuthorizedError
15
- objeto.errors.add(:base, 'no autorizado')
16
- respond_with_bip(objeto)
17
- rescue Pundit::Error => e
18
- Rollbar.error(e)
19
- logger.error(e.message)
20
- objeto.errors.add(:base, e.message)
21
- respond_with_bip(objeto)
22
- end
23
- end
24
- end
@@ -1,106 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PgRails
4
- module EditarEnLugarHelper
5
- def editar_en_lugar(objeto, atributo, tipo = :input, url = nil, collection = nil)
6
- url = pg_rails.editar_en_lugar_path(objeto) if url.nil?
7
- if tipo == :checkbox
8
- best_in_place objeto, atributo, url: url, as: tipo, collection: %w[No Si],
9
- param: objeto.model_name.name
10
- elsif tipo == :date
11
- best_in_place objeto, atributo, url: url, as: tipo, display_with: lambda { |v|
12
- dmy(v)
13
- }, param: objeto.model_name.name
14
- # best_in_place objeto, atributo, url: editar_en_lugarurl(objeto), as: tipo, display_with: lambda { |v| dmy(v) }, class: 'datefield'
15
- elsif tipo == :textarea
16
- funcion = lambda do |valor|
17
- return unless valor.present?
18
-
19
- valor.gsub!("\r\n", '<br>')
20
- valor.gsub!("\n", '<br>')
21
- valor.html_safe
22
- end
23
- best_in_place objeto, atributo, url: url, as: tipo, display_with: funcion,
24
- param: objeto.model_name.name
25
- elsif tipo == :select && collection.present?
26
- best_in_place objeto, atributo, url: url, as: tipo, collection: collection,
27
- param: objeto.model_name.name, value: objeto.send(atributo), inner_class: 'form-control'
28
- else
29
- best_in_place objeto, atributo, url: url, as: tipo, param: objeto.model_name.name
30
- end
31
- end
32
-
33
- # Versión mejorada de editar_en_lugar, pero le pongo v2 por retrocompatibilidad
34
- # La diferencia es que recibe un hash "options" y se le pueden agregar cualquiera de las options
35
- # que admite best_in_place
36
- def editar_en_lugar_v2(objeto, atributo, tipo = :input, options = {})
37
- options[:url] = pg_rails.editar_en_lugar_path(objeto) if options[:url].nil?
38
- options[:as] = tipo
39
- options[:param] = objeto.model_name.name
40
- options[:inner_class] = 'form-control' if options[:inner_class].nil?
41
- options[:class] = 'editar_en_lugar_v2'
42
- options[:html_attrs] = { autocomplete: :off }
43
- # url = pg_rails.editar_en_lugar_path(objeto) if url.nil?
44
- if tipo == :checkbox
45
- options[:collection] = %w[No Si]
46
-
47
- elsif tipo == :date
48
- options[:display_with] = ->(v) { dmy(v) } if options[:display_with].nil?
49
-
50
- elsif tipo == :textarea
51
- funcion = lambda do |valor|
52
- return unless valor.present?
53
-
54
- valor.gsub!("\r\n", '<br>')
55
- valor.gsub!("\n", '<br>')
56
- valor.html_safe
57
- end
58
- options[:display_with] = funcion if options[:display_with].nil?
59
-
60
- elsif tipo == :select && options[:collection].present?
61
- options[:value] = objeto.send(atributo)
62
- end
63
-
64
- best_in_place objeto, atributo, options
65
- end
66
-
67
- # TODO: mover a otro helper
68
- def encabezado(campo, options = {})
69
- clase = (options[:clase] || @clase_modelo)
70
- if options[:ordenable]
71
- field = controller.instance_variable_get(:"@field")
72
- direction = controller.instance_variable_get(:"@direction")
73
- uri = URI.parse(request.url)
74
- if uri.query.present?
75
- cgi = CGI.parse(uri.query)
76
- else
77
- cgi = {}
78
- end
79
- cgi["order_by"] = campo
80
- cgi["order_direction"] =
81
- if field.to_s == campo.to_s && direction.to_s == 'asc'
82
- 'desc'
83
- else
84
- 'asc'
85
- end
86
-
87
- if field.to_s == campo.to_s
88
- symbol =
89
- if direction.to_s == 'asc'
90
- '<i class="bi bi-sort-down-alt" />'
91
- elsif direction.to_s == 'desc'
92
- '<i class="bi bi-sort-up" />'
93
- end
94
- else
95
- symbol = ''
96
- end
97
-
98
- uri.query = cgi.map {|a,b| [a, (b.length == 1 ? b.first : b)]}.to_h.to_query
99
-
100
- link_to(clase.human_attribute_name(campo), uri.to_s) + " #{symbol}".html_safe
101
- else
102
- clase.human_attribute_name(campo)
103
- end
104
- end
105
- end
106
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PgRails
4
- module FormHelper
5
- def pg_form_for(object, *args, &block)
6
- options = args.extract_options!
7
-
8
- options[:builder] = PgFormBuilder
9
- options[:html] ||= {}
10
- options[:html][:class] = if options[:html].key?(:class)
11
- ['pg-form', options[:html][:class]].compact
12
- else
13
- 'pg-form'
14
- end
15
-
16
- simple_form_for(object, *(args << options), &block)
17
- end
18
-
19
- def url_change_format(url)
20
- uri = URI.parse(url)
21
- uri.path = "#{uri.path}.xlsx"
22
- uri.to_s
23
- end
24
- end
25
- end
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PgRails
4
- class AsociacionCreableInput < SimpleForm::Inputs::StringInput
5
- include ActionView::Helpers::FormTagHelper
6
-
7
- def boton(wrapper_options = {})
8
- if PgRails.config.bootstrap_version >= 4
9
- button_tag('', wrapper_options)
10
- else
11
- button_tag('<span class="caret">'.html_safe, wrapper_options)
12
- end
13
- end
14
-
15
- def hidden_input(wrapper_options = {})
16
- merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
17
- merged_input_options = merge_wrapper_options(merged_input_options, { class: 'oculto' })
18
- @builder.text_field(attribute_name, merged_input_options)
19
- end
20
-
21
- def input(wrapper_options = nil)
22
- unless string?
23
- input_html_classes.unshift('string')
24
- input_html_options[:type] ||= input_type if html5?
25
- end
26
-
27
- merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
28
- merged_input_options = merge_wrapper_options(merged_input_options, { class: 'keep-disabled' })
29
-
30
- text_field_tag(nil, object.send(reflection.name).to_s, merged_input_options)
31
- end
32
-
33
- def seleccionar_asociado(wrapper_options = {})
34
- icon = content_tag :span, nil, class: 'fa fa-hand-pointer'
35
- merged_input_options = merge_wrapper_options(wrapper_options,
36
- { class: 'seleccionar_asociado dropdown-item', href: 'javascript:void(0)',
37
- data: { url: options[:url_seleccionar] } })
38
- anchor = content_tag :a, "#{icon} Seleccionar".html_safe, merged_input_options
39
- if PgRails.config.bootstrap_version >= 4
40
- anchor
41
- else
42
- "<li>#{anchor}</li>".html_safe
43
- end
44
- end
45
-
46
- def crear_asociado(wrapper_options = {})
47
- icon = content_tag :span, nil, class: 'fa fa-plus-square'
48
- merged_input_options = merge_wrapper_options(wrapper_options,
49
- { class: 'crear_asociado dropdown-item', href: 'javascript:void(0)',
50
- data: { url: options[:url_crear] } })
51
- anchor = content_tag :a, "#{icon} Crear".html_safe, merged_input_options
52
- if PgRails.config.bootstrap_version >= 4
53
- anchor
54
- else
55
- "<li>#{anchor}</li>".html_safe
56
- end
57
- end
58
-
59
- def borrar_seleccion(wrapper_options = {})
60
- icon = content_tag :span, nil, class: 'fa fa-trash'
61
- merged_input_options = merge_wrapper_options(wrapper_options,
62
- { class: 'borrar_seleccion dropdown-item',
63
- href: 'javascript:void(0)' })
64
- anchor = content_tag :a, "#{icon} Borrar selección".html_safe, merged_input_options
65
- if PgRails.config.bootstrap_version >= 4
66
- anchor
67
- else
68
- "<li>#{anchor}</li>".html_safe
69
- end
70
- end
71
- end
72
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PgRails
4
- class FechaInput < SimpleForm::Inputs::StringInput
5
- def input(wrapper_options = nil)
6
- # esto es porque si no Rails llama a value_before_type_cast
7
- if object.is_a? Draper::Decorator
8
- # Salteo el decorator para que me tome la fecha con formato inglés
9
- value = object.object.public_send(attribute_name)
10
- else
11
- value = object.public_send(attribute_name)
12
- end
13
- @input_type = 'date'
14
-
15
- options = merge_wrapper_options({ value: value, class: '', autocomplete: 'off' },
16
- wrapper_options)
17
- super(options)
18
- end
19
- end
20
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PgRails
4
- class SelectsDependientesInput < SimpleForm::Inputs::CollectionSelectInput
5
- include ActionView::Helpers::FormOptionsHelper
6
-
7
- # TODO
8
- end
9
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # TODO: fix hackeo
4
- # class PgFormBuilder < NestedForm::SimpleBuilder
5
- class PgFormBuilder < SimpleForm::FormBuilder
6
- def mensajes_de_error
7
- return unless object.errors.present?
8
-
9
- errors = object.errors.full_messages.map { |m| "<li>#{m}</li>" }.join
10
- "<div class='alert alert-danger'>#{errors}</div>".html_safe
11
- end
12
-
13
- map_type :date, to: PgRails::FechaInput
14
- # map_type :datetime, to: PgRails::FechaInput
15
-
16
- def asociacion_creable(atributo, url_seleccionar, url_crear, options = {})
17
- options[:as] = 'pg_rails/asociacion_creable'
18
- options[:wrapper] = :asociacion_creable
19
- options[:url_seleccionar] = url_seleccionar
20
- options[:url_crear] = url_crear
21
- options[:wrapper_html] = { class: 'completado' } if object.send(atributo).present?
22
- association atributo, options
23
- end
24
-
25
- def submit_button(*args, &block)
26
- options = args.extract_options!.dup
27
- options[:class] = ['btn-primary', options[:class]].compact
28
- args << options
29
- send(:submit, *args, &block)
30
- end
31
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PgRails
4
- class ApplicationRecord < ActiveRecord::Base
5
- extend Enumerize
6
- include PrintHelper
7
- include PostgresHelper
8
-
9
- self.abstract_class = true
10
-
11
- attr_accessor :current_user
12
-
13
- before_create :setear_creado_y_actualizado_por
14
- before_update :setear_actualizado_por
15
-
16
- def self.nombre_plural
17
- model_name.human(count: 2)
18
- end
19
-
20
- def self.nombre_singular
21
- model_name.human(count: 1)
22
- end
23
-
24
- def to_s
25
- %i[nombre name].each do |campo|
26
- return send(campo) if try(campo).present?
27
- end
28
- if id.present?
29
- "#{self.class.nombre_singular} ##{id}"
30
- else
31
- super
32
- end
33
- end
34
-
35
- private
36
-
37
- def setear_creado_y_actualizado_por
38
- setear_si_existe :creado_por, current_user
39
- setear_si_existe :actualizado_por, current_user
40
- end
41
-
42
- def setear_actualizado_por
43
- setear_si_existe :actualizado_por, current_user
44
- end
45
-
46
- def setear_si_existe(campo, valor)
47
- metodo = "#{campo}="
48
- send(metodo, valor) if respond_to?(metodo) && valor.present?
49
- end
50
- end
51
- end
@@ -1,14 +0,0 @@
1
- $(function() {
2
- var modal = $('<%= j render contenido %>').modal();
3
-
4
- <% if defined? extra_js %>
5
- <% [extra_js].flatten.each do |partial| %>
6
- <%= render partial: partial %>
7
- <% end %>
8
- <% end %>
9
- $(modal).on('hidden.bs.modal', function () {
10
- $(this).data('bs.modal', null);
11
- $(this).remove();
12
- });
13
- PgRails.bindear('.modal')
14
- });
@@ -1,3 +0,0 @@
1
- = smart_listing_update(smart_listing_key)
2
-
3
- | PgRails.bindear('##{smart_listing_key}');
@@ -1,8 +0,0 @@
1
- $(function() {
2
- $('.modal').modal('hide');
3
- <% if @saved %>
4
- $('.smart-listing').smart_listing().reload();
5
- <% else %>
6
- <%= render partial: 'abrir_modal', locals: { contenido: contenido, extra_js: extra_js } %>
7
- <% end %>
8
- });