Screens
A screen is a page of the web interface described as data in TypeScript: a list, a record form, dialogs, commands
and custom elements. The core renders it with the element <tt- and reads and writes through the HTTP API.
A screen has two parts: a definition registered in TypeScript and a page controller in PHP that names the screen and the actions each actor may perform.
Register a screen
Register screens with register in the entry module of the package (see Frontend). The
list of working-time models, shortened:
import { registerScreen } from '@adsum/core/screens/registry.js';
registerScreen('workingTimeModels', {
list: {
path: '/working-time-models',
link: '/working-time/models/{id}',
columns: [
{ key: 'code', label: 'screen.model.code' },
{ key: 'name', label: 'screen.common.name' },
{ key: 'scheduleType', label: 'screen.model.scheduleType', type: 'enum', enumPrefix: 'screen.model.scheduleType.' },
{ key: 'weeklyTargetSeconds', label: 'screen.model.weeklyTarget', type: 'duration' },
],
filters: [
{ name: 'archived', label: 'screen.model.archivedOnly', type: 'boolean' },
],
actions: [
{ key: 'archive', label: 'screen.common.archive', icon: 'archive', method: 'POST',
path: '/working-time-models/{id}/archive', confirm: 'screen.common.archiveQuestion', when: '!archived' },
],
},
create: { collection: '/working-time-models', label: 'screen.model.create', form: { fields: modelFields(false) } },
});
All label values are translation keys (see Translations and Icons). Paths are API paths
without the /api/ prefix. {parameter} placeholders are filled from the page parameters first, then from the
row.
Parts of a screen
A screen definition has these optional parts; a section may use them too.
list- A collection of rows from one API operation.
create- A dialog that creates a row of the list. It has
collection(the path to post to),labelandform.method: 'PUT'withwrapsends several records in a list.revealnames a property of the created record that is shown once, such as the secret of a token. edit- A dialog that edits a row of the list:
resource(the path of the row),methodandform. record- One record that is edited in place:
resource,method(PATCHby default, orPUT) andform. component- A custom element, given by its tag name.
sections- Tabs. Each section has a
key, alabeland any of the parts above. subjectandcommands- The record the screen is about and the buttons that act on it (see below).
Lists
list has the following properties:
path- The collection operation.
itemsnames the property that holds the rows; the default isKey items. columns- Each column has
key,labeland atype:text(default),localised,Text duration,date,date,Time boolean,enum,enum,List reference,jsonorlookup. Anenumcolumn needsenum, the prefix of the translation keys of the values. APrefix lookupcolumn needslookup, the collection that names the IDs.sortmakes a column sortable by that value of thesortparameter. filters- Each filter has
name(the query parameter),labeland atype:choice,booleanordate. Achoicehasoptionsoroptions.From facet: trueoffers only values that leave rows. search- The name of the search query parameter of the operation.
link- The page a row links to.
actions- Row actions:
key,label,method(POST,DELETEorEVENT),path, and optionallyicon,confirm,when,version,Of bodyanddisplay(textshows the label instead of an icon).versionis the resource whose version is sent asOf If-.Match defaults- Values for parameters the operation requires, such as
{ from: 'month. Besides dates,Start', to: 'month End' } today,month,Start month,End yearandStart yearare allowed.End per,Page tree,download- The page size, a tree view of the same rows, and a download link for the same rows (
labelandpath).
A when condition is checked against the row. archived holds when the property is truthy,
state: when it equals or contains the value, and a leading ! negates the condition.
Forms
A form is a list of fields:
const fields: FieldDefinition[] = [
{ name: 'code', type: 'text', label: 'screen.model.code', required: true },
{ name: 'name', source: 'names', type: 'localisedText', label: 'screen.common.name', required: true },
{ name: 'scheduleType', type: 'choice', label: 'screen.model.scheduleType', required: true,
options: [
{ value: 'fixed', label: 'screen.model.scheduleType.fixed' },
{ value: 'flextime', label: 'screen.model.scheduleType.flextime' },
] },
{ name: 'workingTimeModelId', type: 'choice', label: 'screen.rotation.model',
optionsFrom: { path: '/working-time-models?perPage=200', label: 'name' } },
];
The field types are text, textarea, email, password, number, duration, date, time,
boolean, choice, multi, tags, localised (one value per language) and object
(rows of nested fields).
Fields have these further properties:
nameis the property the API writes,sourcethe property it reads if that is another one.required,readandOnly nullablecontrol input.helpis the translation key of a hint.optionsare fixed choices,optionsreads choices from a collection (From path,label, optionalvalue), andoptionsoffers the IANA time zones.Of: 'time Zones' sectionis the translation key of a heading shown before the field.defaultis the start value of a new record.objectfields takeList fields,fixedandRows default.Rows
Commands
Commands are buttons on a screen that act on its subject, the record named by the screen:
registerScreen('employee', {
subject: '/employees/{employee}',
commands: [
{ key: 'cancelExit', label: 'screen.employee.cancelExit', path: '/employees/{employee}/exit/cancel',
when: 'exitDate', versioned: true, confirm: 'screen.employee.cancelExitQuestion' },
],
});
A command has key, label, path and method (POST by default, or DELETE). Further properties:
form- Opens a dialog with the fields and sends them as the request body.
confirm- The translation key of a question asked first.
when- A condition on the subject. The command is offered only if it holds.
versioned- Sends the version of the subject as
If-.Match then- The page to open after the command succeeded.
answer- A custom element that shows the answer of the operation below the form. The dialog stays open. Use it for a preview.
Sections
A screen with sections shows them as tabs. This is the page of one working-time model:
registerScreen('workingTimeModel', {
sections: [
{ key: 'data', label: 'screen.model.data',
record: { resource: '/working-time-models/{model}', method: 'PUT', form: { fields: modelFields(true) } } },
{ key: 'versions', label: 'screen.model.versions',
list: { path: '/working-time-models/{model}/versions', columns: [
{ key: 'effectiveFrom', label: 'screen.model.effectiveFrom', type: 'date' },
] } },
],
});
A section with restricted: true is shown only if the action <section>. is allowed.
Custom elements
component names a custom element, defined in the entry module of the package. It receives the page parameters
as the property parameters and the attribute editable if the action named like its tag is allowed. With
component it is rendered only if that action is allowed.
Page controller
A page controller connects a route to a screen. It calls Screen with the screen name, the
translation key of the title, the actions and optional parameters:
#[AsController]
final readonly class WorkingTimePageController
{
public function __construct(
private ScreenPage $screens,
) {}
#[Route('/working-time/models', name: 'app_working_time_models', methods: ['GET'])]
#[Access('hr', 'admin')]
public function models(): Response
{
return $this->screens->render('workingTimeModels', 'screen.model.title', ['create' => ['hr', 'admin'], 'archive' => ['hr', 'admin']]);
}
#[Route('/working-time/models/{id}', name: 'app_working_time_model', requirements: ['id' => '[0-9a-f-]{36}'], methods: ['GET'])]
#[Access('hr', 'admin')]
public function model(string $id): Response
{
return $this->screens->render('workingTimeModel', 'screen.model.record', ['data.edit' => ['hr', 'admin']], ['model' => $id]);
}
}
The third argument maps each action to the actors that may perform it, in the vocabulary of # (see
Navigation and Access). The screen offers buttons, row actions and edit forms only for the allowed
actions and shows everything else read-only. The fourth argument gives the path parameters of the screen, such as
{model}.
Action names:
createandeditfor the dialogs and the record form of the screen- the
keyof a row action or a command, such asarchive <section>.<action>inside a section, such asdata.oredit versions.view
The API operation behind a screen checks the access again.