pg_rails 7.0.8.pre.alpha.10 → 7.0.8.pre.alpha.12

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: d3efd952ef548d103ed1c4aea21b903f039792ed601fc66e93fb5b84dce4d39d
4
- data.tar.gz: 148ae25de52ab06846c1b7b313f6f87db0d6d6ba502a9186104559e0e37ec114
3
+ metadata.gz: 84eace9e9d023c54401e822df64d253dd94dcdf3831fd19ce1c77bb0ad674541
4
+ data.tar.gz: 3c1b74610da49e737f4fba5d9b89737a529650831278f95fcfc4c66ebd32a1f6
5
5
  SHA512:
6
- metadata.gz: 68b63352e0ac30ff6f3c7a22e3a2fb73f8918ee91dfefe51b2c8371915c9d7adde99eb114c1ba935387182fa10966d0c5776c672e477486cff17a82993ff68fb
7
- data.tar.gz: 1fda6ee9f5416f813e811268f307b87638b69de4a3db4659a7259c6101dc6b8281d9b351e92998e517a0d492cc39eea71780add28b2c240c4971aa26f87a2000
6
+ metadata.gz: 2c350c91dc1f91c4eb6c2b7ad866296d1057c89637ec3b45922ec89a0720d7942a4706a0ab3659adabb34da2a8f681d56367a722b5d7d4f1595210bb3bda12dc
7
+ data.tar.gz: '0806e415216083b9afe67adb247328764964cd537351a4406e88c7768946b71fe661de0a469f3d61af215d85706312d772e12cf52b03f65c083cb773cf06d687'
@@ -23,7 +23,7 @@ export default class extends Controller {
23
23
  }
24
24
 
25
25
  disconnect (e) {
26
+ this.modalPuntero.hide()
26
27
  this.modalPuntero.dispose()
27
- document.querySelectorAll('.modal-backdrop').forEach(e => { e.remove() })
28
28
  }
29
29
  }
@@ -1,24 +1,21 @@
1
1
  ActiveAdmin.register Account do
2
- permit_params :plan, :nombre, :hashid
2
+ permit_params :plan, :nombre
3
3
 
4
4
  index do
5
5
  selectable_column
6
6
  id_column
7
7
  column :plan
8
8
  column :nombre
9
- column :hashid
10
9
  actions
11
10
  end
12
11
 
13
12
  filter :plan
14
13
  filter :nombre
15
- filter :hashid
16
14
 
17
15
  form do |f|
18
16
  f.inputs do
19
17
  f.input :plan
20
18
  f.input :nombre
21
- f.input :hashid
22
19
  end
23
20
  f.actions
24
21
  end
@@ -15,19 +15,19 @@ module Admin
15
15
  private
16
16
 
17
17
  def atributos_permitidos
18
- %i[plan nombre hashid]
18
+ %i[plan nombre]
19
19
  end
20
20
 
21
21
  def atributos_para_buscar
22
- %i[plan nombre hashid]
22
+ %i[plan nombre]
23
23
  end
24
24
 
25
25
  def atributos_para_listar
26
- %i[plan nombre hashid]
26
+ %i[plan nombre]
27
27
  end
28
28
 
29
29
  def atributos_para_mostrar
30
- %i[plan nombre hashid]
30
+ %i[plan nombre]
31
31
  end
32
32
  end
33
33
  end
@@ -210,6 +210,8 @@ module PgEngine
210
210
  def buscar_instancia
211
211
  if Object.const_defined?('FriendlyId') && @clase_modelo.is_a?(FriendlyId)
212
212
  @clase_modelo.friendly.find(params[:id])
213
+ elsif @clase_modelo.respond_to? :find_by_hashid
214
+ @clase_modelo.find_by!(hashid: params[:id])
213
215
  else
214
216
  @clase_modelo.find(params[:id])
215
217
  end
@@ -0,0 +1,11 @@
1
+ module PgEngine
2
+ module PgRailsHelper
3
+ def dev?
4
+ Rails.env.development? || current_user&.developer?
5
+ end
6
+
7
+ def current_account
8
+ current_user&.current_account
9
+ end
10
+ end
11
+ end
@@ -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 = (number % 1).positive? ? 2 : 0
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?)
@@ -6,25 +6,18 @@
6
6
  #
7
7
  # id :bigint not null, primary key
