Changeset - 7d68a9db8319
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 7 years ago 2018-06-08 05:53:04
drewp@bigasterisk.com
working on /live choice attrs and dangling settings
Ignore-this: dca5e4933a06222d7a3dbc43a1e65edc
1 file changed with 20 insertions and 6 deletions:
0 comments (0 inline, 0 general)
light9/web/live/live.coffee
Show inline comments
 
@@ -72,12 +72,14 @@ coffeeElementSetup(class Light9LiveContr
 

	
 
  clear: ->
 
    @pickedChoice = null
 
    @sliderWriteValue = 0
 
    if @deviceAttrRow.useColor
 
      @value = '#000000'
 
    else if @deviceAttrRow.useChoice
 
      @value = @pickedChoice = null
 
    else
 
      @value = @immediateSlider = 0
 
)
 

	
 
coffeeElementSetup(class Light9LiveDeviceControl extends Polymer.Element
 
  @is: "light9-live-device-control"
 
@@ -252,52 +254,60 @@ class GraphToControls
 

	
 
  shouldBeStored: (deviceAttr, value) ->
 
    # this is a bug for zoom=0, since collector will default it to
 
    # stick at the last setting if we don't explicitly send the
 
    # 0. rx/ry similar though not the exact same deal because of
 
    # their remap.
 
    return value != 0 and value != '#000000'
 
    return value? and value != 0 and value != '#000000'
 

	
 
  emptyEffect: ->
 
    new Map(@settings).forEach (row, key) =>
 
      row.onChangeFunc(null)
 
      @_removeEffectSetting(row.setting)
 

	
 
  controlChanged: (device, deviceAttr, value) ->
 
    if not value? or (typeof value == "number" and isNaN(value))
 
    # value is float or #color or (Uri or null)
 
    if (value == undefined or (typeof value == "number" and isNaN(value)) or (not value.id and typeof value == "object"))
 
      throw new Error("controlChanged sent bad value " + value)
 
    effectSetting = @effectSettingLookup(device, deviceAttr)
 
    if @shouldBeStored(deviceAttr, value)
 
      if not effectSetting?
 
        @_addEffectSetting(device, deviceAttr, value)
 
      else
 
        @_patchExistingEffectSetting(effectSetting, deviceAttr, value)
 
    else
 
      @_removeEffectSetting(effectSetting)
 

	
 
  _nodeForValue: (value) ->
 
    if value.id?
 
      return value
 
    return @graph.prettyLiteral(value)
 

	
 
  _addEffectSetting: (device, deviceAttr, value) ->
 
    log('change: _addEffectSetting', deviceAttr.value, value)
 
    U = (x) => @graph.Uri(x)
 
    quad = (s, p, o) => @graph.Quad(s, p, o, @ctx)
 
    effectSetting = @graph.nextNumberedResource(@effect.value + '_set')
 
    @addSettingsRow(device, deviceAttr, effectSetting, value)
 
    addQuads = [
 
      quad(@effect, U(':setting'), effectSetting),
 
      quad(effectSetting, U(':device'),  device),
 
      quad(effectSetting, U(':deviceAttr'), deviceAttr),
 
      quad(effectSetting, valuePred(@graph, deviceAttr), @graph.prettyLiteral(value))
 
      quad(effectSetting, valuePred(@graph, deviceAttr), @_nodeForValue(value))
 
    ]
 
    patch = {addQuads: addQuads, delQuads: []}
 
    log('save', patch)
 
    @graph.applyAndSendPatch(patch)
 

	
 
  _patchExistingEffectSetting: (effectSetting, deviceAttr, value) ->
 
    log('patch existing', effectSetting.value)
 
    @graph.patchObject(effectSetting, valuePred(@graph, deviceAttr), @graph.prettyLiteral(value), @ctx)
 
    log('change: patch existing', effectSetting.value)
 
    @graph.patchObject(effectSetting, valuePred(@graph, deviceAttr), @_nodeForValue(value), @ctx)
 

	
 
  _removeEffectSetting: (effectSetting) ->
 
    U = (x) => @graph.Uri(x)
 
    log('change: _removeEffectSetting', effectSetting.value)
 
     U = (x) => @graph.Uri(x)
 
    quad = (s, p, o) => @graph.Quad(s, p, o, @ctx)
 
    if effectSetting?
 
      toDel = [quad(@effect, U(':setting'), effectSetting, @ctx)]
 
      for q in @graph.graph.getQuads(effectSetting)
 
        toDel.push(q)
 
      @graph.applyAndSendPatch({delQuads: toDel, addQuads: []})
 
@@ -326,12 +336,16 @@ coffeeElementSetup(class Light9LiveContr
 
    @currentSettings = {}
 

	
 
  onGraph: ->
 
    @graphToControls = new GraphToControls(@graph)
 
    @graph.runHandler(@update.bind(@), 'Light9LiveControls update')
 

	
 
    effect = new URL(window.location.href).searchParams.get('effect')
 
    if effect?
 
      @effectChoice = effect
 

	
 
  effectSettingLookup: (device, attr) ->
 
    if @graphToControls == null
 
      throw new Error('not ready')
 
    return @graphToControls.effectSettingLookup(device, attr)
 

	
 
  newEffect: ->
0 comments (0 inline, 0 general)