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
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgEngine
4
+ module IndexHelper
5
+ def encabezado(campo, options = {})
6
+ clase = options[:clase] || @clase_modelo
7
+ if options[:ordenable]
8
+ field = controller.instance_variable_get(:@field)
9
+ direction = controller.instance_variable_get(:@direction)
10
+ uri = URI.parse(request.url)
11
+ cgi = if uri.query.present?
12
+ CGI.parse(uri.query)
13
+ else
14
+ {}
15
+ end
16
+ cgi['order_by'] = campo
17
+ cgi['order_direction'] =
18
+ if field.to_s == campo.to_s && direction.to_s == 'asc'
19
+ 'desc'
20
+ else
21
+ 'asc'
22
+ end
23
+
24
+ symbol = if field.to_s == campo.to_s
25
+ if direction.to_s == 'asc'
26
+ '<i class="bi bi-sort-down-alt" />'
27
+ elsif direction.to_s == 'desc'
28
+ '<i class="bi bi-sort-up" />'
29
+ end
30
+ else
31
+ ''
32
+ end
33
+
34
+ uri.query = cgi.transform_values { |b| (b.length == 1 ? b.first : b) }.to_query
35
+
36
+ link_to(clase.human_attribute_name(campo), uri.to_s) + " #{symbol}".html_safe
37
+ else
38
+ clase.human_attribute_name(campo)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module PgRails
3
+ module PgEngine
4
4
  module PostgresHelper
5
5
  # Le pone la timezone
6
6
  def add_timezone(field)
@@ -1,29 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module PgRails
3
+ module PgEngine
4
4
  module PrintHelper
5
5
  include ActionView::Helpers::NumberHelper
6
6
 
7
7
  class FechaInvalidaError < StandardError
8
8
  end
9
9
 
10
- # Genera un falso link que al clickear carga la url por ajax
11
- # Es igual a los links con remote: true, pero evita que abran el link en otra
12
- # pestaña. Movido de probella
13
- def pg_ajax_link(url, options = {})
14
- content_tag :span, class: 'pg_ajax_link', data: options.merge(url: url) do
15
- block_given? ? yield : ''
16
- end
17
- end
18
-
19
10
  def mostrar_con_link(objeto, options = {})
20
- return unless objeto.present?
11
+ return if objeto.blank?
21
12
 
22
13
  if policy(objeto).show?
23
14
  content = truncate_title(block_given? ? yield : objeto)
24
15
  if options[:new_tab]
25
16
  content += "&nbsp;<i class='fa fa-external-link'>".html_safe
26
- link_to content.html_safe, objeto, target: :_blank
17
+ link_to content.html_safe, objeto, target: :_blank, rel: :noopener
27
18
  else
28
19
  link_to content.html_safe, objeto
29
20
  end
@@ -36,7 +27,7 @@ module PgRails
36
27
  string = input.to_s
37
28
  if string.length > length
38
29
  content_tag :span, title: input, rel: :tooltip do
39
- truncate string, length: length
30
+ truncate string, length:
40
31
  end
41
32
  else
42
33
  string
@@ -44,7 +35,7 @@ module PgRails
44
35
  end
45
36
 
46
37
  def print_cuit(cuit_number)
47
- return '' unless cuit_number.present?
38
+ return '' if cuit_number.blank?
48
39
 
49
40
  str = cuit_number.to_s
50
41
  "#{str[0..1]}-#{str[2..9]}-#{str[10]}"
@@ -52,42 +43,42 @@ module PgRails
52
43
 
53
44
  def dmy_time(date)
54
45
  date = parsear_tiempo(date) if date.is_a? String
55
- return unless date.present?
46
+ return if date.blank?
56
47
 
57
48
  date.strftime('%d/%m/%Y %H:%M')
58
49
  end
59
50
 
60
51
  def dmy(date)
61
52
  date = parsear_fecha(date) if date.is_a? String
62
- return unless date.present?
53
+ return if date.blank?
63
54
 
64
55
  date.strftime('%d/%m/%Y')
