base_editing_bootstrap 1.5.0 → 1.6.0

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: e6bf71d45d64bd942a3891d528a28a6ef9b300c31e5764aa27a2c26bd58b64a8
4
- data.tar.gz: f2d6638d9c2db49c57f91883a4be6dc7aa5e4232c64b4b98304c3233c61e02bb
3
+ metadata.gz: 0f292b335541e77a9d78ae97f8ef87cc436468094aaccd69750dae0f8dcf44af
4
+ data.tar.gz: 7c3f97b3261d736258efc021f36cc131943763b13f7d933cfb0967cbf58e5f36
5
5
  SHA512:
6
- metadata.gz: 0b552e2dbb6d71861e4a073ee49a11cdceb3612ced84b4320661583e6c468020c17b8392790b7e87dfd7f0e8b05f7c94e4565b18921a43d0763e68b34da960e1
7
- data.tar.gz: 351b8dd26cbaa739e9010d9b24d2721e554b7fdd3f478c5e5bce75717097fcc5ae377b26fadcbfec25b6d5d57b614f5881918a5f6148462fa4deb6a8f32f5fd0
6
+ metadata.gz: 3ec5909dab19b68590b2e2beb5dbcf7b502f2bbeb9ae3c2c244117837c4eeb54d20848ca30381f0cae4c88f6047bf3d55c2dfeef37dd28623b7b59933970e33c
7
+ data.tar.gz: dbaca2890a7a8a6ea1f9cde44fcd6d07495a6f289ba82f62698cc8b9cac6bfe20809133590ca05c91cecd1078ea7ce4a87087c0501e52570146eca17efd65486
data/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
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
+ ## 1.6.0 - 2025-01-23
6
+ #### Features
7
+ - Add new test helper for association relation - (15690c7) - Marino Bonetti
8
+ #### Tests
9
+ - Fix association for order - (9e2bdd4) - Marino Bonetti
10
+ - Example order by ransack - (79cccc7) - Marino Bonetti
11
+
12
+ - - -
13
+
14
+ ## 1.5.1 - 2025-01-22
15
+ #### Bug Fixes
16
+ - Ricerca template anche con contesto del controller - (ac93a9f) - Marino Bonetti
17
+ #### Miscellaneous Chores
18
+ - Remove unused files - (0b56f94) - Marino Bonetti
19
+
20
+ - - -
21
+
5
22
  ## 1.5.0 - 2025-01-16
6
23
  #### Documentation
7
24
  - Update documentation - (3a29e34) - Marino Bonetti
@@ -71,8 +71,8 @@ module Utilities
71
71
  "form_field",
72
72
  generic_field
73
73
  )
74
- Rails.logger.debug { "#{type}->#{generic_field}->#{template}->#{ locals.inspect}" }
75
- render template, **locals
74
+ Rails.logger.debug { "#{type}->#{generic_field}->#{template.short_identifier}->#{ locals.inspect}" }
75
+ template.render(self, locals)
76
76
  end
77
77
 
78
78
  end
@@ -32,7 +32,7 @@ module Utilities
32
32
  # @return [ActiveSupport::SafeBuffer]
33
33
  def render_cell_field(obj, field)
34
34
  template = template_for_column(obj.class, field, "cell_field")
35
- render template, obj:, field:
35
+ template.render(self,{obj:, field:})
36
36
  end
37
37
 
38
38
  ##
@@ -42,7 +42,7 @@ module Utilities
42
42
  # @return [ActiveSupport::SafeBuffer]
43
43
  def render_header_cell_field(search_instance, field)
44
44
  template = template_for_column(search_instance.model_klass, field, "header_field")
45
- render template, obj: search_instance.model_klass, field:, search_instance: search_instance
45
+ template.render(self,{obj: search_instance.model_klass, field:, search_instance: search_instance})
46
46
  end
47
47
 
48
48
  ##
@@ -17,10 +17,23 @@ module Utilities::TemplateHelper
17
17
  # avere la partial_path
18
18
  partial_path = (obj.respond_to? :to_partial_path) ? obj.to_partial_path : obj._to_partial_path
19
19
  obj_base_path = "#{partial_path}/#{base_path}"
