Mercurial > code > home > repos > light9
changeset 1447:8a9a9b58a4e2
live page now knows that collector needs all settings on each request
Ignore-this: 79ad8d1e001b98b6fce6d14f75f92745
author | drewp@bigasterisk.com |
---|---|
date | Sat, 11 Jun 2016 21:40:37 +0000 |
parents | ba6594263fa7 |
children | 931d2dafca12 |
files | light9/web/light9-collector-client.html light9/web/live/index.html light9/web/live/live.coffee |
diffstat | 3 files changed, 15 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/light9/web/light9-collector-client.html Sat Jun 11 21:29:06 2016 +0000 +++ b/light9/web/light9-collector-client.html Sat Jun 11 21:40:37 2016 +0000 @@ -17,6 +17,7 @@ ready: function() { this.self = this; var self = this; + this.lastSent = []; self.$.put.addEventListener( 'error', function() { self.status = 'err'; }); @@ -29,7 +30,7 @@ self.status = 'ready'; }, ping: function() { - this.send([]); + this.send(this.lastSent); }, send: function(settings) { this.$.put.body = JSON.stringify({ @@ -37,6 +38,7 @@ "client": window.location.href, "clientSession": this.clientSession}); this.$.put.generateRequest(); + this.lastSent = settings.slice(); } }); </script>
--- a/light9/web/live/index.html Sat Jun 11 21:29:06 2016 +0000 +++ b/light9/web/live/index.html Sat Jun 11 21:40:37 2016 +0000 @@ -106,7 +106,6 @@ <div class="deviceAttr"> <span>attr <a href="{{dattr.uri}}">{{dattr.uri}}</a></span> <light9-live-control - client="{{client}}" device="{{device.uri}}" device-attr="{{dattr}}"></light9-live-control> </div>
--- a/light9/web/live/live.coffee Sat Jun 11 21:29:06 2016 +0000 +++ b/light9/web/live/live.coffee Sat Jun 11 21:40:37 2016 +0000 @@ -3,7 +3,6 @@ Polymer is: 'light9-live-control' properties: - client: { type: Object } device: { type: String } deviceAttr: { type: Object } max: { type: Number, value: 1 } @@ -25,7 +24,6 @@ @lastSent = [[@device, @deviceAttr.uri, value]] @resend() resend: -> - @client.send(@lastSent) window.gather(@lastSent) clear: -> if @deviceAttr.useColor @@ -38,6 +36,7 @@ is: "light9-live-controls" properties: graph: { type: Object, notify: true } + client: { type: Object, notify: true } devices: { type: Array, notify: true } currentSettings: { type: Object, notify: true } # dev+attr: [dev, attr, value] effectPreview: { type: String, notify: true } @@ -56,6 +55,14 @@ else @currentSettings[key] = [dev, devAttr, value] @effectPreview = JSON.stringify(v for k,v of @currentSettings) + + @debounce('send', @sendAll.bind(@), 2) + + currentSettingsList: -> (v for k,v of @currentSettings) + + sendAll: -> + @client.send(@currentSettingsList()) + saveNewEffect: -> uriName = @newEffectName.replace(/[^a-zA-Z0-9_]/g, '') return if not uriName.length @@ -71,8 +78,8 @@ quad(effectUri, U('rdfs:label'), @graph.Literal(@newEffectName)) quad(effectUri, U(':publishAttr'), U(':strength')) ] - settings = @graph.nextNumberedResources(effectUri + '_set', Object.keys(@currentSettings).length) - for _, row of @currentSettings + settings = @graph.nextNumberedResources(effectUri + '_set', @currentSettingsList().length) + for row in @currentSettingsList() if row[2] == 0 or row[2] == '#000000' continue setting = settings.shift() @@ -90,6 +97,7 @@ patch = {addQuads: addQuads, delQuads: []} log('save', patch) @graph.applyAndSendPatch(patch) + @newEffectName = '' onGraph: -> @graph.runHandler(@update.bind(@))