8
8
  # discarded_at :datetime
9
- # hashid :string
10
9
  # nombre :string not null
11
10
  # plan :integer not null
12
11
  # created_at :datetime not null
13
12
  # updated_at :datetime not null
14
- # actualizado_por_id :bigint
15
- # creado_por_id :bigint
16
- #
17
- # Indexes
18
- #
19
- # index_accounts_on_actualizado_por_id (actualizado_por_id)
20
- # index_accounts_on_creado_por_id (creado_por_id)
13
+ # actualizado_por_id :bigint indexed
14
+ # creado_por_id :bigint indexed
21
15
  #
22
16
  # Foreign Keys
23
17
  #
24
18
  # fk_rails_... (actualizado_por_id => users.id)
25
19
  # fk_rails_... (creado_por_id => users.id)
26
20
  #
27
- # generado con pg_rails
28
21
 
29
22
  class Account < ApplicationRecord
30
23
  audited
@@ -47,10 +47,10 @@ module PgEngine
47
47
 
48
48
  def to_s
49
49
  %i[nombre name].each do |campo|
50
- return "#{send(campo)} ##{id}" if try(campo).present?
50
+ return "#{send(campo)} ##{to_param}" if try(campo).present?
51
51
  end
52
- if id.present?
53
- "#{self.class.nombre_singular} ##{id}"
52
+ if to_param.present?
53
+ "#{self.class.nombre_singular} ##{to_param}"
54
54
  else
55
55
  super
56
56
  end
@@ -3,41 +3,36 @@
3
3
  # Table name: users
4
4
  #
5
5
  # id :bigint not null, primary key
6
+ # apellido :string not null
6
7
  # confirmation_sent_at :datetime
7
- # confirmation_token :string
8
+ # confirmation_token :string indexed
8
9
  # confirmed_at :datetime
9
10
  # current_sign_in_at :datetime
10
11
  # current_sign_in_ip :string
11
12
  # developer :boolean default(FALSE), not null
12
13
  # discarded_at :datetime
13
- # email :string default(""), not null
14
+ # email :string default(""), not null, indexed
14
15
  # encrypted_password :string default(""), not null
15
16
  # failed_attempts :integer default(0), not null
16
17
  # last_sign_in_at :datetime
17
18
  # last_sign_in_ip :string
18
19
  # locked_at :datetime
20
+ # nombre :string not null
19
21
  # remember_created_at :datetime
20
22
  # reset_password_sent_at :datetime
21
- # reset_password_token :string
23
+ # reset_password_token :string indexed
22
24
  # sign_in_count :integer default(0), not null
23
25
  # unconfirmed_email :string
24
- # unlock_token :string
26
+ # unlock_token :string indexed
25
27
  # created_at :datetime not null
26
28
  # updated_at :datetime not null
27
29
  #
28
- # Indexes
29
- #
30
- # index_users_on_confirmation_token (confirmation_token) UNIQUE
31
- # index_users_on_email (email) UNIQUE
32
- # index_users_on_reset_password_token (reset_password_token) UNIQUE
33
- # index_users_on_unlock_token (unlock_token) UNIQUE
34
- #
35
30
  class User < ApplicationRecord
36
31
  # ApplicationRecord should be defined on Application
37
32
 
38
33
  # Include default devise modules. Others available are:
39
34
  devise :database_authenticatable, :registerable,
40
- :recoverable, :rememberable, :validatable,
35
+ :recoverable, :rememberable,
41
36
  :lockable, :timeoutable, :trackable, :confirmable
42
37
 
43
38
  audited
@@ -46,7 +41,19 @@ class User < ApplicationRecord
46
41
  has_many :user_accounts
47
42
  has_many :accounts, through: :user_accounts
48
43
 
49
- validates :email, :nombre, :apellido, presence: true
44
+ validates :nombre, :apellido, presence: true
45
+
46
+ validates_presence_of :email
47
+ validates_uniqueness_of :email, message: 'ya pertenece a un usuario'
48
+ validates_format_of :email, with: /\A[^@\s]+@[^@\s]+\z/
49
+ validates_presence_of :password, if: :password_required?
50
+ validates_confirmation_of :password, if: :password_required?, message: 'Las contraseñas no coinciden'
51
+ validates_length_of :password, if: :password_required?, within: 6..128,
52
+ message: 'es demasiado corta (6 caracteres mínimo)'
53
+
54
+ def password_required?
55
+ !persisted? || !password.nil? || !password_confirmation.nil?
56
+ end
50
57
 