65
56
  end
66
57
 
67
58
  def ymd(date)
68
59
  date = parsear_fecha(date) if date.is_a? String
69
- return unless date.present?
60
+ return if date.blank?
70
61
 
71
62
  date.strftime('%Y/%m/%d')
72
63
  end
73
64
 
74
65
  def dmyg(date)
75
66
  date = parsear_fecha(date) if date.is_a? String
76
- return unless date.present?
67
+ return if date.blank?
77
68
 
78
69
  date.strftime('%d-%m-%Y')
79
70
  end
80
71
 
81
72
  def ymdg(date)
82
73
  date = parsear_fecha(date) if date.is_a? String
83
- return unless date.present?
74
+ return if date.blank?
84
75
 
85
76
  date.strftime('%Y-%m-%d')
86
77
  end
87
78
 
88
79
  def myg(date)
89
80
  date = parsear_fecha(date) if date.is_a? String
90
- return unless date.present?
81
+ return if date.blank?
91
82
 
92
83
  date.strftime('%m-%Y')
93
84
  end
@@ -108,14 +99,7 @@ module PgRails
108
99
  end
109
100
 
110
101
  def print_currency(number, moneda = 'pesos')
111
- return unless number.present?
112
-
113
- "<span class='currency #{moneda}'>#{number_with_precision(number, delimiter: '.',
114
- separator: ',', precision: 2)}</span>".html_safe
115
- end
116
-
117
- def print_currency2(number, moneda = 'pesos')
118
- return unless number.present?
102
+ return if number.blank?
119
103
 
120
104
  "#{simbolo_moneda(moneda)} #{number_with_precision(number, delimiter: '.', separator: ',',
121
105
  precision: 2)}"
@@ -152,7 +136,7 @@ module PgRails
152
136
  end
153
137
 
154
138
  def parsear_tiempo(datetime)
155
- return nil unless datetime.present?
139
+ return nil if datetime.blank?
156
140
 
157
141
  DateTime.parse(datetime)
158
142
  rescue ArgumentError
@@ -160,7 +144,7 @@ module PgRails
160
144
  end
161
145
 
162
146
  def parsear_fecha(date)
163
- return nil unless date.present?
147
+ return nil if date.blank?
164
148
 
165
149
  Date.parse(date)
166
150
  rescue ArgumentError
@@ -168,7 +152,7 @@ module PgRails
168
152
  end
169
153
 
170
154
  def show_percentage(value)
171
- return unless value.present?
155
+ return if value.blank?
172
156
 
173
157
  "#{value.round(2)} %"
174
158
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgEngine
4
+ module RouteHelper
5
+ class NamespaceDeductor
6
+ def self.request(context)
7
+ if context.respond_to?(:request) && context.request
8
+ # Controllers
9
+ context.request
10
+ elsif context.respond_to?(:helpers) && context.helpers
11
+ # Decorators
12
+ context.helpers.request
13
+ elsif context.respond_to?(:template) && context.template
14
+ # FormBuilders
15
+ context.template.request
16
+ end
17
+ end
18
+
19
+ def self.namespace(context)
20
+ req = request(context)
21
+ route = Rails.application.routes.recognize_path(req.path)
22
+ parts = route[:controller].split('/')
23
+ return unless parts.length > 1
24
+
25
+ parts.first.to_sym
26
+ end
27
+ end
28
+
29
+ def pg_namespace
30
+ NamespaceDeductor.namespace(self)
31
+ end
32
+
33
+ def namespaced_path(object, prefix: nil, suffix: nil)
34
+ target = [pg_namespace, object]
35
+ target.prepend prefix if prefix
36
+ target.append suffix if suffix
37
+ target = target.flatten.compact
38
+ polymorphic_url(target, only_path: true)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgEngine
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
+ value = if object.is_a? Draper::Decorator
8
+ # Salteo el decorator para que me tome la fecha con formato inglés
9
+ object.object.public_send(attribute_name)
10
+ else
11
+ object.public_send(attribute_name)
12
+ end
13
+ @input_type = 'date'
14
+
15
+ options = merge_wrapper_options({ value:, class: '', autocomplete: 'off' },
16
+ wrapper_options)
17
+ super(options)
18
+ end
19
+ end
20
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module PgRails
3
+ module PgEngine
4
4
  class FiltrosBuilder
