Files
@ 013cbd7a0f08
Branch filter:
Location: light9/light9/web/live/live.coffee
013cbd7a0f08
5.1 KiB
text/coffeescript
choice-type attrs in live
Ignore-this: 6c762ec4b8f93c4700edbb080990eb5f
Ignore-this: 6c762ec4b8f93c4700edbb080990eb5f
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | log = console.log
Polymer
is: 'light9-live-control'
properties:
device: { type: String }
deviceAttr: { type: Object }
max: { type: Number, value: 1 }
value: { type: Object, notify: true }
immediateSlider: { notify: true, observer: 'onSlider' }
pickedColor: { observer: 'onPickedColor' }
pickedChoice: { observer: 'onChange' }
observers: [
'onChange(value)'
]
ready: ->
onPickedColor: (ev) -> @value = ev.target.value
onSlider: -> @value = @immediateSlider
goWhite: -> @value = "#ffffff"
goBlack: -> @value = "#000000"
onChange: (value) ->
@lastSent = [[@device, @deviceAttr.uri, value]]
@resend()
resend: ->
window.gather(@lastSent)
clear: ->
if @deviceAttr.useColor
@value = '#000000'
else
@value = @immediateSlider = 0
Polymer
is: "light9-live-device-control"
properties:
graph: { type: Object, notify: true }
uri: { type: String, notify: true }
deviceClass: { type: String, notify: true }
deviceAttrs: { type: Array, notify: true }
observers: [
'onGraph(graph)'
]
onGraph: ->
@graph.runHandler(@update.bind(@), "#{@uri} update")
update: ->
U = (x) => @graph.Uri(x)
@deviceClass = @graph.uriValue(@uri, U('rdf:type'))
@deviceAttrs = []
for da in _.unique(_.sortBy(@graph.objects(@deviceClass, U(':deviceAttr'))))
dataType = @graph.uriValue(da, U(':dataType'))
daRow = {
uri: da
dataType: dataType
showColorPicker: dataType == U(':color')
}
if dataType == 'http://light9.bigasterisk.com/color'
daRow.useColor = true
else if dataType == U(':choice')
daRow.useChoice = true
choiceUris = _.sortBy(@graph.objects(da, U(':choice')))
daRow.choices = ({uri: x, label: @graph.labelOrTail(x)} for x in choiceUris)
daRow.choiceSize = Math.min(choiceUris.length + 1, 10)
else
daRow.useSlider = true
daRow.max = 1
if dataType == U(':angle')
# varies
daRow.max = 1
@push('deviceAttrs', daRow)
Polymer
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 }
newEffectName: { type: String, notify: true }
observers: [
'onGraph(graph)'
]
ready: ->
@currentSettings = {}
@effectPreview = JSON.stringify({})
window.gather = (sent) =>
[dev, devAttr, value] = sent[0]
key = dev + " " + devAttr
# 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.
if value == 0 or value == '#000000'
delete @currentSettings[key]
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
U = (x) => @graph.Uri(x)
effectUri = U(":effect") + "/#{uriName}"
ctx = U("http://light9.bigasterisk.com/show/dance2017/effect/#{uriName}")
quad = (s, p, o) => {subject: s, predicate: p, object: o, graph: ctx}
addQuads = [
quad(effectUri, U('rdf:type'), U(':Effect'))
quad(effectUri, U('rdfs:label'), @graph.Literal(@newEffectName))
quad(effectUri, U(':publishAttr'), U(':strength'))
]
settings = @graph.nextNumberedResources(effectUri + '_set', @currentSettingsList().length)
for row in @currentSettingsList()
if row[2] == 0 or row[2] == '#000000'
continue
setting = settings.shift()
addQuads.push(quad(effectUri, U(':setting'), setting))
addQuads.push(quad(setting, U(':device'), row[0]))
addQuads.push(quad(setting, U(':deviceAttr'), row[1]))
scaledAttributeTypes = [U(':color'), U(':brightness'), U(':uv')]
value = if typeof(row[2]) == 'number'
@graph.LiteralRoundedFloat(row[2])
else
@graph.Literal(row[2])
settingType = if row[1] in scaledAttributeTypes then U(':scaledValue') else U(':value')
addQuads.push(quad(setting, settingType, value))
patch = {addQuads: addQuads, delQuads: []}
log('save', patch)
@graph.applyAndSendPatch(patch)
@newEffectName = ''
onGraph: ->
@graph.runHandler(@update.bind(@))
resendAll: ->
for llc in @getElementsByTagName("light9-live-control")
llc.resend()
clearAll: ->
for llc in @getElementsByTagName("light9-live-control")
llc.clear()
update: ->
U = (x) => @graph.Uri(x)
@set('devices', [])
for dc in _.sortBy(@graph.subjects(U('rdf:type'), U(':DeviceClass')))
for dev in _.sortBy(@graph.subjects(U('rdf:type'), dc))
@push('devices', {uri: dev})
|