summaryrefslogtreecommitdiffstats
path: root/src/js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js')
-rw-r--r--src/js/app.js3
-rw-r--r--src/js/wifi.js51
2 files changed, 35 insertions, 19 deletions
diff --git a/src/js/app.js b/src/js/app.js
index 458a5d4..fb7f77f 100644
--- a/src/js/app.js
+++ b/src/js/app.js
@@ -1,5 +1,5 @@
import * as bluetooth from './bluetooth';
-import { init as init_wifi } from './wifi';
+import * as wifi from './wifi';
import { load as load_template } from './templates';
import Mustache from 'mustache';
@@ -20,6 +20,7 @@ export function init() {
Mustache.parse(template);
show();
bluetooth.init();
+ wifi.init();
}, function(error) {
console.error('ERRROR loading main template', error);
});
diff --git a/src/js/wifi.js b/src/js/wifi.js
index 35e7235..d9f91d0 100644
--- a/src/js/wifi.js
+++ b/src/js/wifi.js
@@ -1,34 +1,49 @@
import { network } from 'agl-js-api';
import Mustache from 'mustache';
+import { load as load_template } from './templates';
+import * as app from './app';
var template;
+var page = {
+ devices: []
+}
+function render(){
+ document.body.innerHTML = Mustache.render(template, page);
+}
function update_devices(devices) {
- console.log('update_devices', devices);
- var deviceList = document.getElementById('WifiContainer');
- deviceList.innerHTML = '';
-
+ page.devices = [];
devices.forEach(function(device) {
if( device.properties.type === 'wifi' ) {
- deviceList.innerHTML += Mustache.render(template, device);
+ page.devices.push(device);
}
});
+
+ console.log(page);
+
+ render();
+}
+
+function refresh_devices() {
+ network.services().then(function(result) {
+ update_devices(result.values);
+ });
}
export function init() {
- template = document.getElementById('wifi-device-template').innerHTML;
- Mustache.parse(template);
-
- setInterval(function() {
- network.services().then(function(result) {
- update_devices(result.values);
- })
- }, 10000);
-
- network.on_global_state(function(result) {
- console.log('on_global_state', result);
- }).then(function(){
- console.log('SUBSCRIBED', 'on_global_state');
+ load_template('wifi.template.html').then(function(result) {
+ template = result;
+ Mustache.parse(template);
+ }, function(error) {
+ console.error('ERROR Loading bluetooth template', error);
});
+}
+
+export function show() {
+ refresh_devices();
+}
+
+export function hide() {
+ app.show();
} \ No newline at end of file