summaryrefslogtreecommitdiffstats
path: root/src/js
diff options
context:
space:
mode:
authorHumberto Alfonso Díaz <humberto.alfonso@asvito.es>2019-07-01 12:10:15 +0200
committerHumberto Alfonso Díaz <humberto.alfonso@asvito.es>2019-07-01 12:10:15 +0200
commite5b45e034eb954c10bc545f72e7e0c986c1e3fd1 (patch)
treeb16d12a4b7143bf382d34d8d4af8431ed8bbd84f /src/js
parentaac66099e68d635cbb5945366e00232abf868bdb (diff)
FUNCT Add custom icons with animation
Diffstat (limited to 'src/js')
-rw-r--r--src/js/app.js41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/js/app.js b/src/js/app.js
index 9c65e4f..ee64692 100644
--- a/src/js/app.js
+++ b/src/js/app.js
@@ -11,19 +11,39 @@ 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 show_app(app) {
+ document.getElementById("app-"+app.id).style["display"]="block";
}
-function display_applications(apps) {
+function display_icon(app) {
+ return new Promise(function(resolve, reject) {
+ var iconURL = '/images/icons/'+app.name.toLowerCase()+'_inactive.svg';
+ var image = new Image();
+
+ image.onload = function() {
+ document.getElementById("icon-"+app.id).src = iconURL;
+ resolve();
+ }
+
+ image.onerror = function(){
+ resolve();
+ }
+
+ image.src = iconURL;
+
+ });
+}
+
+
+function render_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(app) {
+ display_icon(app).then(function() {
+ show_app(app);
+ });
+ })(apps[i]);
}
}
@@ -32,7 +52,7 @@ function load_application_list() {
var api_verb = "afm-main/runnables";
ws.call(api_verb, {}).then(
function(obj) {
- display_applications(obj.response);
+ render_applications(obj.response);
},
function(obj) {
//TODO Manage errors
@@ -73,7 +93,8 @@ export function init() {
// host: "raspberrypi3.local:31022",
afb = new AFB({
- host: host+":"+port,
+ host: "raspberrypi3.local:31022",
+ // host: host+":"+port,
token: token
});
load_application_list();