// // 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/tile' 'desc' <' Generate a tile '> 'sig' [ [ [ 'params:MAP' ] [ 'result:MAP' ] ] ] // Signature 'params' { // Signature params description 'params' <' Map of parameters: - **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. '> 'result' 'A map representation of the tile' } 'examples' [ <' { // params 'title' 'Country' // title 'type' 'display' // Type 'endpoint' '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/tile '> ] } 'info' STORE <% !$info INFO SAVE 'context' STORE <% // Code of the actual macro 'params' STORE <% [ 'field' 'defValue' ] STORE <% $params $field CONTAINSKEY SWAP DROP %> <% $params $field GET %> <% $defValue %> IFTE %> 'getOrDef' STORE // default options { 'showDots' false 'showErrors' true 'showStatus' false } 'defOpts' STORE 'options' {} @getOrDef 'opts' STORE $opts KEYLIST <% 'k' STORE $defOpts $opts $k GET $k PUT 'defOpts' STORE %> FOREACH { 'x' 'x' 0 @getOrDef 'y' 'y' 0 @getOrDef 'options' $defOpts 'endpoint' $params 'endpoint' GET 'title' 'title' '' @getOrDef 'rows' 'h' 1 @getOrDef 'cols' 'w' 1 @getOrDef 'type' 'type' 'plot' @getOrDef } 'result' STORE <% $params 'macro' CONTAINSKEY SWAP DROP %> <% $params 'macro' GET ->JSON 'code' STORE $code 1 $code SIZE 2 - SUBSTRING ' EVAL' + 'code' STORE $result $code 'macro' PUT 'result' STORE %> <% $result $params 'data' GET 'data' PUT 'result' STORE %> IFTE $result %> <% // catch any exception RETHROW %> <% // finally, restore the context $context RESTORE %> TRY %> 'macro' STORE // Unit tests $macro