pg_rails 7.1.7 → 7.1.9

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: 41573d568a1fd99ec4100b77846b882c23aadbbf732bb95ddfd066d0c486f095
4
- data.tar.gz: dff45b87624e0913445bd7c39a4a9868e02786fb6fcddc0bc2693886aeb368dc
3
+ metadata.gz: 27fbc8e577ed0fed33aa886661ef3a3b0af756d2485e0af017eba42bedaed7c6
4
+ data.tar.gz: e579a2a15e0dd692d102ee83615ec25f1b641ccc4674b14ca704a41ca93fc11a
5
5
  SHA512:
6
- metadata.gz: 8e94ff6ffb27953e99d8dd053acd9154cb8dec89aff6ee7bdbcfce39214faf5ce9a82d08a8ea95d7717d07ba85a536d9e6c2115431edb1e28296abbc333c4e5c
7
- data.tar.gz: f303020f87d6eb6890c6ea13790a8c5c93a4294f44e23188560d8485e48f3999d59902c4d0b48245fbb3e41887678e817df7186c0bddeacdbbdc8bec044a7d6e
6
+ metadata.gz: 21ced186a92373d6289c79c364510e65252594fdfd46a514c19cac55f39ce55398323325a5ef2d5ae75d3d462fdca5dafa6bc2d1b5c906538a47faed208a0d83
7
+ data.tar.gz: e632afb4c13e2fb01ed5f641acce2efd681b610a96da8ef95ab5d48fed82c896634bd5a049833fef3669e11006db65b98af1fa4c3e2cd440fba72d954598e442
@@ -73,6 +73,11 @@ input[type=datetime-local], input[type=datetime] {
73
73
  padding: 0em 0.3em;
74
74
  }
75
75
 
76
+ .list-group-item {
77
+ --bs-list-group-item-padding-y: 0px;
78
+ --bs-list-group-item-padding-x: 0.3rem;
79
+ }
80
+
76
81
  // FILTROS
