active_fields 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +6 -0
  4. data/README.md +92 -77
  5. data/app/models/concerns/active_fields/customizable_concern.rb +4 -1
  6. data/lib/active_fields/engine.rb +6 -0
  7. data/lib/active_fields/version.rb +1 -1
  8. data/lib/active_fields.rb +51 -31
  9. data/lib/generators/active_fields/install/install_generator.rb +1 -1
  10. data/lib/generators/active_fields/scaffold/USAGE +9 -0
  11. data/lib/generators/active_fields/scaffold/scaffold_generator.rb +25 -0
  12. data/lib/generators/active_fields/scaffold/templates/controllers/active_fields_controller.rb +143 -0
  13. data/lib/generators/active_fields/scaffold/templates/helpers/active_fields_helper.rb +33 -0
  14. data/lib/generators/active_fields/scaffold/templates/javascript/controllers/array_field_controller.js +25 -0
  15. data/lib/generators/active_fields/scaffold/templates/views/active_fields/edit.html.erb +5 -0
  16. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_boolean.html.erb +53 -0
  17. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_date.html.erb +58 -0
  18. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_date_array.html.erb +70 -0
  19. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_datetime.html.erb +63 -0
  20. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_datetime_array.html.erb +75 -0
  21. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_decimal.html.erb +63 -0
  22. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_decimal_array.html.erb +76 -0
  23. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_enum.html.erb +61 -0
  24. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_enum_array.html.erb +73 -0
  25. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_integer.html.erb +58 -0
  26. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_integer_array.html.erb +70 -0
  27. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_text.html.erb +53 -0
  28. data/lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_text_array.html.erb +70 -0
  29. data/lib/generators/active_fields/scaffold/templates/views/active_fields/index.html.erb +41 -0
  30. data/lib/generators/active_fields/scaffold/templates/views/active_fields/new.html.erb +5 -0
  31. data/lib/generators/active_fields/scaffold/templates/views/active_fields/show.html.erb +29 -0
  32. data/lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_boolean.html.erb +8 -0
  33. data/lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_date.html.erb +4 -0
  34. data/lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_date_array.html.erb +12 -0
  35. data/lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_datetime.html.erb +4 -0
  36. data/lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_datetime_array.html.erb +12 -0
  37. data/lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_decimal.html.erb +4 -0
  38. data/lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_decimal_array.html.erb +12 -0
  39. data/lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_enum.html.erb +4 -0
  40. data/lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_enum_array.html.erb +4 -0
  41. data/lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_integer.html.erb +4 -0
  42. data/lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_integer_array.html.erb +12 -0
  43. data/lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_text.html.erb +4 -0
  44. data/lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_text_array.html.erb +12 -0
  45. data/lib/generators/active_fields/scaffold/templates/views/shared/_array_field.html.erb +19 -0
  46. metadata +39 -3
