pg_rails 7.0.8.pre.alpha.53 → 7.0.8.pre.alpha.54

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: 8e9b803dcc4fc1155fb31efdeb33f3ab8f7b25f43db8abc04cd851c35f8f9db1
4
+ data.tar.gz: c99433c397a93742e57a71736f602f8f3e3b7c093e82792bcdbb3230f79beb55
5
5
  SHA512:
6
- metadata.gz: 46fe858cbdfde69a00935a3e92aa2524729a030217629556a3f4a6717b7f873c80ccf72fee9698f0599b0b7768ddd27b392273b01685eb556c46c236a1eb1450
7
- data.tar.gz: 3be35c7a9db5507e1c84f62e3b405772986ffb3fd63a09b5a93f5fd54128fca897da7f707437e66556a5aee9f6d26bfe639bdf51dceac99f210730cfd089134d
6
+ metadata.gz: 534f5411925466cd4db3a5a0cb908c36f5212faceafd4a523e94f939d036f53b4db4ff5d52abed8675f4edc9eb783e2a17c900760a2f0ad6947ad9c01da7e87e
7
+ data.tar.gz: a116bda2dfc46a994cf7218364444d1488a8d4f4b285f74224766c82893dc545207f88a79dde19794662f27c9b79685ae63cd98974a099680a10b86e20f45a13
@@ -22,12 +22,36 @@ 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
+ @error_msg = <<~HTML.html_safe # rubocop:disable Rails/OutputSafety
35
+ <div>
36
+ Ocurrió algo inesperado
37
+ <br>
38
+ Por favor, intentá nuevamente
39
+ <br>
40
+ o <a class="text-decoration-underline" href="#{new_public_mensaje_contacto_path}">ponete en contacto</a> y pronto lo resolveremos
41
+ </div>
42
+ HTML
43
+
44
+ respond_to do |format|
45
+ format.html do
46
+ render 'pg_layout/error', layout: 'pg_layout/containerized'
47
+ end
48
+ format.turbo_stream do
49
+ flash.now[:critical] = @error_msg
50
+ render turbo_stream: (turbo_stream.remove_all('.modal') + render_turbo_stream_flash_messages)
51
+ end
52
+ end
53
+ end
54
+
31
55
  before_action do
32
56
  Current.user = current_user
33
57
  end
@@ -47,8 +71,8 @@ module PgEngine
47
71
  layout 'pg_layout/base'
48
72
 
49
73
  # Los flash_types resultantes serían:
50
- # [:alert, :notice, :warning, :success]
51
- add_flash_types :warning, :success
74
+ # [:critical, :alert, :notice, :warning, :success]
75
+ add_flash_types :critical, :warning, :success
52
76
 
53
77
  before_action do
54
78
  console if dev_user_or_env? && (params[:show_web_console] || params[:wc])
@@ -76,32 +100,13 @@ module PgEngine
76
100
 
77
101
  protected
78
102
 
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
103
  def not_authorized
100
104
  respond_to do |format|
101
105
  format.json do
102
106
  render json: { error: 'Acceso no autorizado' },
103
107
  status: :unprocessable_entity
104
108
  end
109
+ # TODO: responder a turbo_stream
105
110
  format.html do
106
111
  if request.path == root_path
107
112
  # 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,39 @@ 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.content_type).to include 'text/html'
53
+ end
54
+
55
+ context 'cuando acepta turbo stream' do
56
+ before do
57
+ request.headers['Accept'] = 'text/vnd.turbo-stream.html,text/html'
58
+ end
59
+
60
+ it do
61
+ subject
62
+ expect(response).to have_http_status(:ok)
63
+ expect(response.content_type).to include 'text/vnd.turbo-stream.html'
64
+ expect(response.body).to include 'Ocurrió algo inesperado'
65
+ expect(response.body).to include '<turbo-stream action="remove" targets=".modal">'
66
+ end
67
+ end
68
+ end
69
+
31
70
  describe 'not_authorized' do
32
71
  subject do
33
72
  get :test_not_authorized
@@ -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,11 @@
1
+ <div class="d-flex justify-content-around">
2
+ <div class="alert alert-danger d-flex align-items-center">
3
+ <div>
4
+ <span class="bi bi-emoji-dizzy fs-1 me-3"></span>
5
+ <%# <span class="bi bi-exclamation-triangle fs-1 me-3"></span> %>
6
+ </div>
7
+ <div>
8
+ <%= @error_msg %>
9
+ </div>
10
+ </div>
11
+ </div>
@@ -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.54'
5
5
  end
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.54
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
@@ -1017,6 +1017,7 @@ files:
1017
1017
  - pg_layout/app/views/pg_layout/_navbar.html.erb
1018
1018
  - pg_layout/app/views/pg_layout/_sidebar.html.erb
1019
1019
  - pg_layout/app/views/pg_layout/_sidebar_mobile.html.erb
1020
+ - pg_layout/app/views/pg_layout/error.html.erb
1020
1021
  - pg_layout/lib/pg_layout.rb
1021
1022
  - pg_layout/lib/pg_layout/engine.rb
1022
1023
  - pg_layout/spec/lib/navbar_spec.rb