Skip to main content

PageDef

Struct PageDef 

Source
pub struct PageDef { /* private fields */ }
Expand description

What a Page declares: its slug, sidebar entry, access and header actions.

Page::declare returns one, and Panel::page_with adjusts it for one panel. Every setting has a default, so a page sets only what differs:

struct MediaLibraryPage;

impl Page for MediaLibraryPage {
    fn declare() -> PageDef {
        PageDef::new().slug("media").icon(tablo_ui::icons::IMAGE)
    }

    async fn render(_cx: &Cx) -> Result<impl View> {
        Ok(())
    }
}

The panel builds the def once when it mounts and serves the result to every request.

Implementations§

Source§

impl PageDef

Source

pub fn new() -> Self

A def with every default: the slug and label from the page’s type name, and access for every signed-in user.

Source

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

The URL segment under the panel prefix: "media" mounts the page at {panel prefix}/media.

Defaults to the page type’s name without a trailing Page, kebab-cased: MediaLibraryPage → media-library. Panel::home mounts the page at the prefix and does not read it.

Source

pub fn label(self, label: impl Into<Text>) -> Self

The sidebar label.

Defaults to the message page-{name} of the panel’s catalogs, else the page type’s name without a trailing Page, in sentence case: MediaLibraryPage reads page-media-library, else Media library.

Source

pub fn icon(self, icon: IconData) -> Self

The icon of the page’s sidebar entry, replacing the icon of a navigation item.

Source

pub fn navigation_order(self, order: i32) -> Self

Where the sidebar entry sorts among the panel’s entries, lowest first; defaults to 0, and entries of equal order keep their registration order. It replaces the order of a navigation item.

Source

pub fn navigation_group(self, group: impl Into<Text>) -> Self

The labelled sidebar group the entry renders in, such as "Reports"; defaults to none, above every group. It replaces the group of a navigation item.

Source

pub fn navigation(self, item: NavigationItem) -> Self

Replaces the sidebar entry, for one that links somewhere other than the page: NavigationItem::at("Exports", "/admin/reports?tab=exports"). icon, navigation_order and navigation_group still apply to it.

Source

pub fn access( self, access: impl Fn(&Cx) -> bool + Send + Sync + 'static, ) -> Self

Whether the request’s user may open the page. The panel answers 403 and leaves the page out of the sidebar when it answers false. Defaults to every signed-in user.

struct BillingPage;

impl Page for BillingPage {
    fn declare() -> PageDef {
        PageDef::new().access(|cx| auth::user::<Staff>(cx).is_some_and(|staff| staff.admin))
    }

    async fn render(cx: &Cx) -> Result<impl View> {
        Ok(view! { cx => tablo_ui::page(tablo_ui::page_title("Billing")) })
    }
}
Source

pub fn header_action<A: HeaderAction>(self) -> Self

Adds the HeaderAction A after the ones already declared, served at {url}/-/actions/{NAME}. header_action_buttons renders their buttons where render places it. An A::NAME that is not a single URL path segment does not compile.

The actions run for whoever may open the page: a page has no policy. An action that writes a resource’s records asks that resource’s policy in its own can_run.

Trait Implementations§

Source§

impl Debug for PageDef

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PageDef

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> ErasedDestructor for T
where T: 'static,

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