Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Surfaces

A surface is a screen describing itself to a caller: its controls, the parts inside it and what each part does.

Describe a component

use laterite_admin::ability::{AbilityCx, AbilityError, Outcome};
use laterite_admin::surface::{Control, Part, Request, Surface, READ, SHOW};
use laterite_admin::AdminRegistry;
use laterite_core::serde_json::json;
use laterite_core::{t, Text};
use std::sync::Arc;

struct Overview;

#[laterite_core::strata::async_trait]
impl Surface for Overview {
    fn path(&self) -> &str {
        "/acme/overview"
    }

    fn label(&self) -> Text {
        t!("Overview")
    }

    fn permission(&self) -> Option<&str> {
        Some("acme.reports.view")
    }

    async fn parts(&self, _cx: &AbilityCx<'_>) -> Result<Part, AbilityError> {
        Ok(Part::new("overview", t!("Overview")).act(SHOW).part(
            Part::new("orders_by_day", t!("Orders by day"))
                .describe(t!("How many orders arrived each day."))
                .control(
                    Control::new("range", t!("Period"), "date_range")
                        .value(json!({ "from": "2026-10-01", "to": "2026-10-31" })),
                )
                .control(Control::new("group_by", t!("Group by"), "select").values(["day", "week"]))
                .act(READ),
        ))
    }

    async fn act(&self, cx: &AbilityCx<'_>, request: &Request) -> Result<Outcome, AbilityError> {
        if request.act == SHOW {
            return Ok(Outcome::new(t!("Opened the overview.")).go("/admin/acme/overview"));
        }
        let from = request.set["range"]["from"]
            .as_str()
            .ok_or_else(|| AbilityError::invalid("set/range: give `from` and `to`"))?;
        let points = acme::orders::by_day(cx.db(), from, request.text("group_by")).await?;
        Ok(Outcome::new(t!("The orders by day.")).data(json!({ "points": points })))
    }
}

fn register(&self, registry: &mut laterite_core::Registry) {
    registry.add_surface(Arc::new(Overview));
}
MethodAnswersDefault
pathwhere the screen is under the admin root; it names the surfacerequired
labelwhat a person calls the screenrequired
describewhat the screen is fornone
permissionthe permission a person needs to see itevery signed-in person
partsthe screen as this person sees itrequired
actsets the controls a request names and does its actrequired

Build the description

PartSets
Part::new(name, label)the name a caller uses, the name a person reads
describe(text)what the part shows
control(control)something a caller sets
part(part)a component inside this one
act(name)something the part does: SHOW, READ, or a word of its own
ControlSets
Control::new(name, label, kind)the name, the label, and text, number, boolean, date, date_range, select or a word of its own
describe(text)what it narrows or changes
values([..])the fixed set of values it takes
value(value)what it is set to now
ActDoes
SHOW (show)answers Outcome::go with the screen’s address, the controls set
READ (read)answers Outcome::data with what the part holds

Read a request

let part: &[String] = &request.part;      // ["orders_by_day"]
let act: &str = &request.act;             // "read"
let grouping = request.text("group_by");  // Some("day")
let range = &request.set["range"];        // { "from": .., "to": .. }
FieldHolds
partthe names from the surface down to the part; empty for the surface itself
actan act that part lists
setthe controls to set, by name; each one the part lists

Return AbilityError::invalid("set/range: ..") for a value the control does not take.

Call a surface

use laterite_core::serde_json::json;

let abilities = ctx.abilities();
let screens = abilities.run(&user, "backend.screens.list", json!({}), None).await?;
let described = abilities
    .run(&user, "backend.screens.describe", json!({ "screen": "/acme/overview" }), None)
    .await?;
let read = abilities
    .run(&user, "backend.screens.act", json!({
        "screen": "/acme/overview",
        "part": "orders_by_day",
        "act": "read",
        "set": { "range": { "from": "2026-11-01", "to": "2026-11-15" }, "group_by": "day" }
    }), None)
    .await?;
AbilityInputAnswers
backend.screens.listnoneevery screen open to the person: screen, label, describe
backend.screens.describescreenits controls, parts and acts
backend.screens.actscreen, part (names joined with /), set, actthe act’s Outcome
{
  "screen": "/acme/overview", "name": "overview", "label": "Overview", "acts": ["show"],
  "parts": [{
    "name": "orders_by_day", "label": "Orders by day", "acts": ["read"],
    "controls": [
      { "name": "range", "label": "Period", "kind": "date_range",
        "value": { "from": "2026-10-01", "to": "2026-10-31" } },
      { "name": "group_by", "label": "Group by", "kind": "select", "values": ["day", "week"] }
    ]
  }]
}

Add a surface while mounting

impl Screen for Sales {
    fn mount(&self, ctx: &RouteCtx) -> Router {
        let board = Arc::new(self.board());
        ctx.add_surface(board.surface("/acme/sales", t!("Sales")));
        Router::new().nest_service("/board", board.routes(ctx))
    }
}
CallWhen
registry.add_surface(surface)in register, for a surface known then
ctx.add_surface(surface)in Screen::mount, for one built there; the same path replaces
board.surface(path, label)a board and its widgets as a surface

Lists

Every resource that offers record abilities is a surface named by its path.

ControlIs
searchthe list’s search
each filter by its keythat filter, with its values for a select
sort, dira sortable column, and asc or desc
{ "screen": "/posts", "act": "show", "set": { "status": "live", "views_min": 1000, "sort": "views", "dir": "desc" } }

Settings pages

Every settings page with fields is a surface at its page’s path, behind the page’s permission.

ControlIs
each field by its namethe field, with its value as stored; a person’s own for a per-person page
ActAnswers
showthe page’s address
readthe stored values by field name

A password or sensitive field is never named. A request that sets a control is refused: a setting is changed on its page.