tablo_core/panel.rs
1//! `Panel` — resources and pages under one prefix, which an app mounts into its router.
2
3mod actions;
4pub(crate) mod area;
5mod banner;
6mod bar;
7mod build;
8pub(crate) mod commit_hook;
9mod detail;
10pub(crate) mod error_page;
11mod extension;
12mod files;
13mod forms;
14pub(crate) mod gate;
15mod headers;
16mod host;
17mod impersonation;
18mod input;
19mod list;
20mod load;
21mod mounted;
22mod page_filters;
23pub(crate) mod pages;
24mod record_nav;
25mod record_page;
26mod register;
27mod relations;
28mod search;
29mod shell;
30pub(crate) mod state;
31#[cfg(test)]
32pub(crate) mod test_support;
33pub mod url;
34mod widgets;
35mod write;
36
37use topcoat::{asset::Asset, font::Font, router::LayoutRenderFn};
38
39pub use self::{
40 area::{Area, AreaGroup},
41 banner::Banner,
42 build::{PanelHandle, RouterBuilderPanelExt},
43 commit_hook::{ChangedField, ChangedRecord, CommitHook, PanelChange},
44 gate::{can_list, can_open, can_view_field},
45 impersonation::Impersonate,
46 list::{WiredTable, list_query, wired_table},
47 load::{Load, loaded},
48 mounted::{MountedResource, mounted_resources},
49 page_filters::page_filters,
50 pages::page_filter_bar,
51 shell::{Brand, Environment, Look, Radius, SidebarFrame, Theme},
52 widgets::{record_table, stats, widgets},
53};
54pub(crate) use self::{bar::header_bar, pages::current_page};
55use self::{
56 register::{PageRegistration, Registration, ResourceRegistration},
57 shell::ShellAssets,
58};
59use crate::{
60 DeclarationError, DeclarationErrorKind, Page, PageDef,
61 resource::{Resource, ResourceDef},
62};
63
64/// `R`'s sidebar entry in the context's panel, with its label, URL and icon; `None` when the
65/// panel does not register `R`. A resource hidden from the sidebar still has one, to link to it by.
66pub fn navigation_item<R: Resource>(cx: &topcoat::context::Cx) -> Option<crate::NavigationItem> {
67 crate::resource::mounted::<R>(cx).map(|resource| resource.navigation.clone())
68}
69
70/// An admin panel: resources and pages under one prefix, framed by one shell
71/// and gated by one [`Auth`](crate::auth::Auth). Its pages carry a `robots` tag that asks search
72/// engines to neither index them nor follow their links.
73///
74/// The app owns the router and mounts the panel into it with
75/// [`RouterBuilderPanelExt::panel`]:
76///
77/// ```rust,no_run
78/// # use tablo_core::{NoForm, Panel, Resource, RouterBuilderPanelExt};
79/// # use topcoat::router::{Router, RouterBuilderDiscoverExt};
80/// # #[derive(Debug, Clone, toasty::Model, tablo_core::PanelModel)]
81/// # struct User { #[key] #[auto] id: uuid::Uuid, name: String }
82/// # struct UserResource;
83/// # impl Resource for UserResource {
84/// # type Model = User;
85/// # type Form = NoForm<User>;
86/// # }
87/// # fn main() -> topcoat::Result<()> {
88/// # let db: toasty::Db = todo!();
89/// let mut builder = Router::builder().discover().with(db);
90/// builder.panel(Panel::new("admin").resource::<UserResource>())?;
91/// let router = builder.build();
92/// # let _ = router;
93/// # Ok(())
94/// # }
95/// ```
96///
97/// Registering is declarative: mounting builds each resource's [`ResourceDef`] and checks every
98/// slug, route and declaration before the panel serves anything.
99///
100/// Besides its resources' and pages' routes, a panel at `/admin` serves:
101///
102/// - `GET /admin`: the [home page](Self::home), or a redirect to the first registered resource's
103/// list when there is none;
104/// - `GET`, `POST /admin/login` and `POST /admin/logout`, unless authentication is disabled, and
105/// `POST /admin/tenant`, the tenant switcher, when the panel also acts for tenants: it offers a
106/// tenant registration or settings page, or mounts a tenant-scoped resource;
107/// - `/admin/register`, `/admin/profile`, `/admin/forgot-password` and `/admin/reset-password` when
108/// [`Auth`](crate::auth::Auth) installs the feature each serves;
109/// - `POST /admin/{page}/-/actions/{action}` for a page's header actions, and
110/// `/admin/-/actions/{action}` for the home page's;
111/// - `GET /admin/-/search?q=`, the [global search](Self::without_global_search)'s results page,
112/// when the panel searches a resource;
113/// - every other path under `/admin`, with any method, as a 404 behind the auth gate, so a visitor
114/// signs in before learning a path serves nothing. The app's own routes under the prefix still
115/// take precedence.
116pub struct Panel {
117 prefix: String,
118 /// The one host [`Self::host`] binds the panel to.
119 host: Option<String>,
120 shell_assets: Option<ShellAssets>,
121 brand: Option<Brand>,
122 /// Whether [`Self::dark_by_default`] starts a visitor who has not chosen a theme dark.
123 dark_mode: bool,
124 /// The deployment [`Self::environment`] names on every page.
125 environment: Option<Environment>,
126 /// Frames the panel's pages; `None` renders the shipped shell.
127 layout: Option<LayoutRenderFn>,
128 /// The resources and pages, in registration order.
129 registrations: Vec<Box<dyn Registration>>,
130 /// The `Content-Security-Policy` of every response under the prefix.
131 content_security_policy: headers::Policy,
132 /// The sources [`content_security_policy_source`](Self::content_security_policy_source)
133 /// adds to the policy, as `(directive, source)`.
134 content_security_policy_sources: Vec<(String, String)>,
135 /// `Strict-Transport-Security`'s `max-age`, when the panel sends it.
136 strict_transport_security: Option<std::time::Duration>,
137 /// Mistakes in the panel's own configuration, for mount to report.
138 configuration_errors: Vec<DeclarationError>,
139 /// Where file field bytes go; `None` refuses to mount a form with a file field.
140 uploads: Option<crate::upload::InstalledUploader>,
141 /// App-owned filesystem directories served with hardening headers.
142 served_dirs: Vec<headers::ServedDir>,
143 login_hint: Option<crate::Text>,
144 /// The app's entries in the user menu, above Sign out.
145 user_menu: Vec<crate::NavigationItem>,
146 banners: Vec<banner::BannerFn>,
147 auth: crate::auth::AuthConfig,
148 /// The paths of the runtime endpoints that answer only this panel's sessions.
149 endpoints: Vec<String>,
150 /// Whether the topbar shows the bell over the user's stored notifications.
151 notifications: bool,
152 /// The zone a user without their own reads and enters wall-clock times in.
153 time_zone: jiff::tz::TimeZone,
154 /// The locales the panel offers, the default first.
155 locales: Vec<topcoat::l10n::Locale>,
156 /// The app's catalogs, by locale, over Tablo's.
157 translations: Vec<(topcoat::l10n::Locale, String)>,
158 /// The catalogs of crates that extend the panel, under Tablo's and the app's.
159 default_translations: Vec<(topcoat::l10n::Locale, String)>,
160 /// Whether the topbar shows the global search box.
161 global_search: bool,
162 limits: crate::Limits,
163 /// The hooks every write of the panel runs before it commits, each type once, in order.
164 commit_hooks: Vec<(std::any::TypeId, commit_hook::CommitHookFn)>,
165 /// The hooks auth runs on each of its events, each type once, in order.
166 auth_hooks: Vec<(std::any::TypeId, crate::auth::hook::AuthHookFn)>,
167 /// The models [`require_model`](Self::require_model) names, as Toasty names them.
168 required_models: Vec<String>,
169 /// What the panel loads for each request it admits, in registration order.
170 loads: Vec<load::LoadFn>,
171}
172
173impl Panel {
174 /// Creates a `Panel` mounted at `prefix`, defaulting an empty prefix to `"/admin"`.
175 pub fn new(prefix: impl Into<String>) -> Self {
176 let prefix = crate::naming::normalize_prefix(&prefix.into());
177 let configuration_errors = prefix
178 .trim_matches('/')
179 .split('/')
180 .filter_map(|segment| build::validate_route_segment("panel prefix", segment).err())
181 .map(DeclarationError::panel)
182 .collect();
183 Self {
184 prefix,
185 host: None,
186 shell_assets: None,
187 brand: None,
188 dark_mode: false,
189 environment: None,
190 layout: None,
191 registrations: Vec::new(),
192 content_security_policy: headers::Policy::Default,
193 content_security_policy_sources: Vec::new(),
194 strict_transport_security: None,
195 configuration_errors,
196 uploads: None,
197 served_dirs: Vec::new(),
198 login_hint: None,
199 user_menu: Vec::new(),
200 banners: Vec::new(),
201 auth: crate::auth::Auth::default().into_config(),
202 endpoints: Vec::new(),
203 notifications: false,
204 time_zone: jiff::tz::TimeZone::UTC,
205 locales: vec![crate::i18n::ENGLISH.clone()],
206 translations: Vec::new(),
207 default_translations: Vec::new(),
208 global_search: true,
209 limits: crate::Limits::default(),
210 commit_hooks: Vec::new(),
211 auth_hooks: Vec::new(),
212 required_models: Vec::new(),
213 loads: Vec::new(),
214 }
215 }
216
217 /// Returns the mount prefix, e.g. `"/admin"`.
218 pub fn prefix(&self) -> &str {
219 &self.prefix
220 }
221
222 /// The id of the panel this declares, which
223 /// [`PanelUser::can_access_panel`](crate::PanelUser::can_access_panel) receives once it is
224 /// mounted.
225 pub fn id(&self) -> crate::PanelId {
226 crate::PanelId::new(&self.prefix)
227 }
228
229 /// Registers the stylesheet and font the default shell links, resolved through the router's
230 /// asset bundle.
231 pub fn shell_assets(mut self, stylesheet: Asset, font: Font) -> Self {
232 self.shell_assets = Some(ShellAssets { stylesheet, font });
233 self
234 }
235
236 /// Registers the [`Resource`] `R` at `{prefix}/{slug}` with its routes and sidebar entry, as
237 /// [`Resource::declare`] declares it.
238 ///
239 /// A resource with the slug `users`, on a panel at `/admin`, serves:
240 ///
241 /// | Method | Path | Serves |
242 /// | --- | --- | --- |
243 /// | `GET` | `/admin/users` | the list |
244 /// | `GET` | `/admin/users/{id}` | the detail page; 404 when the resource's view is empty |
245 /// | `POST` | `/admin/users/{id}/delete` | delete one record |
246 /// | `POST` | `/admin/users/-/bulk-delete` | delete the selected records |
247 /// | `GET` | `/admin/users/-/export` | the list as CSV |
248 /// | `GET`, `POST` | `/admin/users/-/create` | the create form ¹ |
249 /// | `GET`, `POST` | `/admin/users/{id}/edit` | the edit form ¹ |
250 /// | `GET` | `/admin/users/-/options` | a searchable or dependent choice's options ¹ |
251 /// | `POST` | `/admin/users/{id}/-/actions/{action}` | a record action on one record ² |
252 /// | `POST` | `/admin/users/-/actions/{action}` | a header action, or a bulk action ³ |
253 /// | `GET` | `/admin/users/-/actions/{action}/options` | an action input's options ² ³ |
254 /// | `POST` | `/admin/users/{id}/-/relations/{relation}/-/actions/{action}` | attach, or detach the selection ⁴ |
255 /// | `POST` | `/admin/users/{id}/-/relations/{relation}/{related}/-/actions/{action}` | detach one record ⁴ |
256 /// | `GET` | `/admin/users/{id}/-/relations/{relation}/-/actions/{action}/options` | the attach dialog's options ⁴ |
257 ///
258 /// ¹ Only for a resource whose `Form` is a record form, not [`NoForm`](crate::NoForm).
259 /// ² Only when an action is placed on a row, the detail page or the edit page.
260 /// ³ Only when the resource has a header action, or an action placed on the bulk bar.
261 /// ⁴ Only when the resource has a [many-to-many relation](crate::Relation::belongs_to_many).
262 ///
263 /// `{id}` is the record's primary key. The `-` segment keeps the list's own routes apart from
264 /// a record's: a record whose key is `create` still has its detail page at
265 /// `/admin/users/create`. Each route checks the resource's policy.
266 pub fn resource<R: Resource>(self) -> Self {
267 self.resource_with::<R>(|def| def)
268 }
269
270 /// Registers the [`Resource`] `R` as [`resource`](Self::resource) does, with `customize`
271 /// adjusting its def for this panel only:
272 ///
273 /// ```rust
274 /// # use tablo_core::{NoForm, Panel, ReadOnly, Resource};
275 /// # #[derive(Debug, Clone, toasty::Model, tablo_core::PanelModel)]
276 /// # struct Post { #[key] #[auto] id: uuid::Uuid, title: String }
277 /// # struct PostResource;
278 /// # impl Resource for PostResource {
279 /// # type Model = Post;
280 /// # type Form = NoForm<Post>;
281 /// # }
282 /// Panel::new("portal").resource_with::<PostResource>(|def| def.policy(ReadOnly));
283 /// ```
284 pub fn resource_with<R: Resource>(
285 mut self,
286 customize: impl FnOnce(ResourceDef<R>) -> ResourceDef<R> + Send + 'static,
287 ) -> Self {
288 self.registrations
289 .push(Box::new(ResourceRegistration::<R>(Box::new(customize))));
290 self
291 }
292
293 /// Declares a [`Page`] at `{prefix}/{slug}` with its sidebar entry, as [`Page::declare`]
294 /// declares it; pages share the resources' slug namespace.
295 pub fn page<P: Page>(self) -> Self {
296 self.page_with::<P>(|def| def)
297 }
298
299 /// Declares the [`Page`] `P` as [`page`](Self::page) does, with `customize` adjusting its def
300 /// for this panel only:
301 ///
302 /// ```rust
303 /// # use tablo_core::{Page, Panel};
304 /// # use topcoat::{Result, context::Cx, view::View};
305 /// # struct ReportsPage;
306 /// # impl Page for ReportsPage {
307 /// # async fn render(_cx: &Cx) -> Result<impl View> { Ok(()) }
308 /// # }
309 /// # fn is_manager(_cx: &Cx) -> bool { true }
310 /// Panel::new("portal").page_with::<ReportsPage>(|def| def.access(is_manager));
311 /// ```
312 pub fn page_with<P: Page>(
313 mut self,
314 customize: impl FnOnce(PageDef) -> PageDef + Send + 'static,
315 ) -> Self {
316 self.registrations.push(Box::new(PageRegistration::<P> {
317 home: false,
318 customize: Box::new(customize),
319 _page: std::marker::PhantomData,
320 }));
321 self
322 }
323
324 /// Registers `area`, a part of the panel under `{prefix}/{slug}` with a sidebar of its own,
325 /// after the resources and pages already registered: see [`Area`].
326 pub fn area(mut self, area: Area) -> Self {
327 self.registrations.push(Box::new(area));
328 self
329 }
330
331 /// Declares the panel's home page at the panel prefix, replacing the redirect to the first
332 /// resource's list. The page mounts with its def as [`Page::declare`] returns it.
333 pub fn home<P: Page>(mut self) -> Self {
334 self.registrations.push(Box::new(PageRegistration::<P> {
335 home: true,
336 customize: Box::new(|def| def),
337 _page: std::marker::PhantomData,
338 }));
339 self
340 }
341
342 /// Frames the panel's pages with `render` instead of the shipped shell; `render` usually wraps
343 /// [`Panel::layout_shell`].
344 ///
345 /// The panel registers its layout at its prefix itself, with or without this call: a
346 /// `#[layout]` of the app's own there would nest a second document inside the first.
347 pub fn layout(mut self, render: LayoutRenderFn) -> Self {
348 self.layout = Some(render);
349 self
350 }
351
352 /// Sets branding for the shell (sidebar header and the topbar below `md`) and for the sign-in
353 /// and sign-up pages, above their card.
354 pub fn brand(mut self, brand: Brand) -> Self {
355 self.configuration_errors.extend(
356 brand
357 .declaration_errors()
358 .into_iter()
359 .map(DeclarationError::panel),
360 );
361 self.brand = Some(brand);
362 self
363 }
364
365 /// Starts a visitor who has not chosen a theme dark; without the call the panel starts light.
366 pub fn dark_by_default(mut self) -> Self {
367 self.dark_mode = true;
368 self
369 }
370
371 /// Configures this panel's authentication, defaulting to password auth; sessions belong to the
372 /// panel that signed them in.
373 pub fn auth<U: crate::PanelUser>(mut self, auth: crate::auth::Auth<U>) -> Self {
374 self.auth = auth.into_config();
375 self
376 }
377
378 /// Declares a shard or procedure the app serves on this panel's pages: a request to it
379 /// answers as a request under the prefix does.
380 ///
381 /// Topcoat serves shards and procedures under its runtime path, outside every panel's
382 /// prefix. A request to an endpoint no panel declares runs as the panel whose session sent
383 /// it, whichever panel that is; a panel without sign-in has no session, so its request runs as
384 /// no panel, and [`scoped_query`](crate::scoped_query) and the [`url`](crate::url) helpers
385 /// find no resource. A declared one runs as this panel: a session another panel
386 /// signed in is no session here, so it answers 401 when the panel requires sign-in, and
387 /// [`auth::guard`](crate::auth::guard), [`auth::user`](crate::auth::user), the tenant and
388 /// [`can_list`] answer for this panel. Several panels may declare the same
389 /// endpoint; each of their sessions reaches it.
390 ///
391 /// The router still registers the endpoint, through discovery or `.route(..)`. A route
392 /// outside Topcoat's runtime path refuses to mount: the panel's prefix or the app's own
393 /// layers guard it.
394 ///
395 /// ```rust
396 /// # use tablo_core::{Panel, auth};
397 /// # use topcoat::{Result, context::Cx, runtime::shard, view::{View, view}};
398 /// #[shard]
399 /// async fn revenue(cx: &Cx) -> Result<impl View> {
400 /// auth::guard(cx)?;
401 /// Ok(view! { "…" })
402 /// }
403 ///
404 /// Panel::new("admin").endpoint(revenue);
405 /// ```
406 pub fn endpoint(mut self, endpoint: impl topcoat::router::Route) -> Self {
407 let path = endpoint.path().as_str().to_owned();
408 if !state::under_prefix(crate::topcoat_compat::RUNTIME_PREFIX, &path) {
409 self.configuration_errors.push(DeclarationError::panel(
410 DeclarationErrorKind::EndpointOutsideRuntime { path: path.clone() },
411 ));
412 }
413 self.endpoints.push(path);
414 self
415 }
416
417 /// Adds `item` to the user menu in the sidebar's footer, above Sign out: a profile or a
418 /// settings page. The item names its URL with
419 /// [`NavigationItem::at`](crate::NavigationItem::at); its badge shows in the sidebar only.
420 pub fn user_menu_item(mut self, item: crate::NavigationItem) -> Self {
421 self.user_menu.push(item);
422 self
423 }
424
425 /// Shows `B` above every page, under the bar that names whom a user acts as; several show in
426 /// the order they are added.
427 pub fn banner<B: Banner>(mut self) -> Self {
428 self.banners.push(banner::erased::<B>);
429 self
430 }
431
432 /// Shows a bell in the topbar over the signed-in user's
433 /// [stored notifications](crate::Notifications): an unread count, and a sheet
434 /// that lists them newest first, to mark read or unread and remove. Once the page loads, the
435 /// bell keeps updating over Topcoat's runtime connection, and a notification sent while the
436 /// page is open also shows as a toast.
437 ///
438 /// The bell lists what was sent on this panel for the tenant the user acts for, and what was
439 /// sent for no tenant; its procedures mark and remove only those, so an id it does not list
440 /// changes nothing. An open bell checks the session again before it shows anything new, and
441 /// [`auth::revoke_sessions_for_user`](crate::auth::revoke_sessions_for_user) stops the user's
442 /// open bells at once. A send wakes the bells open on the process that sent it: behind a load
443 /// balancer, a bell on another process shows the notification on its next page load.
444 ///
445 /// The panel needs auth and the [`StoredNotification`] model, which
446 /// [`models!`](crate::models!) registers. Nothing deletes stored notifications on its own.
447 ///
448 /// ```rust
449 /// # use tablo_core::Panel;
450 /// Panel::new("admin").notifications();
451 /// ```
452 ///
453 /// [`StoredNotification`]: crate::notification::StoredNotification
454 pub fn notifications(mut self) -> Self {
455 self.notifications = true;
456 self
457 }
458
459 /// Sets the time zone a user whose [`PanelUser::time_zone`](crate::PanelUser::time_zone) names
460 /// none reads and enters wall-clock times in, and that an unsigned request uses: UTC by
461 /// default. See [`time_zone`](crate::time_zone).
462 ///
463 /// ```rust
464 /// # use tablo_core::Panel;
465 /// let zone = jiff::tz::TimeZone::get("Europe/Paris").expect("the zone database names it");
466 /// Panel::new("admin").time_zone(zone);
467 /// ```
468 pub fn time_zone(mut self, zone: jiff::tz::TimeZone) -> Self {
469 self.time_zone = zone;
470 self
471 }
472
473 /// Sets the locales the panel offers, the default first: `en` by default. Each request reads
474 /// one, which [`topcoat::l10n::locale()`] returns: the one the visitor picked from the shell's
475 /// language menu, else the signed-in user's [`PanelUser::locale`](crate::PanelUser::locale),
476 /// else the browser's best match, else the default. A locale matches the closest offered one
477 /// of its language and script, as `fr-CA` reads `fr` and `zh-HK` reads `zh-Hant`.
478 ///
479 /// Offering several shows the language menu in the sidebar footer, each locale named by an
480 /// attribute of the message `tablo-shell-language` and falling back to its tag; picking one
481 /// remembers it in a cookie under the panel's prefix, and on the signed-in user's account
482 /// through [`Authenticator::store_locale`](crate::Authenticator::store_locale).
483 ///
484 /// Tablo translates its own words into `en` and `fr`; a locale it does not translate needs the
485 /// app's catalog, from [`translations`](Self::translations). The pseudo-locale `en-XA` spells
486 /// every catalog's English with accented letters, so a word that reads plain on its page is one
487 /// no catalog spells.
488 ///
489 /// ```rust
490 /// # use tablo_core::Panel;
491 /// use topcoat::l10n::locale;
492 ///
493 /// Panel::new("admin").locales([locale!("fr"), locale!("en")]);
494 /// ```
495 ///
496 /// The panel refuses to mount an empty list, a repeated locale, and a locale no catalog
497 /// translates.
498 pub fn locales(mut self, locales: impl IntoIterator<Item = topcoat::l10n::Locale>) -> Self {
499 self.locales = locales.into_iter().collect();
500 self
501 }
502
503 /// Adds the app's Fluent catalog for `locale`: the messages its [`Text`](crate::Text)s name,
504 /// and any of Tablo's it spells otherwise.
505 ///
506 /// A message the request's locale leaves out reads from the default locale's catalogs, then
507 /// from English; an English locale reads English alone. A catalog for a language, such as `fr`,
508 /// serves its regions too: `fr-CA` reads it under its own.
509 ///
510 /// ```rust,ignore
511 /// Panel::new("admin")
512 /// .locales([locale!("fr"), locale!("en")])
513 /// .translations(locale!("fr"), include_str!("../locales/fr.ftl"))
514 /// .translations(locale!("en"), include_str!("../locales/en.ftl"));
515 /// ```
516 ///
517 /// Tablo's messages name a tenant through the Fluent term `-tenant`, so an app that calls its
518 /// tenants teams overrides that one term in each of its catalogs rather than each message.
519 /// Each locale's term has the forms its messages read, listed atop Tablo's catalog for it;
520 /// the French one adds a `.gender` attribute the messages agree with:
521 ///
522 /// ```ftl
523 /// -tenant = { $form ->
524 /// *[lower] team
525 /// [upper] Team
526 /// [upper-plural] Teams
527 /// [indefinite] a team
528 /// }
529 /// ```
530 ///
531 /// The panel refuses to mount a catalog that is not valid Fluent, and one for a locale it does
532 /// not offer, `en` aside.
533 pub fn translations(
534 mut self,
535 locale: topcoat::l10n::Locale,
536 catalog: impl Into<String>,
537 ) -> Self {
538 self.translations.push((locale, catalog.into()));
539 self
540 }
541
542 /// Leaves out the global search the panel otherwise shows: the box in its topbar and its
543 /// results page.
544 ///
545 /// By default the topbar holds a search box over every resource the panel mounts, unless a
546 /// resource opts out with
547 /// [`ResourceDef::without_global_search`](crate::ResourceDef::without_global_search). As the
548 /// user types, it lists up to 5 results of each resource, headed by the resource's plural
549 /// label in the sidebar's order, and links the page at `{prefix}/-/search?q=`, which lists up
550 /// to 25 of each and which Enter opens, with or without JavaScript. Cmd+K, or Ctrl+K, focuses
551 /// the box from anywhere on the page. The term matches a record
552 /// when each of its first 8 distinct words does;
553 /// [`ResourceDef::global_search`](crate::ResourceDef::global_search) says what a word matches,
554 /// which records show and what each opens.
555 ///
556 /// A resource is not searched when it has no searchable column and no title column, or when no
557 /// result could open a page: its records have no URL, or it has neither a detail page nor a
558 /// form. The box shows to a request that may list one of the searched resources, and a panel
559 /// that searches none serves no results page.
560 ///
561 /// The box's results are a shard the panel declares as its [endpoint](Self::endpoint), so they
562 /// answer for a panel without sign-in too. Topcoat serves it at one path for every panel, and
563 /// runs it as the panel that signed the session in, else as the first such panel without
564 /// sign-in. On any other panel, such as the second of two without sign-in, the box lists no
565 /// results as the user types and links the results page alone.
566 ///
567 /// ```rust
568 /// # use tablo_core::Panel;
569 /// Panel::new("admin").without_global_search();
570 /// ```
571 pub fn without_global_search(mut self) -> Self {
572 self.global_search = false;
573 self
574 }
575
576 /// Renders a line under the sign-in card for demo credentials or deployment hints.
577 pub fn login_hint(mut self, hint: impl Into<crate::Text>) -> Self {
578 self.login_hint = Some(hint.into());
579 self
580 }
581
582 /// Sets the bounds the panel holds each request to: rows exported and imported, records one
583 /// bulk action runs on, and bytes a request body holds. [`Limits::default`](crate::Limits)
584 /// lists the defaults.
585 pub fn limits(mut self, limits: crate::Limits) -> Self {
586 self.limits = limits;
587 self
588 }
589}
590
591/// What the panel serves at its prefix.
592enum Root {
593 /// A redirect to the first declared resource's list that the sidebar shows.
594 Redirect(String),
595 /// The [`Panel::home`] page.
596 Home,
597}
598
599#[cfg(test)]
600mod tests;