Skip to content

Instantly share code, notes, and snippets.

@jbPellicciaImensi
Last active March 21, 2024 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbPellicciaImensi/df9b45e14b979caace65998ceb9e0def to your computer and use it in GitHub Desktop.
Save jbPellicciaImensi/df9b45e14b979caace65998ceb9e0def to your computer and use it in GitHub Desktop.
Here is a little tricks to implement a download button in the Discovery Explorer tool of Warp10.
// @endpoint https://sandbox.senx.io/api/v0/exec
// @preview discovery
// @theme dark
[ 'red' 'yellow' 'green' 'white' ] 'color' STORE
1 4 <%
'i' STORE
NEWGTS
1 30 <%
RAND + STU * NOW + NaN NaN NaN RAND ADDVALUE
%> FOR
'data_' $i TOSTRING + RENAME
{ 'color' $color $i 1 - GET } SETATTRIBUTES WRAP
%> FOR STACKTOLIST 'data' STORE
{
'title' 'My Download Dashboard'
'cellHeight' 120
'vars' {
'data' $data
}
'tiles' [
{
'title' 'Download'
'type' 'display'
'options' { 'eventHandler' 'type=variable,tag=SomeData' }
'x' 5 'y' 0 'w' 2 'h' 1
'macro' <%
<'
fileName = "data.json";
const jsonString = encodeURIComponent(JSON.stringify({{{jsonData}}}));
const dataUri = `data:application/json;charset=utf-8,${jsonString}`;
const a = document.createElement('a');
a.href = dataUri;
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
'>
{
"jsonData" $data <% UNWRAP %> F LMAP ->JSON
} TEMPLATE
'download_script_js' STORE
<'
<button style='background-color: DodgerBlue;' onclick='{{download_script_js}}' >Download</button>
'>
{
'download_script_js' $download_script_js
} TEMPLATE
%>
}
{
'title' 'Some Data'
'type' 'line'
'x' 0 'y' 1 'w' 12 'h' 4
'macro' <%
$data <% UNWRAP %> F LMAP 'data' STORE
{
'data' $data
'params' [
{ 'datasetColor' $data 0 GET ATTRIBUTES 'color' GET 'xAxis' 0 }
{ 'datasetColor' $data 1 GET ATTRIBUTES 'color' GET 'xAxis' 0 }
{ 'type' 'area' 'datasetColor' $data 2 GET ATTRIBUTES 'color' GET 'xAxis' 1 }
{ 'datasetColor' $data 3 GET ATTRIBUTES 'color' GET 'xAxis' 0 }
]
'events' [ { 'tags' 'SomeData' 'type' 'variable' 'selector' 'data' } ]
}
%>
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment