Skip to main content

tablo_core/
lib.rs

1//! Tablo: a server-rendered admin toolkit on [Topcoat](topcoat) and [Toasty](toasty).
2//!
3//! A [`Panel`] serves one [`Resource`] per Toasty model. A resource names the model, whose
4//! [`ModelColumns`](derive@ModelColumns) give its default table and detail page, and the record
5//! form its create and edit submissions parse into, which [`ModelForm`](derive@ModelForm) derives
6//! from the model or [`RecordForm`](derive@RecordForm) from a struct of its own. It declares the
7//! rest as one [`ResourceDef`] value: its [`Policy`], which denies by default, and any [`Table`],
8//! [`Schema`] or [`Detail`] that replaces or extends the defaults.
9//! The app mounts the panel on its own Topcoat router with [`RouterBuilderPanelExt::panel`], which
10//! builds each def once and checks it against the database schema first; one router mounts any
11//! number of panels at distinct prefixes.
12//!
13//! ```rust,no_run
14//! # use tablo_core::{Allow, Panel, Resource, ResourceDef, RouterBuilderPanelExt};
15//! # use toasty::Db;
16//! # use topcoat::router::{Router, RouterBuilderDiscoverExt};
17//! # fn main() -> topcoat::Result<()> {
18//! #[derive(Debug, Clone, toasty::Model, tablo_core::ModelColumns, tablo_core::ModelForm)]
19//! pub struct Book {
20//!     #[key]
21//!     #[auto]
22//!     pub id: uuid::Uuid,
23//!     pub title: String,
24//! }
25//!
26//! pub struct BookResource;
27//!
28//! impl Resource for BookResource {
29//!     type Model = Book;
30//!     type Form = BookForm;
31//!
32//!     fn declare() -> ResourceDef<Self> {
33//!         ResourceDef::new().policy(Allow)
34//!     }
35//! }
36//!
37//! # let db: Db = todo!();
38//! let router = Router::builder()
39//!     .discover()
40//!     .app_context(db)
41//!     .panel(Panel::new("admin").resource::<BookResource>())?
42//!     .build();
43//! # let _ = router;
44//! # Ok(())
45//! # }
46//! ```
47//!
48//! The [user guide](https://y-l.fr/tablo/nightly/guide/) walks through a complete panel and each
49//! part of it. [`ResourceDef`] lists everything a resource declares, [`Resource`] the hooks it
50//! overrides, and [`Panel`] every builder call.
51
52// The derives emit `tablo_core::` paths; this lets them expand inside this
53// crate's own tests too.
54extern crate self as tablo_core;
55
56#[doc(hidden)]
57pub mod __macro {
58    pub use toasty::{
59        Executor, Result as DbResult,
60        codegen_support::Version,
61        schema::{Embed, Model},
62        stmt,
63        stmt::{List, Path},
64    };
65    pub use topcoat::context::Cx;
66
67    pub use crate::{
68        Color, Lens, Text,
69        detail::Detail,
70        extend::{Includes, OptionSource},
71        form::{
72            FieldError, FormField, FormInput, FormScalar, FormValues, NullableScalar, RecordForm,
73            assert_form_scalar, links_include, links_key, parse_list, parse_password, parse_scalar,
74            required_input, write_links,
75        },
76        i18n::option_label,
77        schema::{
78            ChoiceField, CustomField, EmbeddedForm, Field, FileField, HoldsTabs, IntoSchema,
79            Options, RepeaterField, Schema, TextField,
80            embedded::{Embedded, EmbeddedBuilder, embedded_field, take_leaf, take_value},
81            form_key, parse_items,
82            tree::Retype,
83            write_items,
84        },
85        table::{ModelColumns, Table, model::pick},
86        toasty_compat::VariantId,
87    };
88}
89// Each public item has one path. Types live at the root; a public module is a namespace for
90// the functions and constants that read best qualified (`auth::user`, `csrf::verify`).
91pub mod auth;
92mod bus;
93mod column;
94pub mod csrf;
95pub mod db;
96mod declaration;
97mod derive;
98mod detail;
99mod display;
100#[doc(hidden)]
101pub mod dom;
102mod error;
103pub mod extend;
104mod flash;
105mod form;
106mod i18n;
107mod lens;
108mod models;
109mod naming;
110mod navigation;
111pub mod notification;
112mod outcome;
113mod page;
114mod panel;
115mod policy;
116mod resource;
117#[cfg(feature = "rich-text")]
118pub mod rich_text;
119mod schema;
120mod table;
121mod tenancy;
122#[cfg(test)]
123mod test_support;
124mod toasty_compat;
125mod topcoat_compat;
126mod upload;
127mod values;
128
129/// The future a type-erased, dyn-compatible method returns.
130pub(crate) type BoxFuture<'a, T> = std::pin::Pin<Box<dyn Future<Output = T> + Send + 'a>>;
131
132pub use auth::{
133    config::Auth,
134    mail::AuthMail,
135    panel_user::{Authenticator, PanelUser},
136    password::{PasswordAuth, PasswordSignUp},
137    password_reset::PasswordReset,
138    profile::{Profile, ProfileEditor, ProfileUpdate},
139    registration::{Registrar, SignUp},
140    tenant_registration::TenantRegistration,
141    throttle::LoginThrottle,
142    two_factor::TwoFactor,
143    verification::EmailVerification,
144};
145#[cfg(feature = "rich-text")]
146pub use column::RichTextColumn;
147pub use column::{
148    BooleanColumn, ColorColumn, ColumnToggle, ColumnWidth, ComputedColumn, CountColumn, DateColumn,
149    DateValue, EmbeddedColumn, FileColumn, ImageColumn, IntoColumns, RelationColumn, RelationLens,
150    RepeaterColumn, TextColumn, ToOneRelation, contains_expr,
151};
152pub use declaration::{
153    ActionInputFault, AuthMailFault, DeclarationError, DeclarationErrorKind, FieldAccessFault,
154    FieldRuleFault, LocaleFault, ManyToManyFault, MountError, ProfileFault, ResetFault,
155    SegmentFault, SignUpFault, Site, TenancyFault, TenantProfileFault, TenantRegistrationFault,
156    TwoFactorFault, VerificationFault,
157};
158pub use derive::{EmbeddedForm, FormInput, ModelColumns, ModelForm, Options, RecordForm};
159pub use detail::{Detail, IntoDetail};
160pub use display::{Alignment, Color, Currency, Number, Numeric};
161pub use form::{NoForm, Posted, RecordForm};
162pub use i18n::Text;
163pub use lens::{Lens, Reads};
164pub use models::register_models;
165pub use navigation::{NavTarget, NavigationItem};
166pub use notification::stored::Notifications;
167pub use outcome::{Notification, NotificationAction, NotificationStatus, Outcome};
168pub use page::{Page, PageDef};
169pub use panel::{
170    Brand, MAX_IMPORT_ROWS, Panel, PanelHandle, RouterBuilderPanelExt, WiredTable, can_list,
171    can_open, navigation_item, pages::header_action_buttons, url, wired_table,
172};
173pub use policy::{Abilities, Ability, Allow, And, Deny, Or, Policy, ReadOnly, When, when};
174pub use resource::{
175    Action, Change, FieldAccess, ForeignKey, GlobalSearch, HeaderAction, HeaderActions, Places,
176    PublicLink, Relation, Resource, ResourceDef, Trashed, WriteError, can, scoped_query,
177    scoped_query_in, write_create, write_update,
178};
179#[cfg(feature = "rich-text")]
180pub use rich_text::tool::Tool;
181#[cfg(feature = "rich-text")]
182pub use schema::RichTextField;
183pub use schema::{
184    ChoiceField, CustomField, EmbeddedForm, Field, FileField, Grid, Group, IntoFormValue,
185    IntoOptions, IntoSchema, MAX_RELATIONSHIP_OPTIONS, MAX_REPEATER_ROWS, Options, RepeaterField,
186    Schema, Section, Source, Switch, Tab, Tabs, TextField, Toggle, Watched, input::FormInput,
187    parse_items, write_items,
188};
189pub use table::{
190    ActionLayout, Cursor, DEFAULT_PAGE_SIZE, DEFAULT_PER_PAGE_OPTIONS, DateFilter, FilterValue,
191    IntoFilters, ModelColumns, PagePosition, Pagination, QueryFilter, SelectFilter, Sort, Table,
192    TablePage, TableState, TernaryFilter,
193};
194pub use tenancy::{Membership, Tenancy, Tenant, TenantColumn, TenantId, require_tenant, tenant_id};
195pub use upload::{DirUploader, Uploader, sanitize_filename};
196pub use values::{
197    FieldError, FieldErrorKind, FieldErrors, FormField, FormScalar, FormValue, FormValues,
198    parse_list, parse_password, parse_scalar, time_zone, write_list,
199};