Skip to main content

PanelHandle

Struct PanelHandle 

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

A panel’s mounted resources and its database, which a background job or a test keeps to build a context per run without declaring the panel again. A router’s mounted panel gives it through panel_handle, a panel no router mounts through Panel::handle. Cloning it is cheap.

let builder = Router::builder()
    .discover()
    .app_context(db)
    .panel(Panel::new("admin").resource::<PostResource>())?;
let admin = builder.panel_handle("admin").expect("mounted above");
let router = builder.build();

// In the job, once per run:
let cx = admin.context().with(Tenant(tenant));
let posts = scoped_query::<PostResource>(&cx)?;

Implementations§

Source§

impl PanelHandle

Source

pub fn context(&self) -> Cx

A context outside any request in which the panel’s resources answer as the panel mounted them: what a job or a test passes to scoped_query, can, write_create and the other entry points that answer from a mounted def. It holds the database and the resources, and no request, session or tenant. Add a tenant with cx.with(Tenant(id)). It carries no signed-in user, so a policy that reads one answers as for a signed-out request.

The context is one unit of work, as a request is: loads it memoizes stay cached for its lifetime, so a job builds one per run. A context built with no panel at all knows no resource: every entry point that reads a mounted def answers as for a resource the panel does not mount.

Source

pub fn enter(&self, cx: &Cx) -> Cx

cx answering as this panel, for a request outside every panel’s prefix, such as a public page: scoped_query, can and the other entry points that answer from a mounted def answer as this panel mounted its resources, and, for a handle a router gives, the url helpers answer with its URLs. A request outside every prefix answers as no panel until it enters one, however many panels the router mounts. It runs no auth gate and signs no one in, so a public page’s context knows no user. Enter only outside every prefix: under a panel’s prefix, a handle Panel::handle gives leaves the request answering as its own panel.

async fn public_posts(cx: &Cx, admin: &PanelHandle) -> Result<Vec<Post>> {
    let cx = admin.enter(cx);
    Ok(scoped_query::<PostResource>(&cx)?
        .exec(&mut tablo_core::db::db(&cx)?)
        .await?)
}
Source

pub fn url(&self) -> Option<String>

The panel’s prefix, e.g. /admin, for a public page’s link to it; None for Panel::handle’s, which no router mounts.

Source

pub fn notifications(&self) -> Notifications

Sends stored notifications to this panel’s users from outside a request, such as from a job, for no tenant until Notifications::tenant names one. The bells they have open update when the handle is a router’s.

admin
    .notifications()
    .tenant(tenant)
    .send(owner_id, Notification::info("The nightly import finished"))
    .await?;
Source

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

Renders a complete HTML document around a page outside every prefix with this panel’s shell settings: its stylesheet, font, scripts, favicon and dark-mode default. A handle Panel::handle gives renders the document without them.

/// The handle `panel_handle("admin")` returned, kept in the app context.
struct Admin(PanelHandle);

#[layout("/blog")]
async fn blog_layout(cx: &Cx, slot: Slot<'_>) -> Result<impl View> {
    let Admin(admin) = app_context::<Admin>(cx);
    admin.document(cx, "Blog", view! { <main>(slot)</main> }).await
}

Trait Implementations§

Source§

impl Clone for PanelHandle

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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> CloneAny for T
where T: Any + Clone,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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