base_editing_bootstrap 0.16.1 → 1.0.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: e764be908fc80fc7426404c064b407cd2b47239c30d81cb812f30d26e013e0c6
4
- data.tar.gz: ce54c97213e70582b4493632cfd9652e2a33c8774d91106854381af17119adda
3
+ metadata.gz: 92f7fc93b1d2aa476674d85893b5ac441887e2d5b889ce3f6520887dd8915240
4
+ data.tar.gz: af0568325773e2ca156be541734afcb3bccf7a214b8de2c98942b741071e2fa1
5
5
  SHA512:
6
- metadata.gz: ac4e714e64560dbaa5b5851e67ff3ac439cd9ec5aa2d21b8a5fa246e0850da6f45f641b892576343604ca01bfb3dc984e7afab63470f1818e53479f20e1c5aff
7
- data.tar.gz: ae23fcf542349cd98c4d4a1c9f6435261a54fa39c44fdf981e30f179319e04f1c6b0cdba4485acff348fa6fc8d0e0241b30e28d5f8f42f08a18b6fddfc73346a
6
+ metadata.gz: dd1ad3622c616b241a780e46e18ffdb4712d4d7975584e2fb4a0b0162dee9315acfef0d70f95fdf47b8b068436808aba2bcb975edc48c7b4e2744a42186b8140
7
+ data.tar.gz: c9b9bebec5692f48f2e283bdca287dc3a045787b54a7414013149c7ca3735c1b3018fbe7fae72ed4d97061c1c772626d8d1f2a821e95cb033e06cc634693adad
data/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
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.0.0 - 2024-11-26
6
+ #### Bug Fixes
7
+ - Remove fixed versions - (f8dc4b8) - Marino Bonetti
8
+ - Utilizziamo metodo di kaminari per totale pagine - (4451592) - Marino Bonetti
9
+ #### Documentation
10
+ - Add debug info for ransack - (e1355ef) - Marino Bonetti
11
+ #### Features
12
+ - Print header search results - (20fc7be) - Marino Bonetti
13
+ #### Miscellaneous Chores
14
+ - Rails 8.0 stable in test case - (87aff45) - Marino Bonetti
15
+ #### Tests
16
+ - Debugging - (663d5e9) - Marino Bonetti
17
+
18
+ - - -
19
+
5
20
  ## 0.16.1 - 2024-11-22
6
21
  #### Bug Fixes
7
22
  - Correct case when attribute to print is virtual - (b86e478) - Marino Bonetti
data/README.md CHANGED
@@ -133,6 +133,10 @@ Utilizzo per modello base, in questo esempio prendiamo come modello Post come es
133
133
  ```shell
134
134
  rails g base_editing_bootstrap:cell_override ModelName field1 field2:type
135
135
  ```
136
+ - [OPTIONAL] e per fare il rendering dell'header della tabella della index
137
+ ```shell
138
+ rails g base_editing_bootstrap:header_override ModelName field1 field2:type
139
+ ```
136
140
  - [OPTIONAL] Base overrides:
137
141
  E' possibile anche fare un override generico dei campi, sono previsti questi tipi di partial
138
142
  legati al tipo di dati:
@@ -30,35 +30,18 @@ module Utilities
30
30
  # @param [Symbol] field
31
31
  # @return [ActiveSupport::SafeBuffer]
32
32
  def render_cell_field(obj, field)
33
- generic_field = case field
34
- when :created_at, :updated_at
35
- "timestamps"
36
- else
37
- type = obj.class.type_for_attribute(field).type
38
- case type
39
- when :boolean
40
- "boolean"
41
- else
42
- "base"
43
- end
44
-
45
- end
46
- template = find_template_with_fallbacks(
47
- obj,
48
- field,
49
- "cell_field",
50
- generic_field
51
- )
33
+ template = template_for_column(obj.class, field, "cell_field")
52
34
  render template, obj:, field:
53
35
  end
54
36
 
55
37
  ##
