pg_rails 7.0.8.pre.alpha.26 → 7.0.8.pre.alpha.27

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
  SHA256:
3
- metadata.gz: 67cb2b4ac12dba97e33e5d859a101b7d38502c9be7366122c52e3c67102e26f5
4
- data.tar.gz: 18426e296a8ac94c30540ac0ce01e6152e0b0cd4aa7ca0750d4f671d24bc3aa6
3
+ metadata.gz: 985cc55b4ff43af3479e08cd3d7ae868a065d42cc6f6aae0493609bda38d9fda
4
+ data.tar.gz: 335191165185260bc86fcc0adfec689470dd3abe5a88ad153187977f4b16b5de
5
5
  SHA512:
6
- metadata.gz: 202ce67c321c3614f84ebae1be41329300ea76be4629381288e11658e58d374d7afcb990f9742dc30071f229dd47d04f610902228238af3f97da31dc62cd77a0
7
- data.tar.gz: 8c97bc615beb0888ecc9f98636bba1ea7a181aa6c5723c80d29e4b8a40a4a6219cd2c0ef652be3e4c7548c0685e8daeb8f453425f6829410181b69b5debd2062
6
+ metadata.gz: 9ff8d46bc53fa905b023a2cce88a24555129e7ee4cc146c0c58038c2a35046744be61750e8ef2d73b5d606f3dbb7396cecbbf218ba947bd327991073ae01c788
7
+ data.tar.gz: 032aa328bfc8a622cadb3f5cd2c914cf9a870c35c2d2aabf8c1d8fcb8f501b0d0561e123d63364c897856392507bb001d155a0e7a00b0cd7916fb6b49f3fc64a
@@ -21,6 +21,7 @@ module PgEngine
21
21
  @collection = filtros_y_policy atributos_para_buscar
22
22
  @collection = sort_collection(@collection)
23
23
  @records_filtered = policy_scope(clase_modelo).any? if @collection.empty?
24
+ # FIXME: si hay pero en páginas anteriores, mostrar texto correspondiente
24
25
  pg_respond_index
25
26
  end
26
27
 
@@ -54,6 +54,10 @@ module PgEngine
54
54
  'opened'
55
55
  end
56
56
  @navbar = Navbar.new(current_user)
57
+
58
+ if Rollbar.configuration.enabled && Rails.application.credentials.rollbar.present?
59
+ @rollbar_token = Rails.application.credentials.rollbar.access_token_client
60
+ end
57
61
  end
58
62
 
59
63
  def mobile_device?
@@ -2,6 +2,8 @@ module PgEngine
2
2
  module ErrorHelper
3
3
  extend ActiveSupport::Concern
4
4
 
5
+ # pg_engine/config/initializers/simple_form_monkey_patch.rb
6
+
5
7
  def merge_association_errors(object, details, assoc_key)
6
8
  details = details.except(assoc_key)
7
9
  assoc_items = object.send(assoc_key).map(&:errors).map(&:details)
@@ -26,11 +26,30 @@ class PgFormBuilder < SimpleForm::FormBuilder
26
26
  end
27
27
 
28
28
  def mensajes_de_error
29
+ title = error_notification(message: mensaje, class: 'text-danger mb-2 error-title') if mensaje
30
+
29
31
  base_errors = object.errors[:base]
30
32
  base_message = (base_errors.map(&:to_s).join('<br>') if base_errors.present?)
31
- title = error_notification(message: mensaje, class: 'text-danger mb-2') if mensaje
32
33
  base_tag = error_notification(message: base_message, class: 'alert alert-danger') if base_message
33
- (title || '') + (base_tag || '')
34
+
35
+ all_errors_tag = build_all_errors_tag unless base_tag
36
+
37
+ "#{title}#{base_tag}#{all_errors_tag}"
38
+ end
39
+
40
+ def build_all_errors_tag
41
+ details = object.errors.details.dup
42
+ details.delete(:base)
43
+ not_base_errors = details.any?
44
+
45
+ return unless not_base_errors
46
+
47
+ # TODO!: poder pasar un block para que no se ejecute si no se va a loguear por el log level
48
+ pg_warn "Not base errors en pg_form: #{object.errors.details}. Record: #{object.inspect}", :debug
49
+
50
+ # rubocop:disable Rails/OutputSafety
51
+ "<span class='not_base_errors' data-errors='#{object.errors.details.to_json}'></span>".html_safe
52
+ # rubocop:enable Rails/OutputSafety
34
53
  end
