plutonium 0.12.8 → 0.12.10
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/app/assets/plutonium.js +24 -1
- data/app/assets/plutonium.js.map +3 -3
- data/app/assets/plutonium.min.js +5 -5
- data/app/assets/plutonium.min.js.map +4 -4
- data/app/views/components/form/form_component.html.erb +1 -3
- data/app/views/components/interactive_action_form/interactive_action_form_component.html.erb +5 -7
- data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.html.erb +2 -2
- data/app/views/components/sidebar/sidebar_component.html.erb +1 -1
- data/app/views/components/sidebar/sidebar_component.rb +2 -2
- data/app/views/components/sidebar_menu_item/sidebar_menu_item_component.html.erb +6 -6
- data/app/views/components/sidebar_menu_item/sidebar_menu_item_component.rb +14 -4
- data/app/views/components/table_search_input/table_search_input_component.html.erb +8 -2
- data/app/views/resource/_interactive_resource_action_form.html.erb +1 -1
- data/app/views/resource/_resource_details.html.erb +9 -2
- data/app/views/resource/_resource_table.html.erb +9 -1
- data/lib/generators/pu/core/assets/templates/tailwind.config.js +2 -0
- data/lib/generators/pu/core/install/install_generator.rb +1 -1
- data/lib/generators/pu/core/install/templates/config/initializers/plutonium.rb +4 -0
- data/lib/generators/pu/eject/layout/layout_generator.rb +3 -2
- data/lib/generators/pu/eject/shell/shell_generator.rb +3 -2
- data/lib/generators/pu/field/input/input_generator.rb +32 -0
- data/lib/generators/pu/field/input/templates/.keep +0 -0
- data/lib/generators/pu/field/input/templates/input.rb.tt +15 -0
- data/lib/generators/pu/field/renderer/renderer_generator.rb +32 -0
- data/lib/generators/pu/field/renderer/templates/.keep +0 -0
- data/lib/generators/pu/field/renderer/templates/renderer.rb.tt +9 -0
- data/lib/plutonium/core/actions/interactive_action.rb +2 -2
- data/lib/plutonium/core/associations/renderers/base.rb +77 -0
- data/lib/plutonium/core/associations/renderers/factory.rb +0 -2
- data/lib/plutonium/core/associations/renderers/has_many_renderer.rb +6 -4
- data/lib/plutonium/core/controllers/crud_actions.rb +1 -1
- data/lib/plutonium/core/controllers/presentable.rb +3 -3
- data/lib/plutonium/core/definers/field_definer.rb +4 -4
- data/lib/plutonium/core/definers/{input_definer.rb → field_input_definer.rb} +4 -4
- data/lib/plutonium/core/definers/{renderer_definer.rb → field_renderer_definer.rb} +10 -10
- data/lib/plutonium/core/fields/inputs/attachment_input.rb +2 -2
- data/lib/plutonium/core/fields/inputs/base.rb +76 -10
- data/lib/plutonium/core/fields/inputs/checkbox_input.rb +3 -1
- data/lib/plutonium/core/fields/inputs/date_time_input.rb +3 -1
- data/lib/plutonium/core/fields/inputs/nested_input.rb +36 -21
- data/lib/plutonium/core/fields/inputs/noop_input.rb +1 -4
- data/lib/plutonium/core/fields/inputs/polymorphic_belongs_to_association_input.rb +8 -7
- data/lib/plutonium/core/fields/inputs/simple_form_association_input.rb +4 -5
- data/lib/plutonium/core/fields/inputs/simple_form_input.rb +2 -3
- data/lib/plutonium/core/fields/renderers/association_renderer.rb +11 -5
- data/lib/plutonium/core/fields/renderers/attachment_renderer.rb +3 -10
- data/lib/plutonium/core/fields/renderers/base.rb +83 -0
- data/lib/plutonium/core/fields/renderers/basic_renderer.rb +3 -17
- data/lib/plutonium/core/fields/renderers/factory.rb +0 -1
- data/lib/plutonium/core/renderable.rb +20 -0
- data/lib/plutonium/helpers/display_helper.rb +1 -1
- data/lib/plutonium/resource/controller.rb +1 -1
- data/lib/plutonium/resource/policy.rb +1 -1
- data/lib/plutonium/resource/presenter.rb +3 -3
- data/lib/plutonium/resource/query_object.rb +4 -4
- data/lib/plutonium/resource/record.rb +1 -1
- data/lib/plutonium/simple_form/attachment_component.rb +1 -1
- data/lib/plutonium/version.rb +1 -1
- data/package.json +1 -1
- data/src/js/controllers/register_controllers.js +2 -0
- data/src/js/controllers/resource_collapse_controller.js +30 -0
- data/src/js/controllers/resource_drop_down_controller.js +1 -1
- metadata +14 -5
- data/lib/plutonium/core/associations/renderers/basic_renderer.rb +0 -28
@@ -8,20 +8,18 @@
|
|
8
8
|
</svg>
|
9
9
|
<div>
|
10
10
|
<span class="font-medium"><%= f.error_notification %></span>
|
11
|
-
<!--
|
12
11
|
<ul class="mt-1.5 list-disc list-inside">
|
13
12
|
<% f.object.errors.full_messages.each do |message| %>
|
14
13
|
<li><%= f.error_notification message: message %></li>
|
15
14
|
<% end %>
|
16
15
|
</ul>
|
17
|
-
-->
|
18
16
|
</div>
|
19
17
|
</div>
|
20
18
|
<% end %>
|
21
19
|
|
22
20
|
<div>
|
23
21
|
<% form.inputs.values.each do |input| %>
|
24
|
-
<%= input.
|
22
|
+
<%= render input.with(form: f, record: form.record) %>
|
25
23
|
<% end %>
|
26
24
|
</div>
|
27
25
|
|
data/app/views/components/interactive_action_form/interactive_action_form_component.html.erb
CHANGED
@@ -8,20 +8,18 @@
|
|
8
8
|
</svg>
|
9
9
|
<div>
|
10
10
|
<span class="font-medium"><%= f.error_notification %></span>
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
<% end %>
|
11
|
+
<ul class="mt-1.5 list-disc list-inside">
|
12
|
+
<% f.object.errors.full_messages.each do |message| %>
|
13
|
+
<li><%= f.error_notification message: message %></li>
|
14
|
+
<% end %>
|
16
15
|
</ul>
|
17
|
-
-->
|
18
16
|
</div>
|
19
17
|
</div>
|
20
18
|
<% end %>
|
21
19
|
|
22
20
|
<div>
|
23
21
|
<% interactive_action.inputs.values.each do |input| %>
|
24
|
-
<%= input.
|
22
|
+
<%= render input.with(form: f, record: interaction) %>
|
25
23
|
<% end %>
|
26
24
|
</div>
|
27
25
|
|
data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.html.erb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
<%= form.simple_fields_for name, new_record, child_index: 'NEW_RECORD' do |nested| %>
|
12
12
|
<fieldset class="border-t mt-4 pt-4 first:border-t-0 first:pt-0 nested-resource-form-fields" data-new-record="<%= nested.object.new_record? %>">
|
13
13
|
<% inputs.values.each do |input| %>
|
14
|
-
<%= input.
|
14
|
+
<%= render input.with(form: nested, record: new_record) %>
|
15
15
|
<% end %>
|
16
16
|
|
17
17
|
<div class="text-right">
|
@@ -34,7 +34,7 @@
|
|
34
34
|
<%= form.simple_fields_for name do |nested| %>
|
35
35
|
<fieldset class="border-t mt-4 pt-4 first:border-t-0 first:pt-0 nested-resource-form-fields" data-new-record="<%= nested.object.new_record? %>">
|
36
36
|
<% inputs.values.each do |input| %>
|
37
|
-
<%= input.
|
37
|
+
<%= render input.with(form: nested, record: new_record) %>
|
38
38
|
<% end %>
|
39
39
|
|
40
40
|
<div>
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<%= content %>
|
9
9
|
</div>
|
10
10
|
|
11
|
-
<div class="hidden absolute bottom-0 left-0 justify-center p-4 space-x-4 w-full lg:flex bg-white dark:bg-gray-800 z-20">
|
11
|
+
<div class="hidden absolute bottom-0 left-0 justify-center p-4 space-x-4 w-full lg:flex bg-white dark:bg-gray-800 z-20 border-r border-gray-200 dark:border-gray-700">
|
12
12
|
<div data-controller="resource-drop-down">
|
13
13
|
<button
|
14
14
|
type="button"
|
@@ -3,11 +3,11 @@ module PlutoniumUi
|
|
3
3
|
private
|
4
4
|
|
5
5
|
def sidebar_class
|
6
|
-
"fixed top-0 left-0 z-40 w-64 h-screen pt-14 transition-transform -translate-x-full
|
6
|
+
"fixed top-0 left-0 z-40 w-64 h-screen pt-14 transition-transform -translate-x-full lg:translate-x-0"
|
7
7
|
end
|
8
8
|
|
9
9
|
def sidebar_container_class
|
10
|
-
"overflow-y-auto py-5 px-3 h-full bg-white dark:bg-gray-800"
|
10
|
+
"overflow-y-auto py-5 px-3 h-full bg-white border-r border-gray-200 dark:bg-gray-800 dark:border-gray-700"
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -3,10 +3,10 @@
|
|
3
3
|
<button
|
4
4
|
type="button"
|
5
5
|
class="<%= link_button_class %> w-full transition duration-75"
|
6
|
-
data-resource-
|
7
|
-
aria-controls="
|
6
|
+
data-resource-collapse-target="trigger"
|
7
|
+
aria-controls="side-menu-item-<%= name.parameterize %>">
|
8
8
|
<% if icon.present? %>
|
9
|
-
<%= render_icon icon, size: :lg %>
|
9
|
+
<%= render_icon icon, size: :lg, classname: icon_class %>
|
10
10
|
<% else %>
|
11
11
|
<div class="shrink-0 w-6 h-6">
|
12
12
|
|
@@ -28,7 +28,7 @@
|
|
28
28
|
</svg>
|
29
29
|
</button>
|
30
30
|
|
31
|
-
<ul id="
|
31
|
+
<ul id="side-menu-item-<%= name.parameterize %>" data-resource-collapse-target="menu" class="hidden py-2 space-y-2">
|
32
32
|
<% sub_items.each do |sub_item| %>
|
33
33
|
<%#= sub_item %>
|
34
34
|
<li>
|
@@ -43,9 +43,9 @@
|
|
43
43
|
<% else %>
|
44
44
|
<a
|
45
45
|
href="<%= url %>"
|
46
|
-
class="<%=
|
46
|
+
class="<%= link_link_class %>">
|
47
47
|
<% if icon.present? %>
|
48
|
-
<%= render_icon icon, size: :lg %>
|
48
|
+
<%= render_icon icon, size: :lg, classname: icon_class %>
|
49
49
|
<% else %>
|
50
50
|
<div class="shrink-0 w-6 h-6">
|
51
51
|
|
@@ -14,21 +14,27 @@ module PlutoniumUi
|
|
14
14
|
{
|
15
15
|
id: "sidebar-menu-item-#{name.parameterize}",
|
16
16
|
classname: "sidebar-menu-item",
|
17
|
-
controller: ["sidebar-menu-item", sub_items.any? ? "resource-
|
18
|
-
link_button_class: "
|
17
|
+
controller: ["sidebar-menu-item", sub_items.any? ? "resource-collapse" : nil],
|
18
|
+
link_button_class: "flex items-center p-2 w-full text-base font-normal text-gray-900 rounded-lg transition duration-75 group hover:bg-gray-100 dark:text-white dark:hover:bg-gray-700",
|
19
|
+
link_link_class: "flex items-center p-2 text-base font-normal text-gray-900 rounded-lg dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 group",
|
19
20
|
link_label_class: "flex-1 ml-3 text-left whitespace-nowrap",
|
20
|
-
sub_link_button_class: "flex items-center p-2 pl-11 w-full text-base font-
|
21
|
+
sub_link_button_class: "flex items-center p-2 pl-11 w-full text-base font-normal text-gray-900 rounded-lg transition duration-75 group hover:bg-gray-100 dark:text-white dark:hover:bg-gray-700",
|
22
|
+
icon_class: "text-gray-400 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white"
|
21
23
|
}
|
22
24
|
end
|
23
25
|
|
24
26
|
def filtered_attributes
|
25
|
-
%i[link_button_class link_label_class sub_link_button_class]
|
27
|
+
%i[link_button_class link_label_class sub_link_button_class link_link_class icon_class]
|
26
28
|
end
|
27
29
|
|
28
30
|
def link_button_class
|
29
31
|
raw_attributes_hash[:link_button_class]
|
30
32
|
end
|
31
33
|
|
34
|
+
def link_link_class
|
35
|
+
raw_attributes_hash[:link_link_class]
|
36
|
+
end
|
37
|
+
|
32
38
|
def link_label_class
|
33
39
|
raw_attributes_hash[:link_label_class]
|
34
40
|
end
|
@@ -36,6 +42,10 @@ module PlutoniumUi
|
|
36
42
|
def sub_link_button_class
|
37
43
|
raw_attributes_hash[:sub_link_button_class]
|
38
44
|
end
|
45
|
+
|
46
|
+
def icon_class
|
47
|
+
raw_attributes_hash[:icon_class]
|
48
|
+
end
|
39
49
|
end
|
40
50
|
end
|
41
51
|
|
@@ -7,7 +7,11 @@
|
|
7
7
|
<path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" clip-rule="evenodd" />
|
8
8
|
</svg>
|
9
9
|
</div>
|
10
|
-
|
10
|
+
|
11
|
+
<%=
|
12
|
+
render search_object.search_filter.input_definitions[:search].with(
|
13
|
+
form: f,
|
14
|
+
record:nil,
|
11
15
|
wrapper: false, label: false,
|
12
16
|
as: :string, # force string for search
|
13
17
|
placeholder: "search...",
|
@@ -21,7 +25,9 @@
|
|
21
25
|
# form_target: "focus",
|
22
26
|
turbo_permanent: true
|
23
27
|
}
|
24
|
-
|
28
|
+
}
|
29
|
+
)
|
30
|
+
%>
|
25
31
|
</div>
|
26
32
|
|
27
33
|
|
@@ -9,12 +9,19 @@
|
|
9
9
|
<div class="p-4">
|
10
10
|
<dl class="divide-y divide-gray-100">
|
11
11
|
<% details.fields.each do |name, renderer| %>
|
12
|
+
<%#
|
13
|
+
TODO:
|
14
|
+
For now, we are hacking around the need to call #with before #label
|
15
|
+
This proves there's an issue with the rendering api.
|
16
|
+
While I think of an elegant solution, this works for now.
|
17
|
+
%>
|
18
|
+
<% renderer.with(record: details.record) %>
|
12
19
|
<div class="py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
|
13
20
|
<dt class="text-sm font-medium leading-6 text-gray-900 dark:text-gray-300">
|
14
21
|
<%= renderer.label %>
|
15
22
|
</dt>
|
16
23
|
<dd class="mt-1 text-sm leading-6 text-gray-700 dark:text-gray-200 sm:col-span-2 sm:mt-0">
|
17
|
-
<%=
|
24
|
+
<%= render renderer %>
|
18
25
|
</dd>
|
19
26
|
</div>
|
20
27
|
<% end %>
|
@@ -24,6 +31,6 @@
|
|
24
31
|
|
25
32
|
<% if present_associations? %>
|
26
33
|
<% details.associations.each do |name, renderer| %>
|
27
|
-
<%= renderer.
|
34
|
+
<%= render renderer.with(record: details.record) %>
|
28
35
|
<% end %>
|
29
36
|
<% end %>
|
@@ -71,8 +71,16 @@
|
|
71
71
|
<% end %>
|
72
72
|
|
73
73
|
<% fields.each do |name, field| %>
|
74
|
+
<%#
|
75
|
+
TODO:
|
76
|
+
For now, we are hacking around the need to call #with before #label
|
77
|
+
This proves there's an issue with the rendering api.
|
78
|
+
While I think of an elegant solution, this works for now.
|
79
|
+
%>
|
80
|
+
<% field.with(record: resources[0]) %>
|
74
81
|
<% table.column(name:, label: field.label, search_object: search_object) do |resource| %>
|
75
|
-
|
82
|
+
<% field.with(record: resource) %>
|
83
|
+
<%= render field %>
|
76
84
|
<% end %>
|
77
85
|
<% end %>
|
78
86
|
<% end %>
|
@@ -13,6 +13,8 @@ module.exports = {
|
|
13
13
|
`${__dirname}/app/helpers/**/*.rb`,
|
14
14
|
`${__dirname}/app/assets/stylesheets/**/*.css`,
|
15
15
|
`${__dirname}/app/javascript/**/*.js`,
|
16
|
+
`${__dirname}/app/plutonium/**/*.rb`,
|
17
|
+
`${__dirname}/packages/**/app/plutonium/**/*.rb`,
|
16
18
|
`${__dirname}/packages/**/app/views/**/*.html.erb`,
|
17
19
|
].concat(plutoniumTailwindConfig.content),
|
18
20
|
}
|
@@ -15,11 +15,11 @@ module Pu
|
|
15
15
|
class_option :rodauth, type: :boolean
|
16
16
|
|
17
17
|
def start
|
18
|
-
destination_dir = (destination_app == "main_app") ? "app/views/" : "packages/#{destination_app}/app/views
|
18
|
+
destination_dir = (destination_app == "main_app") ? "app/views/" : "packages/#{destination_app}/app/views/"
|
19
19
|
[
|
20
20
|
"layouts/resource.html.erb"
|
21
21
|
].each do |file|
|
22
|
-
copy_file Plutonium.root.join("app", "views", file), Rails.root.join(destination_dir)
|
22
|
+
copy_file Plutonium.root.join("app", "views", file), Rails.root.join(destination_dir, file)
|
23
23
|
end
|
24
24
|
rescue => e
|
25
25
|
exception "#{self.class} failed:", e
|
@@ -33,6 +33,7 @@ module Pu
|
|
33
33
|
|
34
34
|
def copy_file(source_path, destination_path)
|
35
35
|
if File.exist?(source_path)
|
36
|
+
FileUtils.mkdir_p(File.dirname(destination_path))
|
36
37
|
FileUtils.cp(source_path, destination_path)
|
37
38
|
say_status("info", "Copied #{source_path} to #{destination_path}", :green)
|
38
39
|
else
|
@@ -14,12 +14,12 @@ module Pu
|
|
14
14
|
class_option :dest, type: :string
|
15
15
|
|
16
16
|
def start
|
17
|
-
destination_dir = (destination_app == "main_app") ? "app/views/" : "packages/#{destination_app}/app/views
|
17
|
+
destination_dir = (destination_app == "main_app") ? "app/views/" : "packages/#{destination_app}/app/views"
|
18
18
|
[
|
19
19
|
"application/_resource_header.html.erb",
|
20
20
|
"application/_resource_sidebar.html.erb"
|
21
21
|
].each do |file|
|
22
|
-
copy_file Plutonium.root.join("app", "views", file), Rails.root.join(destination_dir)
|
22
|
+
copy_file Plutonium.root.join("app", "views", file), Rails.root.join(destination_dir, file)
|
23
23
|
end
|
24
24
|
rescue => e
|
25
25
|
exception "#{self.class} failed:", e
|
@@ -33,6 +33,7 @@ module Pu
|
|
33
33
|
|
34
34
|
def copy_file(source_path, destination_path)
|
35
35
|
if File.exist?(source_path)
|
36
|
+
FileUtils.mkdir_p(File.dirname(destination_path))
|
36
37
|
FileUtils.cp(source_path, destination_path)
|
37
38
|
say_status("info", "Copied #{source_path} to #{destination_path}", :green)
|
38
39
|
else
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../lib/plutonium_generators"
|
4
|
+
|
5
|
+
module Pu
|
6
|
+
module Field
|
7
|
+
class InputGenerator < Rails::Generators::Base
|
8
|
+
include PlutoniumGenerators::Generator
|
9
|
+
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
|
12
|
+
desc "Generates a field input"
|
13
|
+
|
14
|
+
argument :name
|
15
|
+
|
16
|
+
def start
|
17
|
+
in_root do
|
18
|
+
template "input.rb", "app/plutonium/fields/inputs/#{name.underscore}_input.rb"
|
19
|
+
insert_into_file "config/initializers/plutonium.rb", registration_statement, after: /.*# Register components here.*\n/
|
20
|
+
end
|
21
|
+
rescue => e
|
22
|
+
exception "#{self.class} failed:", e
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def registration_statement
|
28
|
+
indent "Plutonium::Core::Fields::Inputs::Factory.map_type :#{name.underscore}, to: Fields::Inputs::#{name.camelize}Input\n", 2
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../lib/plutonium_generators"
|
4
|
+
|
5
|
+
module Pu
|
6
|
+
module Field
|
7
|
+
class RendererGenerator < Rails::Generators::Base
|
8
|
+
include PlutoniumGenerators::Generator
|
9
|
+
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
|
12
|
+
desc "Generates a field renderer"
|
13
|
+
|
14
|
+
argument :name
|
15
|
+
|
16
|
+
def start
|
17
|
+
in_root do
|
18
|
+
template "renderer.rb", "app/plutonium/fields/renderers/#{name.underscore}_renderer.rb"
|
19
|
+
insert_into_file "config/initializers/plutonium.rb", registration_statement, after: /.*# Register components here.*\n/
|
20
|
+
end
|
21
|
+
rescue => e
|
22
|
+
exception "#{self.class} failed:", e
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def registration_statement
|
28
|
+
indent "Plutonium::Core::Fields::Renderers::Factory.map_type :#{name.underscore}, to: Fields::Renderers::#{name.camelize}Renderer\n", 2
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
File without changes
|
@@ -2,7 +2,7 @@ module Plutonium
|
|
2
2
|
module Core
|
3
3
|
module Actions
|
4
4
|
class InteractiveAction < Plutonium::Core::Action
|
5
|
-
include Plutonium::Core::Definers::
|
5
|
+
include Plutonium::Core::Definers::FieldInputDefiner
|
6
6
|
|
7
7
|
Context = Data.define :resource_class
|
8
8
|
|
@@ -37,7 +37,7 @@ module Plutonium
|
|
37
37
|
|
38
38
|
def set_interaction(interaction)
|
39
39
|
@interaction = interaction
|
40
|
-
@inputs =
|
40
|
+
@inputs = defined_field_inputs_for(*(interaction.filters.keys - [:resource, :resources]))
|
41
41
|
@inline = @inputs.blank? unless inline == false
|
42
42
|
end
|
43
43
|
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Plutonium
|
2
|
+
module Core
|
3
|
+
module Associations
|
4
|
+
module Renderers
|
5
|
+
class Base
|
6
|
+
include Plutonium::Core::Renderable
|
7
|
+
|
8
|
+
attr_reader :name, :reflection
|
9
|
+
|
10
|
+
def initialize(name, reflection:, **user_options)
|
11
|
+
@name = name
|
12
|
+
@reflection = reflection
|
13
|
+
@user_options = user_options
|
14
|
+
end
|
15
|
+
|
16
|
+
# Sets the record object on the renderer and merges render options.
|
17
|
+
#
|
18
|
+
# @param record [Object] the record object.
|
19
|
+
# @param render_options [Hash] additional options for rendering.
|
20
|
+
# @return [self] the renderer instance.
|
21
|
+
def with(record:, **render_options)
|
22
|
+
@record = record
|
23
|
+
@render_options = render_options
|
24
|
+
@options = build_options(render_options)
|
25
|
+
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# Returns the merged options for rendering.
|
32
|
+
#
|
33
|
+
# @raise [RuntimeError] if accessed before rendering.
|
34
|
+
# @return [Hash] the merged options.
|
35
|
+
def options
|
36
|
+
raise "cannot access #options before calling #with" unless defined?(@options)
|
37
|
+
|
38
|
+
@options
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the record object.
|
42
|
+
#
|
43
|
+
# @raise [RuntimeError] if accessed before rendering.
|
44
|
+
# @return [Object] the record object.
|
45
|
+
def record
|
46
|
+
raise "cannot access #record before calling #with" unless defined?(@record)
|
47
|
+
|
48
|
+
@record
|
49
|
+
end
|
50
|
+
|
51
|
+
def renderer_options
|
52
|
+
{}
|
53
|
+
end
|
54
|
+
|
55
|
+
def label
|
56
|
+
options[:label] || record.class.human_attribute_name(name)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns the value of the record's attribute corresponding to the renderer's name.
|
60
|
+
#
|
61
|
+
# @return [Object] the value of the attribute.
|
62
|
+
def value
|
63
|
+
record.public_send(name)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Builds the options for rendering by merging renderer options, user options, and render options.
|
67
|
+
#
|
68
|
+
# @param render_options [Hash] additional options for rendering.
|
69
|
+
# @return [Hash] the merged options.
|
70
|
+
def build_options(render_options)
|
71
|
+
renderer_options.deep_merge(@user_options).deep_merge(render_options)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -17,8 +17,6 @@ module Plutonium
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.for_resource_association(resource_class, attr_name, **options)
|
20
|
-
options[:label] ||= resource_class.human_attribute_name(attr_name)
|
21
|
-
|
22
20
|
association = resource_class.try(:reflect_on_association, attr_name)
|
23
21
|
raise ArgumentError, "#{attr_name} is not a valid association of #{resource_class}" unless association.present?
|
24
22
|
raise ArgumentError, "#{association.klass} does is not a resource record" unless association.klass.include?(Plutonium::Resource::Record)
|
@@ -2,12 +2,14 @@ module Plutonium
|
|
2
2
|
module Core
|
3
3
|
module Associations
|
4
4
|
module Renderers
|
5
|
-
class HasManyRenderer <
|
6
|
-
def render
|
7
|
-
|
5
|
+
class HasManyRenderer < Base
|
6
|
+
def render
|
7
|
+
render_component(
|
8
|
+
:has_many_panel,
|
8
9
|
title: label,
|
9
|
-
src:
|
10
|
+
src: resource_url_for(reflection.klass, parent: record),
|
10
11
|
**options
|
12
|
+
)
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -15,7 +15,7 @@ module Plutonium
|
|
15
15
|
@search_object = current_query_object
|
16
16
|
base_query = policy_scope(resource_class)
|
17
17
|
base_query = @search_object.apply(base_query)
|
18
|
-
base_query = base_query.
|
18
|
+
base_query = base_query.public_send(params[:scope].to_sym) if params[:scope].present?
|
19
19
|
@pagy, @resource_records = pagy base_query
|
20
20
|
@collection = build_collection
|
21
21
|
|
@@ -32,7 +32,7 @@ module Plutonium
|
|
32
32
|
Plutonium::Core::Ui::Collection.new(
|
33
33
|
resource_class:,
|
34
34
|
records: @resource_records,
|
35
|
-
fields: current_presenter.
|
35
|
+
fields: current_presenter.defined_field_renderers_for(*presentable_attributes),
|
36
36
|
actions: current_presenter.actions,
|
37
37
|
pager: @pagy,
|
38
38
|
search_object: @search_object
|
@@ -43,7 +43,7 @@ module Plutonium
|
|
43
43
|
Plutonium::Core::Ui::Detail.new(
|
44
44
|
resource_class:,
|
45
45
|
record: resource_record,
|
46
|
-
fields: current_presenter.
|
46
|
+
fields: current_presenter.defined_field_renderers_for(*presentable_attributes),
|
47
47
|
associations: current_presenter.defined_association_renderers_for(*permitted_associations),
|
48
48
|
actions: current_presenter.actions
|
49
49
|
)
|
@@ -52,7 +52,7 @@ module Plutonium
|
|
52
52
|
def build_form
|
53
53
|
Plutonium::Core::Ui::Form.new(
|
54
54
|
record: resource_record,
|
55
|
-
inputs: current_presenter.
|
55
|
+
inputs: current_presenter.defined_field_inputs_for(*presentable_attributes)
|
56
56
|
)
|
57
57
|
end
|
58
58
|
|
@@ -4,14 +4,14 @@ module Plutonium
|
|
4
4
|
module FieldDefiner
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
-
include
|
8
|
-
include
|
7
|
+
include FieldInputDefiner
|
8
|
+
include FieldRendererDefiner
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def define_field(name, type: nil, input: nil, renderer: nil, input_options: {}, renderer_options: {})
|
13
|
-
|
14
|
-
|
13
|
+
define_field_input(name, type:, input:, **input_options)
|
14
|
+
define_field_renderer(name, type:, renderer:, **renderer_options)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Plutonium
|
2
2
|
module Core
|
3
3
|
module Definers
|
4
|
-
module
|
4
|
+
module FieldInputDefiner
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
include Plutonium::Core::Autodiscovery::InputDiscoverer
|
7
7
|
|
@@ -47,14 +47,14 @@ module Plutonium
|
|
47
47
|
attr_reader :hash
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
50
|
+
def defined_field_inputs_for(*names)
|
51
51
|
(names - input_definitions.keys).each do |name|
|
52
|
-
|
52
|
+
define_field_input(name, input: autodiscover_input(name))
|
53
53
|
end
|
54
54
|
input_definitions.slice(*names)
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
57
|
+
def define_field_input(name, input: nil, type: nil, **options)
|
58
58
|
input_definitions[name] = if input.present?
|
59
59
|
input
|
60
60
|
elsif type.present?
|