Class: Plutonium::UI::Page::Index

Inherits:
Base show all
Defined in:
lib/plutonium/ui/page/index.rb

Direct Known Subclasses

Definition::Base::IndexPage

Class Method Summary collapse

Methods inherited from Base

#initialize, #view_template

Methods included from Component::Behaviour

#around_template

Methods included from Component::Tokens

#classes, #tokens

Methods included from Component::Kit

#BuildActionButton, #BuildActionsDropdown, #BuildAvatar, #BuildBlock, #BuildBreadcrumbs, #BuildBulkActionsToolbar, #BuildColorModeSelector, #BuildDynaFrameContent, #BuildDynaFrameHost, #BuildEmptyCard, #BuildFrameNavigatorPanel, #BuildModalCentered, #BuildModalSlideover, #BuildPageHeader, #BuildPanel, #BuildRowActionsDropdown, #BuildSkeletonTable, #BuildTabList, #BuildTableFilterPills, #BuildTableInfo, #BuildTablePagination, #BuildTableScopesBar, #BuildTableScopesPills, #BuildTableSearchBar, #BuildTableToolbar, #BuildTableViewSwitcher, #method_missing, #respond_to_missing?

Constructor Details

This class inherits a constructor from Plutonium::UI::Page::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Plutonium::UI::Component::Kit

Class Method Details

.collection_dom_id(resource_class) ⇒ Object

DOM id of the wrapper around the rendered collection (table OR grid; never the kanban board, which owns its own column frames).

This is the turbo-stream target the reposition endpoint updates when a drop leaves the client's optimistic view stale, and the element the drag controllers (Tasks 7/8) scope themselves to. Resource-scoped so two collections of DIFFERENT resources on one page (a nested association panel inside a show page) don't collide.



33
34
35
# File 'lib/plutonium/ui/page/index.rb', line 33

def self.collection_dom_id(resource_class)
  "pu-collection-#{resource_class.model_name.plural}"
end

.resolve_view(definition, resource_class, view_param, cookies) ⇒ Object

Resolves the index view to render. Extracted to a class method because the reposition endpoint has to re-render the SAME view the user is looking at, and re-deriving that from scratch in the controller would be a second, drifting copy of this precedence.

Resolution order:

  1. ?view= URL param (so a shared link can pin a view)
  2. The view-preference cookie (sticky per-resource selection)
  3. The resource's default_index_view (which itself defaults to index_views.first)


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/plutonium/ui/page/index.rb', line 47

def self.resolve_view(definition, resource_class, view_param, cookies)
  enabled = definition.defined_index_views

  requested = view_param&.to_sym
  return requested if requested && enabled.include?(requested)

  stored = cookies[view_cookie_name(resource_class)]&.to_sym
  return stored if stored && enabled.include?(stored)

  definition.default_index_view
end

Cookie name carrying a per-resource view preference. Single source of truth — Table::Resource, Grid::Resource, and the Stimulus view-switcher controller all read from here. Underscored token-only characters keep this RFC 6265-compliant (the : form this replaces is technically forbidden, even if browsers accept it in practice).



13
14
15
# File 'lib/plutonium/ui/page/index.rb', line 13

def self.view_cookie_name(resource_class)
  "pu_view_#{resource_class.name.gsub("::", "_").underscore}"
end

Cookie Path scoped to the engine mount point (request.script_name). Two portals mounting the same resource class get independent view preferences instead of leaking through a site-wide cookie.



20
21
22
23
# File 'lib/plutonium/ui/page/index.rb', line 20

def self.view_cookie_path(request)
  path = request.script_name.to_s
  path.empty? ? "/" : path
end