pg_rails 7.0.8.pre.alpha.53 → 7.0.8.pre.alpha.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc65c537b0f07c6659a716cf31aca506a9da7d7ee43f6bbaa425a756864875ef
4
- data.tar.gz: ba019b72eb7fac96fc364396da6890040a86b7743e2532e73c677a20809c546d
3
+ metadata.gz: c3988a9c0d903ba20bb3cd83e2c5cacce2b4be38e630ebadc216bf55953bf349
4
+ data.tar.gz: 491bdc7eea79682ac8d34e2f04619c6f5a69be94fccc4d27de4874b0d42c5035
5
5
  SHA512:
6
- metadata.gz: 46fe858cbdfde69a00935a3e92aa2524729a030217629556a3f4a6717b7f873c80ccf72fee9698f0599b0b7768ddd27b392273b01685eb556c46c236a1eb1450
7
- data.tar.gz: 3be35c7a9db5507e1c84f62e3b405772986ffb3fd63a09b5a93f5fd54128fca897da7f707437e66556a5aee9f6d26bfe639bdf51dceac99f210730cfd089134d
6
+ metadata.gz: 94e6f9f80d69ca2de0a80f4d2684fd0aea928cb4c9bc93d168c9e6eb1e2ce37ec8982cfffbf8a0c74e0aecef8a23c0f32ab63deb98977e6033df0e35481c8047
7
+ data.tar.gz: af872ab696c047befe1000bf53c5c493390ca449fdb904d5507c7239fac28eb1de6b3a40be031926daf9fe3de5dafcfa9c3aea10c7fdab2f2367a75d3d0cf21a
@@ -22,12 +22,26 @@ module PgEngine
22
22
 
23
23
  protect_from_forgery with: :exception
24
24
 
25
- rescue_from PrintHelper::FechaInvalidaError, with: :fecha_invalida
25
+ rescue_from PgEngine::Error, with: :internal_error
26
26
  rescue_from Pundit::NotAuthorizedError, with: :not_authorized
27
27
  rescue_from Redirect do |e|
28
28
  redirect_to e.url
29
29
  end
30
30
 
31
+ def internal_error(error)
32
+ pg_err error
33
+
34
+ respond_to do |format|
35
+ format.html do
36
+ render 'pg_layout/error', layout: 'pg_layout/containerized'
37
+ end
38
+ format.turbo_stream do
39
+ flash.now[:critical] = self.class.render(partial: 'pg_layout/default_error_message')
40
+ render turbo_stream: (turbo_stream.remove_all('.modal') + render_turbo_stream_flash_messages)
41
+ end
42
+ end
43
+ end
44
+
31
45
  before_action do
32
46
  Current.user = current_user
33
47
  end
@@ -47,8 +61,8 @@ module PgEngine
47
61
  layout 'pg_layout/base'
48
62
 
49
63
  # Los flash_types resultantes serían:
50
- # [:alert, :notice, :warning, :success]
51
- add_flash_types :warning, :success
64
+ # [:critical, :alert, :notice, :warning, :success]
65
+ add_flash_types :critical, :warning, :success
52
66
 
53
67
  before_action do
54
68
  console if dev_user_or_env? && (params[:show_web_console] || params[:wc])
@@ -76,32 +90,13 @@ module PgEngine
76
90
 
77
91
  protected
78
92
 
79
- # TODO: ver qué pasa en producción
80
- # def default_url_options(options = {})
81
- # if Rails.env.production?
82
- # options.merge(protocol: 'https')
83
- # else
84
- # options
85
- # end
86
- # end
87
-
88
- # TODO!: ver qué onda esto, tiene sentido acá?
89
- def fecha_invalida
90
- respond_to do |format|
91
- format.json do
92
- render json: { error: 'Formato de fecha inválido' },
93
- status: :unprocessable_entity
94
- end
95
- format.html { go_back('Formato de fecha inválido') }
96
- end
97
- end
98
-
99
93
  def not_authorized
100
94
  respond_to do |format|
101
95
  format.json do
102
96
  render json: { error: 'Acceso no autorizado' },
103
97
  status: :unprocessable_entity
104
98
  end
99
+ # TODO: responder a turbo_stream
105
100
  format.html do
106
101
  if request.path == root_path
107
102
  # TODO!: renderear un 500.html y pg_err
@@ -17,6 +17,10 @@ module Public
17
17
  def new; end
18
18
 
19
19
  def create
20
+ if Current.user.present?
21
+ @mensaje_contacto.email = Current.user.email
22
+ @mensaje_contacto.nombre = Current.user.nombre_completo
23
+ end
20
24
  if @mensaje_contacto.save
21
25
  render turbo_stream: turbo_stream.update('mensaje_contacto', partial: 'gracias')
22
26
  else
@@ -14,7 +14,7 @@ module PgEngine
14
14
  case flash_type
15
15
  when 'notice'