77
82
  .filter {
78
83
  display: inline-block;
@@ -6,6 +6,7 @@ module PgEngine
6
6
  clazz.helper_method :atributos_para_mostrar
7
7
  clazz.helper_method :current_page_size
8
8
  clazz.helper_method :show_filters?
9
+ clazz.helper_method :available_page_sizes
9
10
  end
10
11
 
11
12
  # Public endpoints
@@ -18,7 +19,7 @@ module PgEngine
18
19
  end
19
20
 
20
21
  def index
21
- @collection = filtros_y_policy atributos_para_buscar
22
+ @collection = filtros_y_policy(atributos_para_buscar, default_sort)
22
23
 
23
24
  pg_respond_index
24
25
  end
@@ -53,6 +54,14 @@ module PgEngine
53
54
 
54
55
  protected
55
56
 
57
+ def default_sort
58
+ nil
59
+ end
60
+
61
+ def available_page_sizes
62
+ [10, 20, 30, 50, 100].push(current_page_size).uniq.sort
63
+ end
64
+
56
65
  def show_filters?
57
66
  cur_route = pg_current_route
58
67
  idtf = cur_route[:controller] + '#' + cur_route[:action] + '#open-filters'
@@ -68,15 +77,18 @@ module PgEngine
68
77
 
69
78
  def current_page_size
70
79
  if params[:page_size].present?
71
- session[:page_size] = params[:page_size]
72
- params[:page_size].to_i
73
- else
74
- default_page_size
80
+ session[page_size_session_key] = params[:page_size].to_i
75
81
  end
82
+
83
+ session[page_size_session_key].presence || default_page_size
84
+ end
85
+
86
+ def page_size_session_key
87
+ "#{controller_name}/#{action_name}/page_size"
76
88
  end
77
89
 
78
90
  def default_page_size
79
- session[:page_size].present? ? session[:page_size].to_i : 10
91
+ 10
80
92
  end
81
93
 
82
94
  def pg_respond_update
@@ -282,7 +294,7 @@ module PgEngine
282
294
  @clase_modelo ||= self.class.name.singularize.gsub('Controller', '').constantize
283
295
  end
284
296
 
285
- def filtros_y_policy(campos)
297
+ def filtros_y_policy(campos, dflt_sort = nil)
286
298
  @filtros = PgEngine::FiltrosBuilder.new(
287
299
  self, clase_modelo, campos
288
300
  )
@@ -292,6 +304,9 @@ module PgEngine
292
304
 
293
305
  shared_context = Ransack::Adapters::ActiveRecord::Context.new(scope)
294
306
  @q = @clase_modelo.ransack(params[:q], context: shared_context)
307
+
308
+ @q.sorts = dflt_sort if @q.sorts.empty? && dflt_sort.present?
309
+
295
310
  shared_context.evaluate(@q)
296
311
  end
297
312
 
@@ -8,12 +8,12 @@ module PgEngine
8
8
  sort_field = input.last
9
9
  else
10
10
  campo = sort_field = input
11
+ sort_field = sort_field.to_s.sub(/_f\z/, '')
12
+ sort_field = sort_field.to_s.sub(/_text\z/, '')
11
13
  end
12
14
 
13
15
  campo = campo.to_s.sub(/_f\z/, '')
14
16
  campo = campo.to_s.sub(/_text\z/, '')
15
- sort_field = sort_field.to_s.sub(/_f\z/, '')
16
- sort_field = sort_field.to_s.sub(/_text\z/, '')
17
17
 
18
18
  clase = options[:clase] || @clase_modelo
19
19
  key = [controller_name, action_name, 'listado_header', campo].join('.')
@@ -21,7 +21,11 @@ module PgEngine
21
21
  human_name = clase.human_attribute_name(key, default: dflt)
22
22
 
23
23
  if options[:ordenable]
24
- sort_link(@q, sort_field, human_name, default_order: default_order(campo))
24
+ if sort_field.is_a? Array
25
+ sort_link(@q, sort_field.first, sort_field, human_name, default_order: default_order(campo))
26
+ else
27
+ sort_link(@q, sort_field, human_name, default_order: default_order(campo))
28
+ end
25
29
  else
26
30
  human_name
27
31
  end
@@ -58,8 +58,15 @@ div
58
58
  = object.edit_link(text: '', klass: 'btn-light')
59
59
  = object.destroy_link
60
60
 
61
- .ps-3.justify-content-center
61
+ .d-flex.justify-content-center
62
62
  = paginate(@collection)
63
+ .d-flex.align-items-center.justify-content-center.opacity-50
64
+ label.me-2 Filas por página:
65
+ ul.list-group.list-group-horizontal
66
+ - available_page_sizes.each do |page_size|
67
+ = link_to page_size,
68
+ namespaced_path(@clase_modelo, page_size:),
69
+ class: "list-group-item #{'active' if current_page_size == page_size}"
63
70
  - elsif @records_filtered
64
71
  - i18n_key = "#{controller_key}.#{action_name}.index.empty_but_filtered"
65
72
  p.m-3
@@ -0,0 +1,26 @@
1
+ # Initially generated with PgRails::SystemSpecGenerator
2
+ # https://github.com/martin-rosso/pg_rails
3
+
4
+ require 'rails_helper'
5
+
6
+ # By default uses selenium_chrome_headless_iphone driver
7
+ # run with DRIVER environment variable to override, eg:
8
+ #
9
+ # DRIVER=selenium rspec
10
+ describe 'Page sizes' do
11
+ let(:logged_user) { create :user, :developer }
12
+
13
+ before do
14
+ login_as logged_user
15
+ create_list :cosa, 8
16
+ end
17
+
18
+ describe 'some case' do
19
+ it do
20
+ visit '/admin/cosas?page_size=2'
21
+ expect(page).to have_css('.page-item', count: 6)
22
+ visit '/admin/cosas?page_size=5'
23
+ expect(page).to have_css('.page-item', count: 4)
24
+ end
25
+ end
26
+ end
@@ -74,7 +74,7 @@ html
74
74
  = render FlashContainerComponent.new
75
75
  / TODO: si hay varios flashes toast, se superponen. habría que
76
76
  hacer un container con position absolute para los toasts
77
- / FIXME: el yield(filtros)
77
+ = yield(:filtros)
78
78
  = content
79
79
  div style="width:100%; height: 10em"
80
80
  = render partial: 'layouts/footer'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRails
4
- VERSION = '7.1.7'
4
+ VERSION = '7.1.9'
5
5
  end
@@ -0,0 +1,5 @@
1
+ Description:
2
+ Generates a system spec
3
+
4
+ Example:
5
+ rails generate pg_rails:system_spec "Some feature"
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgRails
4
+ class SystemSpecGenerator < Rails::Generators::NamedBase
5
+ source_root File.expand_path('templates', __dir__)
6
+
7
+ def copy_application_policy
8
+ template 'system_spec.rb', "spec/system/#{file_name}.rb"
9
+ end
10
+
11
+ private
12
+
13
+ def file_name
14
+ "#{name.downcase.gsub(' ', '_')}_spec"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # Initially generated with PgRails::SystemSpecGenerator
2
+ # https://github.com/martin-rosso/pg_rails
3
+
4
+ require 'rails_helper'
5
+
6
+ # By default uses selenium_chrome_headless_iphone driver
7
+ # run with DRIVER environment variable to override, eg:
8
+ #
9
+ # DRIVER=selenium rspec
10
+ describe '<%= name %>' do
11
+ subject(:visitar) do
12
+ visit 'some url'
13
+ end
14
+
15
+ let(:logged_user) { create :user }
16
+ let(:account) { logged_user.current_account }
17
+
18
+ before do
19
+ login_as logged_user
20
+ end
21
+
22
+ describe 'some case' do
23
+ it do
24
+ visitar
25
+
26
+ expect(page).to have_text 'some text'
27
+ end
28
+ end
29
+ end
@@ -3,13 +3,15 @@ require 'rails_helper'
3
3
  require 'generators/pg_rspec/scaffold/scaffold_generator'
4
4
  require 'generators/pg_decorator/pg_decorator_generator'
5
5
  require 'generators/pg_active_record/model/model_generator'
6
+ require 'generators/pg_rails/system_spec/system_spec_generator'
6
7
 
7
8
  TEST_ENV_NUMBER = ENV.fetch('TEST_ENV_NUMBER', '')
8
9
  DESTINATION_PATH = File.expand_path("./../../tmp/generator_testing#{TEST_ENV_NUMBER}", __dir__)
9
10
 
10
11
  describe 'Generators', type: :generator do
12
+ destination DESTINATION_PATH
13
+
11
14
  describe 'PgDecoratorGenerator' do
12
- destination DESTINATION_PATH
13
15
  tests PgDecoratorGenerator
14
16
 
15
17
  before { prepare_destination }
@@ -24,7 +26,6 @@ describe 'Generators', type: :generator do
24
26
  end
25
27
 
26
28
  describe 'ScaffoldGenerator' do
27
- destination DESTINATION_PATH
28
29
  tests PgRspec::Generators::ScaffoldGenerator
29
30
 
30
31
  before { prepare_destination }
@@ -40,7 +41,6 @@ describe 'Generators', type: :generator do
40
41
  end
41
42
 
42
43
  describe PgActiveRecord::ModelGenerator do
43
- destination DESTINATION_PATH
44
44
  tests described_class
45
45
 
46
46
  before { prepare_destination }
@@ -53,4 +53,19 @@ describe 'Generators', type: :generator do
53
53
  end
54
54
  end
55
55
  end
56
+
57
+ describe PgRails::SystemSpecGenerator do
58
+ tests described_class
59
+
60
+ before { prepare_destination }
61
+
62
+ it do
63
+ run_generator(['Filtros en listados'])
64
+
65
+ my_assert_file 'spec/system/filtros_en_listados_spec.rb' do |content|
66
+ expect(content).to match(/rails_helper/)
67
+ expect(content).to include 'describe \'Filtros en listados\' do'
68
+ end
69
+ end
70
+ end
56
71
  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.1.7
4
+ version: 7.1.9
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-08-01 00:00:00.000000000 Z
11
+ date: 2024-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -791,6 +791,7 @@ files:
791
791
  - pg_engine/spec/system/destroy_spec.rb
792
792
  - pg_engine/spec/system/login_spec.rb
793
793
  - pg_engine/spec/system/noticed_spec.rb
794
+ - pg_engine/spec/system/page_sizes_spec.rb
794
795
  - pg_engine/spec/system/send_mail_spec.rb
795
796
  - pg_engine/spec/system/signup_spec.rb
796
797
  - pg_engine/spec/system/tooltips_spec.rb
@@ -857,8 +858,6 @@ files:
857
858
  - pg_layout/lib/pg_layout.rb
858
859
  - pg_layout/lib/pg_layout/engine.rb
859
860
  - pg_layout/spec/lib/navbar_spec.rb
860
- - pg_rails/dist/types/pg_associable/app/javascript/asociable_controller.d.ts
861
- - pg_rails/dist/types/pg_layout/app/javascript/utils/utils.d.ts
862
861
  - pg_rails/js/index.js
863
862
  - pg_rails/lib/pg_rails.rb
864
863
  - pg_rails/lib/pg_rails/capybara_support.rb
@@ -890,6 +889,9 @@ files:
890
889
  - pg_scaffold/lib/generators/pg_rails/instalar/USAGE
891
890
  - pg_scaffold/lib/generators/pg_rails/instalar/instalar_generator.rb
892
891
  - pg_scaffold/lib/generators/pg_rails/instalar/templates/pg_rails.rb
892
+ - pg_scaffold/lib/generators/pg_rails/system_spec/USAGE
893
+ - pg_scaffold/lib/generators/pg_rails/system_spec/system_spec_generator.rb
894
+ - pg_scaffold/lib/generators/pg_rails/system_spec/templates/system_spec.rb
893
895
  - pg_scaffold/lib/generators/pg_resource_route/pg_resource_route_generator.rb
894
896
  - pg_scaffold/lib/generators/pg_rspec/model/model_generator.rb
895
897
  - pg_scaffold/lib/generators/pg_rspec/model/templates/model_spec.rb
@@ -1,17 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus'
2
- export default class extends Controller {
3
- static outlets: string[]
4
- lastValue: any
5
- subWrapper: any
6
- elemId: any
7
- input: any
8
- connect(): void;
9
- resetResultados(): void;
10
- setMaxHeight(): void;
11
- crearItem(): void;
12
- escribiAlgo(): void;
13
- buscando(): void;
14
- selectItem(e: any): void;
15
- doSearch(force?: boolean): void;
16
- completarCampo(object: any): void;
17
- }
@@ -1,7 +0,0 @@
1
- export declare function round(value: any): number;
2
- export declare function printCurrency(value: any, simboloMoneda?: string): string;
3
- export declare function showPercentage(value: any): string;
4
- export declare function numberWithDots(x: any): any;
5
- export declare function flashMessage(message: any, flashType?: string, toast?: boolean): void;
6
- export declare function fadeOut(e: any): void;
7
- export declare function fadeIn(e: any): void;