20
- return "#{obj_base_path}/#{field}" if lookup_context.exists?(field, [obj_base_path], true)
21
- return "#{obj_base_path}/#{generic_field}" if lookup_context.exists?(generic_field, [obj_base_path], true)
22
- return "base_editing/#{base_path}/#{generic_field}" if lookup_context.find_all("base_editing/#{base_path}/_#{generic_field}").any?
23
- "base_editing/#{base_path}/base"
20
+
21
+ # Precedenza modello e campo specifico
22
+ if lookup_context.exists?(field, [obj_base_path], true)
23
+ return lookup_context.find(field, [obj_base_path], true)
24
+ end
25
+ # Ricerca tramite campo generico e prefissi di contesto che contiene anche controller e namespace di controller
26
+ if lookup_context.exists?("#{base_path}/#{generic_field}", lookup_context.prefixes, true)
27
+ view = lookup_context.find_all("#{base_path}/#{generic_field}", lookup_context.prefixes, true)
28
+ return view.first
29
+ end
30
+ if lookup_context.exists?(generic_field, [obj_base_path], true)
31
+ return lookup_context.find(generic_field, [obj_base_path], true)
32
+ end
33
+ if lookup_context.exists?("base_editing/#{base_path}/#{generic_field}", [], true)
34
+ return lookup_context.find_all("base_editing/#{base_path}/#{generic_field}", [], true).first
35
+ end
36
+ lookup_context.find("base_editing/#{base_path}/base", [], true)
24
37
  end
25
38
 
26
39
  end
@@ -1 +1 @@
1
- 1.5.0
1
+ 1.6.0
@@ -37,6 +37,47 @@ RSpec.shared_examples "a standard base model policy" do |factory, check_default_
37
37
  end
38
38
  end
39
39
 
40
+ # Controllo che se negli elementi dei #sortable_search_result_fields è presente un elemento
41
+ # che ha come prefisso il nome di una relazione presente in #permitted_associations_for_ransack
42
+ # allora nella policy della relativa associazione dovrò trovare in #permitted_attributes_for_ransack
43
+ # il nome della colonna da ordinare.
44
+ # ES:
45
+ # relazione: User -> Post
46
+ # class PostPolicy
47
+ # def sortable_search_result_fields = %i[user_username]
48
+ # def permitted_associations_for_ransack = %i[user]
49
+ # end
50
+ # class UserPolicy
51
+ # def permitted_attributes_for_ransack = %[username]
52
+ # end
53
+ # ordinamento per #user_username, quindi devo cercare relazione in `user` e attribute `username`
54
+ it "check associated sortable attributes" do
55
+ klass = instance.record.class
56
+ # non facciamo nulla se non è un active record il record da controllare
57
+ if klass.respond_to?(:reflect_on_association)
58
+
59
+ # escludiamo le colonne del modello
60
+ col_to_check = (instance.sortable_search_result_fields.collect(&:to_s) - instance.record.class.column_names).uniq
61
+
62
+ elenco_campi_ordinabili_in_relazione = col_to_check.map do |field|
63
+ instance.permitted_associations_for_ransack.map do |rel|
64
+ if field.match(/^#{rel}_(.*)$/)
65
+ [rel, Regexp.last_match(1)]
66
+ end
67
+ end
68
+ end.flatten(1).compact.uniq
69
+
70
+ elenco_campi_ordinabili_in_relazione.each do |relation,field|
71
+ reflection = klass.reflect_on_association(relation.to_s)
72
+ policy = Pundit.policy(instance.user, reflection.class_name.constantize.new)
73
+ expect(policy.permitted_attributes_for_ransack.collect(&:to_sym).include?(field.to_sym)).to be_truthy, lambda{
74
+ "Mi aspetto che `#{policy.class.name}#permitted_attributes_for_ransack` includa `#{field}` per permettere l'ordinamento del campo tramite relazione"
75
+ }
76
+ end
77
+
78
+ end
79
+ end
80
+
40
81
  describe "standard_methods" do
41
82
  where(:method, :response) do
42
83
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: base_editing_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marino Bonetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-16 00:00:00.000000000 Z
11
+ date: 2025-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -320,11 +320,8 @@ files:
320
320
  - README.md
321
321
  - Rakefile
322
322
  - app/assets/config/base_editing_bootstrap_manifest.js
323
- - app/assets/images/base_editing_bootstrap/.keep
324
- - app/assets/stylesheets/base_editing_bootstrap/.keep
325
323
  - app/controllers/.keep
326
324
  - app/controllers/base_editing_controller.rb
327
- - app/controllers/concerns/.keep
328
325
  - app/controllers/restricted_area_controller.rb
329
326
  - app/helpers/.keep
330
327
  - app/helpers/base_editing_helper.rb
@@ -334,10 +331,6 @@ files:
334
331
  - app/helpers/utilities/page_helper.rb
335
332
  - app/helpers/utilities/search_helper.rb
336
333
  - app/helpers/utilities/template_helper.rb
337
- - app/jobs/.keep
338
- - app/mailers/.keep
339
- - app/models/.keep
340
- - app/models/concerns/.keep
341
334
  - app/policies/base_model_policy.rb
342
335
  - app/views/.keep
343
336
  - app/views/base_editing/_edit_page_title_header.html.erb
File without changes
File without changes
File without changes
data/app/jobs/.keep DELETED
File without changes
data/app/mailers/.keep DELETED
File without changes
data/app/models/.keep DELETED
File without changes
File without changes