easy-admin-rails 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/builds/easy_admin.base.js +7 -0
- data/app/assets/builds/easy_admin.base.js.map +2 -2
- data/app/assets/builds/easy_admin.css +207 -35
- data/app/components/easy_admin/fields/form/belongs_to_component.rb +0 -1
- data/app/components/easy_admin/form_layout_component.rb +553 -0
- data/app/components/easy_admin/permissions/user_role_permissions_component.rb +1 -3
- data/app/components/easy_admin/show_layout_component.rb +694 -24
- data/app/controllers/easy_admin/application_controller.rb +0 -5
- data/app/controllers/easy_admin/batch_actions_controller.rb +0 -1
- data/app/controllers/easy_admin/concerns/inline_field_editing.rb +4 -11
- data/app/controllers/easy_admin/concerns/resource_loading.rb +10 -9
- data/app/controllers/easy_admin/concerns/resource_pagination.rb +3 -0
- data/app/controllers/easy_admin/dashboards_controller.rb +0 -1
- data/app/controllers/easy_admin/resources_controller.rb +1 -5
- data/app/controllers/easy_admin/row_actions_controller.rb +1 -4
- data/app/helpers/easy_admin/fields_helper.rb +8 -22
- data/app/javascript/easy_admin/controllers/infinite_scroll_controller.js +12 -0
- data/app/views/easy_admin/resources/edit.html.erb +2 -2
- data/app/views/easy_admin/resources/new.html.erb +2 -2
- data/app/views/easy_admin/resources/show.html.erb +3 -1
- data/lib/easy_admin/field.rb +3 -2
- data/lib/easy_admin/layouts/builders/base_layout_builder.rb +245 -0
- data/lib/easy_admin/layouts/builders/form_layout_builder.rb +208 -0
- data/lib/easy_admin/layouts/builders/index_layout_builder.rb +22 -0
- data/lib/easy_admin/layouts/builders/show_layout_builder.rb +199 -0
- data/lib/easy_admin/layouts/dsl.rb +200 -0
- data/lib/easy_admin/layouts/layout_context.rb +189 -0
- data/lib/easy_admin/layouts/nodes/base_node.rb +88 -0
- data/lib/easy_admin/layouts/nodes/divider.rb +27 -0
- data/lib/easy_admin/layouts/nodes/field_node.rb +57 -0
- data/lib/easy_admin/layouts/nodes/grid.rb +60 -0
- data/lib/easy_admin/layouts/nodes/render_node.rb +41 -0
- data/lib/easy_admin/layouts/nodes/root.rb +25 -0
- data/lib/easy_admin/layouts/nodes/section.rb +46 -0
- data/lib/easy_admin/layouts/nodes/spacer.rb +17 -0
- data/lib/easy_admin/layouts/nodes/stubs.rb +109 -0
- data/lib/easy_admin/layouts/nodes/tab.rb +40 -0
- data/lib/easy_admin/layouts/nodes/tabs.rb +40 -0
- data/lib/easy_admin/layouts.rb +28 -0
- data/lib/easy_admin/permissions/resource_permissions.rb +1 -5
- data/lib/easy_admin/resource/base.rb +2 -2
- data/lib/easy_admin/resource/dsl.rb +2 -11
- data/lib/easy_admin/resource/field_registry.rb +58 -2
- data/lib/easy_admin/resource.rb +0 -9
- data/lib/easy_admin/resource_modules.rb +21 -4
- data/lib/easy_admin/version.rb +1 -1
- data/lib/generators/easy_admin/permissions/install_generator.rb +0 -10
- data/lib/generators/easy_admin/permissions/templates/migrations/create_permission_tables.rb +33 -3
- metadata +21 -9
- data/lib/easy_admin/resource/form_builder.rb +0 -123
- data/lib/easy_admin/resource/layout_builder.rb +0 -249
- data/lib/easy_admin/resource/show_builder.rb +0 -359
- data/lib/generators/easy_admin/permissions/templates/migrations/update_users_for_permissions.rb +0 -6
- data/lib/generators/easy_admin/rbac/rbac_generator.rb +0 -244
- data/lib/generators/easy_admin/rbac/templates/add_rbac_to_admin_users.rb +0 -23
- data/lib/generators/easy_admin/rbac/templates/super_admin.rb +0 -34
@@ -0,0 +1,40 @@
|
|
1
|
+
module EasyAdmin
|
2
|
+
module Layouts
|
3
|
+
module Nodes
|
4
|
+
# Container for tab nodes
|
5
|
+
class Tabs < BaseNode
|
6
|
+
def initialize(attributes = {})
|
7
|
+
super
|
8
|
+
@attributes[:type] ||= :horizontal
|
9
|
+
@attributes[:id] ||= "tabs-#{SecureRandom.hex(4)}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def horizontal?
|
13
|
+
@attributes[:type] == :horizontal
|
14
|
+
end
|
15
|
+
|
16
|
+
def vertical?
|
17
|
+
@attributes[:type] == :vertical
|
18
|
+
end
|
19
|
+
|
20
|
+
def tabs_id
|
21
|
+
@attributes[:id]
|
22
|
+
end
|
23
|
+
|
24
|
+
def active_tab_index
|
25
|
+
@attributes[:active_tab] || 0
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get all tab children
|
29
|
+
def tabs
|
30
|
+
@children.select { |child| child.is_a?(Tab) }
|
31
|
+
end
|
32
|
+
|
33
|
+
# Find tab by name
|
34
|
+
def find_tab(name)
|
35
|
+
tabs.find { |tab| tab[:name] == name.to_s }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module EasyAdmin
|
2
|
+
module Layouts
|
3
|
+
# Registry for custom components
|
4
|
+
mattr_accessor :registered_components, default: {}
|
5
|
+
|
6
|
+
class << self
|
7
|
+
# Register a custom component for use in DSL
|
8
|
+
def register_component(name, component_class)
|
9
|
+
registered_components[name.to_sym] = component_class
|
10
|
+
end
|
11
|
+
|
12
|
+
# Unregister a component
|
13
|
+
def unregister_component(name)
|
14
|
+
registered_components.delete(name.to_sym)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Clear all registered components
|
18
|
+
def clear_registered_components!
|
19
|
+
registered_components.clear
|
20
|
+
end
|
21
|
+
|
22
|
+
# Check if component is registered
|
23
|
+
def component_registered?(name)
|
24
|
+
registered_components.key?(name.to_sym)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -74,8 +74,6 @@ module EasyAdmin
|
|
74
74
|
|
75
75
|
# Seed permissions into database
|
76
76
|
def seed_permissions!
|
77
|
-
Rails.logger.info "🔐 Seeding EasyAdmin resource permissions..."
|
78
|
-
|
79
77
|
permissions_data = discover_all_permissions
|
80
78
|
created_count = 0
|
81
79
|
|
@@ -90,8 +88,6 @@ module EasyAdmin
|
|
90
88
|
|
91
89
|
created_count += 1 if permission.saved_change_to_id?
|
92
90
|
end
|
93
|
-
|
94
|
-
Rails.logger.info "✅ Seeded #{created_count} new permissions (#{permissions_data.size} total)"
|
95
91
|
permissions_data.size
|
96
92
|
end
|
97
93
|
|
@@ -228,4 +224,4 @@ module EasyAdmin
|
|
228
224
|
end
|
229
225
|
end
|
230
226
|
end
|
231
|
-
end
|
227
|
+
end
|
@@ -10,8 +10,8 @@ module EasyAdmin
|
|
10
10
|
include EasyAdmin::ResourceModules::Configuration
|
11
11
|
include EasyAdmin::ResourceModules::DSL
|
12
12
|
include EasyAdmin::ResourceModules::FieldRegistry
|
13
|
-
include EasyAdmin::ResourceModules::LayoutBuilder
|
14
13
|
include EasyAdmin::ResourceModules::ScopeManager
|
14
|
+
include EasyAdmin::Layouts::DSL
|
15
15
|
|
16
16
|
# Class attributes for core functionality
|
17
17
|
class_attribute :resource_name, :custom_title
|
@@ -28,8 +28,8 @@ module EasyAdmin
|
|
28
28
|
self.resource_name = name.demodulize.gsub(/Resource$/, '')
|
29
29
|
initialize_configurations
|
30
30
|
initialize_field_registry
|
31
|
-
initialize_layout_builder
|
32
31
|
initialize_scope_manager
|
32
|
+
# Layout initialization is now handled by EasyAdmin::Layouts::DSL
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -77,17 +77,8 @@ module EasyAdmin
|
|
77
77
|
**options.except(:confirmation_label))
|
78
78
|
end
|
79
79
|
|
80
|
-
#
|
81
|
-
|
82
|
-
form_builder = EasyAdmin::ResourceModules::FormBuilder.new(self)
|
83
|
-
form_builder.instance_eval(&block)
|
84
|
-
end
|
85
|
-
|
86
|
-
# Show layout building DSL
|
87
|
-
def show(&block)
|
88
|
-
show_builder = EasyAdmin::ResourceModules::ShowBuilder.new(self)
|
89
|
-
show_builder.instance_eval(&block)
|
90
|
-
end
|
80
|
+
# Layout DSL is now handled by EasyAdmin::Layouts::DSL module
|
81
|
+
# See lib/easy_admin/layouts/dsl.rb for implementation
|
91
82
|
|
92
83
|
# Batch Actions DSL
|
93
84
|
def enable_batch_actions
|
@@ -55,7 +55,13 @@ module EasyAdmin
|
|
55
55
|
|
56
56
|
# Field categorization methods
|
57
57
|
def index_fields
|
58
|
-
|
58
|
+
# If custom index layout is defined, extract fields from the AST
|
59
|
+
if has_custom_index_layout?
|
60
|
+
extract_index_fields_from_layout
|
61
|
+
else
|
62
|
+
# Default behavior: return fields excluding certain types
|
63
|
+
fields_config.select { |field| ![:text, :has_many, :file].include?(field[:type]) }
|
64
|
+
end
|
59
65
|
end
|
60
66
|
|
61
67
|
def sortable_fields
|
@@ -183,7 +189,57 @@ module EasyAdmin
|
|
183
189
|
def association_fields_count
|
184
190
|
association_fields.count
|
185
191
|
end
|
192
|
+
|
193
|
+
private
|
194
|
+
|
195
|
+
# Extract fields from custom index layout AST
|
196
|
+
def extract_index_fields_from_layout
|
197
|
+
return [] unless index_layout_content
|
198
|
+
|
199
|
+
# Extract field nodes from the index layout AST
|
200
|
+
extract_field_configs_from_ast_node(index_layout_content)
|
201
|
+
end
|
202
|
+
|
203
|
+
# Helper method to recursively extract field configs from AST nodes
|
204
|
+
def extract_field_configs_from_ast_node(node)
|
205
|
+
field_configs = []
|
206
|
+
|
207
|
+
if node.is_a?(EasyAdmin::Layouts::Nodes::FieldNode)
|
208
|
+
# For index layouts, look up the field config from registered fields
|
209
|
+
base_field_config = find_field_config(node.field_name)
|
210
|
+
|
211
|
+
if base_field_config
|
212
|
+
# Use the registered field config with any node-specific overrides
|
213
|
+
# Only merge non-nil values from node attributes to preserve base config
|
214
|
+
field_config = base_field_config.dup
|
215
|
+
node.attributes.each do |key, value|
|
216
|
+
field_config[key] = value unless value.nil?
|
217
|
+
end
|
218
|
+
field_configs << field_config
|
219
|
+
else
|
220
|
+
field_config = {
|
221
|
+
name: node.field_name,
|
222
|
+
type: :string,
|
223
|
+
label: node.field_name.to_s.humanize,
|
224
|
+
sortable: true,
|
225
|
+
searchable: false,
|
226
|
+
filterable: false,
|
227
|
+
readonly: false
|
228
|
+
}.merge(node.attributes)
|
229
|
+
field_configs << field_config
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
# Recursively process child nodes
|
234
|
+
if node.respond_to?(:children) && node.children
|
235
|
+
node.children.each do |child_node|
|
236
|
+
field_configs += extract_field_configs_from_ast_node(child_node)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
field_configs
|
241
|
+
end
|
186
242
|
end
|
187
243
|
end
|
188
244
|
end
|
189
|
-
end
|
245
|
+
end
|
data/lib/easy_admin/resource.rb
CHANGED
@@ -1,14 +1,5 @@
|
|
1
1
|
module EasyAdmin
|
2
2
|
class Resource
|
3
3
|
include EasyAdmin::ResourceModules::Base
|
4
|
-
|
5
|
-
# Legacy methods - kept for backward compatibility
|
6
|
-
# These delegate to the appropriate modules
|
7
|
-
|
8
|
-
# Deprecated classes - kept for backward compatibility
|
9
|
-
# Use EasyAdmin::ResourceModules::FormBuilder instead
|
10
|
-
FormBuilder = EasyAdmin::ResourceModules::FormBuilder
|
11
|
-
ShowBuilder = EasyAdmin::ResourceModules::ShowBuilder
|
12
|
-
ChartBuilder = EasyAdmin::ResourceModules::ChartBuilder
|
13
4
|
end
|
14
5
|
end
|
@@ -4,8 +4,25 @@
|
|
4
4
|
require_relative 'resource/configuration'
|
5
5
|
require_relative 'resource/field_registry'
|
6
6
|
require_relative 'resource/scope_manager'
|
7
|
-
require_relative 'resource/layout_builder'
|
8
|
-
require_relative 'resource/form_builder'
|
9
|
-
require_relative 'resource/show_builder'
|
10
7
|
require_relative 'resource/dsl'
|
11
|
-
require_relative 'resource/base'
|
8
|
+
require_relative 'resource/base'
|
9
|
+
|
10
|
+
# Layout system modules
|
11
|
+
require_relative 'layouts'
|
12
|
+
require_relative 'layouts/nodes/base_node'
|
13
|
+
require_relative 'layouts/nodes/root'
|
14
|
+
require_relative 'layouts/nodes/tabs'
|
15
|
+
require_relative 'layouts/nodes/tab'
|
16
|
+
require_relative 'layouts/nodes/field_node'
|
17
|
+
require_relative 'layouts/nodes/render_node'
|
18
|
+
require_relative 'layouts/nodes/section'
|
19
|
+
require_relative 'layouts/nodes/grid'
|
20
|
+
require_relative 'layouts/nodes/divider'
|
21
|
+
require_relative 'layouts/nodes/spacer'
|
22
|
+
require_relative 'layouts/nodes/stubs'
|
23
|
+
require_relative 'layouts/layout_context'
|
24
|
+
require_relative 'layouts/builders/base_layout_builder'
|
25
|
+
require_relative 'layouts/builders/show_layout_builder'
|
26
|
+
require_relative 'layouts/builders/form_layout_builder'
|
27
|
+
require_relative 'layouts/builders/index_layout_builder'
|
28
|
+
require_relative 'layouts/dsl'
|
data/lib/easy_admin/version.rb
CHANGED
@@ -24,11 +24,6 @@ module EasyAdmin
|
|
24
24
|
def create_migrations
|
25
25
|
migration_template 'migrations/create_permission_tables.rb',
|
26
26
|
'db/migrate/create_easy_admin_permission_tables.rb'
|
27
|
-
|
28
|
-
if options[:user_model] != 'User' || has_user_model_changes?
|
29
|
-
migration_template 'migrations/update_users_for_permissions.rb',
|
30
|
-
'db/migrate/update_users_for_easy_admin_permissions.rb'
|
31
|
-
end
|
32
27
|
end
|
33
28
|
|
34
29
|
def create_initializer
|
@@ -79,11 +74,6 @@ module EasyAdmin
|
|
79
74
|
options[:contexts]
|
80
75
|
end
|
81
76
|
|
82
|
-
def has_user_model_changes?
|
83
|
-
# Check if we need to add permissions_cache column
|
84
|
-
!File.exist?("app/models/#{options[:user_model].underscore}.rb") ||
|
85
|
-
!File.read("app/models/#{options[:user_model].underscore}.rb").include?('permissions_cache')
|
86
|
-
end
|
87
77
|
end
|
88
78
|
end
|
89
79
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class CreateEasyAdminPermissionTables < ActiveRecord::Migration<%= migration_version %>
|
2
2
|
def change
|
3
|
-
# Roles table
|
3
|
+
# Roles table
|
4
4
|
create_table :easy_admin_roles do |t|
|
5
5
|
t.string :name, null: false
|
6
6
|
t.string :slug, null: false
|
@@ -13,15 +13,45 @@ class CreateEasyAdminPermissionTables < ActiveRecord::Migration<%= migration_ver
|
|
13
13
|
t.index :active
|
14
14
|
end
|
15
15
|
|
16
|
-
# User-Role join table
|
16
|
+
# User-Role join table with support for scoped and temporary permissions
|
17
17
|
create_table :easy_admin_user_roles do |t|
|
18
18
|
t.references :user, null: false, foreign_key: true
|
19
19
|
t.references :role, null: false, foreign_key: { to_table: :easy_admin_roles }
|
20
|
+
|
21
|
+
# For scoped permissions (e.g., role applies only to specific organization/project)
|
22
|
+
t.string :context_type
|
23
|
+
t.integer :context_id
|
24
|
+
|
25
|
+
# For temporary permissions
|
26
|
+
t.datetime :expires_at
|
27
|
+
|
28
|
+
# Track who granted this role
|
29
|
+
t.integer :granted_by_id
|
30
|
+
|
20
31
|
t.boolean :active, default: true
|
21
32
|
t.timestamps
|
22
33
|
|
23
|
-
|
34
|
+
# Unique constraint for user-role-context combination
|
35
|
+
t.index [:user_id, :role_id, :context_type, :context_id],
|
36
|
+
unique: true,
|
37
|
+
name: 'index_easy_admin_user_roles_unique'
|
38
|
+
|
39
|
+
# Performance indexes
|
24
40
|
t.index [:user_id, :active], name: 'index_easy_admin_user_roles_active'
|
41
|
+
t.index [:user_id, :context_type, :context_id], name: 'index_easy_admin_user_roles_context'
|
42
|
+
t.index [:context_type, :context_id], name: 'index_easy_admin_user_roles_on_context'
|
43
|
+
t.index :expires_at
|
44
|
+
end
|
45
|
+
|
46
|
+
# Add permissions_cache to admin_users if needed
|
47
|
+
unless column_exists?(:easy_admin_admin_users, :permissions_cache)
|
48
|
+
add_column :easy_admin_admin_users, :permissions_cache, :json, default: {}
|
49
|
+
add_index :easy_admin_admin_users, :permissions_cache
|
50
|
+
end
|
51
|
+
|
52
|
+
# Add role_id to admin_users for default role assignment
|
53
|
+
unless column_exists?(:easy_admin_admin_users, :role_id)
|
54
|
+
add_reference :easy_admin_admin_users, :role, foreign_key: { to_table: :easy_admin_roles }
|
25
55
|
end
|
26
56
|
end
|
27
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy-admin-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Slaurmagan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-09-
|
11
|
+
date: 2025-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -261,6 +261,7 @@ files:
|
|
261
261
|
- app/components/easy_admin/fields/show/text_component.rb
|
262
262
|
- app/components/easy_admin/fields/show/textarea_component.rb
|
263
263
|
- app/components/easy_admin/filters_component.rb
|
264
|
+
- app/components/easy_admin/form_layout_component.rb
|
264
265
|
- app/components/easy_admin/form_tabs_component.rb
|
265
266
|
- app/components/easy_admin/infinite_scroll_component.rb
|
266
267
|
- app/components/easy_admin/lazy_chart_card_component.rb
|
@@ -425,6 +426,24 @@ files:
|
|
425
426
|
- lib/easy_admin/delete_action.rb
|
426
427
|
- lib/easy_admin/engine.rb
|
427
428
|
- lib/easy_admin/field.rb
|
429
|
+
- lib/easy_admin/layouts.rb
|
430
|
+
- lib/easy_admin/layouts/builders/base_layout_builder.rb
|
431
|
+
- lib/easy_admin/layouts/builders/form_layout_builder.rb
|
432
|
+
- lib/easy_admin/layouts/builders/index_layout_builder.rb
|
433
|
+
- lib/easy_admin/layouts/builders/show_layout_builder.rb
|
434
|
+
- lib/easy_admin/layouts/dsl.rb
|
435
|
+
- lib/easy_admin/layouts/layout_context.rb
|
436
|
+
- lib/easy_admin/layouts/nodes/base_node.rb
|
437
|
+
- lib/easy_admin/layouts/nodes/divider.rb
|
438
|
+
- lib/easy_admin/layouts/nodes/field_node.rb
|
439
|
+
- lib/easy_admin/layouts/nodes/grid.rb
|
440
|
+
- lib/easy_admin/layouts/nodes/render_node.rb
|
441
|
+
- lib/easy_admin/layouts/nodes/root.rb
|
442
|
+
- lib/easy_admin/layouts/nodes/section.rb
|
443
|
+
- lib/easy_admin/layouts/nodes/spacer.rb
|
444
|
+
- lib/easy_admin/layouts/nodes/stubs.rb
|
445
|
+
- lib/easy_admin/layouts/nodes/tab.rb
|
446
|
+
- lib/easy_admin/layouts/nodes/tabs.rb
|
428
447
|
- lib/easy_admin/permissions.rb
|
429
448
|
- lib/easy_admin/permissions/component.rb
|
430
449
|
- lib/easy_admin/permissions/configuration.rb
|
@@ -442,10 +461,7 @@ files:
|
|
442
461
|
- lib/easy_admin/resource/configuration.rb
|
443
462
|
- lib/easy_admin/resource/dsl.rb
|
444
463
|
- lib/easy_admin/resource/field_registry.rb
|
445
|
-
- lib/easy_admin/resource/form_builder.rb
|
446
|
-
- lib/easy_admin/resource/layout_builder.rb
|
447
464
|
- lib/easy_admin/resource/scope_manager.rb
|
448
|
-
- lib/easy_admin/resource/show_builder.rb
|
449
465
|
- lib/easy_admin/resource_modules.rb
|
450
466
|
- lib/easy_admin/resource_registry.rb
|
451
467
|
- lib/easy_admin/two_factor_authentication.rb
|
@@ -461,7 +477,6 @@ files:
|
|
461
477
|
- lib/generators/easy_admin/permissions/install_generator.rb
|
462
478
|
- lib/generators/easy_admin/permissions/templates/initializers/permissions.rb
|
463
479
|
- lib/generators/easy_admin/permissions/templates/migrations/create_permission_tables.rb
|
464
|
-
- lib/generators/easy_admin/permissions/templates/migrations/update_users_for_permissions.rb
|
465
480
|
- lib/generators/easy_admin/permissions/templates/models/permission.rb
|
466
481
|
- lib/generators/easy_admin/permissions/templates/models/role.rb
|
467
482
|
- lib/generators/easy_admin/permissions/templates/models/role_permission.rb
|
@@ -469,9 +484,6 @@ files:
|
|
469
484
|
- lib/generators/easy_admin/permissions/templates/policies/application_policy.rb
|
470
485
|
- lib/generators/easy_admin/permissions/templates/policies/user_policy.rb
|
471
486
|
- lib/generators/easy_admin/permissions/templates/seeds/permissions.rb
|
472
|
-
- lib/generators/easy_admin/rbac/rbac_generator.rb
|
473
|
-
- lib/generators/easy_admin/rbac/templates/add_rbac_to_admin_users.rb
|
474
|
-
- lib/generators/easy_admin/rbac/templates/super_admin.rb
|
475
487
|
- lib/generators/easy_admin/resource_generator.rb
|
476
488
|
- lib/generators/easy_admin/templates/AUTH_README
|
477
489
|
- lib/generators/easy_admin/templates/README
|
@@ -1,123 +0,0 @@
|
|
1
|
-
module EasyAdmin
|
2
|
-
module ResourceModules
|
3
|
-
# FormBuilder class for form DSL
|
4
|
-
# Handles all form tab and field definitions within forms
|
5
|
-
class FormBuilder
|
6
|
-
def initialize(resource_class)
|
7
|
-
@resource_class = resource_class
|
8
|
-
@current_tab = nil
|
9
|
-
end
|
10
|
-
|
11
|
-
def tab(name = "General", **options, &block)
|
12
|
-
tab_config = {
|
13
|
-
name: name,
|
14
|
-
label: options[:label] || name,
|
15
|
-
icon: options[:icon],
|
16
|
-
fields: []
|
17
|
-
}
|
18
|
-
|
19
|
-
@current_tab = tab_config
|
20
|
-
@resource_class.add_form_tab(tab_config)
|
21
|
-
|
22
|
-
instance_eval(&block) if block_given?
|
23
|
-
@current_tab = nil
|
24
|
-
end
|
25
|
-
|
26
|
-
# Field definition methods within tabs - delegate to resource
|
27
|
-
def field(name, type = :string, **options)
|
28
|
-
field_config = @resource_class.build_field_config(name, type, **options)
|
29
|
-
|
30
|
-
if @current_tab
|
31
|
-
@current_tab[:fields] << field_config
|
32
|
-
end
|
33
|
-
|
34
|
-
# Also add to main fields_config for compatibility
|
35
|
-
@resource_class.add_field_to_registry(field_config)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Convenience methods for form fields
|
39
|
-
def text_field(name, **options)
|
40
|
-
field(name, :string, **options)
|
41
|
-
end
|
42
|
-
|
43
|
-
def textarea_field(name, **options)
|
44
|
-
field(name, :text, **options)
|
45
|
-
end
|
46
|
-
|
47
|
-
def number_field(name, **options)
|
48
|
-
field(name, :number, **options)
|
49
|
-
end
|
50
|
-
|
51
|
-
def email_field(name, **options)
|
52
|
-
field(name, :email, **options)
|
53
|
-
end
|
54
|
-
|
55
|
-
def date_field(name, **options)
|
56
|
-
field(name, :date, **options)
|
57
|
-
end
|
58
|
-
|
59
|
-
def datetime_field(name, **options)
|
60
|
-
field(name, :datetime, **options)
|
61
|
-
end
|
62
|
-
|
63
|
-
def boolean_field(name, **options)
|
64
|
-
field(name, :boolean, **options)
|
65
|
-
end
|
66
|
-
|
67
|
-
def select_field(name, options:, **other_options)
|
68
|
-
field(name, :select, options: options, **other_options)
|
69
|
-
end
|
70
|
-
|
71
|
-
def belongs_to_field(name, **options)
|
72
|
-
field(name, :belongs_to, **options)
|
73
|
-
end
|
74
|
-
|
75
|
-
def has_many_field(name, **options)
|
76
|
-
field(name, :has_many, **options)
|
77
|
-
end
|
78
|
-
|
79
|
-
def file_field(name, **options)
|
80
|
-
field(name, :file, **options)
|
81
|
-
end
|
82
|
-
|
83
|
-
def json_field(name, **options)
|
84
|
-
field(name, :json, **options)
|
85
|
-
end
|
86
|
-
|
87
|
-
def password_field(name = :password, **options)
|
88
|
-
field(name, :password, **options)
|
89
|
-
field("#{name}_confirmation".to_sym, :password,
|
90
|
-
label: options[:confirmation_label] || "Confirm #{name.to_s.humanize}",
|
91
|
-
**options.except(:confirmation_label))
|
92
|
-
end
|
93
|
-
|
94
|
-
# Support for rendering custom components in forms
|
95
|
-
def render(component_class_or_instance, **options)
|
96
|
-
content_config = {
|
97
|
-
type: :custom_component,
|
98
|
-
component_class: component_class_or_instance.class,
|
99
|
-
component_options: options,
|
100
|
-
component_instance: component_class_or_instance
|
101
|
-
}
|
102
|
-
|
103
|
-
if @current_tab
|
104
|
-
@current_tab[:fields] << content_config
|
105
|
-
end
|
106
|
-
|
107
|
-
component_class_or_instance
|
108
|
-
end
|
109
|
-
|
110
|
-
# Support for custom content blocks in forms
|
111
|
-
def content(&block)
|
112
|
-
content_config = {
|
113
|
-
type: :custom_content,
|
114
|
-
block: block
|
115
|
-
}
|
116
|
-
|
117
|
-
if @current_tab
|
118
|
-
@current_tab[:fields] << content_config
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|