51
58
  scope :query, ->(param) { where('email ILIKE ?', "%#{param}%") }
52
59
 
@@ -8,17 +8,10 @@
8
8
  # profiles :integer default([]), not null, is an Array
9
9
  # created_at :datetime not null
10
10
  # updated_at :datetime not null
11
- # account_id :bigint not null
12
- # actualizado_por_id :bigint
13
- # creado_por_id :bigint
14
- # user_id :bigint not null
15
- #
16
- # Indexes
17
- #
18
- # index_user_accounts_on_account_id (account_id)
19
- # index_user_accounts_on_actualizado_por_id (actualizado_por_id)
20
- # index_user_accounts_on_creado_por_id (creado_por_id)
21
- # index_user_accounts_on_user_id (user_id)
11
+ # account_id :bigint not null, indexed
12
+ # actualizado_por_id :bigint indexed
13
+ # creado_por_id :bigint indexed
14
+ # user_id :bigint not null, indexed
22
15
  #
23
16
  # Foreign Keys
24
17
  #
@@ -27,7 +20,6 @@
27
20
  # fk_rails_... (creado_por_id => users.id)
28
21
  # fk_rails_... (user_id => users.id)
29
22
  #
30
- # generado con pg_rails
31
23
 
32
24
  class UserAccount < ApplicationRecord
33
25
  audited
@@ -7,6 +7,5 @@ div style="max-width: 22em"
7
7
  = hidden_field_tag :asociable, true if asociable
8
8
  = f.input :plan
9
9
  = f.input :nombre
10
- = f.input :hashid
11
10
  .mt-2
12
11
  = f.button :submit
@@ -39,7 +39,7 @@ div
39
39
  - object = object.decorate
40
40
  tr id="#{dom_id(object)}"
41
41
  - atributos_para_listar.each do |att|
42
- td = object.send(att)
42
+ td.text-nowrap = object.send(att)
43
43
  td.text-nowrap.text-end.ps-5
44
44
  = object.show_link
45
45
  = object.edit_link
@@ -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
@@ -40,3 +40,7 @@ es:
40
40
  # prompts:
41
41
  # defaults:
42
42
  # age: 'Select your age'
43
+ errors:
44
+ messages:
45
+ blank: ''
46
+ empty: ''
@@ -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 :full_error, wrap_with: { class: 'invalid-feedback' }
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 :full_error, wrap_with: { class: 'invalid-feedback' }
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
 
@@ -0,0 +1,5 @@
1
+ class RemoveHashIds < ActiveRecord::Migration[7.1]
2
+ def change
3
+ remove_column :accounts, :hashid
4
+ end
5
+ end
@@ -1,6 +1,8 @@
1
1
  # NOTE: only doing this in development as some production environments (Heroku)
2
2
  # NOTE: are sensitive to local FS writes, and besides -- it's just not proper
3
3
  # NOTE: to have a dev-mode tool do its thing in production.
4
+ Dotenv.load
5
+
4
6
  if Rails.env.development?
5
7
  require 'annotate'
6
8
  task :set_annotation_options do
@@ -21,7 +23,8 @@ if Rails.env.development?
21
23
  'show_complete_foreign_keys' => 'false',
22
24
  'show_indexes' => 'false',
23
25
  'simple_indexes' => 'true',
24
- 'model_dir' => ['app/models', 'app/overrides'],
26
+ 'model_dir' => ENV['MODEL_PATHS'],
27
+ # 'model_dir' => ['app/models', 'app/overrides'],
25
28
  # 'model_dir' => 'app/models',
26
29
  'root_dir' => '',
27
30
  'include_version' => 'false',
@@ -6,6 +6,5 @@ FactoryBot.define do
6
6
  factory :account do
7
7
  plan { Account.plan.values.sample }
8
8
  nombre { Faker::Lorem.sentence }
9
- hashid { Faker::Lorem.sentence }
10
9
  end
11
10
  end
@@ -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
@@ -3,6 +3,9 @@ export function round (value) {
3
3
  }
4
4
 
