Parsware
All articles

Model-driven apps

A dashboard in an app

A dashboard in Parsware is a screen you draw. Counted tiles, charts, the table's own grid and its quick create form sit on one page, and the page goes into an app's navigation like any table.

A Support overview screen in dark mode inside the Support desk app: four counted tiles, a bar chart of tickets by status, an urgent-or-not donut, a grid of tickets and a New ticket form, next to the title "A dashboard in an app"

A list of rows answers "which ones?". A dashboard answers "how many, and where are they piling up?". In Parsware a dashboard is a drawn screen: you lay out the page in the Application Studio, and the numbers, charts and grids on it are live. Then you put the screen into an app's navigation, next to its tables.

This article uses the studio-dashboard sample. Import it into an environment and open Support overview from the apps list. Every picture is the real product.

What's in the sample

Ticket is a small table: a Summary, a Status choice (New, Active, Resolved) and an Urgent yes/no. It comes with a quick create form, a main form and an All tickets view. The sample's app is one drawn screen, Overview.

The table starts empty, so press Add 24 tickets first. The screen creates them itself, cycling the status and marking every third one urgent:

The Support overview screen: tiles reading All tickets 24, New 8, Active 8, Resolved 8; a bar chart with three equal bars; a donut of urgent and not urgent; a grid of tickets; and an empty New ticket form

Before you add any, the charts say No tickets yet instead of drawing empty axes. That sentence is part of the drawing, shown only while the total is zero.

Add a ticket from the page

The New ticket panel is the table's own quick create form. Its fields, its required rules and its business rules are the same ones the table has everywhere:

The Every ticket grid beside the New ticket form, filled in with Summary Printer on the second floor is out of toner, Status New and Urgent ticked

Save it, then press Refresh. The tiles, the chart and the grid all move together:

After Refresh: All tickets 25, New 9, the New bar now taller than the others, and the printer ticket at the top of the grid, with Saved successfully and Refreshed messages

Press a row in the grid and the ticket's form opens in the panel, with a back arrow to return to the list:

The Every ticket panel showing the ticket's form: a back arrow, Save and Save & Close, and the title Ticket - Printer on the second floor is out of toner

How the numbers are counted

Open the app in the Application Studio and press </> to write code. The screen's Screen opens handler runs one query per number:

The code page for Screen opens: six loadRecords lines on par_ticket, each with top 1, some with a where condition on par_status or par_urgent, and countInto naming total, statusNew, statusActive, statusResolved, urgent and calm

countInto is where the number of matching rows goes, not the number that came back. top: 1 keeps the page of rows as small as it can be, because nobody reads it. Each tile's big number is then a text bound to text(state.total), text(state.statusNew) and so on.

The Refresh button runs the same six lines again.

Charts

Components → Chart draws the platform's own chart: bars, stacked bars, line, area, pie or donut. Its Value is a list of labels and numbers built from those counts:

The code page for the chart's Value binding: a list of three items, label New with value state.statusNew, label Active with state.statusActive, label Resolved with state.statusResolved

You draw where the chart goes and how big it is. The chart itself decides the ticks, the labels and what to do with an odd value, every time it draws, so it copes with data you didn't design against.

The grid and the form are the real ones

Components → Table view or form embeds a model-driven surface. Shows picks a view's rows, a form for a new record, or a form for one record; Table and View (or Form) name what to show:

The Screen properties of the grid panel: Shows A view's rows, Table par_ticket, View left empty, with the note that an empty view or form means the table's default

What appears is the same grid a model-driven app shows, with its own sorting, paging and permissions per record, and the same quick create form. Nothing is redrawn, so a field that is required on the table is required here too.

Your own queries don't reach inside those surfaces. After a handler writes records, it ends with reloadSurfaces(), which starts every embedded grid and form again.

While writing this we found that Add 24 tickets left the grid empty beside tiles reading 24. Record writes wait until the handler finishes, but reloadSurfaces() ran straight away, so the grid reloaded before any ticket existed. It now waits its turn like the writes do, and the grid fills in with the tiles. We also found the sample had no quick create form or view of its own, so its New ticket panel said there was nothing to show. Version 1.1.0 of the sample has both.

The code behind the numbers

The Screen opens handler from the picture above, as text:

