diff service/cardReader/rfid-console.html @ 725:1ecceb2e92a3

rename rfid_pn532_py Ignore-this: 89356f780bb5df4d9ec639c44d2a3a67
author drewp@bigasterisk.com
date Wed, 05 Feb 2020 16:40:46 -0800
parents service/rfid_pn532_py/rfid-console.html@f134b64a0ab7
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/service/cardReader/rfid-console.html	Wed Feb 05 16:40:46 2020 -0800
@@ -0,0 +1,90 @@
+<link rel="import" href="/lib/polymer/1.0.9/iron-ajax/iron-ajax.html">
+<link rel="import" href="/lib/polymer/1.0.9/polymer/polymer.html">
+<link rel="import" href="/rdf/rdf-oneshot.html">
+<link rel="import" href="/rdf/rdf-uri.html">
+<link rel="import" href="/rdf/streamed-graph.html">
+
+<dom-module id="rfid-console">
+  <style>
+   button {
+       min-width: 60px;
+       min-height: 40px;
+   }
+   table {
+       border-collapse: collapse;
+   }
+   
+   td, th {
+       border: 1px solid gray;
+   }
+  </style>
+  <template>
+    
+    <iron-ajax id="rewrite" url="rewrite" method="POST"></iron-ajax>
+    
+    Current RFID reads: 
+    <table>
+      <tr><th>Card UID</th><th>Card text</th><th></th></tr>
+      <template is="dom-repeat" items="{{currentReads}}">
+        <tr>
+          <td>{{item.uidDisplay}}</td>
+          <td>{{item.text}}</td>
+          <td>
+            <div id="form">
+              <button on-click="rewrite">Rewrite</button>
+            </div>
+          </td>
+        </tr>
+      </template>
+    </table>
+
+    <div>
+      <streamed-graph url="graph/events" graph="{{graph}}"></streamed-graph>
+      <!-- also get a graph of users so we can look up cards -->
+    </div>
+  </template>
+  <script>
+   Polymer({
+     is: 'rfid-console',
+     properties: {
+       graph: { type: Object, notify: true, observer: "_onGraph" },
+       currentReads: { type: Array, value: [] },
+     },
+     behaviors: [BigastUri],
+     _onGraph: function(graph) {
+       if (!graph.graph) return;
+       const env = graph.graph.store.rdf;
+
+       this.splice('currentReads', 0, this.currentReads.length);
+       graph.graph.quadStore.quads(
+         {subject: env.createNamedNode('room:frontDoorWindowRfid'),
+          predicate: env.createNamedNode('room:reading'),
+         },
+         (q) => {
+           graph.graph.quadStore.quads(
+             {subject: q.object,
+              predicate: env.createNamedNode('room:cardText'),
+             },
+             (q2) => {
+               this.push(
+                 'currentReads', {
+                   'cardUid': q.object,
+                   'uidDisplay': q.object.toString().replace(/.*\//, ""),
+                   'text': q2.object.toString()
+                 });
+             });
+         });
+     },
+     rewrite: function(ev) {
+       const cardUid = ev.model.item.cardUid;
+
+       // ask for user first
+
+       this.$.rewrite.contentType = "application/json";
+       this.$.rewrite.body = {'cardUid': cardUid.toString(),
+                              'user': "some foaf"};
+       this.$.rewrite.generateRequest();
+     }
+   });
+  </script>
+</dom-module>