5
5
  export function printCurrency (value, simboloMoneda = '$') {
6
+ if (typeof value === 'string') {
7
+ value = parseFloat(value)
8
+ }
6
9
  const decimals = (value % 1 > 0) ? 2 : 0
7
10
  return simboloMoneda + ' ' + numberWithDots(value.toFixed(decimals).replace('.', ','))
8
11
  }
@@ -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.error_notification %>
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),
@@ -14,15 +14,16 @@ html
14
14
  = stylesheet_link_tag 'application', 'data-turbo-track': 'reload'
15
15
  = javascript_include_tag 'application', 'data-turbo-track': 'reload', type: 'module'
16
16
  body
17
- .with-sidebar
18
- = render partial: 'pg_layout/sidebar'
17
+ div class="#{ @sidebar == false ? '' : 'with-sidebar' }"
18
+ - unless @sidebar == false
19
+ = render partial: 'pg_layout/sidebar'
19
20
  div
20
21
  .position-relative.d-flex.justify-content-around
21
22
  #flash.flash.position-absolute.z-1.mt-1
22
23
  = render partial: 'pg_layout/flash'
23
24
  = render partial: 'pg_layout/navbar'
24
25
  div
25
- - if user_signed_in?
26
+ - if user_signed_in? && @breadcrumb != false
26
27
  .d-flex.align-items-center.justify-content-between.px-3.py-1.d-print-none[
27
28
  style="min-height: 2.5em;"]
28
29
  nav aria-label="breadcrumb"
@@ -1,8 +1,10 @@
1
1
  <nav class="navbar navbar-expand-<%= @breakpoint_navbar_expand %> bg-light">
2
2
  <div class="container-fluid">
3
- <button data-controller="navbar" data-action="navbar#expandNavbar" class="btn btn-outline-primary me-2 d-none d-<%= @breakpoint_navbar_expand %>-inline-block">
4
- <i class="bi bi-list"></i>
5
- </button>
3
+ <% unless @sidebar == false %>
4
+ <button data-controller="navbar" data-action="navbar#expandNavbar" class="btn btn-outline-primary me-2 d-none d-<%= @breakpoint_navbar_expand %>-inline-block">
5
+ <i class="bi bi-list"></i>
6
+ </button>
7
+ <% end %>
6
8
  <!-- <a class="navbar-brand" href="#">Navbar</a> -->
7
9
  <button class="navbar-toggler btn btn-outline-primary me-2" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
8
10
  <i class="bi bi-list"></i>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRails
4
- VERSION = '7.0.8-alpha.10'
4
+ VERSION = '7.0.8-alpha.12'
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.10
4
+ version: 7.0.8.pre.alpha.12
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-05 00:00:00.000000000 Z
11
+ date: 2024-03-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rails goodies.
14
14
  email:
@@ -53,6 +53,7 @@ files:
53
53
  - pg_engine/app/helpers/pg_engine/flash_helper.rb
54
54
  - pg_engine/app/helpers/pg_engine/form_helper.rb
55
55
  - pg_engine/app/helpers/pg_engine/index_helper.rb
56
+ - pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
56
57
  - pg_engine/app/helpers/pg_engine/postgres_helper.rb
57
58
  - pg_engine/app/helpers/pg_engine/print_helper.rb
58
59
  - pg_engine/app/helpers/pg_engine/route_helper.rb
@@ -89,6 +90,7 @@ files:
89
90
  - pg_engine/app/views/pg_engine/base/new.html.slim
90
91
  - pg_engine/config/initializers/active_admin.rb
91
92
  - pg_engine/config/initializers/devise.rb
93
+ - pg_engine/config/initializers/simple_form_monkey_patch.rb
92
94
  - pg_engine/config/locales/devise.en.yml
93
95
  - pg_engine/config/locales/es.yml
94
96
  - pg_engine/config/routes.rb
@@ -102,6 +104,7 @@ files:
102
104
  - pg_engine/db/migrate/20240211153049_create_user_accounts.rb
103
105
  - pg_engine/db/migrate/20240222115722_create_active_storage_tables.active_storage.rb
104
106
  - pg_engine/db/migrate/20240305200900_nombre_user.rb
107
+ - pg_engine/db/migrate/20240314114503_remove_hash_ids.rb
105
108
  - pg_engine/db/seeds.rb
106
109
  - pg_engine/lib/pg_engine.rb
107
110
  - pg_engine/lib/pg_engine/configuracion.rb