pg_rails 7.1.6 → 7.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/pg_engine/app/assets/stylesheets/pg_rails_b5.scss +5 -0
- data/pg_engine/app/controllers/concerns/pg_engine/resource.rb +27 -12
- data/pg_engine/app/helpers/pg_engine/index_helper.rb +7 -3
- data/pg_engine/app/views/pg_engine/base/index.html.slim +8 -1
- data/pg_engine/spec/system/page_sizes_spec.rb +26 -0
- data/pg_rails/lib/version.rb +1 -1
- data/pg_scaffold/lib/generators/pg_rails/system_spec/USAGE +5 -0
- data/pg_scaffold/lib/generators/pg_rails/system_spec/system_spec_generator.rb +17 -0
- data/pg_scaffold/lib/generators/pg_rails/system_spec/templates/system_spec.rb +28 -0
- data/pg_scaffold/spec/generators_spec.rb +18 -3
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 191011edebc40d5f12ef69b1dc820b578051ceaa04f44b8cc2d484d34eb702b9
|
4
|
+
data.tar.gz: 8d31123f512ab1e8e75ccd779911a9d91ccc704efce6d8ee00c8108f444734e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 930662b242df39cd0b10e125a7132c176f3d264f355eb7cb0e750e1998304c54858b14c99cdda286ce94f01503b1ccfed4a3b81a192c40e560b1803a8e14bcd7
|
7
|
+
data.tar.gz: 9097148fea5b072ddacf4f8aaf84b5c8ddb6cd71cc9f61e5e27cab061aeee0b0f5d395f14c82cc9990dd2fd0bfd1a3ec80aadcbf552dbe064079616a1adb1e8b
|
@@ -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,11 +19,7 @@ module PgEngine
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def index
|
21
|
-
@collection = filtros_y_policy
|
22
|
-
|
23
|
-
shared_context = Ransack::Adapters::ActiveRecord::Context.new(@collection)
|
24
|
-
@q = @clase_modelo.ransack(params[:q], context: shared_context)
|
25
|
-
@collection = shared_context.evaluate(@q)
|
22
|
+
@collection = filtros_y_policy(atributos_para_buscar, default_sort)
|
26
23
|
|
27
24
|
pg_respond_index
|
28
25
|
end
|
@@ -57,6 +54,14 @@ module PgEngine
|
|
57
54
|
|
58
55
|
protected
|
59
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
|
+
|
60
65
|
def show_filters?
|
61
66
|
cur_route = pg_current_route
|
62
67
|
idtf = cur_route[:controller] + '#' + cur_route[:action] + '#open-filters'
|
@@ -72,15 +77,18 @@ module PgEngine
|
|
72
77
|
|
73
78
|
def current_page_size
|
74
79
|
if params[:page_size].present?
|
75
|
-
session[
|
76
|
-
params[:page_size].to_i
|
77
|
-
else
|
78
|
-
default_page_size
|
80
|
+
session[page_size_session_key] = params[:page_size].to_i
|
79
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"
|
80
88
|
end
|
81
89
|
|
82
90
|
def default_page_size
|
83
|
-
|
91
|
+
10
|
84
92
|
end
|
85
93
|
|
86
94
|
def pg_respond_update
|
@@ -286,13 +294,20 @@ module PgEngine
|
|
286
294
|
@clase_modelo ||= self.class.name.singularize.gsub('Controller', '').constantize
|
287
295
|
end
|
288
296
|
|
289
|
-
def filtros_y_policy(campos)
|
297
|
+
def filtros_y_policy(campos, dflt_sort = nil)
|
290
298
|
@filtros = PgEngine::FiltrosBuilder.new(
|
291
299
|
self, clase_modelo, campos
|
292
300
|
)
|
293
301
|
scope = policy_scope(clase_modelo)
|
294
302
|
|
295
|
-
@filtros.filtrar(scope)
|
303
|
+
scope = @filtros.filtrar(scope)
|
304
|
+
|
305
|
+
shared_context = Ransack::Adapters::ActiveRecord::Context.new(scope)
|
306
|
+
@q = @clase_modelo.ransack(params[:q], context: shared_context)
|
307
|
+
|
308
|
+
@q.sorts = dflt_sort if @q.sorts.empty? && dflt_sort.present?
|
309
|
+
|
310
|
+
shared_context.evaluate(@q)
|
296
311
|
end
|
297
312
|
|
298
313
|
def default_scope_for_current_model
|
@@ -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
|
-
|
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
|
-
.
|
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
|
data/pg_rails/lib/version.rb
CHANGED
@@ -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,28 @@
|
|
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
|
+
|
17
|
+
before do
|
18
|
+
login_as logged_user
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'some case' do
|
22
|
+
it do
|
23
|
+
visitar
|
24
|
+
|
25
|
+
expect(page).to have_text 'some text'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
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.
|
4
|
+
version: 7.1.8
|
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-
|
11
|
+
date: 2024-08-02 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
|
@@ -890,6 +891,9 @@ files:
|
|
890
891
|
- pg_scaffold/lib/generators/pg_rails/instalar/USAGE
|
891
892
|
- pg_scaffold/lib/generators/pg_rails/instalar/instalar_generator.rb
|
892
893
|
- pg_scaffold/lib/generators/pg_rails/instalar/templates/pg_rails.rb
|
894
|
+
- pg_scaffold/lib/generators/pg_rails/system_spec/USAGE
|
895
|
+
- pg_scaffold/lib/generators/pg_rails/system_spec/system_spec_generator.rb
|
896
|
+
- pg_scaffold/lib/generators/pg_rails/system_spec/templates/system_spec.rb
|
893
897
|
- pg_scaffold/lib/generators/pg_resource_route/pg_resource_route_generator.rb
|
894
898
|
- pg_scaffold/lib/generators/pg_rspec/model/model_generator.rb
|
895
899
|
- pg_scaffold/lib/generators/pg_rspec/model/templates/model_spec.rb
|