//
// Copyright 2020 SenX S.A.S.
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see
//
5 m MSTU / MACROTTL
{
'name' '@senx/discovery2/render'
'desc'
<'
Render an HTML dashboard based upon a map of parameters
'>
'sig' [ [ [ 'params:MAP' 'layout:MAP' ] [ 'result:STRING' ] ] ] // Signature
'params' {
// Signature params description
'params'
<'
Map of parameters to execute the dashboard:
- **url**: The Warp 10 exec endpoint that the generated html should use. Defaults to Warp 10 sandbox.
- **bootstrap**: Some WarpScript to execute before the dashboard execution.
- **html.head**: Raw html headers to add (for example ``).
- **head**: html header, inserted before the dashboard.
- **footer**: html footer, inserted after the dashboard.
- **template**: A full html template, that override everything. Contact SenX for more information.
- **cols** and **height**: will be overriden by **cols** and **cellHeight** in the layout map.
'>
'layout'
<'
Map to describe discovery dashboard layout:
- **type**: 'scada' or 'dashboard' (default) or 'flex'.
- **title**: Title of the dashboard - **optional**.
- **descrition**: Descrition of the dashboard - **optional**.
- **tiles**: List of tiles - **mandatory**. Each tile is defined by a `MAP` containing the following entries:
- **title**: Title of the tile - **optional**.
- **x**: Horizontal position in the grid, between 0 and grid width - **optional**, defaults to 0. (useless for flex type)
- **y**: Vertical position in the grid - **optional**, defaults to 0. (useless for flex type)
- **w**: Width of the tile in number of grid columns - **optional**, defaults to 1.
- **h**: Height of the tile in number of grid rows - **optional**, defaults to 1.
- **options**: WarpView specific options - **optional** (!).
- **type**: Type of WarpView tile - **optional**, defaults to `plot`.
- **endpoint**: Warp 10 `/api/v0/exec` url - **mandatory** when `macro` is set.
- **macro**: WarpScript macro to run to produce data for the tile - use only if `data` is not set.
- **data**: Data to represent in the tile resulting from a WarpScript execution - use only if `macro` is not set.
- **cols**: Number of columns of the grid - **optional**, defaults to 12.
- **cellHeight**: Grid cell height in pixels - **optional**, defaults to 220.
'>
'result' 'An HTML dashboard'
}
'examples' [
<'
{
'title' 'Covid' // title
'description' 'The Covid 19 dashboard' // description
'tiles' [ // Tiles
{ // params
'title' 'Country' // title
'type' 'display' // Type
'backend' 'https://warp.senx.io/api/v0/exec' // backend
'x' 0 'y' 0
'w' 2 'h' 1
'options' {
'showStatus' false
'timeMode' 'custom'
}
'macro' <% { 'data' [ 'France' ] } %> // macro
}
]
} // dashboard layout definition
{ 'url' 'https://warp.senx.io/api/v0/exec' } // url (default to sandbox)
@senx/discovery2/render
'>
]
} 'info' STORE
<%
!$info INFO
SAVE 'context' STORE
'params' STORE
<%
[ 'field' 'defValue' ] STORE
<% $params $field CONTAINSKEY SWAP DROP %> <% $params $field GET %> <% $defValue %> IFTE
%> 'getOrDef' STORE
<%
$params '@senx/discovery2/' 'type' 'dashboard' @getOrDef + EVAL
%>
<% // catch any exception
RETHROW
%>
<% // finally, restore the context
$context RESTORE
%> TRY
%>
'macro' STORE
// Unit tests
$macro