base_editing_bootstrap 1.12.0 → 1.14.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 +24 -0
- data/README.md +51 -8
- data/app/assets/config/base_editing_bootstrap_manifest.js +1 -0
- data/app/assets/javascripts/nested_form_controller.js +48 -0
- data/app/helpers/utilities/form_helper.rb +9 -7
- data/app/helpers/utilities/template_helper.rb +18 -16
- data/app/views/base_editing/_nested_row_form.html.erb +1 -1
- data/app/views/base_editing/form_field/_accept_has_many_nested_field.html.erb +21 -1
- data/config/importmap.rb +2 -0
- data/lib/base_editing_bootstrap/VERSION +1 -1
- data/lib/base_editing_bootstrap/base_model.rb +20 -0
- data/lib/base_editing_bootstrap/engine.rb +8 -0
- data/lib/base_editing_bootstrap/forms/base.rb +16 -0
- data/lib/base_editing_bootstrap/logging.rb +14 -0
- data/lib/base_editing_bootstrap.rb +12 -6
- data/lib/generators/base_editing_bootstrap/install/install_generator.rb +3 -3
- data/lib/generators/base_editing_bootstrap/install/templates/initializer.rb +6 -0
- data/spec/support/external_shared/base_model.rb +12 -0
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 74db6610e2c8ab5c7f25de60eb6fb1c7ba1fa83570cd552a3356674356f02518
|
|
4
|
+
data.tar.gz: 8aea6970cecd4fa8623711b21d9ec77e2b2657757dfa94c91e94028b687a074e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5713323d93896548db8ee7fd75b187e5b7b6b61efb76c3855a92c79139eaa993af1a480a6cc1fe85c84a95e9b8af1f2c0dabe615ce14815728450bbd4390b10e
|
|
7
|
+
data.tar.gz: 1a6068cc2a7b296c4f8d0a3a20097efd9dddb1752bb6e5e4844053ec8f6997eac49183af26d6873949c44d4bce05235ebfb655f171d7c0d2e203a48bef8988ae
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
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.14.0 - 2026-03-19
|
|
6
|
+
#### Features
|
|
7
|
+
- Nested elements with limit from rails config (#24) - (f003ce4) - Marino Bonetti
|
|
8
|
+
#### Bug Fixes
|
|
9
|
+
- Correct nested_form when elements are marked for destruction - (9fd6544) - Marino Bonetti
|
|
10
|
+
|
|
11
|
+
- - -
|
|
12
|
+
|
|
13
|
+
## 1.13.0 - 2026-02-03
|
|
14
|
+
#### Features
|
|
15
|
+
- Form submit button inheritance value - (00b04b1) - Marino Bonetti
|
|
16
|
+
- Add customizability on model for form partial (#21) - (b7cead4) - Marino Bonetti
|
|
17
|
+
- Add BaseEditingBootstrap::Logging for form selection - (ecded89) - Marino Bonetti
|
|
18
|
+
#### Bug Fixes
|
|
19
|
+
- Warning escape - (1512271) - Marino Bonetti
|
|
20
|
+
- Correct submit text in case of not ActiveRecord - (6b658d4) - Marino Bonetti
|
|
21
|
+
#### Refactoring
|
|
22
|
+
- Replace `config_accessor` with `mattr_accessor` in BaseEditingBootstrap - (a4c3fb0) - Marino Bonetti
|
|
23
|
+
- BsLogging default tagging - (fbd4f2f) - Marino Bonetti
|
|
24
|
+
#### Miscellaneous Chores
|
|
25
|
+
- Add Ruby 4.0 as a valid version in matrix - (f32795e) - Marino Bonetti
|
|
26
|
+
|
|
27
|
+
- - -
|
|
28
|
+
|
|
5
29
|
## 1.12.0 - 2025-12-05
|
|
6
30
|
#### Features
|
|
7
31
|
- Add Capacity of custom disable action column - (4910fc3) - Marino Bonetti
|
data/README.md
CHANGED
|
@@ -35,16 +35,34 @@ $ bundle exec rails g base_editing_bootstrap:install
|
|
|
35
35
|
|
|
36
36
|
**Si presume quindi che ActiveStorage sia correttamente installato, completo del javascript per il direct upload**
|
|
37
37
|
|
|
38
|
+
### Upgrade Notes
|
|
39
|
+
- From <= 1.13:
|
|
40
|
+
In `app/javascript/controllers/application.js` replace:
|
|
41
|
+
```js
|
|
42
|
+
import RailsNestedForm from '@stimulus-components/rails-nested-form'
|
|
43
|
+
application.register('nested-form', RailsNestedForm)
|
|
44
|
+
```
|
|
45
|
+
with:
|
|
46
|
+
```js
|
|
47
|
+
import NestedForm from 'nested_form_controller';
|
|
48
|
+
application.register('nested-form', NestedForm);
|
|
49
|
+
```
|
|
50
|
+
in `config/importmap.rb` remove:
|
|
51
|
+
```ruby
|
|
52
|
+
pin "@stimulus-components/rails-nested-form"
|
|
53
|
+
```
|
|
54
|
+
and finaly remove in vendor/javascript the `@stimulus-components/rails-nested-form` downloaded dependencies
|
|
55
|
+
|
|
38
56
|
### Note for NestedAttributes
|
|
39
57
|
|
|
40
|
-
|
|
58
|
+
Il controller nested attributes viene importato da importmaps dell'engine.
|
|
59
|
+
E' necessagio registrare il nuovo controller in app/javascript/application.js
|
|
41
60
|
|
|
42
|
-
```
|
|
43
|
-
|
|
61
|
+
```js
|
|
62
|
+
import NestedForm from 'nested_form_controller'; // Mappato con import maps locale
|
|
63
|
+
application.register('nested-form', NestedForm); // Utilizzato nell'interfaccia della form.
|
|
44
64
|
```
|
|
45
65
|
|
|
46
|
-
e seguire installazione https://www.stimulus-components.com/docs/stimulus-rails-nested-form
|
|
47
|
-
|
|
48
66
|
### Generators
|
|
49
67
|
|
|
50
68
|
Then Install dependency (if you run base_editing_bootstrap:install you are good to go):
|
|
@@ -197,6 +215,19 @@ Utilizzo per modello base, in questo esempio prendiamo come modello Post come es
|
|
|
197
215
|
- default => base.html.erb
|
|
198
216
|
|
|
199
217
|
**Form Field**
|
|
218
|
+
- CUSTOM => Nel modello, richiamare il metodo di classe per impostare il partial per lo specifico campo,
|
|
219
|
+
dal punto di vista del helper per ricercare il partial corretto avverrà poi il normale iter di ricerca
|
|
220
|
+
fra namespace di classe e namespace di controller per trovare il corretto partial:
|
|
221
|
+
```ruby
|
|
222
|
+
class MyCustomModel < ApplicationRecord
|
|
223
|
+
include BaseEditingBootstrap::BaseModel
|
|
224
|
+
set_field_to_form_partial :title, :textarea
|
|
225
|
+
end
|
|
226
|
+
```
|
|
227
|
+
E' anche disponibile un helper per testare la corretta configurazione:
|
|
228
|
+
```ruby
|
|
229
|
+
it_behaves_like "a model with custom field_to_form_partial", :importo, :currency
|
|
230
|
+
```
|
|
200
231
|
- Integer => _integer.html.erb
|
|
201
232
|
- Float => _decimal.html.erb
|
|
202
233
|
- Decimal => _decimal.html.erb
|
|
@@ -230,8 +261,8 @@ Utilizzo per modello base, in questo esempio prendiamo come modello Post come es
|
|
|
230
261
|
nested attraverso quanto elencato nella policy dell'oggetto padre.
|
|
231
262
|
- Default/String => _base.html.erb
|
|
232
263
|
|
|
233
|
-
|
|
234
|
-
|
|
264
|
+
In futuro si prevede di aggiungere automatismi per renderizzare senza
|
|
265
|
+
l'intervento dell'utente dei campi.
|
|
235
266
|
- [OPTIONAL] Search Form:
|
|
236
267
|
Per poter aggiungere una form di ricerca basta aggiungere alla policy
|
|
237
268
|
del modello in questione i campi di ricerca che verranno poi utilizzati da ransack
|
|
@@ -263,10 +294,22 @@ Fai riferimento all'implementazione di esempio del dummy `Company->addresses`
|
|
|
263
294
|
|
|
264
295
|
### Translations
|
|
265
296
|
|
|
266
|
-
|
|
297
|
+
#### Index buttons:
|
|
267
298
|
Per i bottoni della index, è possibile eseguire l'override del testo presente nel bottone.
|
|
268
299
|
Leggere la documentazione nel file `app/helpers/base_editing_helper.rb#translate_with_controller_scoped`
|
|
269
300
|
|
|
301
|
+
#### Per i bottoni delle form(Submit):
|
|
302
|
+
E' possibile tradurre il contenuto del bottone andando ad impostare la traduzione direttamente in yml.
|
|
303
|
+
ES:
|
|
304
|
+
Con la class inheritance così composta: Remote < Base < ApplicationRecord < ActiveRecord::Base
|
|
305
|
+
per il bottone dell'oggetto Remote avremo questa ricerca:
|
|
306
|
+
1. en.helpers.submit.remote.create
|
|
307
|
+
2. en.helpers.submit.base.create
|
|
308
|
+
3. en.helpers.submit.create
|
|
309
|
+
|
|
310
|
+
In caso di oggetto persistente verrà ricercata la chiave finale `update`
|
|
311
|
+
|
|
312
|
+
|
|
270
313
|
## Testing helpers
|
|
271
314
|
|
|
272
315
|
### Requirements(installed with generators)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//= link nested_form_controller.js
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import NestedForm from "@stimulus-components/rails-nested-form"
|
|
2
|
+
|
|
3
|
+
// Connects to data-controller="nested-form"
|
|
4
|
+
export default class extends NestedForm {
|
|
5
|
+
|
|
6
|
+
static values = {
|
|
7
|
+
limit: Number,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
add(e) {
|
|
11
|
+
super.add(e);
|
|
12
|
+
this.check_for_enabling_add_button(e);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
remove(e) {
|
|
16
|
+
super.remove(e);
|
|
17
|
+
this.check_for_enabling_add_button(e);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Elenco elementi presenti visibili (e quindi non settati per essere cancellati)
|
|
21
|
+
total_active_elements() {
|
|
22
|
+
let count = 0;
|
|
23
|
+
|
|
24
|
+
this.targetTarget.parentElement.querySelectorAll(this.wrapperSelectorValue).forEach((ele) => {
|
|
25
|
+
if (ele.checkVisibility()) {
|
|
26
|
+
count += 1;
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
return count;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
check_for_enabling_add_button(e) {
|
|
33
|
+
if (this.hasLimitValue) {
|
|
34
|
+
if (this.total_active_elements() >= this.limitValue) {
|
|
35
|
+
// Aggiungiamo classe disable sull'elemento che ha lanciato questo evento
|
|
36
|
+
this.add_button().disabled = "disabled";
|
|
37
|
+
} else {
|
|
38
|
+
this.add_button().removeAttribute("disabled");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
add_button() {
|
|
44
|
+
return this.element.querySelector('[data-action="nested-form#add"]')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
}
|
|
@@ -4,6 +4,7 @@ module Utilities
|
|
|
4
4
|
include EnumHelper
|
|
5
5
|
include IconHelper
|
|
6
6
|
include Pundit::Authorization
|
|
7
|
+
include BaseEditingBootstrap::Logging
|
|
7
8
|
##
|
|
8
9
|
# Metodo su cui eseguire override per i campi specifici rispetto all'oggetto gestito dal controller
|
|
9
10
|
# @deprecated Utilizza form_print_field(form, field) senza sovrascriverlo
|
|
@@ -20,7 +21,9 @@ module Utilities
|
|
|
20
21
|
# @param [Symbol] field
|
|
21
22
|
def form_print_field(form, field)
|
|
22
23
|
locals = {form:, field:}
|
|
23
|
-
if form.object.class.respond_to?(:
|
|
24
|
+
if form.object.class.respond_to?(:field_to_form_partial) and (generic_field = form.object.class.field_to_form_partial(field))
|
|
25
|
+
type= :custom
|
|
26
|
+
elsif form.object.class.respond_to?(:defined_enums) && form.object.class.defined_enums.key?(field.to_s)
|
|
24
27
|
type = :enum
|
|
25
28
|
generic_field = "enum"
|
|
26
29
|
elsif form.object.class.respond_to?(:reflect_on_association) &&
|
|
@@ -88,13 +91,12 @@ module Utilities
|
|
|
88
91
|
"form_field",
|
|
89
92
|
generic_field
|
|
90
93
|
)
|
|
91
|
-
|
|
94
|
+
bs_logger.debug do
|
|
92
95
|
<<~TEXT
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
LOCALS:#{locals}
|
|
96
|
+
TYPE: #{type}
|
|
97
|
+
GENERIC_FIELD: #{generic_field}
|
|
98
|
+
TEMPLATE: #{template.short_identifier}
|
|
99
|
+
LOCALS:#{locals}
|
|
98
100
|
TEXT
|
|
99
101
|
end
|
|
100
102
|
template.render(self, locals)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Utilities::TemplateHelper
|
|
4
|
-
|
|
4
|
+
include BaseEditingBootstrap::Logging
|
|
5
5
|
##
|
|
6
6
|
# Ricerca template con fallbacks.
|
|
7
7
|
# In ordine, cerca di trovare il partial per l'oggetto(tramite il metodo to_partial_path) e il campo specifico.
|
|
@@ -30,21 +30,23 @@ module Utilities::TemplateHelper
|
|
|
30
30
|
start_class = start_class.superclass
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
bs_logger.tagged(field) do
|
|
34
|
+
[
|
|
35
|
+
# Precedenza modello e campo specifico
|
|
36
|
+
["Campo SPECIFICO + inheritance tra modelli", field, obj_base_paths],
|
|
37
|
+
# cerco tramite nome modello semplice, con namespace della risorsa (cell_field,header_field,form_field) e nome del campo specifico
|
|
38
|
+
["Campo specifico con nome modello + inheritance controllers", "#{obj.model_name.element}/#{base_path}/#{field}", lookup_context.prefixes],
|
|
39
|
+
# cerco struttura senza il livello del nome del modello
|
|
40
|
+
["Campo specifico senza nome modello + inheritance controllers", "#{base_path}/#{field}", lookup_context.prefixes],
|
|
41
|
+
# Ricerca tramite campo generico e prefissi di contesto che contiene anche controller e namespace di controller
|
|
42
|
+
["Campo GENERICO + inheritance controllers", "#{base_path}/#{generic_field}", lookup_context.prefixes],
|
|
43
|
+
["Campo GENERICO + inheritance tra modelli", generic_field, obj_base_paths],
|
|
44
|
+
["Default BaseEditingController", "base_editing/#{base_path}/#{generic_field}", []],
|
|
45
|
+
].each do |desc, partial, prefixes|
|
|
46
|
+
bs_logger.debug { "#{desc} - partial:`#{partial}` in #{prefixes.inspect}" }
|
|
47
|
+
if lookup_context.exists?(partial, prefixes, true)
|
|
48
|
+
return lookup_context.find(partial, prefixes, true)
|
|
49
|
+
end
|
|
48
50
|
end
|
|
49
51
|
end
|
|
50
52
|
# fallback finale
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<tr class="nested-form-wrapper" data-new-record="<%= form.object.new_record? %>" id="<%= dom_id(form.object) %>">
|
|
1
|
+
<tr class="nested-form-wrapper <%= (form.object.marked_for_destruction? ? "d-none" : "") %>" data-new-record="<%= form.object.new_record? %>" id="<%= dom_id(form.object) %>">
|
|
2
2
|
|
|
3
3
|
<% policy(form.object).editable_attributes.each do |field| %>
|
|
4
4
|
<td>
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
<%# locals: (form:, field:,new_object:) -%>
|
|
2
|
-
|
|
2
|
+
<%
|
|
3
|
+
|
|
4
|
+
##
|
|
5
|
+
# Costruisco le opzioni per limitare tramite interfaccia (ricevuta da configurazione di Rails nested_attributes_for)
|
|
6
|
+
# il numero di nested elements
|
|
7
|
+
controller_data = {controller: 'nested-form'}
|
|
8
|
+
if (limit = form.object.class.nested_attributes_options[field].dig(:limit))
|
|
9
|
+
controller_data["nested-form-limit-value"] = \
|
|
10
|
+
case limit
|
|
11
|
+
when Symbol #TODO add tests
|
|
12
|
+
form.object.class.send(limit)
|
|
13
|
+
when Proc #TODO add tests
|
|
14
|
+
limit.call
|
|
15
|
+
else
|
|
16
|
+
limit
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
%>
|
|
21
|
+
|
|
22
|
+
<%= content_tag :table, class: "table", data: controller_data do %>
|
|
3
23
|
|
|
4
24
|
<thead>
|
|
5
25
|
<tr>
|
data/config/importmap.rb
ADDED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.14.0
|
|
@@ -11,6 +11,7 @@ module BaseEditingBootstrap
|
|
|
11
11
|
:ransackable_associations,
|
|
12
12
|
:ransackable_scopes, to: :@class
|
|
13
13
|
|
|
14
|
+
class_attribute :_field_to_form_partial
|
|
14
15
|
|
|
15
16
|
##
|
|
16
17
|
# Label da utilizzare nelle option per quando si genera le select dei belongs to
|
|
@@ -44,6 +45,25 @@ module BaseEditingBootstrap
|
|
|
44
45
|
Pundit.policy(BaseEditingBootstrap.authentication_model.new, self.new).permitted_scopes_for_ransack.map(&:to_s)
|
|
45
46
|
end
|
|
46
47
|
end
|
|
48
|
+
|
|
49
|
+
##
|
|
50
|
+
# Questo metodo registra sulla classe la tuppla campo e partial per impostare il
|
|
51
|
+
# partial da utilizzare nel rendering
|
|
52
|
+
#
|
|
53
|
+
# E' presente anche un helper per i test:
|
|
54
|
+
#
|
|
55
|
+
# it_behaves_like "a model with custom field_to_form_partial", :importo, :currency
|
|
56
|
+
#
|
|
57
|
+
def set_field_to_form_partial(field, partial)
|
|
58
|
+
self._field_to_form_partial ||= {}
|
|
59
|
+
self._field_to_form_partial = self._field_to_form_partial.merge(field => partial)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def field_to_form_partial(field)
|
|
63
|
+
return nil unless self._field_to_form_partial
|
|
64
|
+
self._field_to_form_partial.fetch(field, nil)
|
|
65
|
+
end
|
|
66
|
+
|
|
47
67
|
end
|
|
48
68
|
end
|
|
49
69
|
end
|
|
@@ -5,5 +5,13 @@ module BaseEditingBootstrap
|
|
|
5
5
|
app.deprecators[:base_editing_bootstrap] = BaseEditingBootstrap.deprecator
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
+
initializer "base_editing_bootstrap.importmap", before: "importmap" do |app|
|
|
9
|
+
app.config.importmap.paths << Engine.root.join("config/importmap.rb")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
initializer "base_editing_bootstrap.assets.precompile" do |app|
|
|
13
|
+
app.config.assets.precompile << "nested_form_controller.js"
|
|
14
|
+
end
|
|
15
|
+
|
|
8
16
|
end
|
|
9
17
|
end
|
|
@@ -106,6 +106,22 @@ module BaseEditingBootstrap::Forms
|
|
|
106
106
|
# di seguire realmente il link con il browser.
|
|
107
107
|
def submit(value = nil, options = {})
|
|
108
108
|
@template.content_tag(:div, class: "btn-group mr-1") do
|
|
109
|
+
|
|
110
|
+
if value.nil? && object.respond_to?(:model_name)
|
|
111
|
+
key = object.respond_to?(:persisted?) ? (object.persisted? ? :update : :create) : :submit
|
|
112
|
+
defaults = []
|
|
113
|
+
tmp = object.class
|
|
114
|
+
while tmp != ::ActiveRecord::Base && tmp.respond_to?(:model_name)
|
|
115
|
+
defaults << :"helpers.submit.#{tmp.model_name.i18n_key}.#{key}"
|
|
116
|
+
tmp = tmp.superclass
|
|
117
|
+
end
|
|
118
|
+
defaults << :"helpers.submit.#{key}"
|
|
119
|
+
defaults << "_NOT_FOUND_TRANSLATION_"
|
|
120
|
+
|
|
121
|
+
value = I18n.translate(defaults.shift, model: object.model_name.human, default: defaults)
|
|
122
|
+
value = nil if value == "_NOT_FOUND_TRANSLATION_"
|
|
123
|
+
end
|
|
124
|
+
|
|
109
125
|
super(value, options.reverse_merge(class: "btn btn-primary")) +
|
|
110
126
|
@template.link_to(object.class.human_attribute_name(:_submit_undo, default: :undo),
|
|
111
127
|
@template.index_custom_polymorphic_path(object.class),
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BaseEditingBootstrap
|
|
4
|
+
module Logging
|
|
5
|
+
def bs_logger
|
|
6
|
+
@logger ||= begin
|
|
7
|
+
config_logger = BaseEditingBootstrap.logger
|
|
8
|
+
config_logger = config_logger || (defined?(Rails) ? Rails.logger : Logger.new($stdout))
|
|
9
|
+
ActiveSupport::TaggedLogging.new(config_logger).tagged("BASE EDITING BOOTSTRAP")
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -16,29 +16,31 @@ loader.ignore("#{__dir__}/generators")
|
|
|
16
16
|
loader.setup
|
|
17
17
|
|
|
18
18
|
module BaseEditingBootstrap
|
|
19
|
-
|
|
19
|
+
def self.configure
|
|
20
|
+
yield self
|
|
21
|
+
end
|
|
20
22
|
|
|
21
23
|
##
|
|
22
24
|
# Controller da cui derivare poi il BaseEditingController da cui derivano
|
|
23
25
|
# tutti i controller sottostanti
|
|
24
26
|
# @default "ApplicationController"
|
|
25
|
-
|
|
27
|
+
mattr_accessor :inherited_controller, default: "ApplicationController"
|
|
26
28
|
|
|
27
29
|
##
|
|
28
30
|
# Configurazione per alterare lo standard di azione post aggiornamento record
|
|
29
31
|
# il default è andare nella pagina di editing del record
|
|
30
32
|
# possibili valori :edit , :index
|
|
31
|
-
|
|
33
|
+
mattr_accessor :after_success_update_redirect, default: :edit
|
|
32
34
|
|
|
33
35
|
##
|
|
34
36
|
# Configurazione per alterare lo standard di azione post creazione record
|
|
35
37
|
# il default è andare nella pagina di editing del record
|
|
36
38
|
# possibili valori :edit , :index
|
|
37
|
-
|
|
39
|
+
mattr_accessor :after_success_create_redirect, default: :edit
|
|
38
40
|
|
|
39
41
|
##
|
|
40
42
|
# Classe che rappresenta l'utente, solitamente User
|
|
41
|
-
|
|
43
|
+
mattr_accessor :authentication_model_class, default: "User"
|
|
42
44
|
|
|
43
45
|
def self.authentication_model
|
|
44
46
|
self.authentication_model_class.constantize
|
|
@@ -46,12 +48,16 @@ module BaseEditingBootstrap
|
|
|
46
48
|
|
|
47
49
|
##
|
|
48
50
|
# Factory per la creazione del modello che rappresenta l'auteticazione
|
|
49
|
-
|
|
51
|
+
mattr_accessor :authentication_model_factory, default: :user
|
|
50
52
|
|
|
51
53
|
def self.deprecator
|
|
52
54
|
@deprecator ||= ActiveSupport::Deprecation.new("2.0", "BaseEditingBootstrap")
|
|
53
55
|
end
|
|
54
56
|
|
|
57
|
+
##
|
|
58
|
+
# Logger, default to Rails.logger
|
|
59
|
+
mattr_accessor :logger, default: nil
|
|
60
|
+
|
|
55
61
|
end
|
|
56
62
|
|
|
57
63
|
loader.eager_load
|
|
@@ -35,9 +35,9 @@ module BaseEditingBootstrap
|
|
|
35
35
|
# attualmente penso sia più sensato semplicemente scrivere a video i passaggi necessari, dato che
|
|
36
36
|
# potrebbe essere già presente importmap, nested_attribute_controller e le varie configurazioni
|
|
37
37
|
|
|
38
|
-
say "Install
|
|
39
|
-
say "
|
|
40
|
-
|
|
38
|
+
say "Install nested attributes controller, add to application.js:"
|
|
39
|
+
say " import NestedForm from 'nested_form_controller' \n
|
|
40
|
+
application.register('nested-form', NestedForm)"
|
|
41
41
|
|
|
42
42
|
end
|
|
43
43
|
end
|
|
@@ -27,4 +27,10 @@ BaseEditingBootstrap.configure do |config|
|
|
|
27
27
|
# Factory per la creazione del modello che rappresenta l'auteticazione
|
|
28
28
|
# config.authentication_model_factory= :user
|
|
29
29
|
|
|
30
|
+
##
|
|
31
|
+
# Logger, default to Rails.logger
|
|
32
|
+
# @default to Rails.logger or STDOUT if no Rails.logger
|
|
33
|
+
# config.logger = ActiveSupport::TaggedLogging.logger($stdout)
|
|
34
|
+
# config.logger = Rails.logger
|
|
35
|
+
|
|
30
36
|
end
|
|
@@ -84,3 +84,15 @@ RSpec.shared_examples "a validated? object" do
|
|
|
84
84
|
it { is_expected.to be_validated }
|
|
85
85
|
end
|
|
86
86
|
end
|
|
87
|
+
|
|
88
|
+
RSpec.shared_examples "a model with custom field_to_form_partial" do |field, partial|
|
|
89
|
+
|
|
90
|
+
it "when #{field}" do
|
|
91
|
+
expect(described_class.field_to_form_partial(field)).to eq partial
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "anything else" do
|
|
95
|
+
expect(described_class.field_to_form_partial(anything)).to be_nil
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
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.14.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:
|
|
11
|
+
date: 2026-03-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -320,6 +320,7 @@ files:
|
|
|
320
320
|
- README.md
|
|
321
321
|
- Rakefile
|
|
322
322
|
- app/assets/config/base_editing_bootstrap_manifest.js
|
|
323
|
+
- app/assets/javascripts/nested_form_controller.js
|
|
323
324
|
- app/controllers/.keep
|
|
324
325
|
- app/controllers/base_editing_controller.rb
|
|
325
326
|
- app/controllers/restricted_area_controller.rb
|
|
@@ -389,6 +390,7 @@ files:
|
|
|
389
390
|
- app/views/kaminari/_paginator.html.erb
|
|
390
391
|
- app/views/kaminari/_prev_page.html.erb
|
|
391
392
|
- base_editing_bootstrap.gemspec
|
|
393
|
+
- config/importmap.rb
|
|
392
394
|
- config/initializers/base_field_error_proc.rb
|
|
393
395
|
- config/locales/it.yml
|
|
394
396
|
- config/routes.rb
|
|
@@ -400,6 +402,7 @@ files:
|
|
|
400
402
|
- lib/base_editing_bootstrap/forms/base.rb
|
|
401
403
|
- lib/base_editing_bootstrap/generators_helpers.rb
|
|
402
404
|
- lib/base_editing_bootstrap/is_validated.rb
|
|
405
|
+
- lib/base_editing_bootstrap/logging.rb
|
|
403
406
|
- lib/base_editing_bootstrap/resource_finder.rb
|
|
404
407
|
- lib/base_editing_bootstrap/searches/base.rb
|
|
405
408
|
- lib/base_editing_bootstrap/searches/field.rb
|