plutonium 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -0
  3. data/app/assets/js/controllers/application.js +1 -0
  4. data/app/assets/js/controllers/index.js +9 -0
  5. data/app/assets/js/controllers/resource_dismiss_controller.js +37 -0
  6. data/app/assets/js/controllers/resource_drop_down_controller.js +29 -0
  7. data/app/assets/js/turbo/index.js +1 -1
  8. data/app/views/application/_flash.html.erb +1 -1
  9. data/app/views/application/_flash_alerts.html.erb +51 -7
  10. data/app/views/application/_flash_toasts.html.erb +53 -23
  11. data/app/views/application/_resource_header.html.erb +563 -561
  12. data/app/views/components/form/form_builder.rb +2 -2
  13. data/app/views/components/form/form_component.html.erb +5 -6
  14. data/app/views/components/interactive_action_form/interactive_action_form_component.html.erb +1 -1
  15. data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.html.erb +66 -0
  16. data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.rb +23 -0
  17. data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_controller.js +64 -0
  18. data/app/views/components/sidebar/sidebar_component.html.erb +61 -63
  19. data/app/views/components/table_search_input/table_search_input_component.html.erb +1 -1
  20. data/app/views/layouts/resource.html copy.erb +0 -2
  21. data/app/views/layouts/resource.html.erb +1 -3
  22. data/app/views/layouts/rodauth.html.erb +0 -1
  23. data/app/views/resource/_interactive_resource_action_form.html.erb +1 -1
  24. data/exe/pug +6 -0
  25. data/lib/generators/pu/gen/component/component_generator.rb +1 -1
  26. data/lib/generators/pu/gen/pug/pug_generator.rb +1 -1
  27. data/lib/generators/pu/lib/plutonium_generators/cli.rb +42 -0
  28. data/lib/generators/pu/lib/plutonium_generators/generator.rb +1 -5
  29. data/lib/generators/pu/lib/plutonium_generators/model_generator.rb +1 -1
  30. data/lib/generators/pu/lib/plutonium_generators.rb +8 -0
  31. data/lib/plutonium/core/actions/collection.rb +1 -1
  32. data/lib/plutonium/core/controllers/authorizable.rb +4 -4
  33. data/lib/plutonium/core/fields/inputs/base.rb +1 -1
  34. data/lib/plutonium/core/fields/inputs/nested_input.rb +57 -0
  35. data/lib/plutonium/core/fields/inputs/noop_input.rb +1 -1
  36. data/lib/plutonium/core/fields/inputs/phone_input.rb +1 -1
  37. data/lib/plutonium/core/fields/inputs/polymorphic_belongs_to_association_input.rb +1 -1
  38. data/lib/plutonium/core/fields/inputs/simple_form_association_input.rb +1 -1
  39. data/lib/plutonium/core/fields/inputs/simple_form_input.rb +1 -1
  40. data/lib/plutonium/core/fields/renderers/factory.rb +1 -0
  41. data/lib/plutonium/core/fields/renderers/map_renderer.rb +19 -0
  42. data/lib/plutonium/resource/policy.rb +6 -0
  43. data/lib/plutonium/resource/presenter.rb +35 -0
  44. data/lib/plutonium/resource/record.rb +40 -7
  45. data/lib/plutonium/version.rb +1 -1
  46. data/package-lock.json +7 -0
  47. data/package.json +5 -4
  48. data/templates/base.rb +8 -0
  49. metadata +14 -4
  50. data/app/assets/js/controllers/dropdown_controller.js +0 -12
@@ -3,7 +3,7 @@ module Plutonium
3
3
  module Fields
4
4
  module Inputs
5
5
  class PhoneInput < SimpleFormInput
6
- # def render(f, record, **opts)
6
+ # def render(view_context, f, record, **opts)
7
7
  # opts = options.deep_merge opts
8
8
  # opts.delete(:as)
9
9
  # f.input name, **opts
