summaryrefslogtreecommitdiffstats
path: root/src/js/wifi.js
blob: d9f91d05deeb478de58773cde16a2f0f20d5b5cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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) {
    page.devices = [];
    devices.forEach(function(device) {
        if( device.properties.type === 'wifi' ) {
            page.devices.push(device);
        }
    });

    console.log(page);

    render();
}

function refresh_devices() {
    network.services().then(function(result) {
        update_devices(result.values);
    });
}

export function init() {
    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();
}