Mercurial > code > home > repos > homeauto
comparison service/rfid/index.html @ 461:cebc0134254a
last version of rc522 reader; i moved onto pn532 now
Ignore-this: 37d50691ffec46f984a66c185cc27445
author | drewp@bigasterisk.com |
---|---|
date | Sat, 20 Apr 2019 23:33:39 -0700 |
parents | bba6672a0ef8 |
children | b87b6e9cedb2 |
comparison
equal
deleted
inserted
replaced
460:7051b8b4766a | 461:cebc0134254a |
---|---|
1 <!doctype html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title></title> | 4 <title>rfid</title> |
5 <meta charset="utf-8" /> | 5 <meta charset="utf-8" /> |
6 <meta name="mobile-web-app-capable" content="yes"> | |
7 <meta name="viewport" content="width=device-width, initial-scale=1"> | |
8 <script src="/lib/polymer/1.0.9/webcomponentsjs/webcomponents.min.js"></script> | |
9 <script src="/lib/require/require-2.3.3.js"></script> | |
10 <script> | |
11 requirejs.config({ | |
12 paths: { | |
13 "streamed-graph": "/rdf/streamed-graph", | |
14 "quadstore": "/rdf/quadstore", | |
15 "async-module": "/lib/async/80f1793/async", | |
16 "async": "/lib/async/80f1793/async", | |
17 "jsonld-module": "/lib/jsonld.js/0.4.11/js/jsonld", | |
18 "jsonld": "/lib/jsonld.js/0.4.11/js/jsonld", | |
19 "rdfstore": "/lib/rdf_store/0.9.7/dist/rdfstore", | |
20 "moment": "/lib/moment.min", | |
21 "underscore": "/lib/underscore-1.5.2.min", | |
22 } | |
23 }); | |
24 </script> | |
25 <script> | |
26 window.NS = { | |
27 dev: 'http://projects.bigasterisk.com/device/', | |
28 room: 'http://projects.bigasterisk.com/room/', | |
29 rdfs: 'http://www.w3.org/2000/01/rdf-schema#', | |
30 sensor: 'http://bigasterisk.com/homeauto/sensor/', | |
31 }; | |
32 </script> | |
33 <link rel="import" href="/lib/polymer/1.0.9/iron-ajax/iron-ajax.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"> | |
6 </head> | 38 </head> |
7 <body> | 39 <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; | |
8 | 91 |
9 Current read: graph.sensor.card graph.sensor.card.text | 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; | |
10 | 114 |
11 Write new key: [random id] [Write] | 115 // ask for user first |
12 | 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> | |
13 </body> | 127 </body> |
14 </html> | 128 </html> |