This is a preview of the Reports functionality.

It allows defining report templates and then create reports based on the templates.
A template defines:
- parameters - to be set in the report (currently only selection of campaigns, in the future to be extended to selection of lists/segments, and selection from pre-defined options)
- data retrieval / processing code (in Javascript)
- rendering template (in Handlebars)

This main functionality is accompanied by a few minor tweaks here and there. Worth notice is the ability to use server-side ajax table s for multi-selection of campaigns. This is meant for reports that compare data across multiple campaigns. This could possibly be even used for some poor man's A/B testing.

Note that the execution of custom JavaScript in the data retrieval / processing code and definition of custom Handlebars templates is a security issue. This should however be OK in the general case once proper user management with granular permissions is in. This is because definition of a report template is anyway such an expert task that it would normally be performed only by admin. Instantiation of reports based on report templates can be then done by any user because this should no longer be any security problem.
This commit is contained in:
Tomas Bures 2017-04-16 18:09:08 -04:00
parent 2afeb74e68
commit 6ba04d7ff4
31 changed files with 1737 additions and 13 deletions

29
app.js
View file

@ -40,6 +40,8 @@ let blacklist = require('./routes/blacklist');
let editorapi = require('./routes/editorapi');
let grapejs = require('./routes/grapejs');
let mosaico = require('./routes/mosaico');
let reports = require('./routes/reports');
let reportsTemplates = require('./routes/report-templates');
let app = express();
@ -57,6 +59,8 @@ app.disable('x-powered-by');
hbs.registerPartials(__dirname + '/views/partials');
hbs.registerPartials(__dirname + '/views/subscription/partials/');
hbs.registerPartials(__dirname + '/views/report-templates/partials/');
hbs.registerPartials(__dirname + '/views/reports/partials/');
/**
* We need this helper to make sure that we consume flash messages only
@ -119,6 +123,29 @@ hbs.registerHelper('translate', function (context, options) { // eslint-disable-
return new hbs.handlebars.SafeString(result);
});
/* Credits to http://chrismontrois.net/2016/01/30/handlebars-switch/
{{#switch letter}}
{{#case "a"}}
A is for alpaca
{{/case}}
{{#case "b"}}
B is for bluebird
{{/case}}
{{/switch}}
*/
hbs.registerHelper("switch", function(value, options) {
this._switch_value_ = value;
var html = options.fn(this); // Process the body of the switch block
delete this._switch_value_;
return html;
});
hbs.registerHelper("case", function(value, options) {
if (value == this._switch_value_) {
return options.fn(this);
}
});
app.use(compression());
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
@ -221,6 +248,8 @@ app.use('/api', api);
app.use('/editorapi', editorapi);
app.use('/grapejs', grapejs);
app.use('/mosaico', mosaico);
app.use('/reports', reports);
app.use('/report-templates', reportsTemplates);
// catch 404 and forward to error handler
app.use((req, res, next) => {