base_editing_bootstrap 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 621ce2921cb1a39524a523807983ec5e099d0646d9eb06d40a15d4f8d59d9720
4
- data.tar.gz: d7695f7d33150def36bdc1bf5ec357f4c6cb0367b5143ec152fb338d779fba5d
3
+ metadata.gz: fc5e88d1a3608d25d679030ede2eeaa24779f2e5b7e65099ab6591ab86357bee
4
+ data.tar.gz: b99d16876db70bc89645cd21a7c3048a813bd80cfda46f80e3b4718a5826aeaf
5
5
  SHA512:
6
- metadata.gz: 3329ab7c65c74ff2e8b5e91a0f6e3d27f2599e8ad0800f02e53cdb9f70706145a879c147c5c6224d21ac602b2789c7cae531115e899a564060f2a953470b17c5
7
- data.tar.gz: 56b1f76f086abb48c95e9a760af3d2cfc0f5e75bfe427119a74ebb990ef9e6d8fe1c69e559c9852eafa2db813546a0e461eb87449b8183ed4dc8639c18a324b6
6
+ metadata.gz: 1b70ff9cc671acae3f2c0242cd2745409fe7a04afee42b52886c8bbacf217ac8a218982d688790c2c3268e358ad2174a7412fa8eaf5df298dedc0d60799ff072
7
+ data.tar.gz: 75a010274b3cda722a3a87cdc98b8a99664bcc43504ce8440c022a611db5424befb2daf32f1dc14bb41fe7921ba84e17d9a84bc38fc533391cc4747fa08d3d69
data/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
  All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
3
3
 
4
4
  - - -
