// // 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/discovery/render' 'desc' <' Render an HTML dashboard based upon a map of parameters '> 'sig' [ [ [ 'params:MAP' ] [ 'result:STRING' ] ] ] // Signature 'params' { // Signature params description 'params' <' Map of parameters: - **type**: 'scada' or 'dashboard' (default) - **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. - **y**: Vertical position in the grid - **optional**, defaults to 0. - **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. - **html.head**: Additional HTML such as CSS for dashboard customization - **optional**. - **header**: Custom HTML header - **optional**. - **footer**: Custom HTML 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/discovery/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