Skip to content

Report Editor

The Report editor is where a report is written and tested. You edit the template, the script, the helpers and the partials in one window, and see the document that comes out of them without leaving it.

This page describes what the editor shows and what you can do with it. For the language of the report itself (the onInit script, the Handlebars template, the helpers), see Coding Reports. For step-by-step use of the editor, from the user’s point of view, see Customise a report.

There are three ways to open it, described in the user guide:

The window has four areas:

  • the toolbar, at the top;
  • the preview, on the left: the document generated by the report;
  • the tabs, on the right: Template, Script, Helpers and Partials;
  • the Debugger, at the bottom: the errors of the last run and the debug entity in use.

The report editor: preview on the left, the Template tab on the right, the Debugger at the bottom

The title of the window is the name of the report; until it has one, the name of the file, or Unnamed report for a report that was never saved.

ControlWhat it does
Save (floppy disk, with a menu)Save overwrites the file, Save as saves it with another name or in another folder. See Saving
Configuration (gear)opens the configuration dialog
Select debug entitychooses the item to test the report with. See Testing
Rungenerates the document with the debug entity and shows it in the preview
Auto previewruns the report again by itself after every change

The Configuration dialog holds the metadata of the report: the information that does not belong to its code. These are the rules of the editor:

FieldRule
NameRequired. A report cannot be saved without it
TagOptional. A tag is 2 to 20 characters long: lowercase letters, numbers, underscores and hyphens, no spaces
Launch pointsA report with no launch points never appears in a picker. See Launch points
Country, LanguageSee Country and language
Output typeHTML, CSV or Plain text. It also sets how the Template tab is highlighted: as HTML for HTML, as plain text for the others

Description is optional.

Confirm applies the changes to the report being edited: they are saved to the file when you save it. Cancel discards them.

Example. The configuration of the report “Material resource badge (QR)”, with every field filled in:

FieldValue
NameMaterial resource badge (QR)
DescriptionPrintable CR80 badge with QR code, name and code — equipment, substances, work environments
Tagbadge, qr
Launch pointsequipment, substance, work_environment
CountryUnited Kingdom
LanguageEnglish (United Kingdom)
Output typeHTML

With this configuration the report appears in the report picker of a piece of equipment, a substance and a work environment, for people working in the United Kingdom and in English.

TabWhat it contains
Templatethe template
Scriptthe script, with the onInit function
Helpersthe report-specific helpers
Partialsthe partials included in the template, one per row

The Script and Helpers tabs mark syntax errors in the margin of the editor, as you type.

Example. A minimal report shows the name of an item in capitals, with a helper:

TabContent
Template<h1>{{upper name}}</h1>
Scriptasync function onInit() { return { name: 'Pump 1' }; }
Helpersvar helpers = { upper: function (text) { return String(text).toUpperCase(); } };
Partialsnone

The result is a title that reads PUMP 1.

Each row of the Partials tab has an Alias, the file and a Select button:

  1. Add a row.
  2. Click Select and choose the file. The picker shows the .ht, .html and .hdoc files, starting from the project the report belongs to.
  3. The Alias is filled in with the name of the file without its extension, if you have not typed one. Change it to the name you want to use in the template.
  4. In the Template, write {{> alias}} where the piece has to appear.

A row with no alias or no file is ignored when the report is saved. What a partial is and how it uses the data of the report is explained in Partials.

To test a report you first choose the debug entity (see Report Concepts):

  1. Click Select debug entity.
  2. If the report has more than one launch point, choose the one you want to test: the report sees it as this.runtime.target.
  3. Choose the item. The list shows only items of the type that launch point works on: a piece of equipment for equipment, an office for office.equipment_list. A launch point that has no item behind it (for example person_list) needs no choice.

Until you choose a debug entity the preview shows a message asking for one, and Run does nothing. Once chosen, the Debugger header shows the entity and the launch point in use, and a Clear button that drops them.

Click Run to generate the document. The editor first checks the syntax of the template (as Handlebars reads it), of the script and of the helpers: if there is an error the report does not run, the preview keeps the last result and the error is listed in the Debugger. Otherwise the report runs as described in How a report runs, with the debug entity as its this.runtime, and the result appears in the preview, in a document of its own, so that a full page with <html>, <head> and <body> looks as it will when printed.

Example. With the debug entity of a pump, a report with launch points equipment and substance is tested like this:

  1. Click Select debug entity.
  2. Choose the launch point equipment.
  3. Choose the pump from the list of equipment.
  4. Click Run: the document appears in the preview.

Each error is a row with four columns:

ColumnContent
Timewhen the error happened
Placewhere: script, helpers or template
Namethe type of error, for example SyntaxError or ReferenceError
Messagethe message of the error

Example. If in the script you write return { name: foo }; by mistake, without defining foo, the Debugger lists a row:

TimePlaceNameMessage
10:42:03scriptReferenceErrorfoo is not defined

The report does not generate the document until the error is fixed.

With Auto preview on, the report runs by itself a moment after the last change to the template, the script, the helpers, the partials, the configuration or the debug entity. The Debugger is cleared before each run, so it lists only the errors of the report as it is now. It does nothing until a debug entity is chosen.

Click Save to open the menu:

  • Save as opens the file picker. It shows only the folders you can write to, and saves a .ht file. After the first save, the editor keeps working on the new file.
  • Save overwrites the file the editor is working on: the file the report was opened from, or the one chosen with Save as. It is not available for a new report that was never saved.

A report that comes from outside the project (the 4HSE catalogue or a partner’s) and was opened from the print wizard cannot be overwritten: Save is disabled until you use Save as in a folder of the project. The original stays as it was, and the printing uses your copy when you choose This project in the report picker (see Choose a report).

A report cannot be saved without a name: the editor asks for it and does not save.

When a report is saved, the keys the editor does not know are kept as they are.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.