Mercurial > code > home > repos > homeauto
view service/frontDoorLock/index.html @ 1455:1a7cd0cff3eb
rename store's graph uri
Ignore-this: dc2e863eb429456f9d642b53bbae1cc4
darcs-hash:a7cf4772cf49ddbea9dc04d903a597893ff25653
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Wed, 25 Sep 2019 17:33:32 -0700 |
parents | baf1acaa9ac9 |
children | 013e2a89b345 |
line wrap: on
line source
<!doctype html> <html> <head> <title>front door lock</title> <meta charset="utf-8" /> <meta name="mobile-web-app-capable" content="yes"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="/lib/polymer/1.0.9/webcomponentsjs/webcomponents.min.js"></script> <script src="/lib/require/require-2.3.3.js"></script> <script src="/rdf/common_paths_and_ns.js"></script> <link rel="import" href="/rdf/streamed-graph.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"> </head> <body> <dom-module id="door-control"> <style> button { min-width: 60px; min-height: 40px; } div#form { margin: 2px; background: #dff5e5; padding: 10px; line-height: 30px; text-align: center; border: 2px groove white; } .invis-true { visibility: hidden; } </style> <template> <h1>Front door lock</h1> <div id="form"> <div> Door is {{lockState}} </div> <rdf-oneshot id="unlockOneshot" post="output" subject="room:frontDoorLock" predicate="room:state" object="room:unlocked" ></rdf-oneshot> <button on-click="unlock" disabled$="[[!isLocked]]">Unlock 10 seconds</button> <div class$="invis-[[!autoLockIsComing]]"> Locking in {{autoLockInSec}} </div> <div> <rdf-oneshot id="hold" post="/store/values" subject="room:frontDoorLockRequest" predicate="room:state" object="room:unlocked" ></rdf-oneshot> <template is="dom-if" if="{{!isHeld}}"> <button on-click="hold">Hold unlocked</button> </template> <rdf-oneshot id="releaseHold" post="/store/values" subject="room:frontDoorLockRequest" predicate="room:state" object="room:unset" ></rdf-oneshot> <rdf-oneshot id="lockNow" post="output" subject="room:frontDoorLock" predicate="room:state" object="room:locked" ></rdf-oneshot> <template is="dom-if" if="{{isHeld}}"> <button on-click="releaseHold">Release hold; lock door</button> </template> </div> </div> <div> <streamed-graph url="graph/events" graph="{{graph}}"></streamed-graph> <streamed-graph url="/store/store/events" graph="{{storeGraph}}"></streamed-graph> </div> </template> <script> HTMLImports.whenReady(function () { Polymer({ is: 'door-control', properties: { graph: { type: Object, notify: true, observer: "_onGraph" }, storeGraph: { type: Object, notify: true, observer: "_onStoreGraph" }, lockState: { type: String }, autoLockIsComing: { type: Boolean }, autoLockInSec: { type: String}, isHeld: { type: Boolean }, }, behaviors: [BigastUri], _onGraph: function(graph) { if (!graph.graph) return; const env = graph.graph.store.rdf; const unlocked = env.createNamedNode('room:unlocked'); const locked = env.createNamedNode('room:locked'); this.isLocked = null; graph.graph.quadStore.quads( {subject: env.createNamedNode('room:frontDoorLock'), predicate: env.createNamedNode('room:state'), }, (q) => { this.lockState = q.object.toString().replace(/.*\//, ''); this.isLocked = q.object.equals(locked) ? true : (q.object.equals(unlocked) ? false : null); }); this.autoLockIsComing = false; graph.graph.quadStore.quads( {subject: env.createNamedNode('room:frontDoorLock'), predicate: env.createNamedNode('room:autoLockInSec'), }, (q) => { this.autoLockIsComing = true; this.autoLockInSec = parseFloat(q.object.valueOf()); }); }, _onStoreGraph: function(graph) { if (!graph.graph) return; const env = graph.graph.store.rdf; const unlocked = env.createNamedNode('room:unlocked'); const locked = env.createNamedNode('room:locked'); this.isHeld = false; graph.graph.quadStore.quads( {subject: env.createNamedNode('room:frontDoorLockRequest'), predicate: env.createNamedNode('room:state'), }, (q) => { this.isHeld = q.object.equals(unlocked); }); }, unlock: function() { this.$.unlockOneshot.go(); }, hold: function () { this.$.hold.go(); }, releaseHold: function() { this.$.releaseHold.go(); this.$.lockNow.go(); // may race with releaseHold? }, }); }); </script> </dom-module> <door-control></door-control> <template id="t" is="dom-bind"> <streamed-graph url="graph/events" graph="{{graph}}"></streamed-graph> <div id="out"></div> <script type="module" src="/rdf/streamed_graph_view.js"></script> </template> <style> .served-resources { margin-top: 4em; border-top: 1px solid gray; padding-top: 1em; } .served-resources a { padding-right: 2em; } </style> <div class="served-resources"> <a href=".">root</a> <a href="simple/">/simple/</a> <a href="stats/">/stats/</a> <a href="graph">/graph</a> <a href="graph/events">/graph/events</a> <a href="output">(post) output</a> </div> </body> </html>