plutonium 0.15.24 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/plutonium.css +1 -1
- data/lib/plutonium/core/controllers/authorizable.rb +5 -3
- data/lib/plutonium/ui/component/methods.rb +1 -0
- data/lib/plutonium/ui/form/base.rb +13 -4
- data/lib/plutonium/ui/form/components/belongs_to.rb +22 -0
- data/lib/plutonium/ui/form/components/has_many.rb +22 -0
- data/lib/plutonium/ui/form/options/inferred_types.rb +7 -4
- data/lib/plutonium/version.rb +1 -1
- data/src/css/slim_select.css +4 -4
- metadata +4 -2
@@ -16,13 +16,15 @@ module Plutonium
|
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
|
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
|
-
|
25
|
+
relation ||= resource.all
|
24
26
|
|
25
|
-
authorized_scope(
|
27
|
+
authorized_scope(relation, **options)
|
26
28
|
end
|
27
29
|
|
28
30
|
def entity_scope_for_authorize
|
@@ -14,11 +14,20 @@ module Plutonium
|
|
14
14
|
end
|
15
15
|
alias_method :markdown_tag, :easymde_tag
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
11
|
+
case inferred_field_type
|
12
|
+
when :rich_text
|
13
|
+
return :markdown
|
14
|
+
end
|
12
15
|
|
13
|
-
|
14
|
-
case
|
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
|
-
|
23
|
+
inferred_field_component
|
21
24
|
end
|
22
25
|
end
|
23
26
|
end
|
data/lib/plutonium/version.rb
CHANGED
data/src/css/slim_select.css
CHANGED
@@ -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
|
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
|
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
|
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.
|
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-
|
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
|