pub struct PageDef { /* private fields */ }Expand description
What a Page declares: its slug, sidebar entry, title, access, header actions and widgets.
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<Text>) -> Self
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.
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.
Keeps the page out of the sidebar. It stays mounted at its URL, and
access still decides who may open it: link it from a
user menu item, another page or a notification.
Sourcepub fn title(self, title: impl Into<Text>) -> Self
pub fn title(self, title: impl Into<Text>) -> Self
The heading the default render shows. Defaults to the
label when one is given, else the label of the
navigation item, else the label’s default.
Sourcepub fn description(self, description: impl Into<Text>) -> Self
pub fn description(self, description: impl Into<Text>) -> Self
The line the default render shows under the title; defaults to none.
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! { 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}. The default render shows their buttons in the
page’s header; a page that renders itself places
header_action_buttons. 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.
Sourcepub fn filter(self, filter: PageFilter) -> Self
pub fn filter(self, filter: PageFilter) -> Self
Offers filter above the widgets, after the filters already declared: a value the page
keeps in its query string, which its widgets read through
page_filters. The default render shows the
filters’ bar under the header; a page that renders itself places
page_filter_bar. Mounting refuses two filters sharing a key,
and a key that is not ASCII letters, digits, - and _.
Sourcepub fn widget_columns(self, columns: u8) -> Self
pub fn widget_columns(self, columns: u8) -> Self
How many columns the widget grid has on a wide screen, from 1 to 4; defaults to 2. A medium screen shows at most two, a narrow one one.