Last active
March 14, 2019 12:57
-
-
Save mohammed-ali-1/b372ba940d7f8816e327a55d9448efc5 to your computer and use it in GitHub Desktop.
OpenWhisk web action that returns a HTML page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function main({reading}) { | |
var script = ` | |
<script> | |
function latest_readings() { | |
const Http = new XMLHttpRequest(); | |
//URL to getLatestTenReadings web action | |
const url='https://OPENWHISK_HOST:OPENWHISK_PORT/api/v1/web/guest/default/getLatestTenReadings'; | |
Http.open("GET", url); | |
Http.send(); | |
Http.onreadystatechange=(e)=> | |
{ | |
var obj = JSON.parse(Http.responseText); | |
var i = 9; | |
document.getElementById("readings").innerHTML = ""; | |
while (i > 4) { | |
document.getElementById("readings").innerHTML += obj[i].body; | |
document.getElementById("readings").innerHTML += "<br />"; | |
i--; | |
} | |
} | |
} | |
latest_readings(); | |
setInterval(latest_readings,10000); | |
</script>`; | |
return { | |
body: ` | |
<html> | |
<style> | |
#readings { | |
position: fixed; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
border-style: solid; | |
border-width: 2px; | |
} | |
</style> | |
<body> | |
<h3 id="readings"></h3> | |
${script} | |
</body> | |
</html>` | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment