changeset 1660:71ee518b18bf

try to make live page able to load and resave effects, but it's not going to work like this. Needs bigger rewrite Ignore-this: c04d573041a132d12c7da1e5b7dea44f
author drewp@bigasterisk.com
date Sat, 10 Jun 2017 23:36:09 +0000
parents 16e0af42613f
children d8ccc0df69de
files light9/web/live/index.html light9/web/live/live.coffee
diffstat 2 files changed, 40 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/light9/web/live/index.html	Sat Jun 10 23:35:16 2017 +0000
+++ b/light9/web/live/index.html	Sat Jun 10 23:36:09 2017 +0000
@@ -17,14 +17,15 @@
     <script src="/lib/async/dist/async.js"></script>
     <script src="/lib/underscore/underscore-min.js"></script>
     <!-- see live.coffee
-    <script src="/lib/jquery/dist/jquery.js"></script>
-    <script src="/lib/isotope/dist/isotope.pkgd.min.js"></script>
-    <script src="/lib/isotope-fit-columns/fit-columns.js"></script>
-    <script src="/lib/jquery.columnizer/src/jquery.columnizer.js"></script>
-    -->
+         <script src="/lib/jquery/dist/jquery.js"></script>
+         <script src="/lib/isotope/dist/isotope.pkgd.min.js"></script>
+         <script src="/lib/isotope-fit-columns/fit-columns.js"></script>
+         <script src="/lib/jquery.columnizer/src/jquery.columnizer.js"></script>
+       -->
     <link rel="import" href="../rdfdb-synced-graph.html">
-    <link rel="import" href="/resource-display.html">
-    <link rel="import" href="/light9-color-picker.html">
+    <link rel="import" href="../resource-display.html">
+    <link rel="import" href="../light9-color-picker.html">
+    <link rel="import" href="../edit-choice.html">
   </head>
   <body>
     <style>
@@ -255,6 +256,7 @@
           <div>
             effect name: <input type="input" value="{{newEffectName::change}}">
             <button on-click="saveNewEffect">save new effect</button>
+            <edit-choice graph="{{graph}}" uri="{{effect}}"></edit-choice>
           </div>
           <textarea id="preview" value="{{effectPreview}}"></textarea>
         </div>
--- a/light9/web/live/live.coffee	Sat Jun 10 23:35:16 2017 +0000
+++ b/light9/web/live/live.coffee	Sat Jun 10 23:36:09 2017 +0000
@@ -91,8 +91,10 @@
     currentSettings: { type: Object, notify: true } # dev+attr: [dev, attr, value]
     effectPreview: { type: String, notify: true }
     newEffectName: { type: String, notify: true }
+    effect: { type: String, notify: true } # the one being edited, if any
   observers: [
     'onGraph(graph)'
+    'onEffect(effect)'
     ]
   ready: ->
     @currentSettings = {}
@@ -119,37 +121,56 @@
       
   sendAll: ->
     @client.send(@currentSettingsList())
-      
+
+  valuePred: (attr) ->
+    U = (x) => @graph.Uri(x)
+    scaledAttributeTypes = [U(':color'), U(':brightness'), U(':uv')]
+    if attr in scaledAttributeTypes then U(':scaledValue') else U(':value')
+
+  onEffect: ->
+    U = (x) => @graph.Uri(x)
+    return unless @effect
+    log('load', @effect)
+    for s in @graph.objects(@effect, U(':setting'))
+      dev = @graph.uriValue(s, U(':device'))
+      devAttr = @graph.uriValue(s, U(':deviceAttr'))
+
+      pred = @valuePred(devAttr)
+      try
+        value = @graph.floatValue(s, pred)
+      catch
+        value = @graph.stringValue(s, pred)
+      log('got', devAttr, value)
+      window.gather([[dev, devAttr, value]])
+            
   saveNewEffect: ->
     uriName = @newEffectName.replace(/[^a-zA-Z0-9_]/g, '')
     return if not uriName.length
 
     U = (x) => @graph.Uri(x)
 
-    effectUri = U(":effect") + "/#{uriName}"
+    @effect = 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'))
+      quad(@effect, U('rdf:type'), U(':Effect'))
+      quad(@effect, U('rdfs:label'), @graph.Literal(@newEffectName))
+      quad(@effect, U(':publishAttr'), U(':strength'))
       ]
-    settings = @graph.nextNumberedResources(effectUri + '_set', @currentSettingsList().length)
+    settings = @graph.nextNumberedResources(@effect + '_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(@effect, 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))
+      addQuads.push(quad(setting, @valuePred(row[1]), value))
       
     patch = {addQuads: addQuads, delQuads: []}
     log('save', patch)