changeset 1595:013cbd7a0f08

choice-type attrs in live Ignore-this: 6c762ec4b8f93c4700edbb080990eb5f
author Drew Perttula <drewp@bigasterisk.com>
date Sat, 03 Jun 2017 09:20:04 +0000
parents 2dde8da33662
children 7d5d6e7bc526
files bin/collector light9/collector/device.py light9/web/graph.coffee light9/web/live/index.html light9/web/live/live.coffee light9/web/resource-display.html
diffstat 6 files changed, 30 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/bin/collector	Fri Jun 02 07:32:58 2017 +0000
+++ b/bin/collector	Sat Jun 03 09:20:04 2017 +0000
@@ -32,7 +32,11 @@
     body = json.loads(msg)
     settings = []
     for device, attr, value in body['settings']:
-        settings.append((URIRef(device), URIRef(attr), Literal(value)))
+        if isinstance(value, basestring) and value.startswith('http'):
+            value = URIRef(value)
+        else:
+            value = Literal(value)
+        settings.append((URIRef(device), URIRef(attr), value))
     return body['client'], body['clientSession'], settings, body['sendTime']
 
 def startZmq(port, collector):
--- a/light9/collector/device.py	Fri Jun 02 07:32:58 2017 +0000
+++ b/light9/collector/device.py	Sat Jun 03 09:20:04 2017 +0000
@@ -104,6 +104,7 @@
             return 3
         if deviceAttrSettings.get(attr) == L9['g2']:
             return 10
+        return 0
         
     if deviceType == L9['ChauvetColorStrip']:
         r, g, b = rgbAttr(L9['color'])
--- a/light9/web/graph.coffee	Fri Jun 02 07:32:58 2017 +0000
+++ b/light9/web/graph.coffee	Sat Jun 03 09:20:04 2017 +0000
@@ -253,6 +253,13 @@
   uriValue: (s, p) ->
     @_singleValue(s, p)
 
+  labelOrTail: (uri) ->
+    try
+      @graph.stringValue(uri, @graph.Uri('rdfs:label'))
+    catch
+      words = uri.split('/')
+      words[words.length-1]
+
   objects: (s, p) ->
     @_autoDeps.askedFor(s, p, null, null)
     quads = @graph.findByIRI(s, p)
--- a/light9/web/live/index.html	Fri Jun 02 07:32:58 2017 +0000
+++ b/light9/web/live/index.html	Sat Jun 03 09:20:04 2017 +0000
@@ -43,9 +43,10 @@
           <button on-click="goBlack">black</button>
         </template>
         <template is="dom-if" if="{{deviceAttr.useChoice}}">
-          <select size="10">
+          <select size$="{{deviceAttr.choiceSize}}" value="{{pickedChoice::change}}">
+            <option value="">None</option>
             <template is="dom-repeat" items="{{deviceAttr.choices}}">
-              <option>item {{item}}</option>
+              <option value="{{item.uri}}">{{item.label}}</option>
             </template>
           </select>
         </template>
--- a/light9/web/live/live.coffee	Fri Jun 02 07:32:58 2017 +0000
+++ b/light9/web/live/live.coffee	Sat Jun 03 09:20:04 2017 +0000
@@ -10,6 +10,7 @@
     
     immediateSlider: { notify: true, observer: 'onSlider' }
     pickedColor: { observer: 'onPickedColor' }
+    pickedChoice: { observer: 'onChange' }
   observers: [
     'onChange(value)'
     ]
@@ -19,9 +20,6 @@
   onSlider: -> @value = @immediateSlider
   goWhite: -> @value = "#ffffff"
   goBlack: -> @value = "#000000"
-  onChoice: (ev) ->
-    console.log('ch', ev)
-  
   onChange: (value) ->
     @lastSent = [[@device, @deviceAttr.uri, value]]
     @resend()
@@ -38,7 +36,6 @@
   properties:
     graph: { type: Object, notify: true }
     uri: { type: String, notify: true }
-    label: { type: String, notify: true }
     deviceClass: { type: String, notify: true }
     deviceAttrs: { type: Array, notify: true }
   observers: [
@@ -48,13 +45,7 @@
     @graph.runHandler(@update.bind(@), "#{@uri} update")
   update: ->
     U = (x) => @graph.Uri(x)
-
-    @zlabel = (try
-        @graph.stringValue(@uri, U('rdfs:label'))
-      catch
-        words = @uri.split('/')
-        words[words.length-1]
-        )
+    
     @deviceClass = @graph.uriValue(@uri, U('rdf:type'))
     
     @deviceAttrs = []
@@ -70,9 +61,10 @@
 
       else if dataType == U(':choice')
         daRow.useChoice = true
-        daRow.choices = @graph.objects(da, U(':choice'))
+        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')
--- a/light9/web/resource-display.html	Fri Jun 02 07:32:58 2017 +0000
+++ b/light9/web/resource-display.html	Sat Jun 03 09:20:04 2017 +0000
@@ -38,8 +38,8 @@
    Polymer({
        is: "resource-display",
        properties: {
-           graph: { type: Object },
-           uri: { type: String },
+           graph: { type: Object, notify: true },
+           uri: { type: String, notify: true },
            label: { type: String },
            rename: { type: Boolean },
            renameTo: { type: String, notify: true },
@@ -48,10 +48,14 @@
            this.graph.runHandler(this.setLabel.bind(this), `label ${this.uri}`);
        },
        setLabel: function() {
-           this.label = this.graph.stringValue(this.uri,
-                                               this.graph.Uri('rdfs:label'));
+           try {
+             this.label = this.graph.stringValue(this.uri,
+                                                 this.graph.Uri('rdfs:label'));
+           } catch(e) {
+               this.label = null;
+           }
            if (!this.label) {
-               this.label = this.uri;
+               this.label = this.uri || "<no uri>";
            }
        },
        onRename: function() {