16
16
  'info'
17
- when 'alert'
17
+ when 'critical', 'alert'
18
18
  'danger'
19
19
  when 'warning'
20
20
  'warning'
@@ -4,9 +4,6 @@ module PgEngine
4
4
  module PrintHelper
5
5
  include ActionView::Helpers::NumberHelper
6
6
 
7
- class FechaInvalidaError < PgEngine::Error
8
- end
9
-
10
7
  def mostrar_con_link(objeto, options = {})
11
8
  return if objeto.blank?
12
9
 
@@ -42,42 +39,36 @@ module PgEngine
42
39
  end
43
40
 
44
41
  def dmy_time(date)
45
- date = parsear_tiempo(date) if date.is_a? String
46
42
  return if date.blank?
47
43
 
48
44
  date.strftime('%d/%m/%Y %H:%M')
49
45
  end
50
46
 
51
47
  def dmy(date)
52
- date = parsear_fecha(date) if date.is_a? String
53
48
  return if date.blank?
54
49
 
55
50
  date.strftime('%d/%m/%Y')
56
51
  end
57
52
 
58
53
  def ymd(date)
59
- date = parsear_fecha(date) if date.is_a? String
60
54
  return if date.blank?
61
55
 
62
56
  date.strftime('%Y/%m/%d')
63
57
  end
64
58
 
65
59
  def dmyg(date)
66
- date = parsear_fecha(date) if date.is_a? String
67
60
  return if date.blank?
68
61
 
69
62
  date.strftime('%d-%m-%Y')
70
63
  end
71
64
 
72
65
  def ymdg(date)
73
- date = parsear_fecha(date) if date.is_a? String
74
66
  return if date.blank?
75
67
 
76
68
  date.strftime('%Y-%m-%d')
77
69
  end
78
70
 
79
71
  def myg(date)
80
- date = parsear_fecha(date) if date.is_a? String
81
72
  return if date.blank?
82
73
 
83
74
  date.strftime('%m-%Y')
@@ -142,22 +133,6 @@ module PgEngine
142
133
  end
143
134
  end
144
135
 
145
- def parsear_tiempo(datetime)
146
- return nil if datetime.blank?
147
-
148
- DateTime.parse(datetime)
149
- rescue ArgumentError
150
- raise FechaInvalidaError, datetime
151
- end
152
-
153
- def parsear_fecha(date)
154
- return nil if date.blank?
155
-
156
- Date.parse(date)
157
- rescue ArgumentError
158
- raise FechaInvalidaError, date
159
- end
160
-
161
136
  def show_percentage(value)
162
137
  return if value.blank?
163
138
 
@@ -8,8 +8,9 @@
8
8
  = f.mensajes_de_error
9
9
 
10
10
  = hidden_field_tag :asociable, true if asociable
11
- = f.input :nombre, input_html: { style: 'max-width: 22em' }
12
- = f.input :email, input_html: { style: 'max-width: 23em' }
11
+ - unless user_signed_in?
12
+ = f.input :nombre, input_html: { style: 'max-width: 22em' }
13
+ = f.input :email, input_html: { style: 'max-width: 23em' }
13
14
  = f.input :telefono, hint: '(Opcional)', input_html: { style: 'max-width: 15em' }
14
15
  = f.input :mensaje, as: :text, input_html: { rows: 5 }
15
16
  .mt-2
@@ -9,6 +9,10 @@ class DummyBaseController < PgEngine::BaseController
9
9
  raise Pundit::NotAuthorizedError
10
10
  end
11
11
 
12
+ def test_internal_error
13
+ raise PgEngine::Error
14
+ end
15
+
12
16
  def check_dev_user
13
17
  @dev_user_or_env = dev_user_or_env?
14
18
  @dev_user = dev_user?
@@ -20,6 +24,8 @@ end
20
24
  # rubocop:disable RSpec/FilePath
21
25
  # rubocop:disable RSpec/SpecFilePathFormat
22
26
  describe DummyBaseController do
27
+ render_views
28
+
23
29
  describe 'PgEngine::BaseController::Redirect' do
24
30
  before { get :action_with_redirect }
25
31
 
@@ -28,6 +34,40 @@ describe DummyBaseController do
28
34
  end
29
35
  end
30
36
 
37
+ describe 'internal_error' do
38
+ subject do
39
+ get :test_internal_error
40
+ end
41
+
42
+ around do |example|
43
+ PgEngine::PgLogger.raise_errors = false
44
+ example.run
45
+ PgEngine::PgLogger.raise_errors = true
46
+ end
47
+
48
+ it do
49
+ subject
50
+ expect(response).to have_http_status(:ok)
51
+ expect(response.body).to include 'Ocurrió algo inesperado'
52
+ expect(response.body).to include '<html'
53
+ expect(response.content_type).to include 'text/html'
54
+ end
55
+
56
+ context 'cuando acepta turbo stream' do
57
+ before do
58
+ request.headers['Accept'] = 'text/vnd.turbo-stream.html,text/html'
59
+ end
60
+
61
+ it do
62
+ subject
63
+ expect(response).to have_http_status(:ok)
64
+ expect(response.content_type).to include 'text/vnd.turbo-stream.html'
65
+ expect(response.body).to include 'Ocurrió algo inesperado'
66
+ expect(response.body).to include '<turbo-stream action="remove" targets=".modal">'
67
+ end
68
+ end
69
+ end
70
+
31
71
  describe 'not_authorized' do
