-
-
Notifications
You must be signed in to change notification settings - Fork 29
Report Packs Developer Guide
Changelog #2085β#2088 Β· For using it, see Report Packs
Report Packs is a Word-like designer for multi-page reports that export to PDF. This page explains the one idea everything rests on, the files, the design document, how a block gets its data, and the traps that were hit building it.
Requested by Enrique Cabrera, whose own monthly Reporte de disponibilidad de Servicios e Incidencias was the model: a repeating header with logo and dates, a summary, two software charts, per-service uptime with daily bars, and a multi-page incident log.
π This page is the overview. The deep dive is a three-part series:
- The designer - the HTML, CSS and JavaScript: state and undo, why it feels fluid, the SVG-plus-overlay canvas, drag and drop, column-snapped resizing, the ribbon, editing text in place, live toolbox previews
- The layout engine - measuring with the PDF's own fonts, rich text and line breaking, block measurement, splitters, pagination, the SVG and PDF renderers, charts at two resolutions, the runtime
- PHP and SQL - the tables, the API, sharing and roles, the design check, optimistic concurrency, the block registry, timezone-correct periods, the data functions, security, adding a block end to end
Every report designer has to answer where does this line break, and where does this page end? β and answer it identically on screen and in the PDF. If the browser lays out the screen and a PDF library lays out the file, they disagree: a table that ends on page 2 on screen spills onto page 3 in the PDF.
So there is exactly one place that decides layout: assets/js/report-packs/engine.js. It turns the design (plus each block's data) into pages of primitives β text runs, rectangles, lines, dot leaders, images β each at an exact position in millimetres. Two renderers draw those primitives and decide nothing:
design + block data
β
βΌ
engine.js paginate() β every line break, every page break
β
pages: [{items: [{draw: [primβ¦], chart, rich}], headerRich, footerRich, β¦}]
βββββββββββββ΄βββββββββββββ
βΌ βΌ
render-svg.js render-pdf.js
(the designer's pages) (jsPDF: the file)
The engine measures text with jsPDF's metrics for the PDF standard fonts (Helvetica, Times, Courier) β getStringUnitWidth, cached per character β and does its own line breaking. The screen then draws each run at the x the engine chose, with SVG textLength pinning it to the measured width. A browser whose Arial is a hair wider than Helvetica nudges the glyphs; it never wraps differently.
The standard fonts are WinAnsi: English and Western European text, including Spanish accents and Γ±. RPEngine.hasUnsupported() detects anything else, the designer warns in its status bar, and render-pdf.js writes ? rather than garbage. Embedding Unicode fonts (Noto) is the way to lift this, at a cost of several hundred KB per face per pack.
Chart.js draws each chart on a canvas whose CSS size is fixed in millimetres (PX_PER_MM = 4). Only devicePixelRatio changes β the zoom on screen, 3 (β300 dpi) for the PDF. Because Chart.js lays out in CSS pixels, the legend and labels land in the same place at every resolution.
ποΈ schema Β· π access Β· π§± blocks/data Β· π layout Β· ποΈ designer Β· π API Β· π₯οΈ pages Β· π§ͺ tests Β· π docs
| π¨ | File | What it does |
|---|---|---|
| ποΈ |
includes/db_verify_schema.php, database/freeitsm.sql, api/system/db_verify.php
|
report_packs (the design as one JSON document) and report_pack_shares; FKs |
| π | includes/report_packs/access.php |
Roles (owner / edit / view), share matching, the list query, saving shares |
| π§± | includes/report_packs/blocks.php |
The registry: handlers (module, kind, option schema, data function) and toolbox items |
| π§± |
includes/report_packs/blocks_tickets.php Β· blocks_status.php Β· blocks_software.php Β· blocks_assets.php
|
The data functions, one file per area |
| π§± | includes/report_packs/criteria.php |
Date presets resolved in the viewer's timezone; the company clause |
| π§± | includes/services/service_uptime.php |
incidentsBetween / summaryBetween / dailyStripBetween β fixed ranges beside the board's own window methods |
| π | includes/report_packs/design.php |
The design's shape, the starter design, and rpCleanDesign() β the check every save goes through |
| π | assets/js/report-packs/engine.js |
Measurement, rich-text layout, block layout, splitting, pagination |
| π | assets/js/report-packs/charts.js |
Chart.js to canvas at a fixed mm size |
| π |
assets/js/report-packs/render-svg.js Β· render-pdf.js
|
The two renderers |
| π | assets/js/report-packs/runtime.js |
Block data (cached, 4 at a time), header fields, logo, chart images, export |
| ποΈ | assets/js/report-packs/designer.js |
Ribbon, toolbox, canvas, drag and drop, handles, properties, undo, save |
| ποΈ | assets/js/report-packs/editor.js |
In-place rich text: contentEditable β the paragraph model |
| π | api/reporting/packs/ |
list, get, create, save, delete, shares, catalogue, block_data, context
|
| π₯οΈ |
reporting/packs/index.php, designer.php, assets/js/report-packs/list.js, assets/css/report-packs*.css
|
The list and the designer |
| π§ͺ | tests/report-packs-blocks.php |
Every block Γ every option on real data; module refusal; ranges; the design check |
| π§ͺ | tests/report-packs-designer-live.html |
Drives the real designer in a browser (30 checks) |
| π |
lang/en/reporting.php (packs.*), reporting/help.php Β§2, includes/feature_bingo/cards/reporting.php
|
Strings, in-app help, two Bingo cards |
What you do not touch to add a block: the engine, the renderers and the designer. They draw by the data's kind, not by block.
One JSON document per pack, in report_packs.design, read and written whole:
{
v: 1,
page: { size: 'A4', orient: 'portrait', margin: { t: 18, r: 16, b: 18, l: 16 } }, // mm
theme: { font: 'helvetica', size: 10, heading: '#1f3864', accent: '#1f3864',
palette: 'default', th_bg: '#1f3864', th_fg: '#ffffff', stripe: true },
criteria: { range: { preset: 'last_month' }, tenant: 'active' }, // or {preset:'custom', from, to}; 'all' | id
header: { on, rule, first, doc: [...] },
footer: { on, rule, doc: [...] },
cover: { on, doc: [...] },
toc: { on, title },
blocks: [
{ id, type: 'heading', text, level: 1-3, newPage, toc },
{ id, type: 'text', span: 1-12, doc: [...], box, newRow },
{ id, type: 'data', span, handler: 'tickets.breakdown', opts: {...}, title, showTitle, height, legend, newRow },
{ id, type: 'spacer', span, height } | { id, type: 'divider' } | { id, type: 'pagebreak' },
],
}Text boxes, the header, footer and cover are paragraphs of runs:
{ t: 'p' | 'h1' | 'h2' | 'h3' | 'li' | 'img', a: 'left' | 'center' | 'right' | 'justify',
l: 'ul' | 'ol', lv: 0-4, // lists
r: [ { x: 'text' } | { fld: 'page' | 'pages' | 'date_from' | 'date_to' | 'today' | 'title' | 'company' },
+ b, i, u, s, c: '#rrggbb', hl: '#rrggbb', sz: points ] }Two reasons it is not HTML. The engine needs exactly this to break lines, so HTML would only be parsed into it anyway. And there is nothing to sanitise: rpCleanDesign() checks every field for type and range, the renderers write text with textContent, and there is nowhere to put a script, an event handler or a remote image. The only picture is the install's own logo ({t:'img', src:'logo'}).
editor.js converts both ways β docToHtml() builds the editor's HTML from the model (everything escaped), htmlToDoc() reads it back.
Blocks are a flat list. The engine packs them into rows left to right until 12 columns are used. newRow: true starts a new row even when this one has room β that is how dropped below survives a flow layout.
includes/report_packs/blocks.php has two levels:
-
Handlers β what a block is:
module,kind(chart|kpi|table|uptime), an option schema, and its data function. A pack stores the handler key and options. -
Toolbox items β what the designer offers: a searchable, previewable entry dropping in a handler with options already chosen. Tickets by status and by priority are two items over
tickets.breakdown, so one becomes the other by changing Group by.
- Write the data function in the area's file. It receives
($conn, $analystId, $opts, $range, $tenant)and returns one of the four kinds:
['kind' => 'chart', 'chart' => 'bar', 'labels' => [...], 'series' => [['name' => 'β¦', 'values' => [...]]], 'colours' => null]
['kind' => 'kpi', 'tiles' => [['label' => 'β¦', 'value' => '42', 'hint' => 'β¦']]]
['kind' => 'table', 'columns' => [['key', 'label', 'w', 'align']], 'rows' => [...], 'empty' => 'β¦']
// a cell may be a string, ['pill' => text, 'colour' => hex] or ['chips' => [['text','colour']β¦]]
// a row may carry '_detail' - a full-width line under it (the incident log's comments)
['kind' => 'uptime', 'services' => [...]]- Add a handler entry (module, kind, fn, opts) and one or more toolbox entries.
- Add
packs.tool.<key>.title/.desc(and any option labels) tolang/en/reporting.php. - Run
php tests/report-packs-blocks.phpβ it runs every option value of every handler and fails on a missing label.
$opts has already been through rpCleanOpts(): a function never sees a value its schema did not declare.
api/reporting/packs/block_data.php is not tied to a pack. rpBlockData() checks the viewer's access to the handler's module, then the data function scopes to the viewer's companies through rpTenantClause() (active / all / one id the viewer can access β otherwise it refuses). So a pack shared with somebody who lacks Contracts shows them a placeholder; sharing never widens what anyone sees.
Service Status and Intune have no company column β they are the install's β so their blocks ignore the company criterion. Software is scoped through the machine each install is on (software_inventory_detail.host_id = assets.id); note the Software dashboard itself is not company-scoped, so the two can differ on a multi-company install.
rpResolveRange() resolves a preset in the viewer's timezone and converts the bounds to UTC: last month for Santo Domingo starts at 04:00:00 UTC. The end is exclusive; a custom range includes both days the reader picked. Time series bucket UTC timestamps into local days in PHP rather than GROUP BY DATE(), which would bucket in UTC.
service_uptime.php gained *Between methods for fixed ranges, beside the board's *For window methods, which were left untouched β so a pack can never disagree with the board about how uptime is worked out, only about the period.
paginate(design, dataMap, ctx):
- Measures the header and footer with wide page numbers (
888 of 888), so they never grow later. - Measures every block at its width. Tables, uptime lists and long text return a splitter:
start()andtake(state, room). - Flows blocks into rows; places rows. A row that does not fit goes to the next page; a lone splittable block puts what fits here and the rest overleaf, repeating table headers. A heading is kept with the next row.
- Adds the cover and contents pages in front, then lays out every page's header and footer with the real page numbers.
Page numbers count every physical page; the contents' numbers are the physical page each heading starts on.
Every change goes through commit(fn, opts): snapshot for undo, mark unsaved, re-render. Rendering asks the engine for pages, draws them as SVG, and lays an HTML overlay on top for frames, handles, drop guides and header/footer hit areas.
-
Drag and drop is pointer events, not HTML5 DnD.
dropTarget()maps the pointer to before/after a row (horizontal guide) or beside a block (vertical guide, when within its outer 28%). A side drop that overflows the row shrinks the new block, or halves the target. -
Save sends the stamp it loaded; the server refuses a stale save with
conflictand the editor's name, and the designer offers Reload or Save mine. After a save the designer adopts the server's cleaned design, so the screen and the stored pack cannot drift. -
View-only gets the Data tab and Export; criteria changes are local (
{viewer: true}) and never mark the pack unsaved. The server refuses the save regardless.
-
php tests/report-packs-blocks.phpβ 32 checks on real data: every block and option value, labels, per-block module refusal (as a restricted analyst), timezone ranges, the design check. - The packs API driven over HTTP as four real analysts β 35 checks: private until shared, each share type (department matching case- and space-insensitive), View cannot save/share/delete, Edit cannot share/delete, the stale-save conflict, copying.
-
tests/report-packs-designer-live.htmlβ 30 checks in a real browser: toolbox search, insert, a real pointer drag onto a chart's edge, resize, move, delete, undo/redo, keyboard copy/paste, typing and bold in place, header fields, period change, save and read back, PDF page count, and nonullon any tab or pane.tests/is closed to HTTP, so copy it to the web root to run it (instructions in the file). -
The actual PDF was looked at, not just its page count: Enrique's report rebuilt on real data, exported, and rasterised with pdf.js in headless Chrome. (pdf.js's worker does not run under headless virtual time β load
pdf.worker.min.jsinto the page itself.)
-
Chart.js with
responsive: falsereadscanvas.widthas its CSS size. Hand it the backing size and every chart lays outscaletimes bigger with the same fonts β legible on screen, a third the size in the 3Γ PDF. Give it the layout size and letdevicePixelRatioscale. -
replaceChildren()andappend()write a missing element as the text "null". It appeared under the ribbon, in the status bar, and beside every colour picker. Filter before appending. -
An editor's zero-width space is a real character. The one
editor.jsputs after a field (so the caret has somewhere to sit) is not in the PDF fonts and printed as?. Both sides strip it now. - Size an overlay from what is drawn, not from the zoom setting. The text editor took the requested zoom while the page on screen was still the previous one, and sat a line below the text. It now measures the page element.
-
selectionchangeis asynchronous. A ribbon command that restored the saved selection applied bold to the caret instead of the words just selected. Restore only when focus has really taken the selection out of the editor. -
Keep the board's figures out of reach. New needs got new methods (
*Between) rather than new parameters on methods the status board uses.
- Report Packs β for users
- Reporting
-
Groups of People β Developer Guide β why "department" here means
analysts.department
FreeITSM β an open-source IT Service Management platform Β· github.com/edmozley/freeitsm Β· MIT licence
- Installation
- β° Scheduled tasks (cron jobs)
- Architecture
- π§ͺ Developer tests
- AI Providers
- Internationalisation (i18n)
- Timezones & Time Handling
- π Date & Time Formats
- Theming & Dark Mode
- ποΈ Recent β getting back to what you were doing
- β¨οΈ Command palette (βK)
- π Searching inside tickets
- π Attached documents
-
MobileβFriendly
- β³ π« Mobile: Tickets
- β³ π» Mobile: Assets
- β³ π Mobile: Calendar
- β³ π Mobile: Knowledge
- β³ π¦ Mobile: Service Status
- β³ πΌ Mobile: Watchtower
- β³ π§© Mobile: Problem Management
- β³ π Mobile: Change Management
- β³ πΏ Mobile: Software
- β³ β Mobile: Tasks
- β³ π Mobile: Forms
- β³ π Mobile: Contracts
- β³ π Mobile: Domains
- β³ π Mobile: People
- β³ π Mobile: LMS
- β³ πΊοΈ Mobile: CMDB
- β³ πΊοΈ Mobile: Network Mapper
- β³ π§ Mobile: Process Mapper
- β³ βοΈ Mobile: Workflow
- β³ π₯οΈ Mobile: System
- β³ π Mobile: Reporting
- β³ π Mobile: System Wiki
- β³ π Mobile: Self-Service Portal
- β³ π§° Mobile: Techniques & Tricks
-
Security
- Layer 1 β which modules you can enter
- β³ π§© Module Access Control
- β³ π οΈ Module Access β Developer Guide
- Layer 2 β what you can administer
- β³ π Roles & Permissions
- β³ π οΈ Roles β Developer Guide
- β³ π€ Why capabilities are constants
- Layer 3 β the System module
- β³ π Admin Access Control
- Hardening
- β³ π Security review response 2026-08
- β³ π‘οΈ Security hardening 2026-08
- β³ π οΈ Security hardening 2026-08 β Developer Guide
- β³ π‘οΈ Round three β plain English
- β³ π οΈ Round three β Developer Guide
- β³ π‘οΈ CSRF protection (S4) β Developer Guide
- Single Sign-On (SSO)
- ποΈ LDAP & Active Directory
- π CardDAV contact sync
- Browser Extension
- API Reference
-
π REST API β how it works
- β³ π« REST API: Tickets
- β³ π» REST API: Assets
- β³ π΄ REST API: Problems
- β³ π REST API: Changes
- β³ π REST API: Knowledge
- β³ β REST API: Tasks
- β³ ποΈ REST API: CMDB
- β³ π REST API: Contracts
- β³ ποΈ REST API: Calendar
- β³ πΏ REST API: Software
- β³ π REST API: Domains
- β³ π¦ REST API: Service Status
- β³ βοΈ REST API: Morning Checks
- β³ π REST API: Forms
- β³ βοΈ REST API: Workflow
- β³ π·οΈ REST API: Cost centres
- β³ πΊοΈ REST API: Network Mapper
- β³ π§ Using the API docs page
- β³ π OpenAPI specification
- β³ β OpenAPI: kept correct
- β³ π οΈ Maintaining the catalogue
- Watchtower
-
Tickets
- β³ π Rota copy and paste β Developer Deep Dive
- β³ β Checklists & SOPs
- β³ βοΈ Mandatory fields
- β³ π·οΈ Ticket categories
- β³ π₯ Assigning tickets to a team, and escalation
- β³ π’ One board across every company
- β³ Mailbox Authentication
- β³ π€ Email send log
- β³ Basic IMAP mailboxes
- β³ Email rendering & images
- β³ SLA Management
- β³ WhatsApp channel
-
β³
βοΈ Telegram channel - β³ β CSAT company scope and filters β Developer Guide
- β³ π₯ Microsoft Teams channel
- β³ π¨οΈ Mattermost channel
- β³ π¬ Web chat channel
- β³ π£ Slack channel
- β³ π Linking tickets
- β³ β Record previews
- β³ π Ticket notes: internal or shared
- β³ ποΈ Canned responses
- β³ βοΈ Limiting replies to particular senders
- β³ π¨ Telling the analyst a ticket is theirs
- β³ βοΈ Email signatures
- β³ π The public web address
- β³ π’ Ticket numbering
- β³ π Raising a ticket for someone else
- β³ π Merging tickets
- β³ π Confidential tickets
- β³ π₯ Portal managers
- β³ π Who has seen a ticket
- β³ π Reading long tickets
- β³ β Splitting tickets
- β³ β Selecting several tickets
- β³ ποΈ The folder pane
- β³ π½ Just my tickets, or no closed ones
- β³ π οΈ Snoozing tickets β Developer Guide
- β³ π₯ Collision detection
- β³ β±οΈ Time tracking
- β³ π Scheduled work in your own calendar
- Problem Management
- Tasks
-
Assets
- β³ π’ Moving an asset between companies
- β³ π Shared asset locations
- β³ π§βπΌ Assigning assets to analysts
- β³ π Warranty and lease alerts
- β³ π Saved table views
- β³ π¨οΈ Recording anything, and importing it
- β³ π·οΈ QR asset labels
- β³ π Who holds what, and handover documents
- β³ π₯οΈ The inventory agent (PowerShell)
- β³ ποΈ Proxmox VE servers
- β³ βοΈ VMware Cloud Director servers
- β³ π Linking equipment to tickets
- β³ βοΈ Follow-up tasks on a ticket
- Knowledge
- Change Management
- Calendar
- Morning Checks
- Reporting
- Software
-
Forms
- β³ π¨ The form designer β Developer Guide
- β³ π Layout & the grid β Developer Guide
- β³ ποΈ Collections β grouping submissions
- β³ π Submissions as PDFs
- β³ β‘ What happens next β a form's own actions
- β³ π οΈ Sections & conditional logic β Developer Guide
- β³ π οΈ Lookup fields β Developer Guide
- β³ π‘οΈ Catalogue request approvals
- People
- Domains
- Contracts
- Service Status
- π Notifications
- π¨ War Room
- Self-Service Portal
- LMS
- Process Mapper
- CMDB
- Network Mapper
- Workflows
- Issue trackers (Jira, Azure DevOps)
- System
-
Overview
- β³ π Progress tracker
- β³ Concepts & vocabulary
- β³ Email routing & mailboxes
- β³ Settings: global vs per-company
- β³ Users & self-service
- β³ Staff cross-company access
- β³ π’ One board across every company
- β³ Worked examples
- β³ Pitfalls & gotchas
- β³ Scope: what it's for
- β³ π οΈ Developer Guide (make a module multi-company)
- β³ ποΈ Case study: CMDB (a linked graph)
- β³ π§ͺ Test harness (prove it's isolated)
- What this is
-
π Bugs resolved
- β³ πΌοΈ Logo and courses broke on Apache with PHP-FPM
- β³ π’ Chat tickets ignored your ticket numbering
- β³ π Dates shown as a dash, or in server time
- β³ π Assets β Users showed people from other companies
- β³ π Restricted analysts could read other modules' data
- β³ πΌοΈ Replies with a picture in the thread failed to send
- β³ π Reply attachments never reached the customer
- β³ π οΈ Outbound email attachments β Developer Guide
- β³ π A global SSO provider was missing from the portal
- β³ π Behind a proxy, the SSO redirect said http
- β³ βοΈ The portal tagline moved when you saved it
- β³ π¨ The portal settings screen forgot what you saved
- β³ π‘οΈ The approvals inbox said "Error" and nothing else
- β³ π A table's answers were missing from the PDF
- β³ β A single-select column let you tick every option
- β³ π The portal ignored a form's field widths
- β³ π The tasks board stopped taking clicks
- β³ ποΈ #121 The index list is out of date after upgrading
- β³ π #133 The calendar subscription was empty
- β³ π #131 Tasks always reopened on the board
- β³ π₯ #129 Every page returned HTTP 500 after upgrading
- β³ π³ #127 A PHP warning above the System page
- β³ π #126 Notes stamped with the server's clock
- β³ π Storing every date in UTC
- β³ πͺ The portal was down for everyone signed in
- β³ βοΈ #120 Workflow notes could never be written
- β³ βοΈ #123 Three errors when running Database Verification
- β³ π #122 The description box was a stub in the corner
- β³ π£ Demo data deleted real accounts
- β³ π #117 Sign-in redirected to the wrong address
- β³ π¨ #108 The priority dot was invisible
- β³ β±οΈ #116 Time logged from the right-click menu
- β³ π #114 API keys refused by our own guard
- β³ ποΈ #110 Assigning a task told nobody
- β³ πͺ #107 Signed out while still working
- β³ π #103 "Share with Requester" reached nobody
- β³ π #102 Search found nothing for hyphens
- β³ πͺ #101 Source code editor opened behind
- β³ βοΈ #88 Subtasks could not be ticked off
- β³ π» #84 Asset deep link selected nothing
- β³ π« #79 A new ticket arrived with no status
- β³ π§ #79 A ticket from email did not say so
- β³ π #78 Bell opened to nothing
- β³ π¬ #77 Mail only collected from Inbox
- β³ π #74 The default password could not be changed
- β³ π¦ #70 Renaming an impact level
- β³ π€ #67 App-only mailboxes could not send
- β³ π #45 Verify only ever worked for Microsoft
- β³ π #45 IMAP reported as not authenticated
- β³ βοΈ An email template stopped escaping itself
- β³ π The portal dashboard showed the wrong time
- β³ π’ The folder said 99 and the list showed 96