Skip to main content

Panel

Struct Panel 

Source
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

Source

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.

Source

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

pub async fn document<'a>( cx: &'a Cx, title: impl Into<String>, body: impl View + 'a, ) -> Result<BoxView<'a>>

Renders a complete HTML document around a page outside the panel prefix.

Source§

impl Panel

Source

pub fn new(prefix: impl Into<String>) -> Self

Creates a Panel mounted at prefix, defaulting an empty prefix to "/admin".

Source

pub fn prefix(&self) -> &str

Returns the mount prefix, e.g. "/admin".

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn resource_with<R: Resource>( self, customize: impl FnOnce(ResourceDef<R>) -> ResourceDef<R> + Send + 'static, ) -> Self

Registers the Resource R as resource does, with customize adjusting its def for this panel only:

Panel::new("portal").resource_with::<PostResource>(|def| def.policy(ReadOnly))
Source

pub fn page<P: Page>(self) -> Self

Declares a Page at {prefix}/{slug} with its sidebar entry; pages share the resources’ slug namespace.

Source

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.

Source

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.

Source

pub fn brand(self, brand: Brand) -> Self

Sets branding for the shell (sidebar header, login card, and the topbar below md).

Source

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'.

Source

pub fn without_frame_ancestors(self) -> Self

Sends no frame-ancestors directive for deployments whose proxy owns the whole CSP.

Source

pub fn dark_mode(self, enabled: bool) -> Self

Sets the theme a visitor who has not chosen one sees, dark when true.

Source

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.

Source

pub fn login_hint(self, hint: impl Into<String>) -> Self

Renders a line under the login form for demo credentials or deployment hints.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Panel

§

impl !Sync for Panel

§

impl !UnwindSafe for Panel

§

impl Freeze for Panel

§

impl Send for Panel

§

impl Unpin for Panel

§

impl UnsafeUnpin for Panel

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more