5
5
  include ActionView::Helpers
6
6
  include ActionView::Context
@@ -40,22 +40,21 @@ module PgRails
40
40
  def filtrar(query, parametros = nil)
41
41
  parametros = parametros_controller if parametros.nil?
42
42
 
43
- # Filtro soft deleted, y sea con paranoia o con discard
44
- query = query.without_deleted if query.respond_to?(:without_deleted)
45
- query = query.kept if query.respond_to?(:kept)
43
+ # Filtro soft deleted
44
+ query = query.kept if query.respond_to?(:kept) && parametros[:archived] != 'true'
46
45
 
47
- @filtros.each do |campo, _opciones|
48
- next unless parametros[campo].present?
46
+ @filtros.each_key do |campo|
47
+ next if parametros[campo].blank?
49
48
 
50
49
  if @filtros[campo.to_sym].present? && @filtros[campo.to_sym][:query].present?
51
50
  query = @filtros[campo.to_sym][:query].call(query, parametros[campo])
52
51
  elsif tipo(campo) == :enumerized
53
52
  columna = @clase_modelo.columns.find { |c| c.name == campo.to_s }
54
- if columna.array
55
- query = query.where("? = any(#{@clase_modelo.table_name}.#{campo})", parametros[campo])
56
- else
57
- query = query.where("#{@clase_modelo.table_name}.#{campo} = ?", parametros[campo])
58
- end
53
+ query = if columna.array
54
+ query.where("? = any(#{@clase_modelo.table_name}.#{campo})", parametros[campo])
55
+ else
56
+ query.where("#{@clase_modelo.table_name}.#{campo} = ?", parametros[campo])
57
+ end
59
58
  elsif tipo(campo).in?(%i[integer float decimal])
60
59
  campo_a_comparar = "#{@clase_modelo.table_name}.#{sin_sufijo(campo)}"
61
60
  query = query.where("#{campo_a_comparar} #{comparador(campo)} ?", parametros[campo])
@@ -183,7 +182,7 @@ module PgRails
183
182
  @filtros.each do |campo, opciones|
184
183
  if opciones[:oculto] ||
185
184
  (options[:except].present? && options[:except].include?(campo.to_sym)) ||
186
- (options[:only].present? && !options[:only].include?(campo.to_sym))
185
+ (options[:only].present? && options[:only].exclude?(campo.to_sym))
187
186
  next
188
187
  end
189
188
 
@@ -234,7 +233,7 @@ module PgRails
234
233
  nombre_clase = asociacion.options[:class_name]
235
234
  nombre_clase = asociacion.name.to_s.camelize if nombre_clase.nil?
236
235
  clase_asociacion = Object.const_get(nombre_clase)
237
- scope = Pundit.policy_scope!(controller.send(PgRails.configuracion.current_user_method), clase_asociacion)
236
+ scope = Pundit.policy_scope!(controller.send(PgEngine.configuracion.current_user_method), clase_asociacion)
238
237
 
239
238
  # Filtro soft deleted, y sea con paranoia o con discard
240
239
  scope = scope.without_deleted if scope.respond_to?(:without_deleted)
@@ -300,7 +299,7 @@ module PgRails
300
299
  content_tag :div, class: 'col-auto' do
301
300
  content_tag :div, class: 'filter' do
302
301
  text_field_tag(
303
- campo, parametros_controller[campo], class: 'form-control form-control-sm allow-enter-submit', placeholder: placeholder, autocomplete: 'off'
302
+ campo, parametros_controller[campo], class: 'form-control form-control-sm allow-enter-submit', placeholder:, autocomplete: 'off'
304
303
  )
305
304
  end
306
305
  end
@@ -324,9 +323,9 @@ module PgRails
324
323
  content_tag :div, class: 'col-auto' do
