base_editing_bootstrap 1.4.0 → 1.5.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 +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +30 -3
- data/app/helpers/utilities/form_helper.rb +10 -0
- data/app/helpers/utilities/search_helper.rb +8 -1
- data/app/views/base_editing/cell_field/_enum.html.erb +3 -0
- data/app/views/base_editing/form_field/_belongs_to_select.html.erb +6 -0
- data/app/views/base_editing/form_field/_enum.html.erb +1 -1
- data/lib/base_editing_bootstrap/VERSION +1 -1
- data/lib/base_editing_bootstrap/base_model.rb +8 -0
- data/lib/base_editing_bootstrap/searches/base.rb +9 -3
- data/spec/support/external_shared/base_model.rb +9 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6bf71d45d64bd942a3891d528a28a6ef9b300c31e5764aa27a2c26bd58b64a8
|
4
|
+
data.tar.gz: f2d6638d9c2db49c57f91883a4be6dc7aa5e4232c64b4b98304c3233c61e02bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b552e2dbb6d71861e4a073ee49a11cdceb3612ced84b4320661583e6c468020c17b8392790b7e87dfd7f0e8b05f7c94e4565b18921a43d0763e68b34da960e1
|
7
|
+
data.tar.gz: 351b8dd26cbaa739e9010d9b24d2721e554b7fdd3f478c5e5bce75717097fcc5ae377b26fadcbfec25b6d5d57b614f5881918a5f6148462fa4deb6a8f32f5fd0
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,17 @@
|
|
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.5.0 - 2025-01-16
|
6
|
+
#### Documentation
|
7
|
+
- Update documentation - (3a29e34) - Marino Bonetti
|
8
|
+
#### Features
|
9
|
+
- Render enum in index - (c520cd1) - Marino Bonetti
|
10
|
+
- Belongs_to Form fields - (6572b9f) - Marino Bonetti
|
11
|
+
#### Refactoring
|
12
|
+
- Estrapolazione policy in metodo - (711746b) - Marino Bonetti
|
13
|
+
|
14
|
+
- - -
|
15
|
+
|
5
16
|
## 1.4.0 - 2025-01-13
|
6
17
|
#### Bug Fixes
|
7
18
|
- Correct generator for values - (a83f07a) - Marino Bonetti
|
data/README.md
CHANGED
@@ -145,7 +145,20 @@ Utilizzo per modello base, in questo esempio prendiamo come modello Post come es
|
|
145
145
|
**Cell Field**:
|
146
146
|
- created_at => timestamps.html.erb
|
147
147
|
- updated_at => timestamps.html.erb
|
148
|
+
- Enum => _enum.html.erb
|
149
|
+
Per gli enum, le traduzioni dei labels di ogni valore provengono da i18n
|
150
|
+
attraverso l'helper: `Utilities::EnumHelper#enum_translation` con variant `:cell_field`
|
151
|
+
il quale sfrutta human_attribute_name del modello con 'attributo.enum_value',
|
152
|
+
quindi ad esempio per un modello `Post` con enum `categoria` e un enum `importante`, la ricerca nelle traduzioni
|
153
|
+
saranno così composte:
|
154
|
+
- it.activerecord.attributes.post/categoria.importante_cell_field
|
155
|
+
- it.activerecord.attributes.categoria.importante_cell_field
|
156
|
+
- it.attributes.importante_cell_field
|
157
|
+
- it.activerecord.attributes.post/categoria.importante
|
158
|
+
- it.activerecord.attributes.categoria.importante
|
159
|
+
- it.attributes.importante => nil
|
148
160
|
- default => base.html.erb
|
161
|
+
|
149
162
|
**Form Field**
|
150
163
|
- Integer => _integer.html.erb
|
151
164
|
- Float => _decimal.html.erb
|
@@ -154,9 +167,23 @@ Utilizzo per modello base, in questo esempio prendiamo come modello Post come es
|
|
154
167
|
- Date => _date.html.erb
|
155
168
|
- Boolean => _boolean.html.erb
|
156
169
|
- Enum => _enum.html.erb
|
157
|
-
Per gli enum, le traduzioni dei labels di ogni valore
|
158
|
-
attraverso l'helper: `Utilities::EnumHelper#enum_translation`
|
159
|
-
il quale
|
170
|
+
Per gli enum, le traduzioni dei labels di ogni valore provengono da i18n
|
171
|
+
attraverso l'helper: `Utilities::EnumHelper#enum_translation`" con variante `:form_field`
|
172
|
+
il quale sfrutta human_attribute_name del modello con 'attributo.enum_value',
|
173
|
+
quindi ad esempio per un modello `Post` con enum `categoria` e un enum `importante`, la ricerca nelle traduzioni
|
174
|
+
saranno così composte:
|
175
|
+
- it.activerecord.attributes.post/categoria.importante_form_field
|
176
|
+
- it.activerecord.attributes.categoria.importante_form_field
|
177
|
+
- it.attributes.importante_form_field
|
178
|
+
- it.activerecord.attributes.post/categoria.importante
|
179
|
+
- it.activerecord.attributes.categoria.importante
|
180
|
+
- it.attributes.importante => nil
|
181
|
+
- belongs_to => _belongs_to_select.html.erb
|
182
|
+
Come si può leggere dal partial, il modello che viene utilizzato come base dati per la collection deve
|
183
|
+
avere come metodo `option_label` che deve ritornare la label da utilizzare nelle options.
|
184
|
+
Di default questo metodo utilizza il semplice #to_s
|
185
|
+
Ha anche un metodo per il valore da utilizzare come chiave, di default viene dedotto dalla reflection
|
186
|
+
come anche il nome della classe da utilizzare come sorgente dei dati della collection
|
160
187
|
- Default/String => _base.html.erb
|
161
188
|
|
162
189
|
In futuro si prevede di aggiungere automatismi per renderizzare senza
|
@@ -3,6 +3,7 @@ module Utilities
|
|
3
3
|
include TemplateHelper
|
4
4
|
include EnumHelper
|
5
5
|
include IconHelper
|
6
|
+
include Pundit::Authorization
|
6
7
|
##
|
7
8
|
# Metodo su cui eseguire override per i campi specifici rispetto all'oggetto gestito dal controller
|
8
9
|
# @deprecated Utilizza form_print_field(form, field) senza sovrascriverlo
|
@@ -20,7 +21,16 @@ module Utilities
|
|
20
21
|
def form_print_field(form, field)
|
21
22
|
locals = {form:, field:}
|
22
23
|
if form.object.class.respond_to?(:defined_enums) && form.object.class.defined_enums.key?(field.to_s)
|
24
|
+
type = :enum
|
23
25
|
generic_field = "enum"
|
26
|
+
elsif form.object.class.respond_to?(:reflect_on_association) &&
|
27
|
+
form.object.class.reflect_on_association(field.to_s).is_a?(ActiveRecord::Reflection::BelongsToReflection)
|
28
|
+
# Abbiamo una relazione belongs_to da gestire
|
29
|
+
reflection = form.object.class.reflect_on_association(field.to_s)
|
30
|
+
type = :belongs_to
|
31
|
+
generic_field = "belongs_to_select"
|
32
|
+
locals[:relation_class] = reflection.klass
|
33
|
+
locals[:foreign_key] = reflection.foreign_key
|
24
34
|
else
|
25
35
|
if form.object.class.respond_to?(:type_for_attribute)
|
26
36
|
type = form.object.class.type_for_attribute(field).type
|
@@ -3,6 +3,7 @@ module Utilities
|
|
3
3
|
include TemplateHelper
|
4
4
|
include PageHelper
|
5
5
|
include IconHelper
|
6
|
+
include EnumHelper
|
6
7
|
|
7
8
|
##
|
8
9
|
# Per aggiungere bottoni:
|
@@ -71,10 +72,16 @@ module Utilities
|
|
71
72
|
when :created_at, :updated_at
|
72
73
|
"timestamps"
|
73
74
|
else
|
74
|
-
|
75
|
+
if klazz.respond_to?(:defined_enums) && klazz.defined_enums.key?(field.to_s)
|
76
|
+
type = :enum
|
77
|
+
else
|
78
|
+
type = klazz.type_for_attribute(field).type
|
79
|
+
end
|
75
80
|
case type
|
76
81
|
when :boolean
|
77
82
|
"boolean"
|
83
|
+
when :enum
|
84
|
+
"enum"
|
78
85
|
else
|
79
86
|
"base"
|
80
87
|
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<%# locals: (form:, field:,relation_class:,foreign_key:,value_method: :id, label_method: :option_label) -%>
|
2
|
+
<%= form.select(foreign_key, options_from_collection_for_select(policy_scope(relation_class),
|
3
|
+
value_method, label_method,
|
4
|
+
selected: form.object.send(foreign_key)),
|
5
|
+
include_blank: true
|
6
|
+
) %>
|
@@ -1,2 +1,2 @@
|
|
1
1
|
<%# locals: (form:, field:) -%>
|
2
|
-
<%= form.select(field, enum_collection(form.object.class, field)) %>
|
2
|
+
<%= form.select(field, enum_collection(form.object.class, field, :form_field)) %>
|
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.5.0
|
@@ -8,6 +8,14 @@ module BaseEditingBootstrap
|
|
8
8
|
include IsValidated
|
9
9
|
include ActionTranslation
|
10
10
|
delegate :ransackable_attributes, :ransackable_associations, to: :@class
|
11
|
+
|
12
|
+
|
13
|
+
##
|
14
|
+
# Label da utilizzare nelle option per quando si genera le select dei belongs to
|
15
|
+
# @return [String,NilClass]
|
16
|
+
def option_label
|
17
|
+
to_s
|
18
|
+
end
|
11
19
|
end
|
12
20
|
|
13
21
|
class_methods do
|
@@ -37,21 +37,27 @@ module BaseEditingBootstrap::Searches
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def search_fields
|
40
|
-
|
40
|
+
policy.search_fields.collect { |f| Field.new(self, f) }
|
41
41
|
end
|
42
42
|
|
43
43
|
def search_result_fields
|
44
|
-
|
44
|
+
policy.search_result_fields
|
45
45
|
end
|
46
46
|
|
47
47
|
##
|
48
48
|
# Ritorna se il campo deve essere ordinabile o meno
|
49
49
|
def sortable?(field)
|
50
|
-
|
50
|
+
policy.sortable_search_result_fields.include?(field)
|
51
51
|
end
|
52
52
|
|
53
53
|
def persisted?
|
54
54
|
false
|
55
55
|
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# @return [ApplicationPolicy]
|
59
|
+
def policy
|
60
|
+
Pundit.policy(@user, @model_klass)
|
61
|
+
end
|
56
62
|
end
|
57
63
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
RSpec.shared_examples "a base model" do |ransack_permitted_attributes: [], ransack_permitted_associations: []|
|
1
|
+
RSpec.shared_examples "a base model" do |ransack_permitted_attributes: [], ransack_permitted_associations: [], option_label_method: :to_s|
|
2
2
|
|
3
3
|
it_behaves_like "a validated? object"
|
4
4
|
|
@@ -6,6 +6,14 @@ RSpec.shared_examples "a base model" do |ransack_permitted_attributes: [], ransa
|
|
6
6
|
expect(described_class).to respond_to(:human_action_message)
|
7
7
|
end
|
8
8
|
|
9
|
+
it "have method for belongs_to options" do
|
10
|
+
instance = described_class.new
|
11
|
+
expect(instance).to respond_to(:option_label)
|
12
|
+
|
13
|
+
expect(instance).to receive(option_label_method).and_call_original
|
14
|
+
instance.option_label
|
15
|
+
end
|
16
|
+
|
9
17
|
##
|
10
18
|
# Oggetto solitamente di classe User che identifichi l'utente a cui eseguire il check dei permessi
|
11
19
|
let(:auth_object) { :auth_object }
|
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.
|
4
|
+
version: 1.5.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-
|
11
|
+
date: 2025-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -363,9 +363,11 @@ files:
|
|
363
363
|
- app/views/base_editing/_tabs.html.erb
|
364
364
|
- app/views/base_editing/cell_field/_base.html.erb
|
365
365
|
- app/views/base_editing/cell_field/_boolean.html.erb
|
366
|
+
- app/views/base_editing/cell_field/_enum.html.erb
|
366
367
|
- app/views/base_editing/cell_field/_timestamps.html.erb
|
367
368
|
- app/views/base_editing/edit.html.erb
|
368
369
|
- app/views/base_editing/form_field/_base.html.erb
|
370
|
+
- app/views/base_editing/form_field/_belongs_to_select.html.erb
|
369
371
|
- app/views/base_editing/form_field/_boolean.html.erb
|
370
372
|
- app/views/base_editing/form_field/_date.html.erb
|
371
373
|
- app/views/base_editing/form_field/_datetime.html.erb
|