comparison service/rfid_pn532_py/rfid-console.html @ 415:91b4a04a33e7

split console web component Ignore-this: 1af5e69fff09e7e5680ffb25e9236fc0
author drewp@bigasterisk.com
date Sat, 23 Mar 2019 13:57:44 -0700
parents
children f134b64a0ab7
comparison
equal deleted inserted replaced
414:f1a9b4670470 415:91b4a04a33e7
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-control">
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 <div>
23 <streamed-graph url="graph/events" graph="{{graph}}"></streamed-graph>
24 <!-- also get a graph of users so we can look up cards -->
25 </div>
26
27 <iron-ajax id="rewrite" url="rewrite" method="POST"></iron-ajax>
28
29 Current reads:
30 <table>
31 <tr><th>Card UID</th><th>Card text</th><th></th></tr>
32 <template is="dom-repeat" items="{{currentReads}}">
33 <tr>
34 <td>{{item.uidDisplay}}</td>
35 <td>{{item.text}}</td>
36 <td>
37 <div id="form">
38 <button on-click="rewrite">Rewrite</button>
39 </div>
40 </td>
41 </tr>
42 </template>
43 </table>
44
45 </template>
46 <script>
47 Polymer({
48 is: 'rfid-control',
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>