pg_rails 7.0.8.pre.alpha.10 → 7.0.8.pre.alpha.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/pg_associable/app/javascript/modal_controller.js +1 -1
- data/pg_engine/app/helpers/pg_engine/print_helper.rb +2 -2
- data/pg_engine/app/lib/pg_form_builder.rb +21 -0
- data/pg_engine/app/models/user.rb +14 -2
- data/pg_engine/app/views/pg_engine/base/index.html.slim +1 -1
- data/pg_engine/config/initializers/simple_form_monkey_patch.rb +12 -0
- data/pg_engine/config/locales/es.yml +4 -0
- data/pg_engine/config/simple_form/simple_form_bootstrap.rb +2 -4
- data/pg_engine/spec/lib/pg_form_builder_spec.rb +14 -0
- data/pg_layout/app/views/devise/registrations/new.html.erb +3 -4
- data/pg_rails/lib/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd8e2d2862617656464a77ffbb81da7f6a4446d013905748392a062e8f3dab7c
|
4
|
+
data.tar.gz: '082f99be749adde90a68693ebfe00ee234c6a83429c18c0f02b9aff6b831ae53'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d34c9e84d88801ea1b973b275ab94923fb0941bdf9e204fa2a3d76321f9bec079427e3df7d9fae905ef31e3144cda6d92c061ca510f108c66084ec68258de446
|
7
|
+
data.tar.gz: 18fed1f31567205e9ad8bff9e455f9c5e48bf0be4966e2ba9c08fca716995720934e0b8f0011ab1a2bcf7cd39edbd92fb708b296d926849cae2c815c5a1a4352
|
@@ -98,10 +98,10 @@ module PgEngine
|
|
98
98
|
'No'
|
99
99
|
end
|
100
100
|
|
101
|
-
def print_currency(number, simbolo: '$')
|
101
|
+
def print_currency(number, simbolo: '$', precision: nil)
|
102
102
|
return if number.blank?
|
103
103
|
|
104
|
-
precision
|
104
|
+
precision ||= (number % 1).positive? ? 2 : 0
|
105
105
|
"#{simbolo} #{number_with_precision(number, delimiter: '.', separator: ',',
|
106
106
|
precision:)}"
|
107
107
|
end
|
@@ -4,6 +4,27 @@ class PgFormBuilder < SimpleForm::FormBuilder
|
|
4
4
|
include PgAssociable::FormBuilderMethods
|
5
5
|
include PgEngine::ErrorHelper
|
6
6
|
|
7
|
+
def default_prefix(attribute_name)
|
8
|
+
at_name = object.class.human_attribute_name(attribute_name.to_s).downcase
|
9
|
+
"#{articulo(attribute_name)} #{at_name}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def articulo(attribute_name)
|
13
|
+
gender = I18n.t("gender.#{attribute_name}", default: nil)
|
14
|
+
if gender.present?
|
15
|
+
gender == 'f' ? 'La' : 'El'
|
16
|
+
else
|
17
|
+
at_name = object.class.human_attribute_name(attribute_name.to_s).downcase
|
18
|
+
at_name.ends_with?('a') ? 'La' : 'El'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def input(attribute_name, options = {}, &)
|
23
|
+
options[:error_prefix] ||= default_prefix(attribute_name)
|
24
|
+
|
25
|
+
super(attribute_name, options, &)
|
26
|
+
end
|
27
|
+
|
7
28
|
def mensajes_de_error
|
8
29
|
base_errors = object.errors[:base]
|
9
30
|
base_message = (base_errors.map(&:to_s).join('<br>') if base_errors.present?)
|
@@ -37,7 +37,7 @@ class User < ApplicationRecord
|
|
37
37
|
|
38
38
|
# Include default devise modules. Others available are:
|
39
39
|
devise :database_authenticatable, :registerable,
|
40
|
-
:recoverable, :rememberable,
|
40
|
+
:recoverable, :rememberable,
|
41
41
|
:lockable, :timeoutable, :trackable, :confirmable
|
42
42
|
|
43
43
|
audited
|
@@ -46,7 +46,19 @@ class User < ApplicationRecord
|
|
46
46
|
has_many :user_accounts
|
47
47
|
has_many :accounts, through: :user_accounts
|
48
48
|
|
49
|
-
validates :
|
49
|
+
validates :nombre, :apellido, presence: true
|
50
|
+
|
51
|
+
validates_presence_of :email
|
52
|
+
validates_uniqueness_of :email, message: 'ya pertenece a un usuario'
|
53
|
+
validates_format_of :email, with: /\A[^@\s]+@[^@\s]+\z/
|
54
|
+
validates_presence_of :password, if: :password_required?
|
55
|
+
validates_confirmation_of :password, if: :password_required?, message: 'Las contraseñas no coinciden'
|
56
|
+
validates_length_of :password, if: :password_required?, within: 6..128,
|
57
|
+
message: 'es demasiado corta (6 caracteres mínimo)'
|
58
|
+
|
59
|
+
def password_required?
|
60
|
+
!persisted? || !password.nil? || !password_confirmation.nil?
|
61
|
+
end
|
50
62
|
|
51
63
|
scope :query, ->(param) { where('email ILIKE ?', "%#{param}%") }
|
52
64
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module SimpleForm
|
2
|
+
module Components
|
3
|
+
module Errors
|
4
|
+
def error_text
|
5
|
+
text = has_custom_error? ? options[:error] : errors.reject(&:empty?).send(error_method)
|
6
|
+
return if text.blank?
|
7
|
+
|
8
|
+
"#{html_escape(options[:error_prefix])} #{html_escape(text)}".lstrip.html_safe
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -56,8 +56,7 @@ SimpleForm.setup do |config|
|
|
56
56
|
b.optional :readonly
|
57
57
|
b.use :label, class: 'form-label'
|
58
58
|
b.use :input, class: 'form-control', error_class: 'is-invalid'
|
59
|
-
b.use :
|
60
|
-
b.optional :error, wrap_with: { class: 'invalid-feedback' }
|
59
|
+
b.use :error, wrap_with: { class: 'invalid-feedback' }
|
61
60
|
b.use :hint, wrap_with: { class: 'form-text' }
|
62
61
|
end
|
63
62
|
|
@@ -66,8 +65,7 @@ SimpleForm.setup do |config|
|
|
66
65
|
b.optional :readonly
|
67
66
|
b.use :label, class: 'form-label'
|
68
67
|
b.use :input, class: 'form-select', error_class: 'is-invalid'
|
69
|
-
b.use :
|
70
|
-
b.optional :error, wrap_with: { class: 'invalid-feedback' }
|
68
|
+
b.use :error, wrap_with: { class: 'invalid-feedback' }
|
71
69
|
b.use :hint, wrap_with: { class: 'form-text' }
|
72
70
|
end
|
73
71
|
|
@@ -29,4 +29,18 @@ describe PgFormBuilder do
|
|
29
29
|
it { expect(subject).to eq 'Por favor, revisá los campos obligatorios:' }
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
describe '#default_prefix' do
|
34
|
+
context 'cuando el atributo es masculino' do
|
35
|
+
subject { instancia.default_prefix(:nombre) }
|
36
|
+
|
37
|
+
it { expect(subject).to eq 'El nombre' }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'cuando el atributo es femenino' do
|
41
|
+
subject { instancia.default_prefix(:fecha) }
|
42
|
+
|
43
|
+
it { expect(subject).to eq 'La fecha' }
|
44
|
+
end
|
45
|
+
end
|
32
46
|
end
|
@@ -1,15 +1,14 @@
|
|
1
1
|
<h2><%= t(".sign_up") %></h2>
|
2
2
|
|
3
3
|
<%= pg_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
|
4
|
-
<%= f.
|
4
|
+
<%= f.mensajes_de_error %>
|
5
5
|
|
6
6
|
<div class="form-inputs">
|
7
|
+
<%= f.input :nombre, required: true, autofocus: true %>
|
8
|
+
<%= f.input :apellido, required: true %>
|
7
9
|
<%= f.input :email,
|
8
10
|
required: true,
|
9
|
-
autofocus: true ,
|
10
11
|
input_html: { autocomplete: "email" }%>
|
11
|
-
<%= f.input :nombre, required: true %>
|
12
|
-
<%= f.input :apellido, required: true %>
|
13
12
|
<%= f.input :password,
|
14
13
|
required: true,
|
15
14
|
hint: (t('devise.shared.minimum_password_length', count: @minimum_password_length) if @minimum_password_length),
|
data/pg_rails/lib/version.rb
CHANGED
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.
|
4
|
+
version: 7.0.8.pre.alpha.11
|
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-03-
|
11
|
+
date: 2024-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Rails goodies.
|
14
14
|
email:
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- pg_engine/app/views/pg_engine/base/new.html.slim
|
90
90
|
- pg_engine/config/initializers/active_admin.rb
|
91
91
|
- pg_engine/config/initializers/devise.rb
|
92
|
+
- pg_engine/config/initializers/simple_form_monkey_patch.rb
|
92
93
|
- pg_engine/config/locales/devise.en.yml
|
93
94
|
- pg_engine/config/locales/es.yml
|
94
95
|
- pg_engine/config/routes.rb
|