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
impl PageDef
Sourcepub fn new() -> Self
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.
Sourcepub fn slug(self, slug: impl Into<String>) -> Self
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.
Sourcepub fn label(self, label: impl Into<String>) -> Self
pub fn label(self, label: impl Into<String>) -> Self
The sidebar label.
Defaults to the page type’s name without a trailing Page, in sentence case:
MediaLibraryPage → Media library.
Sourcepub fn icon(self, icon: IconData) -> Self
pub fn icon(self, icon: IconData) -> Self
The icon of the page’s sidebar entry, replacing the icon of a
navigation item.
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.
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.
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.
Sourcepub fn access(
self,
access: impl Fn(&Cx) -> bool + Send + Sync + 'static,
) -> Self
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")) })
}
}Sourcepub fn header_action<A: HeaderAction>(self) -> Self
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.