Mercurial > code > home > repos > homeauto
annotate service/arduinoNode/static/output-widgets.html @ 228:f609e1eee4db
add synced graph-view to the bottom of arduinoNode/piNode tester page
Ignore-this: 78a82a81ca80b3499d7bf13faf0e114b
author | drewp@bigasterisk.com |
---|---|
date | Tue, 26 Jan 2016 03:46:05 -0800 |
parents | f8ffb9d8d982 |
children | 4ebb5cc30002 |
rev | line source |
---|---|
193 | 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="/lib/polymer/1.0.9/color-picker-element/dist/color-picker.html"> | |
4 <link rel="import" href="/room/ari/static/rdf-uri.html"> | |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
5 |
193 | 6 <dom-module id="output-sender"> |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
7 <template> |
218
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
8 <iron-ajax id="graphGet" url="../graph" method="GET" headers='{"Accept": "application/ld+json"}'></iron-ajax> |
193 | 9 <iron-ajax id="output" url="../output" method="PUT"></iron-ajax> |
10 Set <a href$="{{subj}}">{{compactUri(subj)}}</a>'s | |
11 <span>{{compactUri(pred)}}</span> to | |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
12 </template> |
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
13 <script> |
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
14 Polymer({ |
193 | 15 is: 'output-sender', |
16 behaviors: [BigastUri], | |
17 properties: { | |
18 subj: { notify: true }, | |
19 pred: { notify: true }, | |
218
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
20 value: { notify: true, observer: 'valueChanged' } |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
21 }, |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
22 ready: function() { |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
23 this.waitOnChangeMs = 100; |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
24 this.smallestRequestPeriodMs = 200; |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
25 this.synced = false; |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
26 |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
27 this.newRequestNeedsSending = false; |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
28 this.lastSendMs = 0; |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
29 this.$.output.addEventListener('response', this.onResponse.bind(this)); |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
30 |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
31 this.loadInitialValue(); |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
32 }, |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
33 loadInitialValue: function() { |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
34 this.$.graphGet.addEventListener('response', function(ev) { |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
35 ev.target.removeEventListener(ev.type, arguments.callee); |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
36 |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
37 ev.detail.response.forEach(function(row) { |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
38 var subj = row['@id']; |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
39 if (subj == this.subj) { |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
40 Object.keys(row).forEach(function(pred) { |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
41 if (pred == this.pred) { |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
42 row[pred].forEach(function(obj) { |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
43 this.value = obj['@value']; |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
44 this.synced = true; |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
45 }.bind(this)); |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
46 } |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
47 }.bind(this)); |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
48 } |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
49 }.bind(this)); |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
50 |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
51 }.bind(this)); |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
52 this.$.graphGet.generateRequest(); |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
53 }, |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
54 onResponse: function() { |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
55 if (!this.newRequestNeedsSending) { |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
56 return; |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
57 } |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
58 if (this.$.output.activeRequests.length > 0) { |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
59 return; // 'response' event will call us back |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
60 } |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
61 |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
62 var now = Date.now(), dt = now - this.lastSendMs; |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
63 if (dt < this.smallestRequestPeriodMs) { |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
64 setTimeout(this.onResponse.bind(this), |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
65 this.smallestRequestPeriodMs - dt); |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
66 return; |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
67 } |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
68 this.newRequestNeedsSending = false; |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
69 this.lastSendMs = now; |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
70 this.$.output.generateRequest(); |
193 | 71 }, |
72 valueChanged: function () { | |
73 if (!this.subj || !this.pred) { | |
74 return; | |
75 } | |
187
fc5fdcc3ed4a
board control ui: output-rgb, fix ajax protocol, display output uris
drewp@bigasterisk.com
parents:
173
diff
changeset
|
76 //this.$.output.headers = {'content-type': ...} |
193 | 77 this.$.output.params = {s: this.subj, p: this.pred}; |
187
fc5fdcc3ed4a
board control ui: output-rgb, fix ajax protocol, display output uris
drewp@bigasterisk.com
parents:
173
diff
changeset
|
78 this.$.output.body = this.value; |
218
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
79 this.newRequestNeedsSending = true; |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
80 setTimeout(this.onResponse.bind(this), this.waitOnChangeMs); |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
81 } |
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
82 }); |
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
83 </script> |
193 | 84 </dom-module> |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
85 |
193 | 86 <dom-module id="output-rgb"> |
187
fc5fdcc3ed4a
board control ui: output-rgb, fix ajax protocol, display output uris
drewp@bigasterisk.com
parents:
173
diff
changeset
|
87 <template> |
218
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
88 <div style="display: flex"> |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
89 <div> |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
90 <output-sender subj="{{subj}}" pred="{{pred}}" value="{{value}}"></output-sender> |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
91 <div>color pick <span>{{value}}</span> |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
92 <button on-click="black">Black</button> |
193 | 93 <button on-click="white">White</button> |
218
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
94 </div> |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
95 </div> |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
96 <div> |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
97 <color-picker id="pick" width="200" height="100" color="{{value}}"></color-picker> |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
98 </div> |
f8ffb9d8d982
multi-boards on one service, new devices, devices return their current
drewp@bigasterisk.com
parents:
193
diff
changeset
|
99 </div> |
193 | 100 </template> |
101 <script> | |
102 Polymer({ | |
103 is: 'output-rgb', | |
104 properties: { | |
105 value: { notify: true }, | |
106 }, | |
107 ready: function () { | |
108 this.$.pick.addEventListener('colorselected', function (ev) { | |
109 this.value = ev.detail.hex; | |
110 }.bind(this)); | |
111 }, | |
112 black: function() {this.value = "#000000";}, | |
113 white: function() {this.value = "#ffffff";} | |
114 }); | |
115 </script> | |
116 </dom-module> | |
117 | |
118 <dom-module id="output-slider"> | |
119 <template> | |
120 <output-sender subj="{{subj}}" pred="{{pred}}" value="{{value}}"></output-sender> | |
121 <input type="range" min="{{min}}" max="{{max}}" step="{{step}}" value="{{value::input}}"> <span>{{value}}</span> | |
187
fc5fdcc3ed4a
board control ui: output-rgb, fix ajax protocol, display output uris
drewp@bigasterisk.com
parents:
173
diff
changeset
|
122 </template> |
fc5fdcc3ed4a
board control ui: output-rgb, fix ajax protocol, display output uris
drewp@bigasterisk.com
parents:
173
diff
changeset
|
123 <script> |
fc5fdcc3ed4a
board control ui: output-rgb, fix ajax protocol, display output uris
drewp@bigasterisk.com
parents:
173
diff
changeset
|
124 Polymer({ |
193 | 125 is: 'output-slider', |
126 properties: { | |
127 max: { notify: true }, | |
128 min: { notify: true }, | |
129 step: { notify: true } | |
130 }, | |
187
fc5fdcc3ed4a
board control ui: output-rgb, fix ajax protocol, display output uris
drewp@bigasterisk.com
parents:
173
diff
changeset
|
131 }); |
fc5fdcc3ed4a
board control ui: output-rgb, fix ajax protocol, display output uris
drewp@bigasterisk.com
parents:
173
diff
changeset
|
132 </script> |
193 | 133 </dom-module> |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
134 |
193 | 135 <!-- |
136 TODO(polyup): Inheriting from other custom elements is not yet supported. | |
137 See: https://www.polymer-project.org/1.0/docs/migration.html#inheritance | |
138 --> | |
139 <dom-module id="output-fixed-text"> | |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
140 <template> |
193 | 141 <output-sender subj="{{subj}}" pred="{{pred}}" value="{{value}}"></output-sender> |
142 <textarea rows="{{rows}}" cols="{{cols}}" value="{{value::input}}"></textarea> | |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
143 </template> |
193 | 144 <script> |
145 Polymer({ | |
146 is: 'output-fixed-text', | |
147 properties: { | |
148 cols: { notify: true }, | |
149 rows: { notify: true } | |
150 }, | |
151 }); | |
152 </script> | |
153 </dom-module> | |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
154 |
193 | 155 <dom-module id="output-switch"> |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
156 <template> |
193 | 157 <output-sender subj="{{subj}}" pred="{{pred}}" value="{{value}}"></output-sender> |
158 <input type="checkbox" checked="{{check::change}}"> <span>{{value}}</span> | |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
159 </template> |
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
160 <script> |
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
161 Polymer({ |
193 | 162 is: 'output-switch', |
163 properties: { | |
164 check: { | |
165 type: Boolean, | |
166 value: false, | |
167 observer: 'checkChanged' | |
168 }, | |
169 value: { notify: true } | |
170 }, | |
171 checkChanged: function () { | |
172 this.value = this.check ? 'high' : 'low'; | |
173 }, | |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
174 }); |
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
175 </script> |
193 | 176 </dom-module> |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
177 |
193 | 178 <dom-module id="output-widget-any"> |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
179 <template></template> |
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
180 <script> |
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
181 Polymer({ |
193 | 182 is: 'output-widget-any', |
183 properties: { | |
184 desc: { type: Object, notify: true } | |
185 }, | |
186 ready: function () { | |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
187 var elem = document.createElement(this.desc.element); |
193 | 188 this.appendChild(elem); |
170
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
189 for (var k of Object.keys(this.desc)) { |
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
190 elem.setAttribute(k, this.desc[k]); |
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
191 } |
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
192 } |
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
193 }); |
376599552a4c
polymer board debug page with working output widgets
drewp@bigasterisk.com
parents:
diff
changeset
|
194 </script> |
193 | 195 </dom-module> |