325
324
  content_tag :div, class: 'filter' do
326
325
  label_tag(nil, placeholder, class: 'text-muted') + \
327
- date_field_tag(
328
- campo, parametros_controller[campo], class: 'form-control form-control-sm d-inline-block w-auto ms-1', placeholder: placeholder, autocomplete: 'off'
329
- )
326
+ date_field_tag(
327
+ campo, parametros_controller[campo], class: 'form-control form-control-sm d-inline-block w-auto ms-1', placeholder:, autocomplete: 'off'
328
+ )
330
329
  end
331
330
  end
332
331
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PgFormBuilder < SimpleForm::FormBuilder
4
+ include PgAssociable::FormBuilderMethods
5
+
6
+ def mensajes_de_error
7
+ errors_to_show = object.errors[:base]
8
+ message = (errors_to_show.map(&:to_s).join('<br>') if errors_to_show.present?)
9
+
10
+ error_notification(message:)
11
+ end
12
+
13
+ map_type :date, to: PgEngine::FechaInput
14
+ # map_type :datetime, to: PgEngine::FechaInput
15
+
16
+ def submit_button(*args, &)
17
+ options = args.extract_options!.dup
18
+ options[:class] = ['btn-primary', options[:class]].compact
19
+ args << options
20
+ send(:submit, *args, &)
21
+ end
22
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgEngine
4
+ # rubocop:disable Rails/ApplicationRecord
5
+ class BaseRecord < ActiveRecord::Base
6
+ # rubocop:enable Rails/ApplicationRecord
7
+ extend Enumerize
8
+ include PrintHelper
9
+ include PostgresHelper
10
+
11
+ self.abstract_class = true
12
+
13
+ attr_accessor :current_user
14
+
15
+ before_create :setear_creado_y_actualizado_por
16
+ before_update :setear_actualizado_por
17
+
18
+ scope :query, ->(param) { param.present? ? where(id: param) : all }
19
+
20
+ def self.ransackable_associations(_auth_object = nil)
21
+ authorizable_ransackable_associations
22
+ end
23
+
24
+ def self.ransackable_attributes(_auth_object = nil)
25
+ authorizable_ransackable_attributes
26
+ end
27
+
28
+ def self.nombre_plural
29
+ model_name.human(count: 2)
30
+ end
31
+
32
+ def self.nombre_singular
33
+ model_name.human(count: 1)
34
+ end
35
+
36
+ def to_s
37
+ %i[nombre name].each do |campo|
38
+ return "#{send(campo)} ##{id}" if try(campo).present?
39
+ end
40
+ if id.present?
41
+ "#{self.class.nombre_singular} ##{id}"
42
+ else
43
+ super
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def setear_creado_y_actualizado_por
50
+ setear_si_existe :creado_por, current_user
51
+ setear_si_existe :actualizado_por, current_user
52
+ end
53
+
54
+ def setear_actualizado_por
55
+ setear_si_existe :actualizado_por, current_user
56
+ end
57
+
58
+ def setear_si_existe(campo, valor)
59
+ metodo = "#{campo}="
60
+ send(metodo, valor) if respond_to?(metodo) && valor.present?
61
+ end
62
+ end
63
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module PgRails
3
+ module PgEngine
4
4
  class ApplicationPolicy
5
5
  attr_reader :user, :record
6
6
 
@@ -88,7 +88,7 @@ module PgRails
88
88
  end
89
89
 
90
90
  def acceso_total?
91
- user.admin?
91
+ user&.admin?
92
92
  end
93
93
 
