pub struct ResourceDef<R: Resource> { /* private fields */ }Expand description
What a Resource declares: its names, navigation, policy, tenancy, table, form, view,
relations and actions.
Resource::declare returns one, and Panel::resource_with
adjusts it for one panel. Every setting has a default, so a resource sets only what differs:
use tablo_core::{ReadOnly, RecordForm, Resource, ResourceDef, TernaryFilter};
impl Resource for PostResource {
type Model = Post;
type Form = PostForm;
fn declare() -> ResourceDef<Self> {
ResourceDef::new()
.label("Blog post")
.policy(ReadOnly)
.table(PostForm::table().filters(TernaryFilter::new(Post::fields().featured())))
}
}The panel builds the def once when it mounts, binding the paths it names to the database schema, and serves the result to every request.
Implementations§
Source§impl<R: Resource> ResourceDef<R>
impl<R: Resource> ResourceDef<R>
Sourcepub fn new() -> Self
pub fn new() -> Self
A def with every default: the policy denies all, rows belong to no tenant, and the record form derives the table, the form and the view.
Sourcepub fn slug(self, slug: impl Into<String>) -> Self
pub fn slug(self, slug: impl Into<String>) -> Self
The URL slug for the resource’s pages: "users" mounts the list at {panel prefix}/users.
Defaults to the resource type’s name without a trailing Resource, pluralized and
kebab-cased: UserResource → users, BlogPostResource → blog-posts.
Sourcepub fn label(self, label: impl Into<String>) -> Self
pub fn label(self, label: impl Into<String>) -> Self
One record’s name, the noun in the “Create {label}” and “Edit {label}” titles.
Defaults to the model’s type name.
Sourcepub fn plural_label(self, label: impl Into<String>) -> Self
pub fn plural_label(self, label: impl Into<String>) -> Self
The list title and sidebar label.
Defaults to the pluralized label: Category → Categories, Person →
People.
Where the sidebar entry sorts among the panel’s entries, lowest first; defaults to 0, and
entries of equal order keep their registration order.
Replaces the sidebar entry, for one that links somewhere other than the list page:
NavigationItem::at("Drafts", "/admin/posts?f.status=draft").
Sourcepub fn policy(self, policy: impl Policy<R::Model>) -> Self
pub fn policy(self, policy: impl Policy<R::Model>) -> Self
Gates every handler; defaults to Deny. Row scoping belongs in
Resource::query, not the policy.
Sourcepub fn tenancy(self, tenancy: Tenancy<R::Model>) -> Self
pub fn tenancy(self, tenancy: Tenancy<R::Model>) -> Self
How rows belong to a tenant; defaults to Tenancy::none.
Sourcepub fn table(self, table: Table<R::Model>) -> Self
pub fn table(self, table: Table<R::Model>) -> Self
The list table; defaults to the record form’s derived table (RecordForm::table).
Sourcepub fn form(self, form: Schema) -> Self
pub fn form(self, form: Schema) -> Self
The schema the create and edit forms render; defaults to the record form’s derived schema
(RecordForm::schema).
The panel refuses a record form field this schema does not declare, and a schema on a
resource whose Form is NoForm.
Sourcepub fn view(self, view: Schema) -> Self
pub fn view(self, view: Schema) -> Self
The read-only detail schema; defaults to the form, and an empty schema
disables the detail page.
Sourcepub fn relation(self, relation: Relation<R::Model>) -> Self
pub fn relation(self, relation: Relation<R::Model>) -> Self
Adds a related resource, rendered as its table narrowed to the record on the detail and edit pages.
Sourcepub fn action<A: Action<R>>(self) -> Self
pub fn action<A: Action<R>>(self) -> Self
Adds the custom Action A after the ones already declared.
An A::NAME that is not a single URL path segment does not compile.
Sourcepub fn create_columns(
self,
columns: impl IntoIterator<Item = &'static str>,
) -> Self
pub fn create_columns( self, columns: impl IntoIterator<Item = &'static str>, ) -> Self
The columns an overriding Resource::create_record sets itself, beyond the form’s
fields.