Pages and cards

4 entries

Markdown

m.screen

One page of the machine, drawn by your Ownbox.

Signature
m.screen(path, *, owner_only=False, title=None)
Example · Where the machine is defined
@m.screen(m.home, title="Quotes")
def quotes_page(query, person):
    return {"v": 1, "title": "Quotes", "blocks": [
        {"kind": "figures", "items": [{"value": 2, "label": "waiting"}]},
        {"kind": "actions", "items": [{"run": "check_quotes", "label": "Check now"}]}]}

At m.home or under it. The function answers with screen.json, a dict of blocks your Ownbox draws in its own look (text, figures, list, table, actions and settings), or with sdk.page(...). It may take query, person ({"id", "role"}) and path, by name. owner_only=True makes a page only the owner opens. A custom machine's page is only read: no JavaScript, no image, no form of its own. Its one form is a settings block, saved by your Ownbox. Use it as a decorator.

Needs in machine.yaml
Nothing

m.panel

A card on another machine's screen.

Signature
m.panel(slot, *, title, render)
Example · Where the machine is defined
m.panel("inbox", title="Quotes waiting",
        render=lambda: {"v": 1, "title": "Quotes waiting", "blocks": [{"kind": "text", "text": "Two."}]})

In slot. render() answers with screen.json of at most 6 blocks and no settings, or sdk.page(...)'s body; it may take person by name. A card is drawn for anyone signed in: check person["role"] for what only the owner should see. Today the Inbox's screen offers the slot inbox.

Needs in machine.yaml
Nothing

A full address for one of the machine's pages.

Signature
m.link(path)
Example · Inside a job
url = m.link(m.home + "/quotes")

Only for a page under m.home; anything else raises ValueError.

Needs in machine.yaml
Nothing
Returns
https://<the Ownbox>/my/....

sdk.page

A page as HTML, for a machine written before screen.json.

Signature
sdk.page(path, *, title, lede='', body)
Example · Inside a job
page = sdk.page(m.home, title="Quotes", body="<p>Two quotes are waiting.</p>")

title and lede are plain words; body is HTML your Ownbox cuts to its allowlist: no script, style, form or image, every attribute but class, colspan and rowspan dropped, and links only to the machine's own pages. A machine written now answers with screen.json instead.

Returns
A page for m.screen to return.