5
+ ## 2.1.0 - 2026-11-19
6
+ #### Features
7
+ - Custom nested attributes order by model (#32) - (42f80ad) - Marino Bonetti
8
+
9
+ - - -
10
+
11
+ ## 2.0.2 - 2026-10-15
12
+ #### Bug Fixes
13
+ - Aggiorna la dipendenza di ransack per supportare versioni maggiori (#31) - (014d9bd) - Marino Bonetti
14
+ - Order by when distinct==true in ransack (#30) - (d86854a) - Marino Bonetti
15
+
16
+ - - -
17
+
5
18
  ## 2.0.1 - 2026-09-17
6
19
  #### Bug Fixes
7
20
  - Correzione limitazione numero sub_elements in nested - (7cc9889) - Marino Bonetti
data/README.md CHANGED
@@ -289,6 +289,10 @@ Note:
289
289
  - nel caso di has_one: `XXXXX_attributes => [Array attributi da editare]`
290
290
  - Il permitted _destroy vale solamente nel caso in cui si definisca nei nested_attributes che debba essere cancellabile.
291
291
  - I campi visualizzati del modello sono presi dalla relativa policy.
292
+ - viene accettato e gestito il parametro :limit in modo che non sia possibile aggiungere più record di quelli definiti
293
+ nel modello sia a livello di ActiveRecord che a livello di UI
294
+ - è presente un metodo di classe `set_accept_nested_attributes_for_order`
295
+ che permette di definire l'ordine dei record nested attraverso l'uso di uno scope sulla relazione.
292
296
 
293
297
  Fai riferimento all'implementazione di esempio del dummy `Company->addresses`
294
298
 
@@ -431,6 +435,12 @@ docker compose up
431
435
  ./bin/local_ci_matrix.sh
432
436
  ```
433
437
 
438
+ ### Testare diverse versioni Rails e Ruby
439
+
440
+ ```bash
441
+ ./bin/local_ci_matrix.sh --rails 8.1 --ruby 4.0 --keep-docker-cache
442
+ ```
443
+
434
444
  ## License
435
445
 
436
446
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -16,6 +16,11 @@
16
16
  limit
17
17
  end
18
18
  end
19
+ fields_for_attributes = [field]
20
+ if(sorted_by = form.object.class.accept_nested_attributes_for_order(field))
21
+ # devo appendere la relazione con l'ordine degli elementi da renderizzare
22
+ fields_for_attributes<<form.object.public_send(field).public_send(sorted_by)
23
+ end
19
24
 
20
25
  %>
21
26
 
@@ -42,7 +47,7 @@
42
47
 
43
48
  <tbody>
44
49
 
45
- <%= form.fields_for field do |form_for_sections| %>
50
+ <%= form.fields_for(*fields_for_attributes) do |form_for_sections| %>
46
51
  <%= render "nested_row_form", form: form_for_sections %>
47
52
  <% end %>
48
53
 
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
  # Policy
34
34
  spec.add_dependency "pundit", ["~> 2.3", ">= 2.3.1"]
35
35
  # Search
36
- spec.add_dependency 'ransack', ['~> 4.0', '>= 4.0.0']
36
+ spec.add_dependency 'ransack', ['>= 4.0.0']
37
37
  # Pagination
38
38
  spec.add_dependency 'kaminari', ['~> 1.2', '>= 1.2.2']
39
39
  spec.add_dependency 'kaminari-i18n', '~> 0.5'
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.1.0
@@ -12,6 +12,7 @@ module BaseEditingBootstrap
12
12
  :ransackable_scopes, to: :@class
13
13
 
14
14
  class_attribute :_field_to_form_partial
15
+ class_attribute :_accept_nested_attributes_for_order
15
16
 
16
17
  ##
17
18
  # Label da utilizzare nelle option per quando si genera le select dei belongs to
@@ -64,6 +65,34 @@ module BaseEditingBootstrap
64
65
  self._field_to_form_partial.fetch(field, nil)
65
66
  end
66
67
 
68
+ ##
69
+ # Questo metodo serve per impostare l'ordinamento da applicare alla relazione has_many durante
70
+ # la creazione della form nel caso di accept_nested_attributes_for
71
+ # ES:
72
+ # has_many :imports do
73
+ # def ui_ordered
74
+ # order(ui_alias: :asc)
75
+ # end
76
+ # end
77
+ # accepts_nested_attributes_for :imports
78
+ # set_accept_nested_attributes_for_order(:imports, :ui_ordered)
79
+ # La firma del metodo è:
80
+ # set_accept_nested_attributes_for_order(association_name, order_method_name)
81
+ #
82
+ #
83
+ # E' presente anche un helper per i test:
84
+ #
85
+ # it_behaves_like "a model with custom accept_nested_attributes_for_order", :imports, :ui_ordered
86
+ def set_accept_nested_attributes_for_order(association_name, order_method_name)
87
+ self._accept_nested_attributes_for_order ||= {}
88
+ self._accept_nested_attributes_for_order = self._accept_nested_attributes_for_order.merge(association_name => order_method_name)
89
+ end
90
+
91
+ def accept_nested_attributes_for_order(field)
92
+ return nil unless self._accept_nested_attributes_for_order
93
+ self._accept_nested_attributes_for_order.fetch(field, nil)
94
+ end
95
+
67
96
  end
68
97
  end
69
98
  end
@@ -27,13 +27,41 @@ module BaseEditingBootstrap::Searches
27
27
  # Risultato della ricerca, fa da pipeline verso ransack
28
28
  # Impostando il sort nel caso in cui non sia già stato impostato da ransack
29
29
  def results
30
- ransack_query
31
- .tap { |r| r.sorts = @sorts if r.sorts.empty? }
32
- .result(distinct: @distinct)
30
+ query = ransack_query
31
+ query.sorts = @sorts if query.sorts.empty?
32
+
33
+ relation = query.result(distinct: @distinct)
34
+ relation = distinct_order_columns(relation, query.sorts) if @distinct && query.sorts.any?
35
+
36
+ relation
33
37
  .tap { |q| Rails.logger.debug { "[Ransack] params:#{params} - sql: #{q.to_sql}" } }
34
38
  .page(params[:page])
35
39
  end
36
40
 
41
+ # PostgreSQL richiede che le colonne usate nell'ORDER BY siano nel SELECT quando DISTINCT è attivo.
42
+ # Aggiungiamo solo le colonne provenienti dalle join, perché la tabella base è già coperta da `table.*`.
43
+ def distinct_order_columns(relation, sorts)
44
+ order_columns = sorts.filter_map do |sort|
45
+ next unless sort.valid?
46
+
47
+ attribute = sort.attr
48
+ next unless attribute.respond_to?(:relation) && attribute.respond_to?(:name)
49
+
50
+ table_name = attribute.relation.name
51
+ next if table_name.nil? || table_name == model_klass.table_name
52
+
53
+ "#{relation.connection.quote_table_name(table_name)}.#{relation.connection.quote_column_name(attribute.name)}"
54
+ end.uniq
55
+
56
+ return relation if order_columns.empty?
57
+
58
+ relation
59
+ .unscope(:select)
60
+ .select("#{relation.connection.quote_table_name(relation.klass.table_name)}.*", *order_columns)
61
+ end
62
+
63
+ private :distinct_order_columns
64
+
37
65
  def ransack_query
38
66
  scope
39
67
  .ransack(params[:q], auth_object: user)
@@ -95,4 +95,16 @@ RSpec.shared_examples "a model with custom field_to_form_partial" do |field, par
95
95
  expect(described_class.field_to_form_partial(anything)).to be_nil
96
96
  end
97
97
 
98
+ end
99
+
100
+ RSpec.shared_examples "a model with custom accept_nested_attributes_for_order" do |association,order_scope|
101
+
102
+ it "when #{association}" do
103
+ expect(described_class.accept_nested_attributes_for_order(association)).to eq order_scope
104
+ end
105
+
106
+ it "anything else" do
107
+ expect(described_class.accept_nested_attributes_for_order(anything)).to be_nil
108
+ end
109
+
98
110
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: base_editing_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marino Bonetti
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-11-19 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: rails
@@ -53,9 +54,6 @@ dependencies:
53
54
  name: ransack
54
55
  requirement: !ruby/object:Gem::Requirement
55
56
  requirements:
56
- - - "~>"
57
- - !ruby/object:Gem::Version
58
- version: '4.0'
59
57
  - - ">="
60
58
  - !ruby/object:Gem::Version
61
59
  version: 4.0.0
@@ -63,9 +61,6 @@ dependencies:
63
61
  prerelease: false
64
62
  version_requirements: !ruby/object:Gem::Requirement
65
63
  requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '4.0'
69
64
  - - ">="
70
65
  - !ruby/object:Gem::Version
71
66
  version: 4.0.0
@@ -443,6 +438,7 @@ licenses:
443
438
  metadata:
444
439
  source_code_uri: https://github.com/oniram88/BaseEditingBootstrap
445
440
  changelog_uri: https://github.com/oniram88/BaseEditingBootstrap/blob/main/CHANGELOG.md
441
+ post_install_message:
446
442
  rdoc_options: []
447
443
  require_paths:
448
444
  - lib
@@ -457,7 +453,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
457
453
  - !ruby/object:Gem::Version
458
454
  version: '0'
459
455
  requirements: []
460
- rubygems_version: 3.6.9
456
+ rubygems_version: 3.5.22
457
+ signing_key:
461
458
  specification_version: 4
462
459
  summary: 'BaseEditing: funzionalità di base per cms rails'
463
460
  test_files: []