//
// 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
//
15 m MSTU / MACROTTL
{
'name' '@senx/discovery2/html'
'desc'
<'
Generate an HTML dashboard from a Layout
See @senx/discovery/layout
'>
'sig' [ [ [ 'layout:MAP' 'params:MAP' ] [ 'result:STRING' ] ] ] // Signature
'params' {
'layout' 'A layout map as generated by @senx/discovery/layout'
'params'
<'
A custom `MAP` for HTML rendering:
- **html.head**: Additional HTML content such as CSS for dashboard customization - **optional**.
- **header**: HTML custom header - **optional**.
- **footer**: HTML custom footer - **optional**.
- **cols**: Number of columns of the grid - **optional**, defaults to 12.
- **height**: Grid cell height in pixels - **optional**, defaults to 220.
- **template**: **Optional** custom HTML template. Must contain the following placeholders:
- {{{CSS}}} // for CSS imports, ideally in the `head` section.
- {{{GRID}}} // the grid placement, ideally in a `div`.
- {{{JS}}} // for js placement, ideally just before the closing `body` tag.
'>
'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
}
]
} {}
@senx/discovery2/html
'>
]
} 'info' STORE
<%
!$info INFO
SAVE 'context' STORE
<%
[ 'layout' 'params' ] STORE
<%
[ 'field' 'defValue' ] STORE
<% $params $field CONTAINSKEY SWAP DROP %> <% $params $field GET %> <% $defValue %> IFTE
%> 'getOrDef' STORE
<'
'>
'js' STORE
<'
'>
'css' STORE
'template'
<'
{{{TITLE}}}
{{{CSS}}}
{{{HEAD}}}
{{{HEADER}}}
{{{DATA}}} EVAL
{{{FOOTER}}}
{{{JS}}}
'>
@getOrDef
{
'DATA' <% $layout %> SNAPSHOT EVAL
'TITLE' 'title' 'Dashboard' @getOrDef
'URL' 'url' 'https://sandbox.senx.io/api/v0/exec' @getOrDef
'HEAD' 'html.head' '' @getOrDef
'CELL_HEIGHT' 'height' 220 @getOrDef
'HEADER' 'header' '' @getOrDef
'FOOTER' 'footer' '' @getOrDef
'CSS' $css
'JS' $js
} TEMPLATE
%>
<% // catch any exception
RETHROW
%>
<% // finally, restore the context
$context RESTORE
%> TRY
%>
'macro' STORE
// Unit tests
$macro