summaryrefslogtreecommitdiffstats
path: root/src/js/app.js
diff options
context:
space:
mode:
authorHumberto Alfonso Díaz <humberto.alfonso@asvito.es>2019-06-20 12:52:29 +0200
committerLorenzo Tilve <ltilve@igalia.com>2020-02-04 19:20:13 +0100
commit0a898f853727a8600ecc57617b006af0f9694502 (patch)
tree6c2448dc5ff9692583fb83d4609bdca50044cf42 /src/js/app.js
parentb1f53f7ee96455fcca4c6e5273c41dd5e498a735 (diff)
FUNCT Add support to load apps from AGL
Diffstat (limited to 'src/js/app.js')
-rw-r--r--src/js/app.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/js/app.js b/src/js/app.js
new file mode 100644
index 0000000..fccf04e
--- /dev/null
+++ b/src/js/app.js
@@ -0,0 +1,59 @@
+import Mustache from 'mustache';
+
+var host = document.location.hostname;
+var port = document.location.port;
+var args = new URLSearchParams(document.location.search.substring(1));
+var token = args.get("x-afb-token") || args.get("token") || "HELLO";
+var afb;
+var template;
+
+function log(smgs) {
+ document.getElementById('log').innerHTML += '<div>'+smgs+'</div>';
+}
+
+function getIcon(app) {
+ if( app.icon.match(/^.*\.svg$/) ) {
+ return '/icons/'+app.id;
+ } else {
+ return '/images/noicon.svg';
+ }
+}
+
+function display_applications(apps) {
+ var appContainer = document.getElementById('AppContainer');
+ for( var i=0; i<apps.length; i++) {
+ apps[i].icon = getIcon(apps[i]);
+ appContainer.innerHTML += Mustache.render(template, apps[i]);
+ }
+}
+
+function load_application_list() {
+ var ws = new afb.ws(function() {
+ var api_verb = "afm-main/runnables";
+ ws.call(api_verb, {}).then(
+ function(obj) {
+ display_applications(obj.response);
+ },
+ function(obj) {
+ //TODO Manage errors
+ log("failure");
+ }
+ );
+ },
+ function() {
+ //TODO manage errors
+ log("ws aborted");
+ });
+}
+
+function init() {
+ template = document.getElementById('item-template').innerHTML;
+ Mustache.parse(template);
+ afb = new AFB({
+ host: "raspberrypi3.local:31022",
+ token: token
+ });
+ load_application_list();
+}
+
+document.addEventListener('DOMContentLoaded', init); \ No newline at end of file