@@ -3,7 +3,7 @@ module Plutonium
3
3
  module Fields
4
4
  module Inputs
5
5
  class PolymorphicBelongsToAssociationInput < SimpleFormAssociationInput
6
- def render(f, record, **opts)
6
+ def render(view_context, f, record, **opts)
7
7
  opts = options.deep_merge opts
8
8
  f.input param, **opts
9
9
  end
@@ -10,7 +10,7 @@ module Plutonium
10
10
  super(name, **user_options)
11
11
  end
12
12
 
13
- def render(f, record, **opts)
13
+ def render(view_context, f, record, **opts)
14
14
  opts = options.deep_merge opts
15
15
  f.association name, **opts
16
16
  end
@@ -3,7 +3,7 @@ module Plutonium
3
3
  module Fields
4
4
  module Inputs
5
5
  class SimpleFormInput < Base
6
- def render(f, record, **opts)
6
+ def render(view_context, f, record, **opts)
7
7
  opts = options.deep_merge opts
8
8
  f.input name, **opts
9
9
  end
@@ -9,6 +9,7 @@ module Plutonium
9
9
 
10
10
  map_type :belongs_to, :has_one, :has_many, to: Plutonium::Core::Fields::Renderers::AssociationRenderer
11
11
  map_type :attachment, to: Plutonium::Core::Fields::Renderers::AttachmentRenderer
12
+ map_type :map, to: Plutonium::Core::Fields::Renderers::MapRenderer
12
13
 
13
14
  def self.build(name, type:, **)
14
15
  mapping = mappings[type] || Plutonium::Core::Fields::Renderers::BasicRenderer
@@ -0,0 +1,19 @@
1
+ module Plutonium
2
+ module Core
3
+ module Fields
4
+ module Renderers
5
+ class MapRenderer < BasicRenderer
6
+ # def initialize(name, reflection:, **user_options)
7
+ # @reflection = reflection
8
+ # super(name, **user_options)
9
+ # end
10
+
11
+ def render(view_context, record)
12
+ # view_context.display_field value:, **options
13
+ view_context.js_map [{latitude: record.lat, longitude: record.lng}]
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -6,6 +6,12 @@ module Plutonium
6
6
  class Scope < Plutonium::Policy::Scope
7
7
  end
8
8
 
9
+ def send_with_report(method)
10
+ raise NotImplementedError, "#{self.class.name} does not implement the required #{method}" unless respond_to? method
11
+
12
+ send method
13
+ end
14
+
9
15
  # Core actions
10
16
 
11
17
  def create?
@@ -37,6 +37,41 @@ module Plutonium
37
37
  define_action Plutonium::Core::Actions::InteractiveAction.new(name, interaction:, **)
38
38
  end
39
39
 
40
+ # TODO: move this to its own definer
41
+ def define_nested_input(name, inputs:, model_class: nil, **options)
42
+ nested_attribute_options = resource_class.all_nested_attributes_options[name]
43
+
44
+ nested_attribute_options_class = nested_attribute_options&.[](:class)
45
+ if nested_attribute_options_class.nil? && model_class.nil?
46
+ raise ArgumentError, "model_class is required if your field is not an association or is polymorphic"
47
+ end
48
+ model_class ||= nested_attribute_options_class
49
+
50
+ macro = nested_attribute_options&.[](:macro)
51
+ allow_destroy = nested_attribute_options&.[](:allow_destroy).presence
52
+ update_only = nested_attribute_options&.[](:update_only).presence
53
+ limit = if macro == :has_one
54
+ 1
55
+ elsif options.key?(:limit)
56
+ options[:limit]
57
+ else
58
+ nested_attribute_options&.[](:limit)
59
+ end
60
+
61
+ input = Plutonium::Core::Fields::Inputs::NestedInput.new(
62
+ name,
63
+ inputs:,
64
+ allow_destroy: options.key?(:allow_destroy) ? options[:allow_destroy] : allow_destroy,
65
+ update_only: options.key?(:update_only) ? options[:update_only] : update_only,
66
+ limit: limit,
67
+ resource_class: model_class,
68
+ **options
69
+ )
70
+ yield input if block_given?
71
+
72
+ define_input name, input:
73
+ end
74
+
40
75
  def resource_class = context.resource_class
