view service/dhcpleases/index.html @ 1000:df5a40967a2f

polymer updates Ignore-this: f4f88b324b54abf90af6dc5360910041 darcs-hash:20150830185325-312f9-8f07ba7ccc6ecd6528159fa5fd09a166d3ce1650
author drewp <drewp@bigasterisk.com>
date Sun, 30 Aug 2015 11:53:25 -0700
parents 76bb0bf74bd1
children 1fbcda1bdc5f
line wrap: on
line source

<!doctype html>
<html>
  <head>
    <title>dhcp leases</title>
    <meta charset="utf-8" />
    <script src="/lib/polymer/1.0.9/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/1.0.9/iron-ajax/iron-ajax.html">
  </head>
  <body>
    <h1>Active dhcp leases</h1>
    <p><a href="../wifi">go to wifi</a></p>

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

        <table>
          <template is="dom-repeat" items="{{devices}}">
            <tr>
              <td>{{item.dhcpHostname}}</td>
              <td>{{item.ip}}</td>
              <td>{{item.mac}}</td>
            </tr>
          </template>
        </table>
      </template>
    </dom-module>
    
    <script>
     HTMLImports.whenReady(function () {
       Polymer({
         is: "dhcp-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:dhcpHostname", null).forEach(function(row) {
             var out = {dhcpHostname: N3.Util.getLiteralValue(row.object)}
             var lease = findOne(null, "room:ethernetAddress",
                                 row.subject).subject;
             out.ip = N3.Util.getLiteralValue(
               findOne(findOne(lease, "room:assignedIp", null).object,
                       "rdfs:label", null).object);
             out.mac = N3.Util.getLiteralValue(
               findOne(findOne(lease, "room:ethernetAddress", null).object,
                       "room:macAddress", null).object);
             this.devices.push(out);
           }.bind(this));
           this.devices = _.sortBy(this.devices, 'dhcpHostname');
         }
       });
     });
    </script>
    <dhcp-table></dhcp-table>
  </body>
</html>