Class: Panda::Core::WidgetRegistry
- Inherits:
-
Object
- Object
- Panda::Core::WidgetRegistry
- Defined in:
- lib/panda/core/widget_registry.rb
Class Attribute Summary collapse
-
.widgets ⇒ Object
readonly
Returns the value of attribute widgets.
Class Method Summary collapse
-
.build(user) ⇒ Array
Build the widget list for the current user.
-
.register(label, component:, visible: nil, position: 0) ⇒ Object
Register a dashboard widget.
-
.reset! ⇒ Object
Clear all registrations (for test isolation).
Class Attribute Details
.widgets ⇒ Object (readonly)
Returns the value of attribute widgets.
9 10 11 |
# File 'lib/panda/core/widget_registry.rb', line 9 def @widgets end |
Class Method Details
.build(user) ⇒ Array
Build the widget list for the current user. Combines the legacy admin_dashboard_widgets lambda with registered widgets.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/panda/core/widget_registry.rb', line 30 def build(user) # Legacy backward-compatible widgets from the lambda legacy = Panda::Core.config.&.call(user) || [] # Registered widgets — filter by visibility, sort by position, instantiate registered = @widgets .select { |w| w[:visible].nil? || w[:visible].call(user) } .sort_by { |w| w[:position] } .map { |w| w[:component].call(user) } legacy + registered end |
.register(label, component:, visible: nil, position: 0) ⇒ Object
Register a dashboard widget. Duplicate labels are replaced (last registration wins).
17 18 19 20 21 22 23 24 |
# File 'lib/panda/core/widget_registry.rb', line 17 def register(label, component:, visible: nil, position: 0) = {label: label, component: component, visible: visible, position: position} if (index = @widgets.index { |w| w[:label] == label }) @widgets[index] = else @widgets << end end |
.reset! ⇒ Object
Clear all registrations (for test isolation).
44 45 46 |
# File 'lib/panda/core/widget_registry.rb', line 44 def reset! @widgets = [] end |