@@ -0,0 +1,70 @@
1
+ <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
2
+ <% if active_field.errors.any? %>
3
+ <div style="color: red">
4
+ <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
5
+
6
+ <ul>
7
+ <% active_field.errors.each do |error| %>
8
+ <li><%= error.full_message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div>
15
+ <%= f.label :type %>
16
+ <%=
17
+ f.text_field :type,
18
+ name: "type",
19
+ value: active_field.type_name,
20
+ disabled: active_field.persisted?,
21
+ readonly: active_field.new_record?
22
+ %>
23
+ </div>
24
+
25
+ <div>
26
+ <%= f.label :customizable_type %>
27
+ <%= f.select :customizable_type, ["TODO: add allowed customizable model names"], {}, { disabled: active_field.persisted? } %>
28
+ </div>
29
+
30
+ <div>
31
+ <%= f.label :name %>
32
+ <%= f.text_field :name %>
33
+ </div>
34
+
35
+ <div>
36
+ <%= f.label :min_size %>
37
+ <%= f.number_field :min_size, disabled: active_field.persisted? %>
38
+ </div>
39
+
40
+ <div>
41
+ <%= f.label :max_size %>
42
+ <%= f.number_field :max_size, disabled: active_field.persisted? %>
43
+ </div>
44
+
45
+ <div>
46
+ <%= f.label :min %>
47
+ <%= f.number_field :min, disabled: active_field.persisted? %>
48
+ </div>
49
+
50
+ <div>
51
+ <%= f.label :max %>
52
+ <%= f.number_field :max, disabled: active_field.persisted? %>
53
+ </div>
54
+
55
+ <div>
56
+ <%= f.label :default_value %>
57
+ <%=
58
+ render_array_field(
59
+ form: f,
60
+ name: :default_value,
61
+ value: active_field.default_value,
62
+ field_method: :number_field,
63
+ )
64
+ %>
65
+ </div>
66
+
67
+ <div>
68
+ <%= f.submit %>
69
+ </div>
70
+ <% end %>
@@ -0,0 +1,53 @@
1
+ <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
2
+ <% if active_field.errors.any? %>
3
+ <div style="color: red">
4
+ <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
5
+
6
+ <ul>
7
+ <% active_field.errors.each do |error| %>
8
+ <li><%= error.full_message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div>
15
+ <%= f.label :type %>
16
+ <%=
17
+ f.text_field :type,
18
+ name: "type",
19
+ value: active_field.type_name,
20
+ disabled: active_field.persisted?,
21
+ readonly: active_field.new_record?
22
+ %>
23
+ </div>
24
+
25
+ <div>
26
+ <%= f.label :customizable_type %>
27
+ <%= f.select :customizable_type, ["TODO: add allowed customizable model names"], {}, { disabled: active_field.persisted? } %>
28
+ </div>
29
+
30
+ <div>
31
+ <%= f.label :name %>
32
+ <%= f.text_field :name %>
33
+ </div>
34
+
35
+ <div>
36
+ <%= f.label :min_length %>
37
+ <%= f.number_field :min_length, disabled: active_field.persisted? %>
38
+ </div>
39
+
40
+ <div>
41
+ <%= f.label :max_length %>
42
+ <%= f.number_field :max_length, disabled: active_field.persisted? %>
43
+ </div>
44
+
45
+ <div>
46
+ <%= f.label :default_value %>
47
+ <%= f.text_field :default_value %>
48
+ </div>
49
+
50
+ <div>
51
+ <%= f.submit %>
52
+ </div>
53
+ <% end %>
@@ -0,0 +1,70 @@
1
+ <%= form_with(model: active_field, scope: :active_field, url: active_field.persisted? ? active_field_path(active_field) : active_fields_path) do |f| %>
2
+ <% if active_field.errors.any? %>
3
+ <div style="color: red">
4
+ <h2><%= pluralize(active_field.errors.count, "error") %> prohibited this record from being saved:</h2>
5
+
6
+ <ul>
7
+ <% active_field.errors.each do |error| %>
8
+ <li><%= error.full_message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div>
15
+ <%= f.label :type %>
16
+ <%=
17
+ f.text_field :type,
18
+ name: "type",
19
+ value: active_field.type_name,
20
+ disabled: active_field.persisted?,
21
+ readonly: active_field.new_record?
22
+ %>
23
+ </div>
24
+
25
+ <div>
26
+ <%= f.label :customizable_type %>
27
+ <%= f.select :customizable_type, ["TODO: add allowed customizable model names"], {}, { disabled: active_field.persisted? } %>
28
+ </div>
29
+
30
+ <div>
31
+ <%= f.label :name %>
32
+ <%= f.text_field :name %>
33
+ </div>
34
+
35
+ <div>
36
+ <%= f.label :min_size %>
37
+ <%= f.number_field :min_size, disabled: active_field.persisted? %>
38
+ </div>
39
+
40
+ <div>
41
+ <%= f.label :max_size %>
42
+ <%= f.number_field :max_size, disabled: active_field.persisted? %>
43
+ </div>
44
+
45
+ <div>
46
+ <%= f.label :min_length %>
47
+ <%= f.number_field :min_length, disabled: active_field.persisted? %>
48
+ </div>
49
+
50
+ <div>
51
+ <%= f.label :max_length %>
52
+ <%= f.number_field :max_length, disabled: active_field.persisted? %>
53
+ </div>
54
+
55
+ <div>
56
+ <%= f.label :default_value %>
57
+ <%=
58
+ render_array_field(
59
+ form: f,
60
+ name: :default_value,
61
+ value: active_field.default_value,
62
+ field_method: :text_field,
63
+ )
64
+ %>
65
+ </div>
66
+
67
+ <div>
68
+ <%= f.submit %>
69
+ </div>
70
+ <% end %>
@@ -0,0 +1,41 @@
1
+ <h1>Active Fields</h1>
2
+
3
+ <div>
4
+ <%= form_with url: new_active_field_path, method: :get do |f| %>
5
+ <span>
6
+ <%= f.select :type, ActiveFields.config.type_names %>
7
+ </span>
8
+ <span>
9
+ <%= f.submit "New" %>
10
+ </span>
11
+ <% end %>
12
+ </div>
13
+
14
+ <table>
15
+ <thead>
16
+ <tr>
17
+ <th></th>
18
+ <th>ID</th>
19
+ <th>Type</th>
20
+ <th>Customizable type</th>
21
+ <th>Name</th>
22
+ <th>Options</th>
23
+ <th>Default value</th>
24
+ <th></th>
25
+ </tr>
26
+ </thead>
27
+ <tbody>
28
+ <% @active_fields.each do |active_field| %>
29
+ <tr>
30
+ <td><%= link_to "Edit", edit_active_field_path(active_field) %></td>
31
+ <td><%= link_to "##{active_field.id}", active_field_path(active_field) %></td>
32
+ <td><%= active_field.type_name %></td>
33
+ <td><%= active_field.customizable_type %></td>
34
+ <td><%= active_field.name %></td>
35
+ <td><code><%= active_field.options %></code></td>
36
+ <td><code><%= active_field.default_value.inspect %></code></td>
37
+ <td><%= button_to "Destroy", active_field_path(active_field), method: :delete %></td>
38
+ </tr>
39
+ <% end %>
40
+ </tbody>
41
+ </table>
@@ -0,0 +1,5 @@
1
+ <h1>New Active Field</h1>
2
+
3
+ <%= render_active_field_form(active_field: @active_field) %>
4
+
5
+ <div><%= link_to "Back", active_fields_path %></div>
@@ -0,0 +1,29 @@
1
+ <h1>Active Field #<%= @active_field.id %></h1>
2
+
3
+ <p><%= link_to "Edit", edit_active_field_path(@active_field) %></p>
4
+ <p><%= button_to "Destroy", active_field_path(@active_field), method: :delete %></p>
5
+
6
+ <p>
7
+ <b>ID:</b>
8
+ <%= @active_field.id %>
9
+ </p>
10
+ <p>
11
+ <b>Type:</b> <%= @active_field.type_name %>
12
+ </p>
13
+ <p>
14
+ <b>Customizable type:</b>
15
+ <%= @active_field.customizable_type %>
16
+ </p>
17
+ <p>
18
+ <b>Name:</b> <%= @active_field.name %>
19
+ </p>
20
+ <p>
21
+ <b>Options:</b>
22
+ <code><%= @active_field.options %></code>
23
+ </p>
24
+ <p>
25
+ <b>Default value:</b>
26
+ <code><%= @active_field.default_value.inspect %></code>
27
+ </p>
28
+
29
+ <div><%= link_to "Back", active_fields_path %></div>
@@ -0,0 +1,8 @@
1
+ <div>
2
+ <%= form.label :value, active_field.name %>
3
+ <% if active_field.nullable? %>
4
+ <%= form.collection_radio_buttons :value, { "Null" => "", "True" => "true", "False" => "false" }, :last, :first, { checked: active_value.value.to_s }, {} %>
5
+ <% else %>
6
+ <%= form.check_box :value, { checked: active_value.value }, "true", "false" %>
7
+ <% end %>
8
+ </div>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <%= form.label :value, active_field.name %>
3
+ <%= form.date_field :value, { value: active_value.value, min: active_field.min, max: active_field.max } %>
4
+ </div>
@@ -0,0 +1,12 @@
1
+ <div>
2
+ <%= form.label :value, active_field.name %>
3
+ <%=
4
+ render_array_field(
5
+ form: form,
6
+ name: :value,
7
+ value: active_value.value,
8
+ field_method: :date_field,
9
+ field_opts: { min: active_field.min, max: active_field.max },
10
+ )
11
+ %>
12
+ </div>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <%= form.label :value, active_field.name %>
3
+ <%= form.datetime_field :value, { value: active_value.value, min: active_field.min, max: active_field.max } %>
4
+ </div>
@@ -0,0 +1,12 @@
1
+ <div>
2
+ <%= form.label :value, active_field.name %>
3
+ <%=
4
+ render_array_field(
5
+ form: form,
6
+ name: :value,
7
+ value: active_value.value,
8
+ field_method: :datetime_field,
9
+ field_opts: { min: active_field.min, max: active_field.max },
10
+ )
11
+ %>
12
+ </div>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <%= form.label :value, active_field.name %>
3
+ <%= form.number_field :value, { value: active_value.value, min: active_field.min, max: active_field.max, step: "any" } %>
4
+ </div>
@@ -0,0 +1,12 @@
1
+ <div>
2
+ <%= form.label :value, active_field.name %>
3
+ <%=
4
+ render_array_field(
5
+ form: form,
6
+ name: :value,
7
+ value: active_value.value,
8
+ field_method: :number_field,
9
+ field_opts: { min: active_field.min, max: active_field.max, step: "any" },
10
+ )
11
+ %>
12
+ </div>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <%= form.label :value, active_field.name %>
3
+ <%= form.select :value, active_field.allowed_values, { include_blank: true, selected: active_value.value } %>
4
+ </div>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <%= form.label :value, active_field.name %>
3
+ <%= form.select :value, active_field.allowed_values, { multiple: true, selected: active_value.value } %>
4
+ </div>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <%= form.label :value, active_field.name %>
3
+ <%= form.number_field :value, { value: active_value.value, min: active_field.min, max: active_field.max } %>
4
+ </div>
@@ -0,0 +1,12 @@
1
+ <div>
2
+ <%= form.label :value, active_field.name %>
3
+ <%=
4
+ render_array_field(
5
+ form: form,
6
+ name: :value,
7
+ value: active_value.value,
8
+ field_method: :number_field,
9
+ field_opts: { min: active_field.min, max: active_field.max },
10
+ )
11
+ %>
12
+ </div>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <%= form.label :value, active_field.name %>
3
+ <%= form.text_field :value, { value: active_value.value, maxlength: active_field.max_length } %>
4
+ </div>
@@ -0,0 +1,12 @@
1
+ <div>
2
+ <%= form.label :value, active_field.name %>
3
+ <%=
4
+ render_array_field(
5
+ form: form,
6
+ name: :value,
7
+ value: active_value.value,
8
+ field_method: :text_field,
9
+ field_opts: { maxlength: active_field.max_length },
10
+ )
11
+ %>
12
+ </div>
@@ -0,0 +1,19 @@
1
+ <div data-controller="array-field">
2
+ <div data-array-field-target="templateFieldGroup">
3
+ <%= form.public_send(field_method, name, { multiple: true, value: "", **field_opts }) %>
4
+ <% unless field_opts[:disabled] %>
5
+ <%= button_tag "Remove", type: "button", data: { action: "click->array-field#removeField" } %>
6
+ <% end %>
7
+ </div>
8
+ <% Array(value).each do |value_element| %>
9
+ <div>
10
+ <%= form.public_send(field_method, name, { multiple: true, value: value_element || "", **field_opts }) %>
11
+ <% unless field_opts[:disabled] %>
12
+ <%= button_tag "Remove", type: "button", data: { action: "click->array-field#removeField" } %>
13
+ <% end %>
14
+ </div>
15
+ <% end %>
16
+ <% unless field_opts[:disabled] %>
17
+ <%= button_tag "Add more", type: "button", data: { action: "click->array-field#addField" } %>
18
+ <% end %>
19
+ </div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Usanov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-09-07 00:00:00.000000000 Z
12
+ date: 2024-09-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -264,6 +264,42 @@ files:
264
264
  - lib/active_fields/version.rb