94
94
  def objeto_borrado?
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ wb = xlsx_package.workbook
4
+ wb.add_worksheet(name: @clase_modelo.nombre_plural) do |sheet|
5
+ sheet.add_row(atributos_para_listar.map { |a| @clase_modelo.human_attribute_name(a) })
6
+
7
+ @collection.decorate.each do |object|
8
+ array = []
9
+ atributos_para_listar.each do |att|
10
+ array.push object.send(att)
11
+ end
12
+ sheet.add_row array
13
+ end
14
+ end
@@ -0,0 +1,51 @@
1
+ - content_for(:title, @clase_modelo.nombre_plural)
2
+ - content_for :actions do
3
+ button.btn.btn-sm.btn-primary[type="button" data-bs-toggle="collapse"
4
+ data-bs-target="#filtros" aria-expanded="false"
5
+ aria-controls="filtros"]
6
+ span.bi.bi-funnel-fill
7
+ span.d-none.d-sm-inline Filtrar
8
+ .ms-1
9
+ = @clase_modelo.new.decorate.new_link
10
+ .ms-1
11
+ = @clase_modelo.new.decorate.export_link(request.url)
12
+ .collapse.p-2.border-bottom#filtros class="#{ 'show' if any_filter? }"
13
+ .d-flex.align-items-center
14
+ .px-2.d-none.d-sm-inline-block
15
+ span.bi.bi-funnel-fill
16
+ = form_tag nil, class: '', method: :get do
17
+ .row.g-1
18
+ = @filtros.filtros_html
19
+ .col-auto
20
+ = button_tag class: 'btn btn-sm btn-primary col-auto' do
21
+ span.bi.bi-search
22
+ .col-auto
23
+ = link_to namespaced_path(@clase_modelo),
24
+ class: 'btn btn-sm btn-secondary col-auto' do
25
+ | Limpiar
26
+
27
+ div
28
+ - if @collection.any?
29
+ .table-responsive
30
+ table.table.table-sm.listado.xpg-revert-width.xborder-end
31
+ caption.ps-3 = page_entries_info @collection
32
+ thead.table-light
33
+ tr
34
+ - atributos_para_listar.each do |att|
35
+ th = encabezado att, ordenable: true
36
+ th
37
+ tbody
38
+ - @collection.each do |object|
39
+ - object = object.decorate
40
+ tr id="#{dom_id(object)}"
41
+ - atributos_para_listar.each do |att|
42
+ th = object.send(att)
43
+ td.text-nowrap.text-end.ps-5
44
+ = object.show_link
45
+ = object.edit_link
46
+ = object.destroy_link
47
+
48
+ .ps-3.justify-content-center
49
+ = paginate(@collection)
50
+ - else
51
+ p.m-3 No hay #{@clase_modelo.nombre_plural.downcase} que mostrar
@@ -0,0 +1,48 @@
1
+ es:
2
+ attributes:
3
+ created_at: Fecha de creación
4
+ updated_at: Fecha de actualización
5
+ discarded_at: Fecha de borrado
6
+ actualizado_por: Actualizado por
7
+ creado_por: Creado por
8
+ ancestry:
9
+ exclude_self: No puede ser hijx de si mismx
10
+ simple_form:
11
+ # labels:
12
+ # user:
13
+ # username: 'User name'
14
+ # password: 'Password'
15
+ # hints:
16
+ error_notification:
17
+ default_message: "hubo algunos errores:"
18
+
19
+ simple_form:
20
+ "yes": 'Sí'
21
+ "no": 'No'
22
+ required:
23
+ text: 'required'
24
+ mark: '*'
25
+ # You can uncomment the line below if you need to overwrite the whole required html.
26
+ # When using html, text and mark won't be used.
27
+ # html: '<abbr title="required">*</abbr>'
28
+ error_notification:
29
+ default_message: "Por favor, revisá los errores debajo:"
30
+ # Examples
31
+ # labels:
32
+ # defaults:
33
+ # password: 'Password'
34
+ # user:
35
+ # new:
36
+ # email: 'E-mail to sign in.'
37
+ # edit:
38
+ # email: 'E-mail.'
39
+ # hints:
40
+ # defaults:
41
+ # username: 'User name to sign in.'
42
+ # password: 'No special characters, please.'
43
+ # include_blanks:
44
+ # defaults:
45
+ # age: 'Rather not say'
46
+ # prompts:
47
+ # defaults:
48
+ # age: 'Select your age'