loadRecords("par_ticket", "probe", { top: 1, countInto: "total" });
loadRecords("par_ticket", "probe", { top: 1, where: { par_status: 100000001 }, countInto: "statusNew" });
loadRecords("par_ticket", "probe", { top: 1, where: { par_status: 100000002 }, countInto: "statusActive" });
loadRecords("par_ticket", "probe", { top: 1, where: { par_status: 100000003 }, countInto: "statusResolved" });
loadRecords("par_ticket", "probe", { top: 1, where: { par_urgent: true }, countInto: "urgent" });
loadRecords("par_ticket", "probe", { top: 1, where: { par_urgent: false }, countInto: "calm" });

Read one line at a time. Each asks the database for the tickets that match its where, keeps at most one of them in a state value called probe that nothing displays, and writes how many matched into the state value named by countInto. The status numbers are the options of the Status choice, so 100000001 is New. Comparing numbers rather than labels keeps the counts right when an option is renamed, or when the app is opened in Persian.

The Refresh button runs the same six lines, then reloadSurfaces() and a message. And Add 24 tickets shows how a screen writes records:

var i = 0;
for (i = 0; i < 24; i = i + 1) {
  var status = 100000001;
  if (i % 3 == 1) { status = 100000002; }
  if (i % 3 == 2) { status = 100000003; }
  createRecord("par_ticket", {
    par_name: "Ticket " + text(i + 1),
    par_status: status,
    par_urgent: i % 3 == 0
  });
}
notify("Twenty-four tickets created.");

Every createRecord goes through the same save as a ticket typed on the form, with its required fields, its rules and the person's permissions. A screen can't write anything the person couldn't write by hand.

Designing a dashboard people use

A dashboard is read in a few seconds, standing up, between other things. That shapes what goes on it.

  • Numbers first, in the order of the question. How many are there, how many are new, how many are urgent? Four tiles across the top answer that before anybody looks further.
  • One chart per question. The bar chart answers where are they?; the donut answers how many are urgent?. A chart that tries to answer both answers neither.
  • The list beside the numbers. A number that worries somebody should be one click from the records behind it. The embedded grid is that click.
  • A way to act. The quick create panel lets the person who spotted the problem log the next ticket without leaving the page.
  • An honest empty state. No tickets yet says something true; an empty pair of axes looks broken.

What a dashboard can count

The where in each line is a plain list of field values that must all match, which covers most tiles: status is New, urgent is true, owned by this team. For a tile that needs or, ranges or totals, such as the value of every open order over £1,000, use a saved query, which can filter with and and or groups and add up a column. Totals and groups shows the kind of query a total comes from, and A dashboard on a screen goes further into the Studio side.

Each tile counts only the records the person may read, because every query runs as them. A team lead and a member of the team can open the same dashboard and see different numbers, each right for them.

Charts that draw themselves

Components → Chart draws bars, stacked bars, a line, an area, a pie or a donut from a list of labels and numbers. You draw where it goes and how big it is; the chart chooses the ticks, the labels and the scale each time it draws. That matters more than it sounds. A chart drawn by hand looks right for the numbers it was drawn with, and wrong the day one bar is ten times the others. The platform's chart copes, because the decisions are made with the real data in front of it. Read a chart shows what people can do with one.

Why a screen and not a dashboard designer

Earlier versions of the platform had a separate dashboard designer, a grid of KPI tiles, charts and views. A drawn Studio screen does everything it did, on the canvas a maker is already using for other screens, with the same components and the same code. So there is one way to lay out numbers, not two. An app that already opens one of the old dashboards still opens it; new ones are drawn.

Put it in an app

A screen nobody can reach isn't much use. Open your solution's Apps, create or edit an app, and in a navigation group press the screen button (the window glyph, beside the table button). We made a Support desk app with the screen and the Ticket table, and chose the screen as the Home page:

The app's navigation group Support holding Support overview (par_dashboard, Screen) and Ticket (par_ticket, 2 forms, 1 views), with Home page set to Support overview

Open the app and it starts on the numbers, with the full list one click away in the rail:

The Support desk app in the Platform Shell: the rail shows Home, then a Support group with Support overview selected and Tickets beneath it, and the dashboard fills the page

The screen and the app travel in their solutions like any other component, so exporting to test and production takes the dashboard with it.

Next: show who created or changed a record.