comparison service/rfid_pn532_py/index.html @ 1218:c571a45c944f

split console web component Ignore-this: 1af5e69fff09e7e5680ffb25e9236fc0 darcs-hash:7acb2532595a2073de5bb224ef708e57b84dc99d
author drewp <drewp@bigasterisk.com>
date Sat, 23 Mar 2019 13:57:44 -0700
parents b48f1ecbc078
children f134b64a0ab7
comparison
equal deleted inserted replaced
1217:c21f433ddbac 1218:c571a45c944f
28 room: 'http://projects.bigasterisk.com/room/', 28 room: 'http://projects.bigasterisk.com/room/',
29 rdfs: 'http://www.w3.org/2000/01/rdf-schema#', 29 rdfs: 'http://www.w3.org/2000/01/rdf-schema#',
30 sensor: 'http://bigasterisk.com/homeauto/sensor/', 30 sensor: 'http://bigasterisk.com/homeauto/sensor/',
31 }; 31 };
32 </script> 32 </script>
33 <link rel="import" href="/lib/polymer/1.0.9/iron-ajax/iron-ajax.html"> 33 <link rel="import" href="rfid-console.html">
34 <link rel="import" href="/rdf/streamed-graph.html">
35 <link rel="import" href="/lib/polymer/1.0.9/polymer/polymer.html">
36 <link rel="import" href="/rdf/rdf-oneshot.html">
37 <link rel="import" href="/rdf/rdf-uri.html">
38 </head> 34 </head>
39 <body> 35 <body>
40 <dom-module id="rfid-control">
41 <style>
42 button {
43 min-width: 60px;
44 min-height: 40px;
45 }
46 table {
47 border-collapse: collapse;
48 }
49
50 td, th {
51 border: 1px solid gray;
52 }
53 </style>
54 <template>
55 <div>
56 <streamed-graph url="graph/events" graph="{{graph}}"></streamed-graph>
57 <!-- also get a graph of users so we can look up cards -->
58 </div>
59
60 <iron-ajax id="rewrite" url="rewrite" method="POST"></iron-ajax>
61
62 Current reads:
63 <table>
64 <tr><th>Card UID</th><th>Card text</th><th></th></tr>
65 <template is="dom-repeat" items="{{currentReads}}">
66 <tr>
67 <td>{{item.uidDisplay}}</td>
68 <td>{{item.text}}</td>
69 <td>
70 <div id="form">
71 <button on-click="rewrite">Rewrite</button>
72 </div>
73 </td>
74 </tr>
75 </template>
76 </table>
77
78 </template>
79 <script>
80 HTMLImports.whenReady(function () {
81 Polymer({
82 is: 'rfid-control',
83 properties: {
84 graph: { type: Object, notify: true, observer: "_onGraph" },
85 currentReads: { type: Array, value: [] },
86 },
87 behaviors: [BigastUri],
88 _onGraph: function(graph) {
89 if (!graph.graph) return;
90 const env = graph.graph.store.rdf;
91
92 this.splice('currentReads', 0, this.currentReads.length);
93 graph.graph.quadStore.quads(
94 {subject: env.createNamedNode('room:frontDoorWindowRfid'),
95 predicate: env.createNamedNode('room:reading'),
96 },
97 (q) => {
98 graph.graph.quadStore.quads(
99 {subject: q.object,
100 predicate: env.createNamedNode('room:cardText'),
101 },
102 (q2) => {
103 this.push(
104 'currentReads', {
105 'cardUid': q.object,
106 'uidDisplay': q.object.toString().replace(/.*\//, ""),
107 'text': q2.object.toString()
108 });
109 });
110 });
111 },
112 rewrite: function(ev) {
113 const cardUid = ev.model.item.cardUid;
114
115 // ask for user first
116
117 this.$.rewrite.contentType = "application/json";
118 this.$.rewrite.body = {'cardUid': cardUid.toString(),
119 'user': "some foaf"};
120 this.$.rewrite.generateRequest();
121 }
122 });
123 });
124 </script>
125 </dom-module>
126 <rfid-control></rfid-control> 36 <rfid-control></rfid-control>
127 </body> 37 </body>
128 </html> 38 </html>