35
54
 
36
55
  def mensaje
@@ -29,7 +29,7 @@ describe PgEngine::ErrorHelper do
29
29
 
30
30
  context 'cuando solo tiene otros errores' do
31
31
  before do
32
- categoria.validate_aux = true
32
+ categoria.validate_base = true
33
33
  end
34
34
 
35
35
  it do
@@ -39,7 +39,7 @@ describe PgEngine::ErrorHelper do
39
39
 
40
40
  context 'cuando tiene multiples errores' do
41
41
  before do
42
- categoria.validate_aux = true
42
+ categoria.validate_base = true
43
43
  categoria.nombre = nil
44
44
  end
45
45
 
@@ -2,11 +2,43 @@ require 'rails_helper'
2
2
 
3
3
  describe PgFormBuilder do
4
4
  let(:categoria) { create :categoria_de_cosa }
5
- let(:template) { double }
5
+ let(:template) do
6
+ klass = Class.new
7
+ klass.include ActionView::Helpers::TagHelper
8
+ klass.new
9
+ end
10
+
6
11
  let(:instancia) { described_class.new('bla', categoria, template, {}) }
7
12
 
8
13
  before { create_list :cosa, 2, categoria_de_cosa: categoria }
9
14
 
15
+ describe '#mensajes_de_error' do
16
+ subject { instancia.mensajes_de_error }
17
+
18
+ # expect(subject)
19
+ # it { expect(subject).to eq 'Por favor, revisá los campos obligatorios:' }
20
+
21
+ context 'cuando solo tiene errores de presencia' do
22
+ before do
23
+ categoria.nombre = nil
24
+ categoria.validate
25
+ end
26
+
27
+ it { expect(subject).to include 'Por favor, revisá los campos obligatorios:' }
28
+ it { expect(subject).to include 'not_base_errors' }
29
+ end
30
+
31
+ context 'cuando solo tiene errores de :base' do
32
+ before do
33
+ categoria.validate_base = true
34
+ categoria.validate
35
+ end
36
+
37
+ it { expect(subject).to include 'Por favor, revisá los siguientes errores' }
38
+ it { expect(subject).not_to include 'not_base_errors' }
39
+ end
40
+ end
41
+
10
42
  describe '#mensaje' do
11
43
  subject { instancia.mensaje }
12
44
 
@@ -1,3 +1,5 @@
1
+ import Rollbar from 'rollbar'
2
+
1
3
  import './config'
2
4
  import './channels'
3
5
  import './controllers'
@@ -5,6 +7,32 @@ import './controllers'
5
7
  // Bootstrap's toasts
6
8
  import * as bootstrap from 'bootstrap'
7
9
 
10
+ let rollbarToken = document.head.querySelector('meta[name=rollbar-token]')
11
+ rollbarToken = rollbarToken && rollbarToken.content
12
+ if (rollbarToken) {
13
+ let rollbarEnv = document.head.querySelector('meta[name=rollbar-env]')
14
+ rollbarEnv = rollbarEnv && rollbarEnv.content
15
+ rollbarEnv = rollbarEnv || 'unknown'
16
+
17
+ window.Rollbar = Rollbar
18
+
19
+ Rollbar.init()
20
+
21
+ Rollbar.global({
22
+ itemsPerMinute: 2,
23
+ maxItems: 5
24
+ })
25
+ Rollbar.configure({
26
+ accessToken: rollbarToken,
27
+ captureUncaught: true,
28
+ captureUnhandledRejections: true,
29
+ reportLevel: 'warning',
30
+ payload: {
31
+ environment: rollbarEnv
32
+ }
33
+ })
34
+ }
35
+
8
36
  document.addEventListener('turbo:load', bindToasts)
9
37
  document.addEventListener('turbo:render', bindToasts)
10
38
 
@@ -1,4 +1,5 @@
1
1
  import { Controller } from '@hotwired/stimulus'
2
+ import Rollbar from 'rollbar'
2
3
 
3
4
  export default class extends Controller {
4
5
  connect () {
@@ -9,5 +10,16 @@ export default class extends Controller {
9
10
  }
10
11
  })
11
12
  })
13
+ const notBaseErrors = this.element.querySelector('.not_base_errors')
14
+
15
+ if (notBaseErrors) {
16
+ const invalidFields = document.querySelector('.form-control.is-invalid,.form-select.is-invalid')
17
+ if (!invalidFields) {
18
+ console.error(notBaseErrors.dataset.errors)
19
+ Rollbar.error(notBaseErrors.dataset.errors)
20
+ const errorTitle = this.element.querySelector('.error-title')
21
+ errorTitle.innerText = 'Lo lamentamos mucho pero ocurrió algo inesperado'
22
+ }
23
+ }
12
24
  }