56
38
  # Renderizza header della tabella della index
57
- # @param [BaseModel] obj
39
+ # @param [BaseEditingBootstrap::Searches::Base] search_instance
58
40
  # @param [Symbol] field
59
41
  # @return [ActiveSupport::SafeBuffer]
60
- def render_header_cell_field(obj, field)
61
- content_tag(:th, obj.human_attribute_name(field))
42
+ def render_header_cell_field(search_instance, field)
43
+ template = template_for_column(search_instance.model_klass, field, "header_field")
44
+ render template, obj: search_instance.model_klass, field:, search_instance: search_instance
62
45
  end
63
46
 
64
47
  ##
@@ -77,6 +60,33 @@ module Utilities
77
60
  def search_form_for_params(ransack_instance)
78
61
  [ransack_instance.ransack_query]
79
62
  end
63
+
64
+ private
65
+
66
+ ##
67
+ # Restituisce il template corretto per la tripletta, andando a ricercare il tipo di campo attraverso le informazioni
68
+ # che type_for_attribute può restituirci
69
+ def template_for_column(klazz, field, partial_type)
70
+ generic_field = case field
71
+ when :created_at, :updated_at
72
+ "timestamps"
73
+ else
74
+ type = klazz.type_for_attribute(field).type
75
+ case type
76
+ when :boolean
77
+ "boolean"
78
+ else
79
+ "base"
80
+ end
81
+
82
+ end
83
+ find_template_with_fallbacks(
84
+ klazz,
85
+ field,
86
+ partial_type,
87
+ generic_field
88
+ )
89
+ end
80
90
  end
81
91
  end
82
92
 
@@ -13,10 +13,14 @@ module Utilities::TemplateHelper
13
13
  # @param [String] base_path
14
14
  # @param [String] generic_field
15
15
  def find_template_with_fallbacks(obj, field, base_path, generic_field)
16
- obj_base_path = "#{obj.to_partial_path}/#{base_path}"
16
+ # nei casi in cui passiamo la classe e non l'oggetto, dobbiamo utilizzare un metodo interno a rails per
17
+ # avere la partial_path
18
+ partial_path = (obj.respond_to? :to_partial_path) ? obj.to_partial_path : obj._to_partial_path
19
+ obj_base_path = "#{partial_path}/#{base_path}"
17
20
  return "#{obj_base_path}/#{field}" if lookup_context.exists?(field, [obj_base_path], true)
18
21
  return "#{obj_base_path}/#{generic_field}" if lookup_context.exists?(generic_field, [obj_base_path], true)
19
- "base_editing/#{base_path}/#{generic_field}"
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
24
  end
21
25
 
22
26
  end
@@ -28,6 +28,12 @@ class BaseModelPolicy < ApplicationPolicy
28
28
 
29
29
  def search_result_fields = []
30
30
 
31
+ ##
32
+ # List of attributes in index to make it sortable
33
+ def sortable_search_result_fields
34
+ search_result_fields
35
+ end
36
+
31
37
  class Scope < Scope
32
38
  def resolve
33
39
  scope.all
@@ -5,7 +5,7 @@
5
5
  </div>
6
6
  <% end %>
7
7
 
8
- <% if @search_instance.results.count > 0 %>
8
+ <% if @search_instance.results.total_pages > 0 %>
9
9
  <div class="card-body table-responsive p-0">
10
10
  <%= render partial: "search_result" %>
11
11
  </div>
@@ -2,7 +2,7 @@
2
2
  <thead>
3
3
  <tr>
4
4
  <% @search_instance.search_result_fields.each do |srf| %>
5
- <%= render_header_cell_field(@search_instance.model_klass, srf) %>
5
+ <%= render_header_cell_field(@search_instance, srf) %>
6
6
  <% end %>
7
7
  <th class="action_col"></th>
8
8
  </tr>