32
72
  subject do
33
73
  get :test_not_authorized
@@ -0,0 +1,11 @@
1
+ <%# locals: (error_msg: nil) %>
2
+
3
+ <div>
4
+ <%= error_msg || 'Ocurrió algo inesperado' %>
5
+ <br>
6
+ Por favor, intentá nuevamente
7
+ <br>
8
+ o <a class="text-decoration-underline" href="<%= new_public_mensaje_contacto_path %>">dejanos un mensaje</a>
9
+ <br>
10
+ y te avisaremos cuando el problema esté resuelto.
11
+ </div>
@@ -0,0 +1,13 @@
1
+ <%# locals: (error_msg: nil) %>
2
+
3
+ <div class="d-flex justify-content-around">
4
+ <div class="alert alert-danger d-flex align-items-center">
5
+ <div>
6
+ <span class="bi bi-emoji-dizzy fs-1 me-3"></span>
7
+ <%# <span class="bi bi-exclamation-triangle fs-1 me-3"></span> %>
8
+ </div>
9
+ <div>
10
+ <%= render partial: 'pg_layout/default_error_message', locals: { error_msg: } %>
11
+ </div>
12
+ </div>
13
+ </div>
@@ -7,14 +7,17 @@
7
7
  data-turbo-temporary="true"
8
8
  aria-live="assertive" aria-atomic="true" role="alert"
9
9
  ]
10
- - case flash_type_to_class(flash_type)
11
- - when 'danger'
10
+ - case flash_type
11
+ - when 'critical'
12
+ / .bi.bi-emoji-dizzy.me-3.fs-2
13
+ .bi.bi-exclamation-triangle-fill.me-3.fs-2
14
+ - when 'alert'
12
15
  .bi.bi-exclamation-triangle-fill.me-2
13
16
  - when 'warning'
14
17
  .bi.bi-exclamation-circle.me-2
15
18
  - when 'success'
16
19
  .bi.bi-check-lg.me-2
17
- - when 'info'
20
+ - when 'notice'
18
21
  .bi.bi-info-circle.me-2
19
22
  = message
20
23
  button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"
@@ -0,0 +1,2 @@
1
+ <%# Se renderea en el rescue de base_controller %>
2
+ <%= render partial: 'pg_layout/error' %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRails
4
- VERSION = '7.0.8-alpha.53'
4
+ VERSION = '7.0.8-alpha.55'
5
5
  end
@@ -241,7 +241,7 @@ RSpec.describe <%= controller_class_name %>Controller do
241
241
 
242
242
  describe 'DELETE #destroy' do
243
243
  subject do
244
- request.headers['Accept'] = "text/vnd.turbo-stream.html,text/html"
244
+ request.headers['Accept'] = 'text/vnd.turbo-stream.html,text/html'
245
245
  delete :destroy, params: { id: <%= file_name %>.to_param, redirect_to: redirect_url }
246
246
  end
247
247
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.8.pre.alpha.53
4
+ version: 7.0.8.pre.alpha.55
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martín Rosso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-03 00:00:00.000000000 Z
11
+ date: 2024-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -1012,11 +1012,14 @@ files:
1012
1012
  - pg_layout/app/views/layouts/pg_layout/container_logo.html.slim
1013
1013
  - pg_layout/app/views/layouts/pg_layout/containerized.html.slim
1014
1014
  - pg_layout/app/views/layouts/pg_layout/devise.html.slim
1015
+ - pg_layout/app/views/pg_layout/_default_error_message.html.erb
1016
+ - pg_layout/app/views/pg_layout/_error.html.erb
1015
1017
  - pg_layout/app/views/pg_layout/_flash.html.slim
1016
1018
  - pg_layout/app/views/pg_layout/_flash_container.html.slim
1017
1019
  - pg_layout/app/views/pg_layout/_navbar.html.erb
1018
1020
  - pg_layout/app/views/pg_layout/_sidebar.html.erb
1019
1021
  - pg_layout/app/views/pg_layout/_sidebar_mobile.html.erb
1022
+ - pg_layout/app/views/pg_layout/error.html.erb
1020
1023
  - pg_layout/lib/pg_layout.rb
1021
1024
  - pg_layout/lib/pg_layout/engine.rb
1022
1025
  - pg_layout/spec/lib/navbar_spec.rb