Simple reports can be produced by navigating to URLs of the format /#/analyse/modelname - see example here.

More useful reports can be run by passing an aggregation pipeline to the server using the format /#/analyse/model?r=[pipeline] - for example /#/analyse/g_conditional_fields?r=[{"$group":{"_id":"$sex","count":{"$sum":1}}}] produces a breakdown of the men and women in a collection.

Options

Reports can be enhanced by passing an object containing the pipeline as a property, along with a number of options:

  • title this option allows a title to be specified. The default is the model name.
  • columnDefs an array of column instruction objects which determines the output order and appearance. For full details see the ng-grid documentation but the most common uses are:
    • field the name of the field in the model.
    • displayName (optional) the column heading.
    • width (optional) the desired display width.
    • align (optional - default left) the desired text alignment. If present must be one of left, right, centre, center.
    • cellClass (optional) a CSS class to be added to the cell.
    • cellFilter (optional) an Angular filter (such as number or currency to be applied to the value.
    • totalsRow (optional - an extension to ng-grid) a text value (generally "Total") or $SUM
  • columnTranslations an array of objects giving instructions for translating returned data. The objects are made up as follows:
    • field (mandatory) the name of the results column to translate
    • ref the name of a Mongoose model to use to look up the current value against (returning a concatenation of the fields with a truthy list key)
    • translations an array of value→display mappings, such as [{value:'M', display:'Male'},{value:'F', display:'Female'}]
  • drilldown a url that clicking on the row will navigate to. A !fieldname! will be replaced with the value of the fieldname in the current row. For example a report listing one row per item might have a drilldown of /#/model/!_id!/edit
  • params contains an array of parameters that can be used in the pipeline, normally in a $match such as {$match:{sex:("sex")}}. Parameters can have the following properties:
    • value is the (mandatory) value used for the query when the page is first generated
    • type can be 'text' (default), 'number' or 'select'. In the case of 'select' values must be defined for
    • label allows you to override the default input label
    • size sets input control width. Options are: mini, small (default), medium, large, xlarge, xxlarge and block-level..
    • enum an array of values to populate a select input
    • required should set to true if the query cannot be run without the parameter
    • noInput can be set to true to prevent the parameter being prompted for. Normally used in conjunction with
    • conversionExpression an angular expression which generates and / or formats the parameter at runtime. For example
      param + ' ' + record.surname | uppercase
      would concatenate the values fom the current parameter and the surname parameter and convert them to uppercase.

Use of date parameters is quite tricky. The following works (quotes omitted for clarity):

        reportSchema = {
            pipeline: [
                { '$match': {$and : [{birth : {$lt:"(periodFinish)"}},{birth : {$gt:"(periodStart)"}}]}},
                {$group:{_id:'People',count:{$sum:1}}
            ],
            params: {
                periodStart: {value: "1800-01-01T00:00:00.000Z", type: 'text', add: 'ui-date ui-date-format ', conversionExpression: "param | date:'yyyy-MM-ddThh:mm:ss.sssZ'"},
                periodFinish: {value: "2099-01-01T00:00:00.000Z", type: 'text', add: 'ui-date ui-date-format ', conversionExpression: "param | date:'yyyy-MM-ddThh:mm:ss.sssZ'"}
                }
        };
        

Using these options the report above can be tidied up.

Schemas

If you looked at the link to that last report you would have realised that using the URL to specify a report format quickly becomes unmanageable. A neater alternative is to put the options into an object which is served up via a static in the model file - see here for some examples.