41
76
  end
42
77
  end
@@ -117,6 +117,23 @@ module Plutonium
117
117
  @has_many_association_routes ||= reflect_on_all_associations(:has_many).map { |assoc| assoc.klass.model_name.plural }
118
118
  end
119
119
 
120
+ def all_nested_attributes_options
121
+ unless Rails.env.local?
122
+ return @all_nested_attributes_options if defined?(@all_nested_attributes_options)
123
+ end
124
+
125
+ @all_nested_attributes_options = reflect_on_all_associations.map do |association|
126
+ setter_method = "#{association.name}_attributes="
127
+ if method_defined?(setter_method)
128
+ [association.name, {
129
+ **nested_attributes_options[association.name],
130
+ macro: association.macro,
131
+ class: association.polymorphic? ? nil : association.klass
132
+ }]
133
+ end
134
+ end.compact.to_h
135
+ end
136
+
120
137
  #
121
138
  # Returns the strong parameters definition for the given attribute names
122
139
  #
@@ -127,6 +144,8 @@ module Plutonium
127
144
  #
128
145
  def strong_parameters_for(*attributes)
129
146
  # attributes that are passed but we do not have a model/database backed definition for e.g. virtual attributes.
147
+ # if they are passed and we are not expecting them, our inputs will filter them out as they apply an additional level
148
+ # of filtering
130
149
  unbacked = attributes - strong_parameters_definition.keys
131
150
 
132
151
  # attributes backed by some model/database definition
@@ -147,8 +166,13 @@ module Plutonium
147
166
  private
148
167
 
149
168
  def strong_parameters_definition
150
- # @strong_parameters ||= begin
169
+ unless Rails.env.local?
170
+ return @strong_parameters if defined?(@strong_parameters)
171
+ end
172
+
151
173
  @strong_parameters = begin
174
+ # Columns
175
+
152
176
  content_column_parameters = content_column_field_names.map do |name|
153
177
  column = columns_hash[name.to_s]
154
178
 
@@ -160,21 +184,30 @@ module Plutonium
160
184
  end
161
185
  parameters = content_column_parameters.to_h
162
186
 
163
- # TODO: add nested support
187
+ # Associations
164
188
 
165
- # TODO:
166
189
  parameters.merge! reflect_on_all_associations(:belongs_to)
167
190
  .map { |reflection|
168
- input_param = (reflection.respond_to?(:options) && reflection.options[:foreign_key]) || :"#{reflection.name}_id"
191
+ input_param = reflection.respond_to?(:options) ? reflection.options[:foreign_key] : :"#{reflection.name}_id"
169
192
  [reflection.name, {input_param => nil}]
170
193
  }
171
194
  .to_h
172
195
 
173
- parameters.merge! has_one_association_field_names.map { |name| [name, {name => nil}] }.to_h
196
+ parameters.merge! has_many_association_field_names
197
+ .map { |name| [name, {"#{name.to_s.singularize}_ids": []}] }
198
+ .to_h
199
+
200
+ # Attachments
201
+
202
+ parameters.merge! has_many_attached_field_names.map { |name| [name, {name => []}] }.to_h
203
+
174
204
  parameters.merge! has_one_attached_field_names.map { |name| [name, {name => nil}] }.to_h
175
205
 
176
- parameters.merge! has_many_association_field_names.map { |name| [name, {"#{name.to_s.singularize}_ids": []}] }.to_h
177
- parameters.merge! has_many_attached_field_names.map { |name| [name, {name: []}] }.to_h
206
+ # Nested Attributes
207
+
208
+ parameters.merge! all_nested_attributes_options.keys
209
+ .map { |name| [name, {"#{name}_attributes" => {}}] }
210
+ .to_h
178
211
 
