view service/tomatoWifi/index.html @ 980:2f1cb8b5950a

rewrites for better graph export, removal of dhcp reader Ignore-this: ecc5280b15d66020412f82ad84862074 darcs-hash:20150504002120-312f9-85bcb342f5bdae78d7b6d9083929944d4a467001
author drewp <drewp@bigasterisk.com>
date Sun, 03 May 2015 17:21:20 -0700
parents
children 6c42d528898b
line wrap: on
line source

<!doctype html>
<html>
  <head>
    <title>dhcp leases</title>
    <meta charset="utf-8" />
    <script src="/lib/polymer/0.8/webcomponentsjs/webcomponents-lite.min.js"></script>
    <script src="/lib/underscore-1.5.2.min.js"></script>
    <link rel="import" href="/rdf/n3+polymer/trig-store.html">
    <link rel="import" href="/lib/polymer/0.8/iron-ajax/iron-ajax.html">
  </head>
  <body>
    <h1>Devices on wifi</h1>

    <dom-module id="wifi-table">
      <template>
        <iron-ajax auto url="graph"
                   handle-as="text"
                   last-response="{{ajaxResponse}}"></iron-ajax>
        <trig-store id="ts" trig-input="{{ajaxResponse}}"></trig-store>

        <table>
          <tr>
            <th>name</th>
            <th>MAC</th>
            <th>Connected</th>
          </tr>
          <template is="x-repeat" items="{{devices}}">
            <tr>
              <td>{{item.deviceName}}</td>
              <td>{{item.mac}}</td>
              <td>{{item.connectedAgo}}</td>
            </tr>
          </template>
        </table>
      </template>
    </dom-module>
    
    <script>
     Polymer({
       is: "wifi-table",
       ready: function() {
         this.$.ts.addEventListener('store-changed', this.storeChanged.bind(this));
         this.devices = [];
       },
       storeChanged: function(ev) {
         var store = ev.detail.value;
         var find = function(s, p, o) { return store.findAllGraphs(s, p, o); };
         var findOne = function(s, p, o) {
           var rows = find(s, p, o);
           return rows[0];
         };

         this.devices = [];
         
         find(null, "room:connected", "http://bigasterisk.com/wifiAccessPoints"
              ).forEach(function(row) {
           var out = {
             mac: N3.Util.getLiteralValue(
               findOne(row.subject, "room:macAddress", null).object),
             connectedAgo: N3.Util.getLiteralValue(
               findOne(row.subject, "room:connectedAgo", null).object)
            
           };
           try {
             var dev = findOne(row.subject, "room:deviceName", null).object;
             out.deviceName = N3.Util.getLiteralValue(dev);
           } catch(e) {

           }           
           
           this.devices.push(out);
         }.bind(this));
         this.devices = _.sortBy(this.devices, 'deviceName');
       }
     });
    </script>
    <wifi-table></wifi-table>
  </body>
</html>