@@ -0,0 +1,9 @@
1
+ <%# Renderizza il campo header della tabella della pagina dei risultati %>
2
+ <%# locals: (obj:,field:,search_instance:) -%>
3
+ <th scope="col">
4
+ <% if search_instance.sortable?(field) %>
5
+ <%= sort_link(search_instance.ransack_query, field, obj.human_attribute_name(field)) %>
6
+ <% else %>
7
+ <%= obj.human_attribute_name(field) %>
8
+ <% end %>
9
+ </th>
@@ -42,9 +42,9 @@ Gem::Specification.new do |spec|
42
42
  spec.add_development_dependency "factory_bot_rails", '~> 6.4'
43
43
  spec.add_development_dependency 'faker', '~> 3.3'
44
44
  spec.add_development_dependency "puma", '~> 6.4'
45
- spec.add_development_dependency "sqlite3", '>= 1.7.x'
45
+ spec.add_development_dependency "sqlite3"
46
46
  spec.add_development_dependency "sprockets-rails", '~> 3.4'
47
- spec.add_development_dependency 'rails-i18n', '~> 7.0' # For 7.0.0
47
+ spec.add_development_dependency 'rails-i18n'
48
48
  spec.add_development_dependency "i18n-debug", '~> 1.2'
49
49
  spec.add_development_dependency "cssbundling-rails", '~> 1.4'
50
50
  spec.add_development_dependency "rspec-parameterized", "~> 1.0", ">= 1.0.0" # https://github.com/tomykaira/rspec-parameterized
@@ -1 +1 @@
1
- 0.16.1
1
+ 1.0.0
@@ -24,9 +24,11 @@ module BaseEditingBootstrap::Searches
24
24
  # Risultato della ricerca, fa da pipeline verso ransack
25
25
  # Impostando il sort nel caso in cui non sia già stato impostato da ransack
26
26
  def results
27
- ransack_query.tap { |r|
28
- r.sorts = @sorts if r.sorts.empty?
29
- }.result(distinct: true).page(params[:page])
27
+ ransack_query
28
+ .tap { |r| r.sorts = @sorts if r.sorts.empty? }
29
+ .result(distinct: true)
30
+ .tap { |q| Rails.logger.debug { "[Ransack] params:#{params} - sql: #{q.to_sql}" } }
31
+ .page(params[:page])
30
32
  end
31
33
 
32
34
  def ransack_query
@@ -42,6 +44,12 @@ module BaseEditingBootstrap::Searches
42
44
  Pundit.policy(@user, @model_klass).search_result_fields
43
45
  end
44
46
 
47
+ ##
48
+ # Ritorna se il campo deve essere ordinabile o meno
49
+ def sortable?(field)
50
+ Pundit.policy(@user, @model_klass).sortable_search_result_fields.include?(field)
51
+ end
52
+
45
53
  def persisted?
46
54
  false
47
55
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BaseEditingBootstrap
4
+ module Generators
5
+ class HeaderOverrideGenerator < ::Rails::Generators::Base
6
+ source_root File.expand_path("../../../../app/views/base_editing", __dir__)
7
+ argument :name, type: :string, banner: "Post", required: true
8
+ argument :attributes, type: :array, default: [], banner: "field field:type"
9
+
10
+ TYPES = %i[base]
11
+
12
+ desc <<-DESCRIPTION.strip_heredoc
13
+ Description:
14
+ Copy partial files for a defined fields,
15
+ the possible types are #{TYPES}
16
+ Default to base
17
+ DESCRIPTION
18
+
19
+ def copy_form_partials
20
+ if attributes.empty?
21
+ say "Need one field"
22
+ else
23
+ singular_name = name.underscore.downcase.singularize
24
+ plural_name = singular_name.pluralize
25
+ attributes.each do |a|
26
+ attr_name, type = a.split(":")
27
+
28
+ type = :base if type.nil?
29
+ type = type.to_sym
30
+ raise "Type #{type} not found in #{TYPES}" unless TYPES.include?(type)
31
+ copy_file "header_field/_#{type}.html.erb", File.join("app/views", plural_name, singular_name, 'header_field', "_#{attr_name}.html.erb")
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -17,6 +17,26 @@ RSpec.shared_examples "a standard base model policy" do |factory, check_default_
17
17
  let(:user) { create(:user) }
