comparison 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
comparison
equal deleted inserted replaced
724:2866c155eb07 725:1ecceb2e92a3
1 <link rel="import" href="/lib/polymer/1.0.9/iron-ajax/iron-ajax.html">
2 <link rel="import" href="/lib/polymer/1.0.9/polymer/polymer.html">
3 <link rel="import" href="/rdf/rdf-oneshot.html">
4 <link rel="import" href="/rdf/rdf-uri.html">
5 <link rel="import" href="/rdf/streamed-graph.html">
6
7 <dom-module id="rfid-console">
8 <style>
9 button {
10 min-width: 60px;
11 min-height: 40px;
12 }
13 table {
14 border-collapse: collapse;
15 }
16
17 td, th {
18 border: 1px solid gray;
19 }
20 </style>
21 <template>
22
23 <iron-ajax id="rewrite" url="rewrite" method="POST"></iron-ajax>
24
25 Current RFID reads:
26 <table>
27 <tr><th>Card UID</th><th>Card text</th><th></th></tr>
28 <template is="dom-repeat" items="{{currentReads}}">
29 <tr>
30 <td>{{item.uidDisplay}}</td>
31 <td>{{item.text}}</td>
32 <td>
33 <div id="form">
34 <button on-click="rewrite">Rewrite</button>
35 </div>
36 </td>
37 </tr>
38 </template>
39 </table>
40
41 <div>
42 <streamed-graph url="graph/events" graph="{{graph}}"></streamed-graph>
43 <!-- also get a graph of users so we can look up cards -->
44 </div>
45 </template>
46 <script>
47 Polymer({
48 is: 'rfid-console',
49 properties: {
50 graph: { type: Object, notify: true, observer: "_onGraph" },
51 currentReads: { type: Array, value: [] },
52 },
53 behaviors: [BigastUri],
54 _onGraph: function(graph) {
55 if (!graph.graph) return;
56 const env = graph.graph.store.rdf;
57
58 this.splice('currentReads', 0, this.currentReads.length);
59 graph.graph.quadStore.quads(
60 {subject: env.createNamedNode('room:frontDoorWindowRfid'),
61 predicate: env.createNamedNode('room:reading'),
62 },
63 (q) => {
64 graph.graph.quadStore.quads(
65 {subject: q.object,
66 predicate: env.createNamedNode('room:cardText'),
67 },
68 (q2) => {
69 this.push(
70 'currentReads', {
71 'cardUid': q.object,
72 'uidDisplay': q.object.toString().replace(/.*\//, ""),
73 'text': q2.object.toString()
74 });
75 });
76 });
77 },
78 rewrite: function(ev) {
79 const cardUid = ev.model.item.cardUid;
80
81 // ask for user first
82
83 this.$.rewrite.contentType = "application/json";
84 this.$.rewrite.body = {'cardUid': cardUid.toString(),
85 'user': "some foaf"};
86 this.$.rewrite.generateRequest();
87 }
88 });
89 </script>
90 </dom-module>