179
212
  # e.g.
180
213
  # {:name=>{:name=>nil}, :cover_image=>{:cover_image=>nil}, :user=>{:user_id=>nil} :comments=>{:comment_ids=>[]}}
@@ -1,3 +1,3 @@
1
1
  module Plutonium
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.0"
3
3
  end
data/package-lock.json CHANGED
@@ -13,6 +13,7 @@
13
13
  "esbuild-plugin-manifest": "^1.0.3",
14
14
  "flowbite": "^2.3.0",
15
15
  "lodash.debounce": "^4.0.8",
16
+ "mapkick": "^0.2.6",
16
17
  "postcss": "^8.4.35",
17
18
  "postcss-cli": "^11.0.0",
18
19
  "postcss-hash": "^3.0.0",
@@ -1380,6 +1381,12 @@
1380
1381
  "node": "14 || >=16.14"
1381
1382
  }
1382
1383
  },
1384
+ "node_modules/mapkick": {
1385
+ "version": "0.2.6",
1386
+ "resolved": "https://registry.npmjs.org/mapkick/-/mapkick-0.2.6.tgz",
1387
+ "integrity": "sha512-sDfPCOhTpQrzJc3Yzwg5XOBy5o2TTNEfH2dG2QZM7RUtfQzhY+xErfhQHrQvSOaWbf4zOegPq/dhaWuv2fo4CA==",
1388
+ "dev": true
1389
+ },
1383
1390
  "node_modules/merge2": {
1384
1391
  "version": "1.4.1",
1385
1392
  "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz",
data/package.json CHANGED
@@ -11,11 +11,12 @@
11
11
  "postcss": "^8.4.35",
12
12
  "postcss-cli": "^11.0.0",
13
13
  "postcss-hash": "^3.0.0",
14
- "tailwindcss": "^3.4.1"
14
+ "tailwindcss": "^3.4.1",
15
+ "mapkick": "^0.2.6"
15
16
  },
16
17
  "scripts": {
17
- "watch": "postcss app/assets/css/plutonium.css -o public/plutonium-assets/build/plutonium-dev.css --watch",
18
- "scripts": "node build.js",
19
- "build": "postcss app/assets/css/plutonium.css -o public/plutonium-assets/build/plutonium.css --watch"
18
+ "watch-css": "postcss app/assets/css/plutonium.css -o public/plutonium-assets/build/plutonium-dev.css --watch",
19
+ "watch-js": "node build.js",
20
+ "build-css": "postcss app/assets/css/plutonium.css -o public/plutonium-assets/build/plutonium.css --watch"
20
21
  }
21
22
  }
data/templates/base.rb ADDED
@@ -0,0 +1,8 @@
1
+ gem "plutonium"
2
+
3
+ after_bundle do
4
+ generate "pu:core:install"
5
+
6
+ git add: "."
7
+ git commit: %( -m 'Install plutonium' )
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plutonium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Froelich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-02 00:00:00.000000000 Z
11
+ date: 2024-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -203,7 +203,8 @@ description: Plutonium extends Rails' capabilities with a powerful, generator-dr
203
203
  you build applications with Rails, optimizing for rapid application development.
204
204
  email:
205
205
  - sfroelich01@gmail.com
206
- executables: []
206
+ executables:
207
+ - pug
207
208
  extensions: []
208
209
  extra_rdoc_files: []
209
210
  files:
@@ -708,8 +709,9 @@ files:
708
709
  - app/assets/icons/solid/zoom-in.svg
709
710
  - app/assets/icons/solid/zoom-out.svg
710
711
  - app/assets/js/controllers/application.js
711
- - app/assets/js/controllers/dropdown_controller.js
712
712
  - app/assets/js/controllers/index.js