18
18
  let(:instance) { described_class.new(user, build(factory)) }
19
19
 
20
+ describe "response to all necessary methods" do
21
+ where(:method) do
22
+ [
23
+ [:sortable_search_result_fields],
24
+ [:search_result_fields],
25
+ [:search_fields],
26
+ [:permitted_associations_for_ransack],
27
+ [:permitted_attributes_for_ransack],
28
+ [:editable_attributes],
29
+ [:permitted_attributes],
30
+ ]
31
+ end
32
+
33
+ with_them do
34
+ it "should " do
35
+ expect(instance).to respond_to(method)
36
+ end
37
+ end
38
+ end
39
+
20
40
  describe "standard_methods" do
21
41
  where(:method, :response) do
22
42
 
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: 0.16.1
4
+ version: 1.0.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: 2024-11-22 00:00:00.000000000 Z
11
+ date: 2024-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -166,14 +166,14 @@ dependencies:
166
166
  requirements:
167
167
  - - ">="
168
168
  - !ruby/object:Gem::Version
169
- version: 1.7.x
169
+ version: '0'
170
170
  type: :development
171
171
  prerelease: false
172
172
  version_requirements: !ruby/object:Gem::Requirement
173
173
  requirements:
174
174
  - - ">="
175
175
  - !ruby/object:Gem::Version
176
- version: 1.7.x
176
+ version: '0'
177
177
  - !ruby/object:Gem::Dependency
178
178
  name: sprockets-rails
179
179
  requirement: !ruby/object:Gem::Requirement
@@ -192,16 +192,16 @@ dependencies:
192
192
  name: rails-i18n
193
193
  requirement: !ruby/object:Gem::Requirement
194
194
  requirements:
195
- - - "~>"
195
+ - - ">="
196
196
  - !ruby/object:Gem::Version
197
- version: '7.0'
197
+ version: '0'
198
198
  type: :development
199
199
  prerelease: false
200
200
  version_requirements: !ruby/object:Gem::Requirement
201
201
  requirements:
202
- - - "~>"
202
+ - - ">="
203
203
  - !ruby/object:Gem::Version
204
- version: '7.0'
204
+ version: '0'
205
205
  - !ruby/object:Gem::Dependency
206
206
  name: i18n-debug
207
207
  requirement: !ruby/object:Gem::Requirement
@@ -342,6 +342,7 @@ files:
342
342
  - app/views/base_editing/form_field/_decimal.html.erb
343
343
  - app/views/base_editing/form_field/_enum.html.erb
344
344
  - app/views/base_editing/form_field/_integer.html.erb
345
+ - app/views/base_editing/header_field/_base.html.erb
345
346
  - app/views/base_editing/index.html.erb
346
347
  - app/views/base_editing/new.html.erb
347
348
  - app/views/base_editing/show.html.erb
@@ -369,6 +370,7 @@ files:
369
370
  - lib/base_editing_bootstrap/version.rb
370
371
  - lib/generators/base_editing_bootstrap/cell_override/cell_override_generator.rb
371
372
  - lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb
373
+ - lib/generators/base_editing_bootstrap/header_override/header_override_generator.rb
372
374
  - lib/generators/base_editing_bootstrap/install/USAGE
373
375
  - lib/generators/base_editing_bootstrap/install/install_generator.rb
374
376
  - lib/generators/base_editing_bootstrap/install/templates/initializer.rb
@@ -403,7 +405,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
403
405
  - !ruby/object:Gem::Version
404
406
  version: '0'
405
407
  requirements: []
406
- rubygems_version: 3.5.3
408
+ rubygems_version: 3.5.16
407
409
  signing_key:
408
410
  specification_version: 4
409
411
  summary: 'BaseEditing: funzionalità di base per cms rails'