pub struct Panel { /* private fields */ }Expand description
An admin panel: resources and pages under one prefix, framed by one shell
and gated by one Auth.
The app owns the router and mounts the panel into it with
RouterBuilderPanelExt::panel:
let router = Router::builder()
.discover()
.app_context(db)
.panel(Panel::new("admin").resource::<UserResource>())?
.build();Registering is declarative: mounting builds each resource’s ResourceDef and checks every
slug, route and declaration before the panel serves anything.
Implementations§
Source§impl Panel
impl Panel
Sourcepub async fn render_shell<'a>(
cx: &'a Cx,
nav_items: &[NavigationItem],
current_path: &str,
slot: Child<'a>,
extra_class: Option<String>,
) -> Result<BoxView<'a>>
pub async fn render_shell<'a>( cx: &'a Cx, nav_items: &[NavigationItem], current_path: &str, slot: Child<'a>, extra_class: Option<String>, ) -> Result<BoxView<'a>>
Renders the shell around slot with an optional outer class.
Sourcepub fn layout_shell<'a>(cx: &'a Cx, slot: Slot<'a>) -> BoxView<'a>
pub fn layout_shell<'a>(cx: &'a Cx, slot: Slot<'a>) -> BoxView<'a>
The panel shell around a page, as a complete HTML document: the layout
every panel registers at its prefix unless Panel::layout replaces
it, and what a replacement calls to keep the shell around its own
markup.
The stylesheet and font are supplied to the Panel builder with
Self::shell_assets. A Panel without those values remains renderable
for tests and custom document owners, but does not pretend that a CSS
bundle exists. Errors from the page slot propagate unchanged when the
document view is resolved.
Source§impl Panel
impl Panel
Sourcepub fn new(prefix: impl Into<String>) -> Self
pub fn new(prefix: impl Into<String>) -> Self
Creates a Panel mounted at prefix, defaulting an empty prefix to "/admin".
Sourcepub fn uploads(self, uploader: impl Uploader) -> Self
pub fn uploads(self, uploader: impl Uploader) -> Self
Installs the Uploader this panel’s file fields store through; without
one a file field stores the sanitized client filename.
Sourcepub fn serve_dir(self, path: impl Into<String>, dir: impl Into<PathBuf>) -> Self
pub fn serve_dir(self, path: impl Into<String>, dir: impl Into<PathBuf>) -> Self
Serves the directory dir at route pattern path, which must end in a catch-all and sits
outside the auth gate with hardening headers.
Sourcepub fn shell_assets(self, stylesheet: Asset, font: Font) -> Self
pub fn shell_assets(self, stylesheet: Asset, font: Font) -> Self
Registers the stylesheet and font the default shell links, resolved through the router’s asset bundle.
Sourcepub fn resource<R: Resource>(self) -> Self
pub fn resource<R: Resource>(self) -> Self
Registers the Resource R at {prefix}/{slug} with its routes and sidebar entry, as
Resource::declare declares it.
Sourcepub fn resource_with<R: Resource>(
self,
customize: impl FnOnce(ResourceDef<R>) -> ResourceDef<R> + Send + 'static,
) -> Self
pub fn resource_with<R: Resource>( self, customize: impl FnOnce(ResourceDef<R>) -> ResourceDef<R> + Send + 'static, ) -> Self
Sourcepub fn page<P: Page>(self) -> Self
pub fn page<P: Page>(self) -> Self
Declares a Page at {prefix}/{slug} with its sidebar entry; pages share the resources’
slug namespace.
Sourcepub fn home<P: Page>(self) -> Self
pub fn home<P: Page>(self) -> Self
Declares the panel’s home page at the panel prefix, replacing the redirect to the first resource’s list.
Sourcepub fn layout(self, render: LayoutRenderFn) -> Self
pub fn layout(self, render: LayoutRenderFn) -> Self
Frames the panel’s pages with render instead of the shipped shell; render usually wraps
Panel::layout_shell.
Sourcepub fn brand(self, brand: Brand) -> Self
pub fn brand(self, brand: Brand) -> Self
Sets branding for the shell (sidebar header, login card, and the topbar below md).
Sourcepub fn frame_ancestors(self, ancestors: impl Into<String>) -> Self
pub fn frame_ancestors(self, ancestors: impl Into<String>) -> Self
Sets the frame-ancestors directive the panel sends on every response under its prefix,
defaulting to 'self'.
Sourcepub fn without_frame_ancestors(self) -> Self
pub fn without_frame_ancestors(self) -> Self
Sends no frame-ancestors directive for deployments whose proxy owns the whole CSP.
Sourcepub fn dark_mode(self, enabled: bool) -> Self
pub fn dark_mode(self, enabled: bool) -> Self
Sets the theme a visitor who has not chosen one sees, dark when true.
Sourcepub fn auth(self, auth: Auth) -> Self
pub fn auth(self, auth: Auth) -> Self
Configures this panel’s authentication, defaulting to password auth; sessions belong to the panel that signed them in.
Sourcepub fn login_hint(self, hint: impl Into<String>) -> Self
pub fn login_hint(self, hint: impl Into<String>) -> Self
Renders a line under the login form for demo credentials or deployment hints.