Lessons from EAF

5. Generate consistent output

When we built the ElseApps Framework we learnt a lot of lessons. This series of short articles discusses some of the key learnings from our framework development. I’m sure most of them will be lessons other developers have already learnt, but many of them weren’t in our vocabulary when we started into the project.

It’s important that any application give its users easy and useful access to their data. With web applications this requirement can pose increased difficulty. Desktop web browsers will offer to print a page of data, but the format will vary from browser to browser – and what about users on smartphones and tablets? Moreover, printed output is only part of the requirement: users also want to export data in a format that allows them to slice and dice it outside the application. For usability, the ElseApps Framework needed to handle both types of output – printing and exporting – in a consistent and effective manner.

fw_pdf01For printing we elected to generate PDF documents instead of relying on the variable effectiveness of the user’s browser. This has the additional advantages of producing output on most mobile devices, and of providing a single file that users can store and retrieve in their own systems.

There are PHP libraries available to help with generating PDF output. We tested several and found them a patchy lot. We decided to wrap one of the more widely used libraries in our own class, a class written to render the twenty data types used in EAF’s dynamically created forms. This approach enabled us to compensate for the library’s worst inconsistencies and, of course, once we’d written this, any and every form created within the application is rendered consistently.

Having created the PDF generation class, extending it to provide output for other areas of the web application was straightforward. We also added configuration settings for the client’s logo, colours and preferred fonts, so configuring printing for a new client is a trivial step.

fw_filesUsers upload supporting files as part of a funding application, and we embed any type and any number of these into the PDF. Once generated, the user has a single PDF document that contains every element of the application.

For exporting data, we built spreadsheet generation into our standard table class. Data collections within EAF are displayed onscreen in tables based on a standard table class which is hydrated using the Knockout Javascript library. By building spreadsheet generation into this class, it is automatically available for all data collections including applications, reports, grants, users, reference data, logs, etc.

fw_logcsv
We’ve called the next lesson from EAF “6. Reusable reusability“.

Lessons from EAFF: 1 2 3 4 5 6 7 8