diff --git a/CHANGELOG.md b/CHANGELOG.md index c16c272..62ec548 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,16 @@ version and its date. Versions follow semantic versioning: a major version when people have to change their setup, a minor one for new skills or abilities, a patch for fixes. +## 1.1.25 - 2026-11-29 + +- `ironflock-templates`: the interview settles which boards an app gets (desktop, mobile or both), proposed as a conclusion and confirmed by the user, one board by default; the two boards are designed and changed independently, each for the people who use it (`board-mobile.md`, "Two boards, two kinds of use"). "Designing for a phone" names the phone patterns and the widget settings that make them: big job buttons (navbutton `fillTile`), a bottom bar (navbar `labels`, `indicator`), a drawer for rare pages (sidenav `presentation: drawer`), a list in place of a wide table (table `rendition`, `listRole`, `rowAction`), photos as a strip (image `multiImageLayout`, `enlargeOnTap`), and dialogs and menus that open as sheets on a phone. +- `ironflock-widgets`: the host contract describes the screen a board is shown on, which is not always the window (`--re-screen-left`, `-top`, `-width`, `-height`): a drawer, a bottom sheet or a full-screen view places itself inside it and takes its width from it. +- Apps can ship a board for phones: `.ironflock/mobile-board-template.yml`, next to `board-template.yml`, with the same schema and its own pages, widgets, layout and style. It is a board like the desktop board with other defaults: 48 columns × 96 rows, a `cell_size` of 8 px (desktop: 96 × 64 and 12 px), and pages that scroll. `ironflock-templates` has a new reference, `board-mobile.md`: when to ship one, its grid, bars and buttons that stay on the screen, which board a user gets and how links behave on both boards, designing for a phone, and looking at it with the image tools' `mobile` page. `example-mobile-board.yml` is a complete one. The board schema's descriptions give the mobile defaults. +- Pages can scroll one by one: a page of a board's layout may set `overflow: true` (it scrolls) or `false` (it is fitted onto the screen). Without it the style's `overflow` applies, which is now the default for the board's pages, and without that a desktop board's pages are fitted and a mobile board's scroll. +- Tiles can be pinned: a position with `pin: top` or `pin: bottom` stays at that edge of the screen while the page scrolls, `h × cell_size − grid_gap` pixels high. Across the full width it reserves a band (a bottom navigation bar, a filter bar), narrower it floats over the page (a floating action button). `board-layout-style.md` describes both features for every board. +- The board validator checks the mobile board with the same checks as the desktop board, on its defaults, and decides per page whether it scrolls: a page that scrolls has no row bound, need not be filled and needs no `fixedHeight`, only enough rows; a fitted page is bounded and must be filled by its unpinned tiles. Pinned tiles are not bounded by the rows, and the validator warns about `fixedHeight` or `fixedWidth` on them. Routes, navigation, bindings, forms and filters are checked on each board by itself, and every finding names the board's file. `widget.py` prints a fixed-size widget's cell count for both boards. A fixed-size widget whose tile spans the whole width (or height) of the grid is no longer asked for `fixedWidth` (or `fixedHeight`). +- The board validator refuses a URL parameter named `editor`, `chrome`, `share` or `ticket` in a filter, switch, toolbar, table edit column, form, binding or route: Studio keeps these names for itself in a board's address. `edit`, the usual name for an edit dialog's parameter, stays free. + ## 1.1.24 - 2026-11-28 - The `alarms` table has a `deleted` column: a deleted alarm keeps a last row with `deleted` true, as in any entity table. The board validator knows the column, and the skills say to filter on it. The causes of an alarm event are `data`, `reset`, `stopped` and `deleted`. diff --git a/VERSION b/VERSION index 3fe3e58..0bfff3d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.24 +1.1.25 diff --git a/plugins/ironflock-appliance/.claude-plugin/plugin.json b/plugins/ironflock-appliance/.claude-plugin/plugin.json index 14bbf84..7f43dfc 100644 --- a/plugins/ironflock-appliance/.claude-plugin/plugin.json +++ b/plugins/ironflock-appliance/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "ironflock-appliance", "displayName": "IronFlock Appliance", - "version": "1.1.24", + "version": "1.1.25", "description": "Add a direct connection from Claude Code to your IronFlock appliance. Configure the appliance’s HTTPS MCP address and sign in to that installation.", "author": { "name": "IronFlock", diff --git a/plugins/ironflock-dev/.claude-plugin/plugin.json b/plugins/ironflock-dev/.claude-plugin/plugin.json index 43bc040..85038fa 100644 --- a/plugins/ironflock-dev/.claude-plugin/plugin.json +++ b/plugins/ironflock-dev/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "ironflock-dev", "displayName": "IronFlock Dev", - "version": "1.1.24", + "version": "1.1.25", "description": "Build on IronFlock: design and scaffold edge apps that keep their state in the app's tables and embed their devices' web UIs in the board, write and validate their .ironflock templates (boards and widgets, data tables, app parameters, remote-access ports, AI agents), and create, change and check the board widgets themselves (@ironflock/widget-* Lit components). Needs the ironflock plugin, which Claude Code installs with it.", "author": { "name": "IronFlock", diff --git a/plugins/ironflock-dev/skills/ironflock-templates/SKILL.md b/plugins/ironflock-dev/skills/ironflock-templates/SKILL.md index d960af4..63bb6d3 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/SKILL.md +++ b/plugins/ironflock-dev/skills/ironflock-templates/SKILL.md @@ -26,6 +26,7 @@ files. Each file is optional and independent: |---|---| | `data-template.yml` | Creates the app's tables in the project's database. The app fills them through the SDK. | | `board-template.yml` | Installs the app's board (dashboard): widgets bound to those tables, laid out on pages. | +| `mobile-board-template.yml` | Installs the app's board for phones, next to that board: pages, widgets and layout of its own on a finer grid ([references/board-mobile.md](references/board-mobile.md)). | | `env-template.yml` | Renders a parameters form per device or device group. Values reach the app as environment variables. | | `port-template.yml` | Lists the ports the app serves. A production install opens a remote-access tunnel for each. | | `ai-template.yml` | Registers the app's AI agents with the IronFlock assistant. | @@ -121,6 +122,13 @@ in it is described. page, into `design/board.md`, and their short form into the board's comment header ("Designing a board" in [references/board-template.md](references/board-template.md) shows both). + The interview decides which boards the app gets: a desktop board, a + mobile board or both, confirmed by the user, one by default. A mobile + board has a brief and a route tree of its own for the jobs people do on a + phone, and the entity pages at the same routes: + [references/board-mobile.md](references/board-mobile.md). The two boards + are designed and changed independently, each for the people who use it + (board-mobile.md, "Two boards, two kinds of use"). Every entity users manage gets the shape that [references/board-assets.md](references/board-assets.md) describes (read it before a board gets a list, a form or a detail page of one): its list (a @@ -152,6 +160,7 @@ in it is described. | A SCADA page | "SCADA pages" in board-template.md, board-layout-style.md, board-bindings.md, board-navigation.md | | A filter dropdown or a date range | board-bindings.md for wiring, board-layout-style.md for placement and the tile background | | Show a device's web UI | board-bindings.md ("Embedding a web UI the app serves"), board-navigation.md | + | Build or change the board for phones (`mobile-board-template.yml`) | board-mobile.md and [references/example-mobile-board.yml](references/example-mobile-board.yml), then the references of the task as for the desktop board, and board-look.md with a `mobile` page | All of them are in `references/`; "Which file to read" in board-template.md says what each one holds. Choose widgets with @@ -168,7 +177,8 @@ in it is described. It checks every template against its schema, the rules the platform otherwise reports only at install time, and each board widget against the widget's - published schema. Each finding names the file, line and path. If it reports a + published schema. It checks both boards, the mobile one on its own grid. + Each finding names the file, line and path. If it reports a missing module, run it as `uv run ${CLAUDE_SKILL_DIR}/scripts/validate.py `, or install `pyyaml` and `jsonschema`. Warnings are judgment calls. Read each one and fix it unless it is deliberate. The validator has its own test suite, so a @@ -177,7 +187,8 @@ in it is described. chose and why, which tables and widgets connect, which design documents you wrote or changed, and anything the app's code still has to do. Tell the user they can open the board in IronFlock's board editor to adjust it visually. The - editor reads and writes the same `board-template.yml`. For a new app, add how + editor reads and writes the same `board-template.yml`, and + `mobile-board-template.yml` for the board for phones. For a new app, add how to get it running: push it to the app's repository in IronFlock and run it on a device from the IDE. That development run gets a tunnel for each port. Its http(s) tunnels are private to its developers, who open them from the IDE's diff --git a/plugins/ironflock-dev/skills/ironflock-templates/references/app-architecture.md b/plugins/ironflock-dev/skills/ironflock-templates/references/app-architecture.md index 9a05b70..809fb72 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/references/app-architecture.md +++ b/plugins/ironflock-dev/skills/ironflock-templates/references/app-architecture.md @@ -43,6 +43,7 @@ An app runs on many devices at once, typically industrial PCs next to machines: | SDK | The program's only link to the platform: tables, realtime feeds, device functions, files | the `ironflock` package (Python, JavaScript, Go) | | Tables | The app's state, in the project's own database | `.ironflock/data-template.yml` | | Board | The app's central UI: widgets bound live to the tables, for all devices | `.ironflock/board-template.yml` | +| Mobile board | Optional: the app's UI on phones, with pages of its own for the jobs people do there | `.ironflock/mobile-board-template.yml` | | Parameters | Settings of one device or device group, made in its app settings | `.ironflock/env-template.yml` | | Remote access | Tunnels to ports the containers serve, such as a web UI | `.ironflock/port-template.yml` | | AI agents | Agents for the IronFlock assistant, with device functions as tools | `.ironflock/ai-template.yml` | @@ -115,6 +116,12 @@ only what the request leaves open, and wait: - who uses the app, where and on what (an operator at a wall screen, a technician on a tablet, a manager at a desk), which is the board's brief in board-design.md; + - **which boards the app gets: a desktop board, a mobile board, or both.** + Ask it as a conclusion from the answers, never as a bare menu: "the + technicians report at the machine on their phone and the planner works at + a desk, so a board for phones and one for the desk?" The user confirms or + drops one. One board is the default; two boards are twice the board work, + so never build both unasked (board-mobile.md, "When to ship one"); - where the data comes from: the machine, sensor or system, its protocol, the sample rate, what is read and what is computed; - what users set or change while the app runs, and what differs per device @@ -147,7 +154,7 @@ its example, and every new app keeps these documents: | `design/README.md` | The index, and the app's purpose: its users, the goal, the value, what this version leaves out | | `design/architecture.md` | The parts (containers, the board, web UIs), what runs where, every table with its kind and its one writer, the data flows between devices and board, parameters, ports and tunnels, device functions and topics, the failure behaviour | | `design/entities.md` | The entity model (below): each entity, its key, its table, who writes it, what users do with it on the board, and the relations | -| `design/board.md` | The board's design: the brief, the route tree with what each page shows and offers, the band plan of each page, the look and the state colours | +| `design/board.md` | The board's design: the brief, the route tree with what each page shows and offers, the band plan of each page, the look and the state colours; the same for the mobile board, when the app has one | | `design/decisions.md` | The decisions, newest first, dated: what was decided between which alternatives, why, and what was left out | Further documents join when the app needs them (a protocol, a data source's diff --git a/plugins/ironflock-dev/skills/ironflock-templates/references/board-bindings.md b/plugins/ironflock-dev/skills/ironflock-templates/references/board-bindings.md index 2b5c5ed..0fdca90 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/references/board-bindings.md +++ b/plugins/ironflock-dev/skills/ironflock-templates/references/board-bindings.md @@ -278,6 +278,10 @@ Filter widgets set URL parameters for other widgets to read: filter needs `timeStartParam` and `timeEndParam` with those names, plus a complete time window, which serves as the default range. +Studio keeps four URL parameter names for itself in a board's address: `editor` +(what the board editor has open), `chrome`, `share` and `ticket`. No widget +may read or set a parameter of those names; the validator refuses them. + ## Embedding a web UI the app serves A device's own web page (a live view, a machine's HMI) reaches the board through diff --git a/plugins/ironflock-dev/skills/ironflock-templates/references/board-layout-style.md b/plugins/ironflock-dev/skills/ironflock-templates/references/board-layout-style.md index 2be9b42..15bfc75 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/references/board-layout-style.md +++ b/plugins/ironflock-dev/skills/ironflock-templates/references/board-layout-style.md @@ -13,7 +13,10 @@ prefixes (`$str:`, `$num:`, `$bool:`) from board-template.md, "Anatomy" and The grid is `style.columns` × `style.rows`, by default 96 × 64. Positions are given in cells: `x`, `y` from 0, and `w`, `h`. Without `overflow`, the whole grid is scaled onto the screen, so the grid is the screen. The exception is a widget with a -fixed width or height (see below). +fixed width or height (see below). The board for phones, +`mobile-board-template.yml`, follows the same rules with other defaults: +48 × 96 cells, a `cell_size` of 8 px, and pages that scroll +(board-mobile.md, "The mobile grid"). - **Fill every page completely.** Any cell no widget covers shows as empty screen, and users read that as unfinished. Plan bands whose heights add up to `rows` and @@ -69,6 +72,48 @@ fixed width or height (see below). - **Layering is allowed.** A small widget (a date picker, a button) may sit on top of a big one. `z` orders them, higher in front. +### Pages that scroll + +A page scrolls or is fitted onto the screen. Its own `overflow` decides, +next to its `gridLayout`; without it the style's `overflow` does, and without +that a desktop board's pages are fitted and a mobile board's scroll. On a page +that scrolls every row is `cell_size` pixels high, the page is as long as its +tiles reach, it need not be filled, and a fixed-height widget needs only +enough rows, no `fixedHeight`. The rules above for filling the grid and +keeping inside its rows hold for fitted pages. + +```yaml +layout: + gridLayout: [...] # fitted, as the board's style says + subRoutes: + log: + overflow: true # this page scrolls + gridLayout: [...] +``` + +### Pinned tiles + +A position with `pin: top` or `pin: bottom` stays at that edge of the screen +while the page scrolls, on fitted and scrolling pages and on both boards. It +keeps its columns (`x`, `w`), its height is `h × cell_size − grid_gap` pixels +on any page, and its `y` only orders the tiles pinned to the same edge (top +to bottom). `fixedHeight` and `fixedWidth` mean nothing on it; the validator +warns about them. A pinned tile is neither bounded by the rows nor counted +when the page is checked for filling. + +- **Across the full width** (`x: 0`, `w` the board's columns) it reserves a + band at its edge, and the page lies between the bands: a fitted page fits + its grid into the space between them, a scrolling page scrolls between + them. A filter bar pinned to the top of a long scrolling page stays in + reach: + + ```yaml + - {id: filters, x: 0, y: 0, w: 96, h: 6, pin: top} # 6 rows of 12 px less the gap + ``` + +- **Narrower**, it floats over the page at its edge and reserves nothing: a + floating action button. + ## Style `style` applies to the whole board. Every key is optional: @@ -134,8 +179,9 @@ on any board, and one with a transparent `tile_background_color` has no frame. S the borderless buttons from "Let navigation blend in" (Layout, above) look the same under every `tile_style`. -`overflow: true` makes the board scroll (cells are then `cell_size` pixels) instead -of scaling to the screen. +`overflow: true` makes the board's pages scroll (cells are then `cell_size` pixels) +instead of scaling to the screen. It is the default for the pages; a page's own +`overflow` wins ("Pages that scroll", above). A style that names only a theme takes its four colours from the theme (its background, title text and axis line colours), so `theme: {theme_name: dark}` diff --git a/plugins/ironflock-dev/skills/ironflock-templates/references/board-look.md b/plugins/ironflock-dev/skills/ironflock-templates/references/board-look.md index fe5dab8..b38208e 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/references/board-look.md +++ b/plugins/ironflock-dev/skills/ironflock-templates/references/board-look.md @@ -16,7 +16,12 @@ four times a minute. The key needs the scope to read data. - **An installed board:** `get_dashboard_image` with `swarm_key` and `dashboard_key` (from `list_dashboards`). - `page` names the page to show (home without it), `full_page` shows the - page's whole height, `width` and `height` set the window. + page's whole height, `width` and `height` set the window. A `page` that + starts with `mobile` shows the board for phones (`mobile`, + `mobile/machines/press-1`), at 390 × 844 when no size is given; one that + starts with `desktop` shows the desktop board. Without either, the window + decides which board is shown: at the default size the desktop board. + board-mobile.md, "Looking at it", has more. **When.** After you built a new board, after a change of layout or style that affects a whole page, and when the user asks how it looks or says that diff --git a/plugins/ironflock-dev/skills/ironflock-templates/references/board-mobile.md b/plugins/ironflock-dev/skills/ironflock-templates/references/board-mobile.md new file mode 100644 index 0000000..f75db8d --- /dev/null +++ b/plugins/ironflock-dev/skills/ironflock-templates/references/board-mobile.md @@ -0,0 +1,291 @@ +# The mobile board + +This reference covers the board an app ships for phones: when to ship one, its +file, its grid, how a user gets it and how links behave, how +to design for a phone, and how to look at it. Everything else about boards +(the anatomy, literal values, bindings, navigation, forms, markdown, the look) +holds for it as for the desktop board, in the references board-template.md +names. + +## When to ship one + +An app can ship a second board, for phones, next to its board for desktops and +tablets. It is a board of its own, not a smaller copy: its own pages, route +tree, widgets, layout and style. It reads the same tables and transforms, +writes through forms, uploads files and photos, and needs the same right to +the app as the desktop board. + +Ship one when people use the app on a phone: at the machine, on a round +through the hall, away from any station. On a phone they do other jobs than +at a desk: report a problem with photos, look up one asset, confirm a task, +check whether a machine runs. Those jobs get the mobile board's pages. The +desktop board keeps the overviews, the wide tables, the charts and the +settings. + +An app without a mobile board shows its desktop board on phones too, scaled +onto the screen, as before. Tablets always get the desktop board. An app may +also ship only a mobile board. + +**Ask before building one.** Which boards an app gets (desktop, mobile or +both) is the user's decision. Propose it as a conclusion from what they told +you about who works where ("they report at the machine on a phone, the +planner works at a desk, so both?"), and build what they confirm. One board +is the default. Two boards are two boards to design, build and look after, +so never add the second one unasked, and never add one to an existing app +without asking. + +## The file + +`.ironflock/mobile-board-template.yml`, next to `.ironflock/board-template.yml`. +Both files are optional and independent. The mobile file has the same schema, +so it starts with the same schema line and has the same top-level keys +(`name`, `widgets`, `layout`, `style`): + +```yaml +# yaml-language-server: $schema=https://ironflock.com/schemas/board-template/v1.yml +name: machine-monitor +widgets: [...] +layout: # its own home page (route /) and page tree + gridLayout: [...] + subRoutes: {...} +style: {...} # its own style; no columns or rows needed +``` + +Nothing is shared with the desktop board: each board's widgets, `layout_id`s, +pages and style are its own. A widget the phone needs too (a menu, a card) is a +widget of the mobile file, configured for a narrow tile. Write the mobile +board's brief and route tree into `design/board.md` beside the desktop +board's, and their short form into the mobile file's comment header +(board-template.md, "Designing a board"). + +[example-mobile-board.yml](example-mobile-board.yml) is a complete, valid +mobile board: the phone side of the app whose desktop board is +example-board.yml. + +## The mobile grid + +A mobile board is a board like the desktop board, with other default numbers. +Everything board-layout-style.md says holds for it, the per-page `overflow` +and pinned tiles included; only the defaults differ: + +| | Desktop board | Mobile board | +|---|---|---| +| `style.columns` | 96 | 48 | +| `style.rows` | 64 | 96 | +| `style.cell_size` | 12 px | 8 px | +| `style.grid_gap` | 8 px | 8 px | +| a page without `overflow` | fitted onto the screen | scrolls | + +- **Pages scroll.** A page of a mobile board scrolls unless it sets + `overflow: false` (or the board's style does): every row is `cell_size` + pixels high, 8 px, the page is as long as its tiles reach, and it need not + fill the screen. Keep every position inside the 48 columns; a full-width + tile is `w: 48`, half the width `w: 24`. +- **Finer than the desktop grid**, because on a narrow screen a few pixels + decide whether two tiles line up. +- **A fitted page** (`overflow: false` on the page) is scaled onto the space + between the bars, as a desktop page is onto the screen: fill all 96 rows + and keep every tile inside them; the validator checks both. Use it for a + page whose content scrolls inside its tile, such as a list. +- **Fixed sizes.** On a page that scrolls every row is 8 px already, so a + widget with a Layout line (`widget.py `) that keeps a fixed height + needs only enough rows, `ceil((px + grid_gap) / 8)`: a navbutton (48 px) + `h: 7`, a navbar (52 px) `h: 8`. On a fitted page it needs `fixedHeight` as + well, as on the desktop board. A fixed width needs `fixedWidth` and its + columns, `w: 24` for a widget-sidenav (184 px), unless the tile spans the + whole width: it then takes the screen's width, which is what it is placed + for. +- **Every style key means the same as on the desktop board**: `overflow` + (the default for the board's pages), `overflowX`, `scaleToFit`, + `aspect_ratio`, `rows` and `gridSnap`. Take the preset's colours as + board-design.md, "Pick a look", says, without its `columns` and `rows`. +- **On a phone held on its side** a fitted mobile page keeps the height it + has upright and scrolls, instead of squeezing its rows. + +### Bars and buttons that stay on the screen + +A position with `pin: bottom` (or `pin: top`) stays at that edge of the +screen while the page scrolls. Its height is `h × cell_size − grid_gap` +pixels on any page, `fixedHeight` and `fixedWidth` mean nothing on it, and +its `y` only orders the tiles pinned to the same edge. + +- **A bottom navigation bar** is a widget-navbar pinned to the bottom across + the full width (`x: 0`, `w: 48`). It reserves a band at the lower edge, and + the page lies above it. +- **A top bar** (a title, a filter) is pinned to the top the same way. +- **A floating action button** is a narrow tile pinned to the bottom: a + widget-navbutton, or a widget-form with `formButton: $bool:true`. It floats + over the page and reserves nothing. +- On a phone the bottom band keeps clear of the home indicator, and tiles + pinned to the bottom are hidden while the on-screen keyboard is open. + +```yaml +report: # scrolls: the form is as long as it needs + gridLayout: + - {id: report-form, x: 0, y: 0, w: 48, h: 88} + - {id: bar, x: 0, y: 88, w: 48, h: 8, pin: bottom} # widget-navbar, 52 px +machines: + overflow: false # fitted between the bars + gridLayout: + - {id: machine-list, x: 0, y: 0, w: 48, h: 96} # scrolls inside its tile + - {id: bar, x: 0, y: 96, w: 48, h: 8, pin: bottom} +``` + +Lists, tables and forms scroll inside their own tile. A list page is +therefore best fitted, with the list filling the space between the bars; a +page of cards, a form or a record's details simply scrolls. + +## How a user gets it + +The app keeps one address, one share link and one set of rights for both +boards. The segment after the board's address names which board is shown: + +| Address | Board shown | +|---|---| +| `/home/` | Studio picks by the space available | +| `/mobile/` | the mobile board | +| `/desktop/` | the desktop board | + +- **`home` picks by the shorter side of the space available.** Up to 500 px + it is the mobile board, so a phone gets it upright and turned; tablets and + desktops get the desktop board. It picks again when the window is resized, + and the address stays `home`. +- **`mobile` and `desktop`** name one board explicitly, for a link built on + purpose or a user who switches by hand. +- **An app that ships only one board always shows that one**, whatever the + address names. +- Share links, notifications and e-mails use `home`, so the person who opens + them gets the board that fits their screen. + +### Links + +- **A board's links stay on that board.** Routes are resolved below the + segment the user came in with, so a navbutton's `/machines` on the mobile + board opens the mobile board's `/machines` page. No widget links from one + board to the other; the user switches in Studio. +- **A link whose route the picked board does not have opens that board's home + page.** A link to `/machines/press-1/history` copied on a laptop opens the + mobile board's home page on a phone, when the mobile board has no such page. +- **So where both boards show the same entity, give its page the same route.** When an entity's page + is `/machines/` (or `/order/`) on both boards, every + link to it works on both: from a share link, a notification, an e-mail or + the AI assistant. The pages around it may differ: the mobile board needs no + `/machines/*/settings`. +- **Route parameters and filter values are in the address**, so they carry + over the same way. The URL parameter names `editor`, `chrome`, `share` and + `ticket` belong to Studio: no filter, switch, toolbar, table edit column or + form may use them, on either board. The validator refuses them. + +## Two boards, two kinds of use + +The two boards are designed and changed independently. Each follows the +people who use it and what they do with it: in a case management app the +inspectors in the field report and look up cases on the mobile board, the +managers in the office review, assign and analyse on the desktop board. Their +pages, routes, widgets and functions differ accordingly. Never mirror a page, +a route or a field onto the other board for the sake of symmetry. + +When you change an app that has both boards: + +- **Decide per board** from its brief whether the change belongs there: a new + field may matter to the inspectors' form and not to the managers' overview, + or the other way round. Say in your answer which board you changed. +- **A removed table or column** breaks the bindings of whichever board reads + it: the validator checks each board on its own and reports them. +- **Where both boards have a page for the same thing,** the same route lets a + shared link or a notification open it on either ("Links", above). That is a + reason to align those two routes, never a reason to add a page. + +## Designing for a phone + +Apply what you know about designing for phones (one job per screen, the +frequent actions within the thumb's reach at the bottom, clear and large +targets, nothing that needs hover, short text), within the rules of a board +below: a board is a grid of widget tiles, and the patterns of a phone app are +made from pinned tiles and widget settings. + +Start with the brief (board-design.md, "The brief") for the phone: who uses +it, where, and which jobs they do there. Then its route tree +(board-route-tree.md): usually short, the jobs at the top, and the entity +pages at the same routes as on the desktop board. The validator checks +reachability and every route on each board separately. + +```text +/ two large buttons: Report a problem, Machines +/report the report form: machine, what happened, photos +/machines the machines as a list; a whole row is the link +/machines/ one machine: its state and its reports (the desktop board's route) +``` + +- **Other jobs, other pages.** A page answers one job on a phone. Do not move + the desktop pages over; leave out what nobody does on a phone. +- **One column, mostly.** Give tiles the full width (`w: 48`) and stack them. + Two tiles side by side (`w: 24` each) only for small things, such as two + figures. +- **Large touch targets, at least 44 px**, which is at least 7 rows of 8 px + with the default gap. The widgets give their own controls 44 px hit areas + (toolbar tools, switch rows, sidenav rows, the filters' whole tile). A + navbutton gets at least `h: 7`; widget-form `fieldLayout.density: + comfortable`; widget-switch `size: big` where switching is the job + (board-interaction.md, "Sizes on a board people touch"). +- **Big buttons for the jobs.** The home page offers the jobs as large + widget-navbuttons with `style.fillTile: $bool:true`: the button fills its + tile, with the icon above the label from 96 px of height. +- **A bottom bar for the frequent pages.** A widget-navbar pinned to the + bottom ("Bars and buttons that stay on the screen", above) with three to + five items (Home and the jobs): `labels: below` (icon with a short label + under it; about 60 px, `h: 9`) or `labels: none` (icons only), and + `indicator: top` or `pill`, so the mark of the current page does not sit + against the screen's edge. +- **A drawer for the rare pages.** Settings, help and the rarely used pages + go into a widget-sidenav with `presentation: drawer`: the tile is a menu + button (about 48 × 48 px, wider with `title`), typically in a bar pinned to + the top, and a tap slides the list in from the side of the screen. Never a + widget-sidenav as an open side menu on a phone: it would take half the + screen. +- **A list in place of a wide table.** widget-table with `rendition: list` + (or `auto`, which turns into the list when the tile is narrower than its + columns) shows an entry per row: per column `styling.listRole` says what it + is in the entry (`title`, `detail`, `badge`, `hidden`; at most two details), + and `styling.rowAction: $bool:true` on a link or edit column makes the whole + entry the link or the edit button. A data-driven widget-sidenav at the full + width, a whole row the link (board-navigation.md, pattern 2), still does + for a plain list of names. +- **Forms usable at 360 px.** Fields take the full width, which they do by + default (`fieldLayout.defaultWidth` full, and two fields side by side need + at least twice the 180 px of `minFieldWidth`). A form that is the job + (report a problem) is the page itself (`formButton: $bool:false`, on a page + that scrolls) and goes back with `submitNavigationRoute` after the save. + Photos come from the camera with a media field and `cameraCapture` + (board-forms.md, "Photos with a form"). A form that opens as a dialog + (`formButton`) opens as a sheet from the bottom on a phone by itself, as do + widget-toolbar's menus. +- **Photos as a strip.** widget-image with `multiImageLayout: strip` (a row + that scrolls sideways) and `enlargeOnTap: $bool:true` (a full-screen view + with previous and next). +- **Readings as cards.** A state or a figure is a widget-markdown card at the + full width (board-markdown.md). A chart needs the full width and some 25 + rows; show a short time window. + +Widgets are the same on both boards and adapt to the width of their tile, not +to the device: a narrow tile on a desktop board gets the same rendition. + +The settings above (`labels`, `indicator`, `presentation`, `fillTile`, +`rendition`, `listRole`, `rowAction`, `multiImageLayout`, `enlargeOnTap`) came +with the widget versions released together with mobile boards. A tile is +checked against the version it pins, so pin the newest version (widget.py +prints it); an older pinned version does not know them. + +## Looking at it + +The image tools (board-look.md) show a mobile page when `page` starts with +`mobile`: `get_dev_dashboard_image` with `page: mobile` for the home page, +`page: mobile/report` or `page: mobile/machines/press-1` for others. Without +`width` and `height` the picture is 390 × 844, a phone held upright; add +`full_page` to see a page that scrolls in its whole length. `desktop` names +the desktop board the same way. Without a segment the tool's window decides, which at its +default size is the desktop board. + +Look at every page of a new mobile board once, and check what board-critique.md +asks with a phone in mind: one column, nothing cut off, fitted pages filled, +buttons and rows large enough to touch, and the bars at their edges. diff --git a/plugins/ironflock-dev/skills/ironflock-templates/references/board-navigation.md b/plugins/ironflock-dev/skills/ironflock-templates/references/board-navigation.md index 7256a8f..0b99ae4 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/references/board-navigation.md +++ b/plugins/ironflock-dev/skills/ironflock-templates/references/board-navigation.md @@ -25,7 +25,9 @@ layout: # / - **Page names** use letters, digits, `.`, `_`, `-` and `*`. A `*` page matches any segment, and the widgets on it read the segment with `useRoute` filters. -- **Every page needs a `gridLayout`.** +- **Every page needs a `gridLayout`.** It may also carry `overflow: true` or + `false`: the page scrolls or is fitted onto the screen (board-layout-style.md, + "Pages that scroll"). - **A widget is on a page** when that page's `gridLayout` has an entry whose `id` is the widget's `layout_id`. - **Shared widgets:** to show the same widget on several pages (a menu, say), add @@ -128,6 +130,10 @@ link such as "Home", "Back to the list" or "Manage documents". A `*` needs a segment at its position: on `/machines`, the route `/machines/*/trend` has no second segment to copy, so the link opens `/machines/trend`. +- **A link stays on its board.** An app's desktop board and its board for + phones (board-mobile.md) each resolve their links against their own pages: a + route the board does not have opens that board's home page. Where both + boards have a page for the same entity, give it the same route there. - **A route that contains `*` loses its trailing slash.** `/line/*/andon/` opens `/line/LINE-1/andon`, so relative links on that page lead next to it (`/line/LINE-1/`), never below it. Item routes built from the row's keys diff --git a/plugins/ironflock-dev/skills/ironflock-templates/references/board-route-tree.md b/plugins/ironflock-dev/skills/ironflock-templates/references/board-route-tree.md index 1e8d950..f63cf31 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/references/board-route-tree.md +++ b/plugins/ironflock-dev/skills/ironflock-templates/references/board-route-tree.md @@ -98,6 +98,14 @@ each answering its line. A board about a single subject can be one page. 11. **The routes at the top are the main menu**, in the order users need them, not in the order of the tree: Streams before Devices when people come for the streams. +12. **A board for phones has a tree of its own, with the same entity pages.** + Its top level holds the jobs people do on a phone (`/report`, `/stream`), + not the desktop board's sections, but every entity it shows keeps the + route it has on the desktop board (`/stream/`). A link opens the + page of that route on whichever board the user gets, and a route the board + does not have opens its home page, so shared links, notifications and + e-mails work on both only with the same entity routes (board-mobile.md, + "Links"). ## An example diff --git a/plugins/ironflock-dev/skills/ironflock-templates/references/board-template.md b/plugins/ironflock-dev/skills/ironflock-templates/references/board-template.md index 351e90f..f6be0f1 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/references/board-template.md +++ b/plugins/ironflock-dev/skills/ironflock-templates/references/board-template.md @@ -33,7 +33,8 @@ What each file holds: - [board-forms.md](board-forms.md): the file side of boards that manage records: the delete form in YAML, uploading files and photos with a form. - [board-layout-style.md](board-layout-style.md): the grid, fixed-size - widgets, layering, the `style` keys, tile frames, the presets in the file. + widgets, layering, pages that scroll, pinned tiles, the `style` keys, tile + frames, the presets in the file. - [board-markdown.md](board-markdown.md): widget-markdown placeholders and HTML, one record as a card, how a value is shown, figures as cards. - [board-charts.md](board-charts.md): charts: when a chart and when a card, @@ -45,6 +46,10 @@ What each file holds: - [board-critique.md](board-critique.md): five checks to run once on a finished or restyled board before you report it, with one round of corrections. +- [board-mobile.md](board-mobile.md): the board for phones in + `mobile-board-template.yml`: when to ship one, its grid, pages that scroll + and pinned bars, + which board a user gets and how links behave, designing for a phone. - This file: [Anatomy](#anatomy), [Literal values](#literal-values), [Designing a board](#designing-a-board) (where the design is written, a sketch on a design canvas), [SCADA pages](#scada-pages), @@ -54,6 +59,12 @@ What each file holds: [example-board.yml](example-board.yml) is a complete, valid three-page board. It has navigation, a data-driven machine menu, route filtering, aggregation and a latest-per-machine table. Read it before writing your first board. +[example-mobile-board.yml](example-mobile-board.yml) is the same app's board for +phones. + +Everything in this file holds for both of an app's boards: `board-template.yml` +for desktops and tablets, and `mobile-board-template.yml` for phones, which has +the same schema and anatomy on a grid of its own (board-mobile.md). ## Anatomy @@ -301,8 +312,10 @@ Some values only exist inside a running platform, and a template cannot know the menu share a route; on an older version, no item links to `/` and no item's route starts another item's in the same menu. 5. Every widget with a Layout line has its `fixedHeight` or `fixedWidth` and - enough cells for it, and navbuttons have no tile border, unless there is a - reason to do otherwise (board-layout-style.md, "Layout"). + enough cells for it (on a page that scrolls and on a pinned tile, enough + rows without the flag; no flag at all on a pinned tile), and navbuttons + have no tile border, unless there is a reason to do otherwise + (board-layout-style.md, "Layout"). 6. `design/board.md` holds the board's design and matches the board; the header says who looks at the board and where, and which look was chosen. `style` holds a preset's values whole (board-design.md, "Pick a look"), @@ -316,4 +329,10 @@ Some values only exist inside a running platform, and a template cannot know the widget-markdown cards with `valueType: $str:number` and a `precision`, live readings with `tsp` and `maxLatency`; widget-value only averages or generates one readout per value of a column (board-design.md, "What goes where"). -8. `scripts/validate.py ` (run it as SKILL.md shows) reports no errors. +8. A mobile board, when people use the app on a phone (board-mobile.md), has a + brief and route tree of its own, the entity pages at the desktop board's + routes, one column of tiles (`w: 48`), touch targets of at least 44 px (7 + rows of 8 px), a bottom bar pinned to the bottom (`pin: bottom`), fitted + pages (`overflow: false`) only where the content scrolls inside its tile, + and no `columns` or `rows` in its style. +9. `scripts/validate.py ` (run it as SKILL.md shows) reports no errors. diff --git a/plugins/ironflock-dev/skills/ironflock-templates/references/example-mobile-board.yml b/plugins/ironflock-dev/skills/ironflock-templates/references/example-mobile-board.yml new file mode 100644 index 0000000..06184eb --- /dev/null +++ b/plugins/ironflock-dev/skills/ironflock-templates/references/example-mobile-board.yml @@ -0,0 +1,240 @@ +# yaml-language-server: $schema=https://ironflock.com/schemas/board-template/v1.yml +# Example mobile-board-template.yml: the board for phones of the app whose +# desktop board is example-board.yml. It reads the same tables, and writes two +# of its own: +# machine_status tsp, machine_id, state, state_text (maintainLatestFlagFor: [machine_id]) +# machine_reports tsp, report_id, machine_id, note (maintainLatestFlagFor: [report_id]) +# machine_photos tsp, photo_id, report_id, file_key (maintainLatestFlagFor: [photo_id]) +# files namespace photos, image/jpeg +# Viewers: technicians at the machine, on their phone (office preset). They come +# to report a problem or to look a machine up, not to watch the line, so the +# pages are not the desktop board's: +# / two large buttons: Report a problem, Machines +# /report the report form: machine, what happened, photos +# /machines the machines as a list; a whole row is the link +# /machines/* one machine: its state and its reports. The same route as on the +# desktop board, so a link to a machine opens its page on either +# One column on every page. Pages scroll (a mobile board's default), except +# /machines, which sets overflow: false: it is fitted between the bars, and its +# list scrolls inside its tile. A bottom bar (widget-navbar) leads home and to +# the two jobs from every page but home: pinned to the bottom across the full +# width, it stays at the lower edge, 8 rows of 8 px (room for its 52 px), and +# the page lies above it. No columns, rows or cell_size in style: a mobile +# board's defaults are 48, 96 and 8. +name: machine-monitor +widgets: + - layout_id: welcome + package_name: widget-markdown + version: 1.1.2 + chartconfig: + markdown: | + ## Machine Monitor + Report a problem at a machine, with photos, or look up how a machine is doing. + - layout_id: go-report + package_name: widget-navbutton + version: 1.0.20 + chartconfig: + title: $str:Report a problem + iconName: $str:add_a_photo + route: $str:/report + style: + fontSize: $num:20 + custom_style: + tile_border_color: transparent + tile_background_color: transparent + - layout_id: go-machines + package_name: widget-navbutton + version: 1.0.20 + chartconfig: + title: $str:Machines + iconName: $str:precision_manufacturing + route: $str:/machines + style: + fontSize: $num:20 + custom_style: + tile_border_color: transparent + tile_background_color: transparent + - layout_id: bar + package_name: widget-navbar + version: 1.0.27 + chartconfig: + style: + fontSize: $num:16 + navItems: + - label: $str:Home + iconName: $str:home + route: $str:/ + - label: $str:Report + iconName: $str:add_a_photo + route: $str:/report + - label: $str:Machines + iconName: $str:precision_manufacturing + route: $str:/machines + - layout_id: report-form + package_name: widget-form + version: 2.3.0 + chartconfig: + title: $str:Report a problem + formButton: $bool:false + submitNavigationRoute: $str:/ + buttonLabels: + submitLabel: $str:Send report + fieldLayout: + density: $str:comfortable + formFields: + - label: $str:Report ID + type: $str:textfield + hiddenField: $bool:true + generateId: $bool:true + targetColumn: {tablename: machine_reports, column: report_id, dataType: string} + - label: $str:Machine + type: $str:dropdown + required: $bool:true + targetColumn: {tablename: machine_reports, column: machine_id, dataType: string} + values: + tableRef: + tablename: machine_status + format: {displayLabel: machine_id, value: machine_id} + queryParams: + limit: 100 + filterAnd: + - {latest: true, column: '', operator: '=', value: '', dataType: boolean} + - label: $str:What happened? + type: $str:textarea + required: $bool:true + targetColumn: {tablename: machine_reports, column: note, dataType: string} + - label: $str:Photos + type: $str:media + cameraCapture: $bool:true + maxPhotos: $num:6 + targetColumn: {tablename: machine_photos, column: file_key, dataType: string} + fileNamespace: $str:photos + acceptedFileTypes: $str:image/* + mediaIdColumn: {tablename: machine_photos, column: photo_id, dataType: string} + mediaLinkField: $str:Report ID + mediaLinkColumn: {tablename: machine_photos, column: report_id, dataType: string} + - layout_id: machine-list + package_name: widget-sidenav + version: 1.0.27 + chartconfig: + title: $str:Machines + style: + fontSize: $num:22 + navItems: + tableRef: + tablename: machine_status + format: + label: machine_id + iconName: $str:precision_manufacturing + route: $str:/machines/{{machine}} # the desktop board's route + variables: + - {label: $str:machine, value: machine_id} + queryParams: + limit: 100 + filterAnd: + - {latest: true, column: '', operator: '=', value: '', dataType: boolean} + - layout_id: machine-state + package_name: widget-markdown + version: 1.1.2 + chartconfig: + markdown: | + +
+
Machine {{machine}}
+
{{state}}
+
since {{since}}
+
+ data: + - label: $str:machine + value: + valueRef: + tablename: machine_status + column: machine_id + queryParams: + limit: 1 + filterAnd: + - {latest: true, column: '', operator: '=', value: '', dataType: boolean} + - {column: machine_id, operator: '=', value: '2', dataType: string, useRoute: true} + - label: $str:state + value: + valueRef: + tablename: machine_status + column: state_text + queryParams: + limit: 1 + filterAnd: + - {latest: true, column: '', operator: '=', value: '', dataType: boolean} + - {column: machine_id, operator: '=', value: '2', dataType: string, useRoute: true} + - label: $str:since + valueType: $str:timestamp + value: + valueRef: + tablename: machine_status + column: tsp + queryParams: + limit: 1 + filterAnd: + - {latest: true, column: '', operator: '=', value: '', dataType: boolean} + - {column: machine_id, operator: '=', value: '2', dataType: string, useRoute: true} + # Two values per row, not the desktop's wide table. + - layout_id: machine-reports + package_name: widget-table + version: 1.3.3 + chartconfig: + title: $str:Reports + columns: + - header: $str:When + type: $str:timestamp + values: + tableRef: + tablename: machine_reports + format: {value: tsp} + queryParams: + limit: 20 + filterAnd: + - {latest: true, column: '', operator: '=', value: '', dataType: boolean} + - {column: machine_id, operator: '=', value: '2', dataType: string, useRoute: true} + - header: $str:What happened + type: $str:string + values: + tableRef: + tablename: machine_reports + format: {value: note} + queryParams: + limit: 20 + filterAnd: + - {latest: true, column: '', operator: '=', value: '', dataType: boolean} + - {column: machine_id, operator: '=', value: '2', dataType: string, useRoute: true} +layout: + gridLayout: + - {id: welcome, x: 0, y: 0, w: 48, h: 56} + - {id: go-report, x: 0, y: 56, w: 48, h: 20} + - {id: go-machines, x: 0, y: 76, w: 48, h: 20} + subRoutes: + report: + gridLayout: + - {id: report-form, x: 0, y: 0, w: 48, h: 88} + - {id: bar, x: 0, y: 88, w: 48, h: 8, pin: bottom} + machines: + overflow: false # fitted: the list scrolls inside its tile + gridLayout: + - {id: machine-list, x: 0, y: 0, w: 48, h: 96} + - {id: bar, x: 0, y: 96, w: 48, h: 8, pin: bottom} + subRoutes: + '*': + gridLayout: + - {id: machine-state, x: 0, y: 0, w: 48, h: 24} + - {id: machine-reports, x: 0, y: 24, w: 48, h: 64} + - {id: bar, x: 0, y: 88, w: 48, h: 8, pin: bottom} +style: # the office preset (board-design.md, Pick a look) + theme: {theme_name: light} + background_color: '#f1f5f9' + text_color: '#1e293b' + tile_background_color: '#ffffff' + tile_border_color: '#e2e8f0' + tile_border_radius: 12px + grid_gap: 8 diff --git a/plugins/ironflock-dev/skills/ironflock-templates/schemas/board-template/v1.yml b/plugins/ironflock-dev/skills/ironflock-templates/schemas/board-template/v1.yml index 91f5621..df72d2b 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/schemas/board-template/v1.yml +++ b/plugins/ironflock-dev/skills/ironflock-templates/schemas/board-template/v1.yml @@ -26,7 +26,10 @@ description: > The board (dashboard) an app installs into every project it is installed in: its widgets, how each widget is configured and bound to the app's data, the pages they sit on, and the board style. Usually written by the board editor in - the IronFlock studio; it can be edited by hand. + the IronFlock studio; it can be edited by hand. The same schema describes both + of an app's boards: board-template.yml, the desktop board, and + mobile-board-template.yml, an independent board for phones that differs only + in its default grid (see style.columns, style.rows and style.cell_size). type: object required: [name, widgets, layout] additionalProperties: false @@ -486,6 +489,13 @@ $defs: description: Widget positions on this page, in grid cells of style.columns × style.rows. items: $ref: "#/$defs/position" + overflow: + type: boolean + description: >- + Whether this page scrolls (rows of style.cell_size pixels) or is + fitted onto the screen. Without it the board style's overflow + applies, and without that a page scrolls on a mobile board and is + fitted on a desktop board. subRoutes: type: object description: >- @@ -550,6 +560,15 @@ $defs: type: number exclusiveMinimum: 0 description: Height divided by width, kept when resizing (SCADA symbols). + pin: + enum: [top, bottom] + description: >- + Keeps the tile at this edge of the screen while the page scrolls. It + keeps its columns (x, w); its height is h × style.cell_size − grid_gap + pixels on any page, and y only orders the tiles pinned to the same + edge. A pinned tile across the full width reserves a band at its edge, + and the page lies between the bands; a narrower one floats over the + page. fixedWidth and fixedHeight have no effect on it. style: type: object @@ -643,19 +662,25 @@ $defs: type: number minimum: 1 maximum: 1000 - description: Grid columns. Default 96. + description: Grid columns. Default 96; 48 on a mobile board. rows: type: number minimum: 1 maximum: 1000 - description: Grid rows. Default 64. Without overflow, the whole grid is scaled onto the screen. + description: >- + Grid rows. Default 64; 96 on a mobile board. Without overflow, the + whole grid is scaled onto the screen. cell_size: type: number exclusiveMinimum: 0 - description: Cell size in pixels when overflow is on. Default 12. + description: Cell size in pixels when overflow is on. Default 12; 8 on a mobile board. overflow: type: boolean - description: Scroll instead of scaling the grid onto the screen. Default false. + description: >- + Scroll instead of scaling the grid onto the screen: the default for + the board's pages, each of which may set its own overflow. Default + false; on a mobile board, pages scroll unless this or the page says + false. overflowX: type: boolean scaleToFit: diff --git a/plugins/ironflock-dev/skills/ironflock-templates/scripts/board_checks.py b/plugins/ironflock-dev/skills/ironflock-templates/scripts/board_checks.py index fa2cbbf..ae3ab2c 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/scripts/board_checks.py +++ b/plugins/ironflock-dev/skills/ironflock-templates/scripts/board_checks.py @@ -11,6 +11,9 @@ - the layout: ids, pages, positions, screen coverage, navigation routes, the fixed height or width a widget declares (`layout` in its definition schema), and filter widgets wired to the widgets they are meant to filter, +- the mobile board (mobile-board-template.yml): the same checks, on its own + default grid, +- URL parameters: none may take a name Studio keeps for itself (`editor` and others), - navigation: menu items that would be highlighted together with others, and whether every page can be reached from the home page by clicking, and left again, following links the way the widgets and the board navigator resolve them, @@ -103,9 +106,38 @@ #: current state of each alarm; alarm_events has none. ALARMS_ENTITY_KEYS = {"alarms": ["alarm_key"]} ALARMS_UNREADABLE = {"alarm_notifications"} -DEFAULT_COLUMNS, DEFAULT_ROWS = 96, 64 +#: Pixels between tiles when the style names none, on both boards. +DEFAULT_GRID_GAP = 8 + + +@dataclass(frozen=True) +class Grid: + """What style.columns, style.rows and style.cell_size are when the style + names none, and whether a page scrolls when neither it nor the style says + (overflow). The only difference between an app's two boards.""" + + columns: int + rows: int + cell_size: int + scrolls: bool + + #: DEFAULT_DASHBOARD_STYLE in Studio's src/types/dashboard.ts. -DEFAULT_CELL_SIZE, DEFAULT_GRID_GAP = 12, 8 +DESKTOP_GRID = Grid(columns=96, rows=64, cell_size=12, scrolls=False) +#: MOBILE_COLUMNS, MOBILE_ROWS and MOBILE_CELL_SIZE in Studio's +#: src/modules/dashboard/board-variant.ts: mobile-board-template.yml. Its +#: pages scroll unless they or the style say otherwise. +MOBILE_GRID = Grid(columns=48, rows=96, cell_size=8, scrolls=True) +#: The screen edges a position may be pinned to (pin). +PIN_EDGES = ("top", "bottom") +#: Query parameters Studio keeps for itself in a board's address, and why. A +#: widget that reads or sets one of them would collide with Studio. +RESERVED_PARAMS = { + "editor": "the board editor opens its panels with it", + "chrome": "it shows the board without Studio's chrome", + "share": "a share link carries its token in it", + "ticket": "it signs a page in", +} COVERAGE_TARGET = 0.9 #: What JavaScript's trim() and Number() skip as whitespace, which is not quite #: Python's: U+FEFF is in, U+001C-U+001F and U+0085 are out. @@ -225,6 +257,7 @@ class Board: doc: Any report: Any data: Any + grid: Grid = DESKTOP_GRID # MOBILE_GRID for mobile-board-template.yml filter_params_used: dict[str, list] = field(default_factory=dict) time_params_used: dict[str, list] = field(default_factory=dict) filter_params_offered: dict[str, list] = field(default_factory=dict) @@ -261,8 +294,11 @@ def is_alarms(provider: Any) -> bool: # -------------------------------------------------------------------------- -def check_board(doc, report, data, offline: bool) -> None: - board = Board(doc, report, data) +def check_board(doc, report, data, offline: bool, mobile: bool = False) -> None: + """One board: the desktop board (board-template.yml), or with mobile the + board for phones (mobile-board-template.yml), which has the same schema + and the same checks, with its own default grid.""" + board = Board(doc, report, data, grid=MOBILE_GRID if mobile else DESKTOP_GRID) tpl = doc.data if isinstance(doc.data, dict) else {} widgets = tpl.get("widgets") if isinstance(tpl.get("widgets"), list) else [] layout = tpl.get("layout") if isinstance(tpl.get("layout"), dict) else None @@ -284,14 +320,15 @@ def check_board(doc, report, data, offline: bool) -> None: board.error(["widgets", i, "layout_id"], f"layout_id '{lid}' is already used by widgets[{ids[lid]}]") ids.setdefault(lid, i) - placements = check_layout(board, layout, ids, tpl.get("style") or {}) if layout else {} + style = tpl.get("style") if isinstance(tpl.get("style"), dict) else {} + placements = check_layout(board, layout, ids, style) if layout else {} schema_cache: dict[tuple[str, str | None], tuple[str | None, dict | None, str | None]] = {} for i, w in enumerate(widgets): if isinstance(w, dict): check_widget(board, i, w, offline, schema_cache, placements) if layout: - check_fixed_sizes(board, layout, widgets, tpl.get("style") or {}, schema_cache) + check_fixed_sizes(board, layout, widgets, style, schema_cache) check_routes(board, layout, placements) check_navigation(board, layout, placements) @@ -329,14 +366,13 @@ def check_layout(board: Board, layout: dict, widget_ids: dict[str, int], style: """Returns layout_id -> routes of the pages it is placed on.""" placements: dict[str, list[list[str]]] = {} orphans: dict[str, list] = {} # layout_id without a widget -> paths of its slots - columns = style.get("columns") if isinstance(style.get("columns"), (int, float)) else DEFAULT_COLUMNS - rows = style.get("rows") if isinstance(style.get("rows"), (int, float)) else DEFAULT_ROWS + columns, rows = grid_size(style, board.grid) snapped = style.get("gridSnap") is not False - overflow_y = bool(style.get("overflow")) overflow_x = bool(style.get("overflowX")) for route, page, path in iter_pages(layout, [], ["layout"]): label = "/" + "/".join(route) + overflow_y = page_scrolls(page, style, board.grid) grid = page.get("gridLayout") if isinstance(page.get("gridLayout"), list) else [] seen: set[str] = set() boxes = [] @@ -357,13 +393,26 @@ def check_layout(board: Board, layout: dict, widget_ids: dict[str, int], style: placements.setdefault(pid, []).append(route) if pos.get("aspectRatio"): has_aspect = True + # A pinned tile stays at its screen edge, h rows of cell_size + # pixels high: its y only orders the tiles pinned to that edge, so + # it is neither bounded by the rows nor part of the page's grid. + pin = pos.get("pin") if pos.get("pin") in PIN_EDGES else None + if pin: + for flag in ("fixedHeight", "fixedWidth"): + if pos.get(flag) is True: + board.warn( + ppath + [flag], + f"{flag} has no effect on a tile pinned to the {pin}: its height is h × cell_size − grid_gap " + "pixels and its width its columns' share of the screen; remove it", + ) if all(isinstance(pos.get(k), (int, float)) for k in "xywh"): x, y, w, h = (pos[k] for k in "xywh") if snapped and not overflow_x and x + w > columns: board.warn(ppath, f"reaches column {x + w:g} but the grid has {columns:g}; the widget is cut off") - if snapped and not overflow_y and y + h > rows: + if snapped and not overflow_y and not pin and y + h > rows: board.warn(ppath, f"reaches row {y + h:g} but the grid has {rows:g}; the widget is cut off") - boxes.append((x, y, w, h, ppath)) + if not pin: + boxes.append((x, y, w, h, ppath)) if not grid: if not is_transient(route, page): # check_navigation warns if users reach it @@ -374,8 +423,8 @@ def check_layout(board: Board, layout: dict, widget_ids: dict[str, int], style: if coverage < COVERAGE_TARGET: board.warn( path + ["gridLayout"], - f"widgets cover {coverage:.0%} of page {label} ({columns:g}x{rows:g} grid); without " - "overflow the grid is scaled onto the whole screen, so the rest shows as empty space", + f"widgets cover {coverage:.0%} of page {label} ({columns:g}x{rows:g} grid); a page without " + "overflow is scaled onto the whole screen, so the rest shows as empty space", ) for pid, paths in orphans.items(): @@ -387,11 +436,29 @@ def check_layout(board: Board, layout: dict, widget_ids: dict[str, int], style: return placements -def fixed_cells(px: float, style: dict) -> int: +def number(value: Any, default: float) -> float: + """A positive style number, or the default when it is unset or not one.""" + return value if isinstance(value, (int, float)) and not isinstance(value, bool) and value > 0 else default + + +def grid_size(style: dict, grid: Grid) -> tuple[float, float]: + """The board's columns and rows.""" + return number(style.get("columns"), grid.columns), number(style.get("rows"), grid.rows) + + +def page_scrolls(page: dict, style: dict, grid: Grid) -> bool: + """Whether a page scrolls (its rows cell_size pixels high) or is fitted onto + the screen: its own overflow, else the style's, else the board's default.""" + for value in (page.get("overflow"), style.get("overflow")): + if isinstance(value, bool): + return value + return grid.scrolls + + +def fixed_cells(px: float, style: dict, grid: Grid) -> int: """Grid cells a fixed axis of px pixels takes: with grid snap each such cell is cell_size pixels, and a tile loses grid_gap (gridToPixel in Studio).""" - cell = style.get("cell_size") - cell = cell if isinstance(cell, (int, float)) and not isinstance(cell, bool) and cell > 0 else DEFAULT_CELL_SIZE + cell = number(style.get("cell_size"), grid.cell_size) gap = style.get("grid_gap") gap = gap if isinstance(gap, (int, float)) and not isinstance(gap, bool) and gap >= 0 else DEFAULT_GRID_GAP return max(1, math.ceil((px + gap) / cell)) @@ -400,8 +467,15 @@ def fixed_cells(px: float, style: dict) -> int: def check_fixed_sizes(board: Board, layout: dict, widgets: list, style: dict, cache: dict) -> None: """A widget whose schema declares `layout: {fixedHeight: true, height: }` (or fixedWidth / width) keeps that size: its positions need the flag, and - enough cells for it. Without grid snap and overflow Studio ignores the flags.""" + enough cells for it. Without grid snap and overflow Studio ignores the flags. + A position that spans the whole width (or height) of the grid needs no + flag: it takes the screen's width there, which is what it is placed for, + and the flag would only make it columns × cell_size pixels wide. On a page + that scrolls, and on a pinned tile, every row is cell_size pixels already, + so a fixed height needs only enough rows; a pinned tile's width is its + columns' share of the screen, which no flag changes.""" snapped = style.get("gridSnap") is not False + span = dict(zip("wh", grid_size(style, board.grid))) hints: dict[str, tuple[str, list[tuple[str, str, str, float]]]] = {} for w in widgets: if not isinstance(w, dict) or not isinstance(w.get("layout_id"), str): @@ -413,34 +487,42 @@ def check_fixed_sizes(board: Board, layout: dict, widgets: list, style: dict, ca continue axes = [ (flag, size, key, block[size]) - for flag, size, key, overflow in (("fixedHeight", "height", "h", "overflow"), ("fixedWidth", "width", "w", "overflowX")) + for flag, size, key in (("fixedHeight", "height", "h"), ("fixedWidth", "width", "w")) if block.get(flag) is True and isinstance(block.get(size), (int, float)) and not isinstance(block.get(size), bool) and block[size] > 0 - and (snapped or style.get(overflow)) ] if axes: hints[w["layout_id"]] = (str(w.get("package_name")), axes) for _route, page, path in iter_pages(layout, [], ["layout"]): grid = page.get("gridLayout") if isinstance(page.get("gridLayout"), list) else [] + overflow = {"h": page_scrolls(page, style, board.grid), "w": bool(style.get("overflowX"))} for j, pos in enumerate(grid): if not isinstance(pos, dict) or pos.get("aspectRatio") or pos.get("id") not in hints: continue package, axes = hints[pos["id"]] + pinned = pos.get("pin") in PIN_EDGES for flag, size, key, px in axes: - cells = fixed_cells(px, style) - if pos.get(flag) is not True: + if not (snapped or overflow[key]) or (pinned and key == "w"): + continue + cells = fixed_cells(px, style, board.grid) + pixel_rows = key == "h" and (pinned or overflow["h"]) + if pos.get(flag) is not True and not pixel_rows: + start = pos.get("x" if key == "w" else "y") + if start == 0 and isinstance(pos.get(key), (int, float)) and pos[key] >= span[key]: + continue # the whole width (height) of the screen board.warn( path + ["gridLayout", j], f"{package} keeps a fixed {size} of about {px:g} px: set {flag}: true " f"and {key}: {cells}, or it scales with the screen", ) elif isinstance(pos.get(key), (int, float)) and pos[key] < cells: + how = "pinned" if pinned and key == "h" else "on a page that scrolls" if pixel_rows else f"with {flag}" board.warn( path + ["gridLayout", j, key], - f"{package} needs about {px:g} px, which is {key}: {cells} with {flag}; " + f"{package} needs about {px:g} px, which is {key}: {cells} {how}; " f"{key}: {pos[key]:g} cuts it off", ) @@ -1322,7 +1404,12 @@ def check_routes(board: Board, layout: dict | None, placements: dict) -> None: collect_routes(w.get("chartconfig"), ["widgets", i, "chartconfig"], routes) for rpath, raw in routes: kind, route = decode(raw) - if kind not in (None, "str") or "{{" in route or route in ("", "/"): + if kind not in (None, "str"): + continue + query = route.split("#", 1)[0].partition("?")[2] + for name in {part.split("=", 1)[0] for part in query.split("&") if part}: + check_reserved_param(board, rpath, name) + if "{{" in route or route in ("", "/"): continue route = re.split(r"[?#]", route, maxsplit=1)[0] target = [s for s in route.strip("/").split("/") if s] @@ -1938,6 +2025,7 @@ def check_filter_wiring(board: Board) -> None: name = decode(raw)[1] if not name: continue + check_reserved_param(board, kpath, name) used = board.filter_params_used if kind == "filter" else board.time_params_used if name not in used and not (kind == "filter" and name in board.params_opening): how = ( @@ -1970,3 +2058,21 @@ def check_filter_wiring(board: Board) -> None: f"no widget on this board sets the URL parameter '{name}' that opens this form; give a widget-table a column of " f"type 'edit' with styling.parameterKey: '{name}', its values bound to the record's key column", ) + # The filter widgets' keys are checked above; these are the parameters + # bindings read, the ones table 'edit' columns set and forms open on. + for found in (board.filter_params_used, board.time_params_used, board.params_set, board.params_opening): + for name, paths in found.items(): + for path in paths: + check_reserved_param(board, path, name) + + +def check_reserved_param(board: Board, path: list, name: Any) -> None: + """A URL parameter a widget reads or sets must not be one Studio keeps for + itself in the board's address.""" + if isinstance(name, str) and name.strip() in RESERVED_PARAMS: + name = name.strip() + board.error( + path, + f"'{name}' is a URL parameter Studio keeps for itself on every board ({RESERVED_PARAMS[name]}); " + "choose another name, here and wherever the board reads or sets it", + ) diff --git a/plugins/ironflock-dev/skills/ironflock-templates/scripts/validate.py b/plugins/ironflock-dev/skills/ironflock-templates/scripts/validate.py index a2fded1..272c61d 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/scripts/validate.py +++ b/plugins/ironflock-dev/skills/ironflock-templates/scripts/validate.py @@ -9,7 +9,8 @@ validate.py [APP_DIR] --offline skip checks that need widget schemas from npm Every template file present is checked against its JSON Schema (the copies in -../schemas, identical to https://ironflock.com/schemas//v1.yml), then +../schemas, identical to https://ironflock.com/schemas//v1.yml; the board +for phones, mobile-board-template.yml, has the board's schema), then against the rules the platform only enforces at install or render time: fleetdb's data-template checks, cross-file references (board data bindings must name real tables and columns), each board widget's config against that @@ -70,7 +71,11 @@ def _bootstrap() -> None: import compose_privileges # noqa: E402 import skill_checks # noqa: E402 -TEMPLATES = ["data-template", "board-template", "env-template", "port-template", "ai-template"] +TEMPLATES = ["data-template", "board-template", "mobile-board-template", "env-template", "port-template", "ai-template"] +#: The board for phones has the desktop board's schema, and so its schema line. +SCHEMA_OF = {"mobile-board-template": "board-template"} +#: The app's boards: the desktop board, and the independent board for phones. +BOARDS = {"board-template": False, "mobile-board-template": True} # name -> mobile # -------------------------------------------------------------------------- @@ -637,7 +642,7 @@ def run(folder: Path, offline: bool) -> Report: if doc.data is None: report.error(doc, [], "file is empty") continue - check_schema(name, doc, report) + check_schema(SCHEMA_OF.get(name, name), doc, report) docs[name] = doc data = check_data(docs["data-template"], report) if "data-template" in docs else DataModel() @@ -649,10 +654,12 @@ def run(folder: Path, offline: bool) -> Report: if "ai-template" in docs: check_ai(docs["ai-template"], report, data) skill_checks.check_skills(folder, docs.get("ai-template"), (folder / "ai-template.yml").exists(), report) - if "board-template" in docs: + if any(name in docs for name in BOARDS): import board_checks - board_checks.check_board(docs["board-template"], report, data, offline) + for name, mobile in BOARDS.items(): + if name in docs: + board_checks.check_board(docs[name], report, data, offline, mobile=mobile) if not docs and not report.issues: report.issues.append(Issue("WARN", str(folder), None, [], "no templates found")) return report diff --git a/plugins/ironflock-dev/skills/ironflock-templates/scripts/widget.py b/plugins/ironflock-dev/skills/ironflock-templates/scripts/widget.py index 37edf4c..8bc256e 100644 --- a/plugins/ironflock-dev/skills/ironflock-templates/scripts/widget.py +++ b/plugins/ironflock-dev/skills/ironflock-templates/scripts/widget.py @@ -331,10 +331,22 @@ def main() -> int: for flag, size, key in (("fixedHeight", "height", "h"), ("fixedWidth", "width", "w")): block = schema.get("layout") if isinstance(schema.get("layout"), dict) else {} if block.get(flag) is True and isinstance(block.get(size), (int, float)): + cells = math.ceil((block[size] + 8) / 12) + # A mobile board has the same rule with its cells of 8 px, but its + # pages scroll by default, and on a page that scrolls (or a pinned + # tile) every row is cell_size pixels already (board-mobile.md). + small = math.ceil((block[size] + 8) / 8) + if key == "h": + mobile = ( + f"On a page that scrolls (a mobile board's default) and on a pinned tile, rows are " + f"cell_size pixels already: {key}: {small} on a mobile board, without the flag." + ) + else: + mobile = f"On a mobile board {small}." print( f"Layout: keeps a fixed {size} of about {block[size]:g} px. Give its position " f"{flag}: true and {key}: ceil(({size} + grid_gap) / cell_size), " - f"{math.ceil((block[size] + 8) / 12)} on the default style." + f"{cells} on the default style. {mobile}" ) print() when = dict(w.split("=", 1) for w in args.when if "=" in w) diff --git a/plugins/ironflock-dev/skills/ironflock-widgets/references/host-contract.md b/plugins/ironflock-dev/skills/ironflock-widgets/references/host-contract.md index a7c6c11..9138ac5 100644 --- a/plugins/ironflock-dev/skills/ironflock-widgets/references/host-contract.md +++ b/plugins/ironflock-dev/skills/ironflock-widgets/references/host-contract.md @@ -153,6 +153,24 @@ element's `class` and `style` attributes, so never overwrite them on `this`. - Each tile is its own stacking context and clips its content. A menu, dialog or tooltip that has to extend beyond the tile must use the top layer (a ``, the popover API, or a Material component that uses it). +- **The screen is not always the window.** The top layer spans the browser + window, but a board can be shown in a part of it: the board editor draws a + mobile board on a phone-sized canvas in the middle of a desktop window, and a + board view has Studio's bar above it. Studio sets the rectangle of the screen + the board is shown on as CSS custom properties, in CSS pixels relative to the + window: `--re-screen-left`, `--re-screen-top`, `--re-screen-width` and + `--re-screen-height`, and its corner radius as `--re-screen-radius` (the + editor's phone canvas has rounded corners, a real screen none). They inherit + into the widget's shadow tree and into its top-layer elements. A panel that + belongs to the screen (a drawer, a bottom sheet, a full-screen view, the + scrim behind them) is drawn inside a box of exactly that rectangle, with that + radius and `overflow: hidden`, so it slides in from the screen's edge and + nothing of it shows outside the screen, and a widget that picks a form by the screen's size (a bottom sheet + below 600 px) reads the width from `--re-screen-width`, not from + `window.innerWidth` or a media query. Read them with `getComputedStyle(this)` + when the panel opens. Where they are not set (Studio before mobile boards, + the Widget Editor's preview, the AI chat) use the window: fall back with + `var(--re-screen-left, 0px)` and so on. - Layout positions can carry `fixedWidth`/`fixedHeight` (the tile keeps a pixel size; a widget asks for it with the root `layout` of its schema, see [config-schema.md](config-schema.md#layout)) and `aspectRatio` (widget-scada: the tile keeps the symbol's shape, and diff --git a/plugins/ironflock/.claude-plugin/plugin.json b/plugins/ironflock/.claude-plugin/plugin.json index ea3f89c..b242c01 100644 --- a/plugins/ironflock/.claude-plugin/plugin.json +++ b/plugins/ironflock/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "ironflock", "displayName": "IronFlock", - "version": "1.1.24", + "version": "1.1.25", "description": "Connect Claude to IronFlock in the cloud with browser sign-in. Work with devices, apps, alarms, logs and project data. Add the optional IronFlock Appliance plugin for a direct connection to a local installation.", "author": { "name": "IronFlock", diff --git a/tests/boards/mobile-board.yml b/tests/boards/mobile-board.yml new file mode 100644 index 0000000..376c96b --- /dev/null +++ b/tests/boards/mobile-board.yml @@ -0,0 +1,170 @@ +# yaml-language-server: $schema=https://ironflock.com/schemas/board-template/v1.yml +# A board for phones, added as mobile-board-template.yml next to the example +# desktop board: every finding must name the mobile file, and the desktop board +# stays clean. A mobile board is checked like a desktop board on its own +# defaults: 48 columns x 96 rows, cells of 8 px, and pages that scroll unless +# they (or the style) set overflow: false. +# board: mobile +# desktop: example +# +# The home page scrolls (the mobile default): columns bound it, rows do not, +# it need not be filled, and its rows are 8 px already, so a fixed-height +# widget needs enough rows but no fixedHeight. +# expect: WARN layout.gridLayout[2] :: reaches column 52 but the grid has 48 +# expect-none: layout.gridLayout[3] +# expect-none: layout.gridLayout +# expect-none: layout.gridLayout[0] +# expect: WARN layout.gridLayout[0].h :: which is h: 7 on a page that scrolls; h: 4 cuts it off +# expect-none: layout.gridLayout[1] +# +# /report sets overflow: false (the schema takes it): it is fitted onto the +# screen, so rows bound it, it must be filled, and fixed sizes need the flag. +# expect-none: layout.subRoutes.report +# expect: WARN layout.subRoutes.report.gridLayout[4] :: reaches row 100 but the grid has 96 +# expect: WARN layout.subRoutes.report.gridLayout :: (48x96 grid) +# expect: WARN layout.subRoutes.report.gridLayout[0].h :: which is h: 7 with fixedHeight; h: 4 cuts it off +# expect-none: layout.subRoutes.report.gridLayout[1] +# expect: WARN layout.subRoutes.report.gridLayout[3] :: set fixedWidth: true and w: 24 +# +# Pinned tiles: y only orders them, so no row bound and no missing flag; a +# flag on one has no effect. The schema takes top and bottom, nothing else, +# and refuses flexHeight. +# expect-none: layout.subRoutes.report.gridLayout[5] +# expect: WARN layout.subRoutes.report.gridLayout[6].fixedHeight :: fixedHeight has no effect on a tile pinned to the bottom +# expect: ERROR layout.subRoutes.report.gridLayout[7].pin :: 'middle' is not one of ['top', 'bottom'] +# expect: ERROR layout.subRoutes.report.gridLayout[2] :: 'flexHeight' was unexpected +# +# /lines is fitted and covered half by a tile, half by a band pinned to the +# bottom: pinned tiles are not part of the grid, so half is empty. +# expect: WARN layout.subRoutes.lines.gridLayout :: widgets cover 50% of page /lines +# +# Routes resolve against this board's pages: /machines is a page of the +# desktop board only. Parameters are checked here too. +# expect: WARN widgets[1].chartconfig.route :: route '/machines' matches no page +# expect: ERROR widgets[5].chartconfig.data[0].value.valueRef.queryParams.filterAnd[0].value :: 'editor' is a URL parameter Studio keeps for itself +name: machine-monitor +widgets: + - layout_id: go-report + package_name: widget-navbutton + version: 1.0.20 + chartconfig: + title: $str:Report a problem + route: $str:/report + - layout_id: go-machines + package_name: widget-navbutton + version: 1.0.20 + chartconfig: + title: $str:Machines + route: $str:/machines + - layout_id: wide + package_name: widget-markdown + version: 1.1.2 + chartconfig: + markdown: | + ## Wide + - layout_id: far-down + package_name: widget-markdown + version: 1.1.2 + chartconfig: + markdown: | + ## Far down + - layout_id: back + package_name: widget-navbutton + version: 1.0.20 + chartconfig: + title: $str:Home + route: $str:/ + - layout_id: state + package_name: widget-markdown + version: 1.1.2 + chartconfig: + markdown: | + {{state}} + data: + - label: $str:state + value: + valueRef: + tablename: machine_status + column: state_text + queryParams: + limit: 1 + filterAnd: + - {column: machine_id, operator: '=', value: editor, dataType: string, useFilter: true} + - layout_id: list + package_name: widget-sidenav + version: 1.0.27 + chartconfig: + title: $str:Machines + navItems: + - label: $str:Home + route: $str:/ + - layout_id: half-list + package_name: widget-sidenav + version: 1.0.27 + chartconfig: + title: $str:Lines + navItems: + - label: $str:Home + route: $str:/ + - layout_id: side + package_name: widget-markdown + version: 1.1.2 + chartconfig: + markdown: | + ## Beside the lines + - layout_id: bar + package_name: widget-navbar + version: 1.0.27 + chartconfig: + navItems: + - label: $str:Home + route: $str:/ + - layout_id: fab + package_name: widget-navbutton + version: 1.0.20 + chartconfig: + title: $str:New + route: $str:/report + - layout_id: odd + package_name: widget-markdown + version: 1.1.2 + chartconfig: + markdown: | + ## Pinned to the middle + - layout_id: top-half + package_name: widget-markdown + version: 1.1.2 + chartconfig: + markdown: | + ## Top half + - layout_id: band + package_name: widget-markdown + version: 1.1.2 + chartconfig: + markdown: | + ## Pinned band +layout: + gridLayout: + - {id: go-report, x: 0, y: 0, w: 48, h: 4} + - {id: go-machines, x: 0, y: 4, w: 48, h: 7} + - {id: wide, x: 0, y: 11, w: 52, h: 15} + - {id: far-down, x: 0, y: 90, w: 48, h: 10} + subRoutes: + report: + overflow: false + gridLayout: + - {id: back, x: 0, y: 0, w: 48, h: 4, fixedHeight: true} + - {id: list, x: 0, y: 4, w: 48, h: 40} + - {id: state, x: 0, y: 44, w: 48, h: 26, flexHeight: true} + - {id: half-list, x: 0, y: 70, w: 24, h: 20} + - {id: side, x: 24, y: 90, w: 24, h: 10} + - {id: bar, x: 0, y: 200, w: 48, h: 8, pin: bottom} + - {id: fab, x: 40, y: 0, w: 8, h: 7, pin: bottom, fixedHeight: true} + - {id: odd, x: 0, y: 0, w: 48, h: 8, pin: middle} + lines: + overflow: false + gridLayout: + - {id: top-half, x: 0, y: 0, w: 48, h: 48} + - {id: band, x: 0, y: 48, w: 48, h: 48, pin: bottom} +style: + grid_gap: 8 diff --git a/tests/boards/page-overflow-fitted.yml b/tests/boards/page-overflow-fitted.yml new file mode 100644 index 0000000..8ff1b1b --- /dev/null +++ b/tests/boards/page-overflow-fitted.yml @@ -0,0 +1,33 @@ +# yaml-language-server: $schema=https://ironflock.com/schemas/board-template/v1.yml +# A desktop board without overflow fits its pages onto the screen (the home +# page is bounded and must be filled), but a page with overflow: true scrolls. +# expect: WARN layout.gridLayout :: (96x64 grid) +# expect-none: layout.subRoutes.long.gridLayout[1] +# expect-none: layout.subRoutes.long.gridLayout +name: page-overflow-fitted +widgets: + - layout_id: notes + package_name: widget-markdown + chartconfig: + markdown: | + ## Notes + - layout_id: home + package_name: widget-navbutton + chartconfig: + title: $str:Home + route: $str:/ + - layout_id: long-link + package_name: widget-navbutton + chartconfig: + title: $str:Long + route: $str:/long +layout: + gridLayout: + - {id: long-link, x: 0, y: 0, w: 24, h: 5, fixedHeight: true} + - {id: notes, x: 0, y: 5, w: 48, h: 30} + subRoutes: + long: + overflow: true + gridLayout: + - {id: home, x: 0, y: 0, w: 24, h: 5, fixedHeight: true} + - {id: notes, x: 0, y: 5, w: 48, h: 200} diff --git a/tests/boards/page-overflow.yml b/tests/boards/page-overflow.yml new file mode 100644 index 0000000..36cdecc --- /dev/null +++ b/tests/boards/page-overflow.yml @@ -0,0 +1,46 @@ +# yaml-language-server: $schema=https://ironflock.com/schemas/board-template/v1.yml +# Scrolling per page on a desktop board: style.overflow is the default for the +# board's pages, and a page's own overflow wins. Here the style scrolls, so the +# home page scrolls (no row bound, no coverage) and /fitted, with overflow: +# false, is fitted onto the screen again. A filter bar pinned to the top of the +# scrolling home page stays there; y only orders it. +# expect-none: layout.gridLayout[0] +# expect-none: layout.gridLayout[1] +# expect-none: layout.gridLayout +# expect: WARN layout.subRoutes.fitted.gridLayout[1] :: reaches row 80 but the grid has 64 +# expect: WARN layout.subRoutes.fitted.gridLayout :: (96x64 grid) +name: page-overflow +widgets: + - layout_id: filters + package_name: widget-markdown + chartconfig: + markdown: | + ## Filters + - layout_id: notes + package_name: widget-markdown + chartconfig: + markdown: | + ## Notes + - layout_id: home + package_name: widget-navbutton + chartconfig: + title: $str:Home + route: $str:/ + - layout_id: fitted-link + package_name: widget-navbutton + chartconfig: + title: $str:Fitted + route: $str:/fitted +layout: + gridLayout: + - {id: filters, x: 0, y: 0, w: 96, h: 6, pin: top} + - {id: notes, x: 0, y: 6, w: 96, h: 120} + - {id: fitted-link, x: 0, y: 126, w: 24, h: 5, fixedHeight: true} + subRoutes: + fitted: + overflow: false + gridLayout: + - {id: home, x: 0, y: 0, w: 24, h: 5, fixedHeight: true} + - {id: notes, x: 0, y: 5, w: 48, h: 75} +style: + overflow: true diff --git a/tests/boards/reserved-params.yml b/tests/boards/reserved-params.yml new file mode 100644 index 0000000..48c90a1 --- /dev/null +++ b/tests/boards/reserved-params.yml @@ -0,0 +1,134 @@ +# yaml-language-server: $schema=https://ironflock.com/schemas/board-template/v1.yml +# URL parameters Studio keeps for itself in a board's address: 'editor' (what the +# board editor has open), 'chrome' (the board without Studio's chrome), 'share' +# (a share link's token) and 'ticket' (a page's sign-in). Every setting that +# names a URL parameter a widget reads or sets is refused when it takes one of +# them; the same settings with other names are not. +# expect: ERROR widgets[0].chartconfig.parameterKey :: 'editor' is a URL parameter Studio keeps for itself +# expect: ERROR widgets[1].chartconfig.startKey :: 'share' is a URL parameter Studio keeps for itself +# expect-none: widgets[1].chartconfig.endKey +# expect: ERROR widgets[2].chartconfig.dataseries[0].parameterKey :: 'chrome' is a URL parameter Studio keeps for itself +# expect: ERROR widgets[3].chartconfig.tools[0].parameterKey :: 'ticket' is a URL parameter Studio keeps for itself +# expect: ERROR widgets[4].chartconfig.columns[1].styling.parameterKey :: 'editor' is a URL parameter Studio keeps for itself +# expect: ERROR widgets[5].chartconfig.openParameter :: 'editor' is a URL parameter Studio keeps for itself +# expect: ERROR widgets[6].chartconfig.dataseries[0].data.tableRef.queryParams.filterAnd[0].value :: 'editor' is a URL parameter Studio keeps for itself +# expect: ERROR widgets[6].chartconfig.dataseries[0].data.tableRef.queryParams.timeStartParam :: 'editor' is a URL parameter Studio keeps for itself +# expect-none: widgets[6].chartconfig.dataseries[0].data.tableRef.queryParams.timeEndParam +# expect: ERROR widgets[7].chartconfig.route :: 'editor' is a URL parameter Studio keeps for itself +# expect-none: widgets[8].chartconfig.route +# 'edit' is not reserved: the usual name of a form's open parameter and a +# table's edit column (edit-dialog.yml), and here a filter and its reader. +# expect-none: widgets[9].chartconfig.parameterKey +# expect-none: widgets[6].chartconfig.dataseries[0].data.tableRef.queryParams.filterAnd[1].value +name: reserved-params +widgets: + - layout_id: machine-filter + package_name: widget-filter-dropdown + chartconfig: + label: $str:Machine + parameterKey: $str:editor + - layout_id: period + package_name: widget-filter-calendar + chartconfig: + startKey: $str:share + endKey: $str:until + - layout_id: view-switch + package_name: widget-switch + chartconfig: + title: $str:View + dataseries: + - label: $str:Only faults + parameterKey: $str:chrome + parameterValue: $str:FAULT + - layout_id: view-bar + package_name: widget-toolbar + chartconfig: + tools: + - label: $str:Only faults + control: $str:switch + parameterKey: $str:ticket + onValue: $str:FAULT + - layout_id: machines + package_name: widget-table + chartconfig: + title: $str:Machines + columns: + - header: $str:Machine + type: $str:string + values: + tableRef: + tablename: machine_status + format: {value: machine_id} + queryParams: + limit: 50 + filterAnd: + - {latest: true, column: '', operator: '=', value: '', dataType: boolean} + - header: $str:Edit + type: $str:edit + values: + tableRef: + tablename: machine_status + format: {value: machine_id} + queryParams: + limit: 50 + filterAnd: + - {latest: true, column: '', operator: '=', value: '', dataType: boolean} + styling: + parameterKey: $str:editor + - layout_id: edit-form + package_name: widget-form + chartconfig: + title: $str:Edit machine + formButton: $bool:true + openParameter: $str:editor + formFields: + - label: $str:Target speed + type: $str:numberfield + targetColumn: {tablename: machine_status, column: target_rpm, dataType: numeric} + - layout_id: trend + package_name: widget-linechart + chartconfig: + title: $str:Temperature + dataseries: + - label: $str:Temperature + data: + tableRef: + tablename: measurements + format: {x: tsp, y: temperature} + queryParams: + limit: 1000 + windowPeriod: hour + windowLength: 24 + nowMinusPeriods: 0 + timeStartParam: editor + timeEndParam: until + filterAnd: + - {column: machine_id, operator: '=', value: editor, dataType: string, useFilter: true} + - {column: state, operator: '=', value: edit, dataType: string, useFilter: true} + - layout_id: open-editor + package_name: widget-navbutton + chartconfig: + title: $str:Reports + route: $str:/?editor=settings + - layout_id: open-filtered + package_name: widget-navbutton + chartconfig: + title: $str:Faults + route: $str:/?state=FAULT + - layout_id: state-filter + package_name: widget-filter-dropdown + chartconfig: + label: $str:State + parameterKey: $str:edit +layout: + gridLayout: + - {id: machine-filter, x: 0, y: 0, w: 24, h: 5, fixedHeight: true} + - {id: period, x: 24, y: 0, w: 24, h: 5, fixedHeight: true} + - {id: view-switch, x: 48, y: 0, w: 24, h: 5} + - {id: view-bar, x: 72, y: 0, w: 24, h: 5} + - {id: machines, x: 0, y: 5, w: 48, h: 59} + - {id: edit-form, x: 48, y: 5, w: 6, h: 6} + - {id: trend, x: 48, y: 11, w: 48, h: 48} + - {id: open-editor, x: 48, y: 59, w: 24, h: 5, fixedHeight: true} + - {id: open-filtered, x: 72, y: 59, w: 24, h: 5, fixedHeight: true} + - {id: state-filter, x: 0, y: 59, w: 24, h: 5, fixedHeight: true, z: 1} diff --git a/tests/run.py b/tests/run.py index 9a155cf..2a57895 100644 --- a/tests/run.py +++ b/tests/run.py @@ -3,11 +3,18 @@ python3 tests/run.py -For the skill's references/example-board.yml and every tests/boards/.yml: -copy tests/app (an app with a data-template.yml) to a temporary folder, add the +For the skill's references/example-board.yml, its +references/example-mobile-board.yml and every tests/boards/.yml: copy +tests/app (an app with a data-template.yml) to a temporary folder, add the board as board-template.yml, run scripts/validate.py and compare its findings: -- the example board must produce no findings at all; +- the example boards must produce no findings at all: the desktop board alone, + the mobile board alone (an app with only a board for phones), and both + together; +- a board with a `# board: mobile` line is added as mobile-board-template.yml + instead, and with a `# desktop: example` line as well the example board as + board-template.yml; every finding about a board must name the file the + board was added as; - every other board must produce each finding its `# expect:` lines list, as `# expect: LEVEL :: `, and no finding at a path its `# expect-none: ` lines list. A board with an @@ -65,30 +72,45 @@ FINDING = re.compile(r"^(ERROR|WARN)\s+(\S+) (\S+): (.*)$") EXPECT = re.compile(r"^# expect:\s*(ERROR|WARN)\s+(\S+)\s+::\s+(.*)$") EXPECT_NONE = re.compile(r"^# expect-none:\s*(\S+)\s*$") +MOBILE = re.compile(r"^# board:\s*mobile\s*$") +WITH_DESKTOP = re.compile(r"^# desktop:\s*example\s*$") +MOBILE_EXAMPLE = SKILL / "references/example-mobile-board.yml" +BOARD_FILES = ("board-template.yml", "mobile-board-template.yml") OFFLINE = re.compile(r"^# offline:\s*\S") CONSUMES = re.compile(r"^# consumes:\s*(.+?)\s*$") -def validate(app: Path, name: str, *flags: str) -> list[tuple[str, str, str]]: +def findings(app: Path, name: str, *flags: str) -> list[tuple[str, str, str, str]]: + """(level, file, path, message) for every finding; the line is cut off the file.""" done = subprocess.run([sys.executable, str(VALIDATE), str(app), *flags], capture_output=True, text=True) if done.returncode not in (0, 1): sys.exit(f"validate.py crashed on {name}:\n{done.stdout}{done.stderr}") - return [(m[1], m[3], m[4]) for m in map(FINDING.match, done.stdout.splitlines()) if m] + return [(m[1], m[2].rsplit(":", 1)[0] if re.search(r":\d+$", m[2]) else m[2], m[3], m[4]) + for m in map(FINDING.match, done.stdout.splitlines()) if m] + + +def validate(app: Path, name: str, *flags: str) -> list[tuple[str, str, str]]: + return [(level, path, message) for level, _, path, message in findings(app, name, *flags)] -def run_board(board: Path) -> list[tuple[str, str, str]]: +def run_board(board: Path, with_desktop: bool = False) -> tuple[list[tuple[str, str, str, str]], str]: + """The findings for an app with this board, and the file it was added as.""" with tempfile.TemporaryDirectory() as tmp: app = Path(tmp) / "app" shutil.copytree(ROOT / "app", app) - shutil.copy(board, app / ".ironflock" / "board-template.yml") lines = board.read_text().splitlines() + mobile = board == MOBILE_EXAMPLE or any(map(MOBILE.match, lines)) + target = BOARD_FILES[mobile] + shutil.copy(board, app / ".ironflock" / target) + if mobile and (with_desktop or any(map(WITH_DESKTOP.match, lines))): + shutil.copy(EXAMPLE, app / ".ironflock" / "board-template.yml") offline = any(map(OFFLINE.match, lines)) consumed = [a.strip() for m in map(CONSUMES.match, lines) if m for a in m[1].split(",") if a.strip()] if consumed: data_template = app / ".ironflock" / "data-template.yml" entries = "".join(f" - app: '{a}'\n reason: Shows its data on the board\n" for a in consumed) data_template.write_text(data_template.read_text(encoding="utf-8") + "consumes:\n" + entries, encoding="utf-8") - return validate(app, board.name, *(["--offline"] if offline else [])) + return findings(app, board.name, *(["--offline"] if offline else [])), target def check_starter() -> list[str]: @@ -601,12 +623,8 @@ def mutate(app: Path) -> None: def skill_findings(app: Path, name: str) -> list[tuple[str, str, str, str]]: - """(level, file, path, message) for every finding; the line is cut off the file.""" - done = subprocess.run([sys.executable, str(VALIDATE), str(app), "--offline"], capture_output=True, text=True) - if done.returncode not in (0, 1): - sys.exit(f"validate.py crashed on {name}:\n{done.stdout}{done.stderr}") - return [(m[1], m[2].rsplit(":", 1)[0] if re.search(r":\d+$", m[2]) else m[2], m[3], m[4]) - for m in map(FINDING.match, done.stdout.splitlines()) if m] + """(level, file, path, message) for every finding, offline.""" + return findings(app, name, "--offline") def check_cases( @@ -648,11 +666,15 @@ def check_cases( def main() -> int: failed = 0 - for board in [EXAMPLE, *sorted((ROOT / "boards").glob("*.yml"))]: - found = run_board(board) + examples = [(EXAMPLE, False, EXAMPLE.name), (MOBILE_EXAMPLE, False, MOBILE_EXAMPLE.name), + (MOBILE_EXAMPLE, True, f"{EXAMPLE.name} with {MOBILE_EXAMPLE.name}")] + boards = [(b, False, b.name) for b in sorted((ROOT / "boards").glob("*.yml"))] + for board, with_desktop, label in examples + boards: + found_in, target = run_board(board, with_desktop) + found = [(lvl, path, msg) for lvl, _, path, msg in found_in] expected = [m.groups() for m in map(EXPECT.match, board.read_text().splitlines()) if m] - if board == EXAMPLE: - problems = [f"unexpected {lvl} {path}: {msg}" for lvl, path, msg in found] + if board in (EXAMPLE, MOBILE_EXAMPLE): + problems = [f"unexpected {lvl} {file} {path}: {msg}" for lvl, file, path, msg in found_in] else: problems = [ f"missing {lvl} {path} :: {text}" @@ -661,8 +683,13 @@ def main() -> int: ] clean = [m[1] for m in map(EXPECT_NONE.match, board.read_text().splitlines()) if m] problems += [f"unexpected {lvl} {path}: {msg}" for lvl, path, msg in found if path in clean] + problems += [ + f"{lvl} {path} names {file}, but the board is {target}: {msg}" + for lvl, file, path, msg in found_in + if file in BOARD_FILES and file != target + ] status = "ok " if not problems else "FAIL" - print(f"{status} {board.name}: {len(found)} finding(s), {len(expected)} expected") + print(f"{status} {label}: {len(found)} finding(s), {len(expected)} expected") for problem in problems: print(f" {problem}") failed += bool(problems)