Power BI (sample widget)

This widget displays graphics from the Baremetric Service

The widget’s Script code

Script CodeExpand source

if("""'{{url|default:"https://powerbi.microsoft.com/en-us/"}}'.indexOf('chromeless') > 0"""){
openAndWait("""{{url|default:'https://powerbi.microsoft.com/en-us/'|safe}}""")
}
else if("""'{{url|default:"https://powerbi.microsoft.com/en-us/"}}'.indexOf('?') > 0"""){
openAndWait("""{{url|default:'https://powerbi.microsoft.com/en-us/'|safe}}&chromeless=1""")
}
else{
openAndWait("""{{url|default:'https://powerbi.microsoft.com/en-us/'|safe}}?chromeless=1""")
}
pause(4)
if("""!!document.getElementById('hero-secondary-cta') || !!document.getElementById('email')"""){
openAndWait("""https://app.powerbi.com/?noSignUpCheck=1""")
pause(3)
type("""#i0116""", """{{email|default:'a@b.c'|safe|addslashes}}""")
runScript("""
document.querySelector("input").dispatchEvent(new Event("change"))
""")
pause(1)
click("""#idSIButton9""")
pause(5)
type("""#i0118""", """{{password|default:'password'|safe|addslashes}}""")
pause(1)
runScript("""
document.querySelector("#i0118").dispatchEvent(new Event("change"))
""")
pause(2)
clickAndWait("""#idSIButton9""")
pause(1)

if ("""!!j('#KmsiCheckboxField').length"""){
click("""#KmsiCheckboxField""")
pause(1)
clickAndWait("""#idSIButton9""")
pause(2)
}
if("""'{{url|default:"https://powerbi.microsoft.com/en-us/"}}'.indexOf('chromeless') > 0"""){
openAndWait("""{{url|default:'https://powerbi.microsoft.com/en-us/'|safe}}""")
}
else if("""'{{url|default:"https://powerbi.microsoft.com/en-us/"}}'.indexOf('?') > 0"""){
openAndWait("""{{url|default:'https://powerbi.microsoft.com/en-us/'|safe}}&chromeless=1""")
}
else{
openAndWait("""{{url|default:'https://powerbi.microsoft.com/en-us/'|safe}}?chromeless=1""")
}
}
else if("""window.location.href.indexOf('login') != -1"""){
click("""#tilesHolder > div:nth-child(1) > div > div > div > div.table-cell.text-left.content > div""")
pause(2)
type("""#i0118""", """{{password|default:'password'|safe|addslashes}}""")
pause(1)
runScript("""
document.querySelector("#i0118").dispatchEvent(new Event("change"))
""")
pause(2)
clickAndWait("""#idSIButton9""")
pause(1)
if ("""!!j('#KmsiCheckboxField').length"""){
click("""#KmsiCheckboxField""")
pause(1)
clickAndWait("""#idSIButton9""")
pause(2)
}
if("""'{{url|default:"https://powerbi.microsoft.com/en-us/"}}'.indexOf('chromeless') > 0"""){
openAndWait("""{{url|default:'https://powerbi.microsoft.com/en-us/'|safe}}""")
}
else if("""'{{url|default:"https://powerbi.microsoft.com/en-us/"}}'.indexOf('?') > 0"""){
openAndWait("""{{url|default:'https://powerbi.microsoft.com/en-us/'|safe}}&chromeless=1""")
}
else{
openAndWait("""{{url|default:'https://powerbi.microsoft.com/en-us/'|safe}}?chromeless=1""")
}
}
pause(2)
if("""!!document.getElementsByClassName('fitContentBtn').length"""){
click(""".fitContentBtn""")
}
repeat(0){
pause({{refresh|default:3600}})
refreshAndWait()
pause(2)
if("""!!document.getElementsByClassName('fitContentBtn').length"""){
click(""".fitContentBtn""")
}
}

The widget’s JSON Schema

We need the declare a schema for the required configuration fields:

  1. email: the email of the user
  2. password: the password of the user
  3. refresh: the refresh rate of the graph
  4. url: the dashboard that you want to display

JSON SchemaExpand source

{
"fields": [
"email",
"password",
"refresh",
"url"
],
"meta": {
"group": 1,
"description": "Display content from Power BI",
"name": "Power BI",
"details": "Display the desired content by providing a link from your Power BI account."
},
"schema": {
"url": {
"title": "<%=generic_widget_param_url%>",
"type": "Text",
"help": "<%=generic_widget_param_powerbi_help%>",
"validators": [
"required"
]
},
"password": {
"type": "Password",
"help": "Required if the dashboard is private.",
"title": "<%=generic_widget_param_password%>"
},
"email": {
"title": "<%=generic_widget_param_email%>",
"type": "Text",
"help": "Required if the dashboard is private.",
"validators": [
"email"
]
},
"refresh": {
"title": "Refresh Interval (sec)",
"type": "Spinner",
"help": "Interval time to request for more data on this url.",
"editorAttrs": {
"max": 9999,
"step": 5,
"min": 60
},
"validators": [
"required"
]
}
}
}