13
25
  }
@@ -30,6 +30,9 @@ class Navbar
30
30
  path: eval(item['path']),
31
31
  show: item['policy'] ? eval(item['policy']) : true
32
32
  }
33
+ rescue StandardError
34
+ # FIXME: testear
35
+ pg_err item
33
36
  end
34
37
  # rubocop:enable Security/Eval
35
38
  end
@@ -16,7 +16,9 @@ html
16
16
 
17
17
  = stylesheet_link_tag 'application', 'data-turbo-track': 'reload'
18
18
  = javascript_include_tag 'application', 'data-turbo-track': 'reload', type: 'module'
19
- = render partial: 'pg_layout/rollbar'
19
+ - if @rollbar_token.present?
20
+ meta name="rollbar-token" content="#{@rollbar_token}"
21
+ meta name="rollbar-env" content="#{Rails.env}"
20
22
  body
21
23
  div class="#{ @sidebar == false ? '' : 'with-sidebar' }"
22
24
  - unless @sidebar == false
@@ -54,16 +54,16 @@
54
54
  </a>
55
55
  </li>
56
56
  <% end %>
57
-
58
- <% else %>
59
- <li class="nav-item">
60
- <%= link_to t("devise.sign_up"), new_user_registration_path, class: 'btn btn-success' %>
61
- </li>
57
+ <% end %>
58
+ </ul>
59
+ <% unless user_signed_in? %>
60
+ <%= link_to t("devise.sign_up"), new_user_registration_path, class: 'btn btn-success' %>
61
+ <ul class="navbar-nav mb-2 mb-lg-0">
62
62
  <li class="nav-item">
63
63
  <%= link_to t("devise.sign_in"), new_user_session_path, class: 'nav-link' %>
64
64
  </li>
65
- <% end %>
66
- </ul>
65
+ </ul>
66
+ <% end %>
67
67
  <% @navbar.extensiones.each do |extension| %>
68
68
  <%= extension %>
69
69
  <% end %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRails
4
- VERSION = '7.0.8-alpha.26'
4
+ VERSION = '7.0.8-alpha.27'
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.26
4
+ version: 7.0.8.pre.alpha.27
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-04-05 00:00:00.000000000 Z
11
+ date: 2024-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -200,7 +200,6 @@ files:
200
200
  - pg_layout/app/views/pg_layout/_flash.html.slim
201
201
  - pg_layout/app/views/pg_layout/_flash_alert.html.slim
202
202
  - pg_layout/app/views/pg_layout/_navbar.html.erb
203
- - pg_layout/app/views/pg_layout/_rollbar.html.erb
204
203
  - pg_layout/app/views/pg_layout/_sidebar.html.erb
205
204
  - pg_layout/lib/pg_layout.rb
206
205
  - pg_layout/lib/pg_layout/engine.rb