713
+ - app/assets/js/controllers/resource_dismiss_controller.js
714
+ - app/assets/js/controllers/resource_drop_down_controller.js
713
715
  - app/assets/js/plutonium.js
714
716
  - app/assets/js/turbo/index.js
715
717
  - app/assets/js/turbo/turbo_actions.js
@@ -745,6 +747,9 @@ files:
745
747
  - app/views/components/interactive_action_form/interactive_action_form_component.html.erb
746
748
  - app/views/components/interactive_action_form/interactive_action_form_component.rb
747
749
  - app/views/components/interactive_action_form/interactive_action_form_controller.js
750
+ - app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.html.erb
751
+ - app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.rb
752
+ - app/views/components/nested_resource_form_fields/nested_resource_form_fields_controller.js
748
753
  - app/views/components/pagination/pagination_component.html.erb
749
754
  - app/views/components/pagination/pagination_component.rb
750
755
  - app/views/components/panel/panel_component.html.erb
@@ -838,6 +843,7 @@ files:
838
843
  - config/initializers/pagy.rb
839
844
  - config/initializers/rabl.rb
840
845
  - config/initializers/simple_form.rb
846
+ - exe/pug
841
847
  - lib/active_model/validations/array_validator.rb
842
848
  - lib/active_model/validations/attached_validator.rb
843
849
  - lib/active_model/validations/url_validator.rb
@@ -866,6 +872,7 @@ files:
866
872
  - lib/generators/pu/gen/pug/pug_generator.rb
867
873
  - lib/generators/pu/gen/pug/templates/pug.rb.tt
868
874
  - lib/generators/pu/lib/plutonium_generators.rb
875
+ - lib/generators/pu/lib/plutonium_generators/cli.rb
869
876
  - lib/generators/pu/lib/plutonium_generators/concerns/actions.rb
870
877
  - lib/generators/pu/lib/plutonium_generators/concerns/config.rb
871
878
  - lib/generators/pu/lib/plutonium_generators/concerns/logger.rb
@@ -1012,6 +1019,7 @@ files:
1012
1019
  - lib/plutonium/core/fields/inputs/date_time_input.rb
1013
1020
  - lib/plutonium/core/fields/inputs/factory.rb
1014
1021
  - lib/plutonium/core/fields/inputs/has_many_association_input.rb
1022
+ - lib/plutonium/core/fields/inputs/nested_input.rb
1015
1023
  - lib/plutonium/core/fields/inputs/noop_input.rb
1016
1024
  - lib/plutonium/core/fields/inputs/phone_input.rb
1017
1025
  - lib/plutonium/core/fields/inputs/polymorphic_belongs_to_association_input.rb
@@ -1021,6 +1029,7 @@ files:
1021
1029
  - lib/plutonium/core/fields/renderers/attachment_renderer.rb
1022
1030
  - lib/plutonium/core/fields/renderers/basic_renderer.rb
1023
1031
  - lib/plutonium/core/fields/renderers/factory.rb
1032
+ - lib/plutonium/core/fields/renderers/map_renderer.rb
1024
1033
  - lib/plutonium/core/ui/collection.rb
1025
1034
  - lib/plutonium/core/ui/detail.rb
1026
1035
  - lib/plutonium/core/ui/form.rb
@@ -1071,6 +1080,7 @@ files:
1071
1080
  - public/plutonium-assets/logo.png
1072
1081
  - sig/plutonium.rbs
1073
1082
  - tailwind.config.js
1083
+ - templates/base.rb
1074
1084
  homepage: https://github.com/radioactive-labs/plutonium-core
1075
1085
  licenses:
1076
1086
  - MIT
@@ -1,12 +0,0 @@
1
- import { Controller } from "@hotwired/stimulus"
2
-
3
- // Connects to data-controller="dropdown"
4
- export default class extends Controller {
5
- connect() {
6
- console.log(`form connected: ${this.element}`)
7
- }
8
-
9
- submit() {
10
- this.element.requestSubmit()
11
- }
12
- }