265
265
  - lib/generators/active_fields/install/USAGE
266
266
  - lib/generators/active_fields/install/install_generator.rb
267
+ - lib/generators/active_fields/scaffold/USAGE
268
+ - lib/generators/active_fields/scaffold/scaffold_generator.rb
269
+ - lib/generators/active_fields/scaffold/templates/controllers/active_fields_controller.rb
270
+ - lib/generators/active_fields/scaffold/templates/helpers/active_fields_helper.rb
271
+ - lib/generators/active_fields/scaffold/templates/javascript/controllers/array_field_controller.js
272
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/edit.html.erb
273
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_boolean.html.erb
274
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_date.html.erb
275
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_date_array.html.erb
276
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_datetime.html.erb
277
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_datetime_array.html.erb
278
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_decimal.html.erb
279
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_decimal_array.html.erb
280
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_enum.html.erb
281
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_enum_array.html.erb
282
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_integer.html.erb
283
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_integer_array.html.erb
284
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_text.html.erb
285
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/forms/_text_array.html.erb
286
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/index.html.erb
287
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/new.html.erb
288
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/show.html.erb
289
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_boolean.html.erb
290
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_date.html.erb
291
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_date_array.html.erb
292
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_datetime.html.erb
293
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_datetime_array.html.erb
294
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_decimal.html.erb
295
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_decimal_array.html.erb
296
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_enum.html.erb
297
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_enum_array.html.erb
298
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_integer.html.erb
299
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_integer_array.html.erb
300
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_text.html.erb
301
+ - lib/generators/active_fields/scaffold/templates/views/active_fields/values/inputs/_text_array.html.erb
302
+ - lib/generators/active_fields/scaffold/templates/views/shared/_array_field.html.erb
267
303
  - lib/tasks/active_fields_tasks.rake
268
304
  - sig/active_fields.rbs
269
305
  homepage: https://github.com/lassoid/active_fields
@@ -288,7 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
324
  - !ruby/object:Gem::Version
289
325
  version: '0'
290
326
  requirements: []
291
- rubygems_version: 3.5.11
327
+ rubygems_version: 3.5.16
292
328
  signing_key:
293
329
  specification_version: 4
294
330
  summary: Add custom fields to ActiveRecord models at runtime.