plutonium 0.15.24 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,13 +16,15 @@ module Plutonium
16
16
 
17
17
  private
18
18
 
19
- def authorized_resource_scope(resource, **options)
19
+ # Use this when getting a scope for a resource that is not the current
20
+ # Use this instead of authorized_scope directly
21
+ def authorized_resource_scope(resource, relation: nil, **options)
20
22
  raise ArgumentError("Expected resource to be a class inheriting ActiveRecord::Base") unless resource.instance_of?(Class) && resource < ActiveRecord::Base
21
23
 
22
24
  options[:with] ||= ActionPolicy.lookup(resource, namespace: authorization_namespace)
23
- resource = resource.all
25
+ relation ||= resource.all
24
26
 
25
- authorized_scope(resource, **options)
27
+ authorized_scope(relation, **options)
26
28
  end
27
29
 
28
30
  def entity_scope_for_authorize
@@ -48,6 +48,7 @@ module Plutonium
48
48
  :current_interactive_action,
49
49
  :current_engine,
50
50
  :policy_for,
51
+ :authorized_resource_scope,
51
52
  :allowed_to?,
52
53
  :registered_resources,
53
54
  :root_path,
@@ -14,11 +14,20 @@ module Plutonium
14
14
  end
15
15
  alias_method :markdown_tag, :easymde_tag
16
16
 
17
- alias_method :basic_select_tag, :select_tag
18
- def slim_select_tag(**, &)
19
- basic_select_tag(**, data_controller: "slim-select", class!: "", &)
17
+ def slim_select_tag(**attributes, &)
18
+ attributes[:data_controller] = tokens(attributes[:data_controller], "slim-select")
19
+ select_tag(**attributes, class!: "", &)
20
+ end
21
+
22
+ def belongs_to_tag(**attributes, &)
23
+ attributes[:data_controller] = tokens(attributes[:data_controller], "slim-select") # TODO: put this behind a config
24
+ create_component(Components::BelongsTo, :belongs_to, **attributes, &)
25
+ end
26
+
27
+ def has_many_tag(**attributes, &)
28
+ attributes[:data_controller] = tokens(attributes[:data_controller], "slim-select") # TODO: put this behind a config
29
+ create_component(Components::HasMany, :has_many, **attributes, &)
20
30
  end
21
- alias_method :select_tag, :slim_select_tag
22
31
 
23
32
  def flatpickr_tag(**, &)
24
33
  create_component(Plutonium::UI::Form::Components::Flatpickr, :flatpickr, **, &)
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plutonium
4
+ module UI
5
+ module Form
6
+ module Components
7
+ class BelongsTo < Phlexi::Form::Components::BelongsTo
8
+ include Plutonium::UI::Component::Methods
9
+
10
+ private
11
+
12
+ def choices
13
+ @choices ||= begin
14
+ collection = authorized_resource_scope(association_reflection.klass, relation: @choice_collection)
15
+ Phlexi::Form::ChoicesMapper.new(collection, label_method: @label_method, value_method: @value_method)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plutonium
4
+ module UI
5
+ module Form
6
+ module Components
7
+ class HasMany < Phlexi::Form::Components::HasMany
8
+ include Plutonium::UI::Component::Methods
9
+
10
+ private
11
+
12
+ def choices
13
+ @choices ||= begin
14
+ collection = authorized_resource_scope(association_reflection.klass, relation: @choice_collection)
15
+ Phlexi::Form::ChoicesMapper.new(collection, label_method: @label_method, value_method: @value_method)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -8,16 +8,19 @@ module Plutonium
8
8
  private
9
9
 
10
10
  def infer_field_component
11
- return :markdown if inferred_field_type == :rich_text
11
+ case inferred_field_type
12
+ when :rich_text
13
+ return :markdown
14
+ end
12
15
 
13
- component = super
14
- case component
16
+ inferred_field_component = super
17
+ case inferred_field_component
15
18
  when :select
16
19
  :slim_select
17
20
  when :date, :time, :datetime
18
21
  :flatpickr
19
22
  else
20
- component
23
+ inferred_field_component
21
24
  end
22
25
  end
23
26
  end
@@ -1,5 +1,5 @@
1
1
  module Plutonium
2
- VERSION = "0.15.24"
2
+ VERSION = "0.16.0"
3
3
  NEXT_MAJOR_VERSION = VERSION.split(".").tap { |v|
4
4
  v[1] = v[1].to_i + 1
5
5
  v[2] = 0
@@ -92,7 +92,7 @@
92
92
  }
93
93
 
94
94
  .ss-main .ss-values .ss-value {
95
- @apply flex select-none items-center w-fit bg-primary-500 rounded-md;
95
+ @apply flex select-none items-center w-fit bg-primary-500 rounded-md text-white;
96
96
  animation: ss-valueIn 0.2s ease-out forwards;
97
97
  }
98
98
 
@@ -101,11 +101,11 @@
101
101
  }
102
102
 
103
103
  .ss-main .ss-values .ss-value .ss-value-text {
104
- @apply text-xs text-white dark:text-gray-900 leading-normal p-[3px_5px];
104
+ @apply text-xs leading-normal p-[3px_5px];
105
105
  }
106
106
 
107
107
  .ss-main .ss-values .ss-value .ss-value-delete {
108
- @apply flex items-center h-[7px] w-[7px] p-[3px_5px] cursor-pointer border-l border-solid border-white dark:border-gray-900 box-content;
108
+ @apply flex items-center h-[7px] w-[7px] p-[3px_5px] cursor-pointer border-l border-solid border-white box-content;
109
109
  }
110
110
 
111
111
  .ss-main .ss-values .ss-value .ss-value-delete svg {
@@ -113,7 +113,7 @@
113
113
  }
114
114
 
115
115
  .ss-main .ss-values .ss-value .ss-value-delete svg path {
116
- @apply fill-none stroke-white dark:stroke-gray-900;
116
+ @apply fill-none stroke-white;
117
117
  stroke-width: 18;
118
118
  stroke-linecap: round;
119
119
  stroke-linejoin: round;
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.15.24
4
+ version: 0.16.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-12-01 00:00:00.000000000 Z
11
+ date: 2024-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -1408,8 +1408,10 @@ files:
1408
1408
  - lib/plutonium/ui/dyna_frame/host.rb
1409
1409
  - lib/plutonium/ui/empty_card.rb
1410
1410
  - lib/plutonium/ui/form/base.rb
1411
+ - lib/plutonium/ui/form/components/belongs_to.rb
1411
1412
  - lib/plutonium/ui/form/components/easymde.rb
1412
1413
  - lib/plutonium/ui/form/components/flatpickr.rb
1414
+ - lib/plutonium/ui/form/components/has_many.rb
1413
1415
  - lib/plutonium/ui/form/concerns/renders_nested_resource_fields.rb
1414
1416
  - lib/plutonium/ui/form/interaction.rb
1415
1417
  - lib/plutonium/ui/form/options/inferred_types.rb