@@ -1,28 +0,0 @@
1
- <% if Rollbar.configuration.enabled && Rails.application.credentials.rollbar.present? %>
2
- <script>
3
- var _rollbarConfig = {
4
- accessToken: '<%= Rails.application.credentials.rollbar.access_token_client %>',
5
- captureUncaught: true,
6
- captureUnhandledRejections: true,
7
- payload: {
8
- environment: <%= Rails.env %>,
9
- //trace_id: 'abc',
10
- client: {
11
- javascript: {
12
- code_version: '1.0.0',
13
- //source_map_enabled: true,
14
- //guess_uncaught_frames: true
15
- }
16
- },
17
- //server: {
18
- //root: 'http://localhost:8000/demo/',
19
- //host: 'host-1',
20
- //branch: 'HEAD',
21
- //},
22
- }
23
- };
24
- // Rollbar Snippet
25
- !function(r){var e={};function o(n){if(e[n])return e[n].exports;var t=e[n]={i:n,l:!1,exports:{}};return r[n].call(t.exports,t,t.exports,o),t.l=!0,t.exports}o.m=r,o.c=e,o.d=function(r,e,n){o.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},o.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},o.t=function(r,e){if(1&e&&(r=o(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var t in r)o.d(n,t,function(e){return r[e]}.bind(null,t));return n},o.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return o.d(e,"a",e),e},o.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},o.p="",o(o.s=0)}([function(r,e,o){"use strict";var n=o(1),t=o(5);_rollbarConfig=_rollbarConfig||{},_rollbarConfig.rollbarJsUrl=_rollbarConfig.rollbarJsUrl||"https://cdn.rollbar.com/rollbarjs/refs/tags/v2.26.3/rollbar.min.js",_rollbarConfig.async=void 0===_rollbarConfig.async||_rollbarConfig.async;var a=n.setupShim(window,_rollbarConfig),l=t(_rollbarConfig);window.rollbar=n.Rollbar,a.loadFull(window,document,!_rollbarConfig.async,_rollbarConfig,l)},function(r,e,o){"use strict";var n=o(2),t=o(3);function a(r){return function(){try{return r.apply(this,arguments)}catch(r){try{console.error("[Rollbar]: Internal error",r)}catch(r){}}}}var l=0;function i(r,e){this.options=r,this._rollbarOldOnError=null;var o=l++;this.shimId=function(){return o},"undefined"!=typeof window&&window._rollbarShims&&(window._rollbarShims[o]={handler:e,messages:[]})}var s=o(4),d=function(r,e){return new i(r,e)},c=function(r){return new s(d,r)};function u(r){return a((function(){var e=this,o=Array.prototype.slice.call(arguments,0),n={shim:e,method:r,args:o,ts:new Date};window._rollbarShims[this.shimId()].messages.push(n)}))}i.prototype.loadFull=function(r,e,o,n,t){var l=!1,i=e.createElement("script"),s=e.getElementsByTagName("script")[0],d=s.parentNode;i.crossOrigin="",i.src=n.rollbarJsUrl,o||(i.async=!0),i.onload=i.onreadystatechange=a((function(){if(!(l||this.readyState&&"loaded"!==this.readyState&&"complete"!==this.readyState)){i.onload=i.onreadystatechange=null;try{d.removeChild(i)}catch(r){}l=!0,function(){var e;if(void 0===r._rollbarDidLoad){e=new Error("rollbar.js did not load");for(var o,n,a,l,i=0;o=r._rollbarShims[i++];)for(o=o.messages||[];n=o.shift();)for(a=n.args||[],i=0;i<a.length;++i)if("function"==typeof(l=a[i])){l(e);break}}"function"==typeof t&&t(e)}()}})),d.insertBefore(i,s)},i.prototype.wrap=function(r,e,o){try{var n;if(n="function"==typeof e?e:function(){return e||{}},"function"!=typeof r)return r;if(r._isWrap)return r;if(!r._rollbar_wrapped&&(r._rollbar_wrapped=function(){o&&"function"==typeof o&&o.apply(this,arguments);try{return r.apply(this,arguments)}catch(o){var e=o;throw e&&("string"==typeof e&&(e=new String(e)),e._rollbarContext=n()||{},e._rollbarContext._wrappedSource=r.toString(),window._rollbarWrappedError=e),e}},r._rollbar_wrapped._isWrap=!0,r.hasOwnProperty))for(var t in r)r.hasOwnProperty(t)&&(r._rollbar_wrapped[t]=r[t]);return r._rollbar_wrapped}catch(e){return r}};for(var p="log,debug,info,warn,warning,error,critical,global,configure,handleUncaughtException,handleAnonymousErrors,handleUnhandledRejection,captureEvent,captureDomContentLoaded,captureLoad".split(","),f=0;f<p.length;++f)i.prototype[p[f]]=u(p[f]);r.exports={setupShim:function(r,e){if(r){var o=e.globalAlias||"Rollbar";if("object"==typeof r[o])return r[o];r._rollbarShims={},r._rollbarWrappedError=null;var l=new c(e);return a((function(){e.captureUncaught&&(l._rollbarOldOnError=r.onerror,n.captureUncaughtExceptions(r,l,!0),e.wrapGlobalEventHandlers&&t(r,l,!0)),e.captureUnhandledRejections&&n.captureUnhandledRejections(r,l,!0);var a=e.autoInstrument;return!1!==e.enabled&&(void 0===a||!0===a||function(r){return!("object"!=typeof r||void 0!==r.page&&!r.page)}(a))&&r.addEventListener&&(r.addEventListener("load",l.captureLoad.bind(l)),r.addEventListener("DOMContentLoaded",l.captureDomContentLoaded.bind(l))),r[o]=l,l}))()}},Rollbar:c}},function(r,e,o){"use strict";function n(r,e,o,n){r._rollbarWrappedError&&(n[4]||(n[4]=r._rollbarWrappedError),n[5]||(n[5]=r._rollbarWrappedError._rollbarContext),r._rollbarWrappedError=null);var t=e.handleUncaughtException.apply(e,n);o&&o.apply(r,n),"anonymous"===t&&(e.anonymousErrorsPending+=1)}r.exports={captureUncaughtExceptions:function(r,e,o){if(r){var t;if("function"==typeof e._rollbarOldOnError)t=e._rollbarOldOnError;else if(r.onerror){for(t=r.onerror;t._rollbarOldOnError;)t=t._rollbarOldOnError;e._rollbarOldOnError=t}e.handleAnonymousErrors();var a=function(){var o=Array.prototype.slice.call(arguments,0);n(r,e,t,o)};o&&(a._rollbarOldOnError=t),r.onerror=a}},captureUnhandledRejections:function(r,e,o){if(r){"function"==typeof r._rollbarURH&&r._rollbarURH.belongsToShim&&r.removeEventListener("unhandledrejection",r._rollbarURH);var n=function(r){var o,n,t;try{o=r.reason}catch(r){o=void 0}try{n=r.promise}catch(r){n="[unhandledrejection] error getting `promise` from event"}try{t=r.detail,!o&&t&&(o=t.reason,n=t.promise)}catch(r){}o||(o="[unhandledrejection] error getting `reason` from event"),e&&e.handleUnhandledRejection&&e.handleUnhandledRejection(o,n)};n.belongsToShim=o,r._rollbarURH=n,r.addEventListener("unhandledrejection",n)}}}},function(r,e,o){"use strict";function n(r,e,o){if(e.hasOwnProperty&&e.hasOwnProperty("addEventListener")){for(var n=e.addEventListener;n._rollbarOldAdd&&n.belongsToShim;)n=n._rollbarOldAdd;var t=function(e,o,t){n.call(this,e,r.wrap(o),t)};t._rollbarOldAdd=n,t.belongsToShim=o,e.addEventListener=t;for(var a=e.removeEventListener;a._rollbarOldRemove&&a.belongsToShim;)a=a._rollbarOldRemove;var l=function(r,e,o){a.call(this,r,e&&e._rollbar_wrapped||e,o)};l._rollbarOldRemove=a,l.belongsToShim=o,e.removeEventListener=l}}r.exports=function(r,e,o){if(r){var t,a,l="EventTarget,Window,Node,ApplicationCache,AudioTrackList,ChannelMergerNode,CryptoOperation,EventSource,FileReader,HTMLUnknownElement,IDBDatabase,IDBRequest,IDBTransaction,KeyOperation,MediaController,MessagePort,ModalWindow,Notification,SVGElementInstance,Screen,TextTrack,TextTrackCue,TextTrackList,WebSocket,WebSocketWorker,Worker,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload".split(",");for(t=0;t<l.length;++t)r[a=l[t]]&&r[a].prototype&&n(e,r[a].prototype,o)}}},function(r,e,o){"use strict";function n(r,e){this.impl=r(e,this),this.options=e,function(r){for(var e=function(r){return function(){var e=Array.prototype.slice.call(arguments,0);if(this.impl[r])return this.impl[r].apply(this.impl,e)}},o="log,debug,info,warn,warning,error,critical,global,configure,handleUncaughtException,handleAnonymousErrors,handleUnhandledRejection,_createItem,wrap,loadFull,shimId,captureEvent,captureDomContentLoaded,captureLoad".split(","),n=0;n<o.length;n++)r[o[n]]=e(o[n])}(n.prototype)}n.prototype._swapAndProcessMessages=function(r,e){var o,n,t;for(this.impl=r(this.options);o=e.shift();)n=o.method,t=o.args,this[n]&&"function"==typeof this[n]&&("captureDomContentLoaded"===n||"captureLoad"===n?this[n].apply(this,[t[0],o.ts]):this[n].apply(this,t));return this},r.exports=n},function(r,e,o){"use strict";r.exports=function(r){return function(e){if(!e&&!window._rollbarInitialized){for(var o,n,t=(r=r||{}).globalAlias||"Rollbar",a=window.rollbar,l=function(r){return new a(r)},i=0;o=window._rollbarShims[i++];)n||(n=o.handler),o.handler._swapAndProcessMessages(l,o.messages);window[t]=n,window._rollbarInitialized=!0}}}}]);
26
- // End Rollbar Snippet
27
- </script>
28
- <% end %>