changeset 1387:26fabcf3a0a8

relocate nextNumberedResource to SyncedGraph Ignore-this: 16d6678d2b5f5ff34d9cd092ca2dcd46
author Drew Perttula <drewp@bigasterisk.com>
date Thu, 09 Jun 2016 06:40:53 +0000
parents 29a1382de5c8
children 2e47c1b4141a
files light9/web/graph.coffee light9/web/timeline/timeline.coffee
diffstat 2 files changed, 24 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/light9/web/graph.coffee	Thu Jun 09 06:34:28 2016 +0000
+++ b/light9/web/graph.coffee	Thu Jun 09 06:40:53 2016 +0000
@@ -272,4 +272,17 @@
     @_autoDeps.askedFor(s, p, o, null)
     return @graph.findByIRI(s, p, o).length > 0
 
+  nextNumberedResources: (base, howMany) ->
+    results = []
+    # we could cache [base,lastSerial]
+    for serial in [0..1000]
+      uri = @Uri("#{base}#{serial}")
+      if not @contains(uri, null, null)
+        results.push(uri)
+        if results.length >= howMany
+          return results
+    throw new Error("can't make sequential uri with base #{base}")
 
+  nextNumberedResource: (base) ->
+    @nextNumberedResources(base, 1)[0]       
+
--- a/light9/web/timeline/timeline.coffee	Thu Jun 09 06:34:28 2016 +0000
+++ b/light9/web/timeline/timeline.coffee	Thu Jun 09 06:40:53 2016 +0000
@@ -221,38 +221,27 @@
     root = @closest('light9-timeline-editor')
     setupDrop @, @$.rows, root, (effect, pos) =>
 
-      if not @graph.contains(effect, RDF + 'type', @graph.Uri(':Effect'))
+      U = (x) -> @graph.Uri(x)
+      quad = (s, p, o) => {subject: s, predicate: p, object: o, graph: @song}
+
+      # we could probably accept some initial overrides right on the
+      # effect uri, maybe as query params
+      
+      if not @graph.contains(effect, RDF + 'type', U(':Effect'))
         log("drop #{effect} is not an effect")
         return
       
       dropTime = @zoomInX.invert(pos.e(1))
       
-      U = (x) -> @graph.Uri(x)
-
-      nextNumberedResources = (graph, base, howMany) ->
-        results = []
-        # we could cache [base,lastSerial]
-        for serial in [0..1000]
-          uri = graph.Uri("#{base}#{serial}")
-          if not graph.contains(uri, null, null)
-            results.push(uri)
-            if results.length >= howMany
-              return results
-        throw new Error("can't make sequential uri with base #{base}")
-
-      nextNumberedResource = (graph, base) ->
-        nextNumberedResources(graph, base, 1)[0]       
+      newNote = graph.nextNumberedResource("#{@song}/n")
+      newCurve = graph.nextNumberedResource("#{newNote}c")
+      points = graph.nextNumberedResources("#{newCurve}p", 4)
       
-      newNote = nextNumberedResource(graph, "#{@song}/n")
-      newCurve = nextNumberedResource(graph, "#{newNote}c")
-      points = nextNumberedResources(graph, "#{newCurve}p", 4)
-      
-      quad = (s, p, o) => {subject: s, predicate: p, object: o, graph: @song}
-
       curveQuads = [
           quad(@song, U(':note'), newNote)
           quad(newNote, RDF + 'type', U(':Note'))
           quad(newNote, U(':originTime'), @graph.LiteralRoundedFloat(dropTime))
+          quad(newNote, U(':effectClass'), effect)
           quad(newNote, U(':curve'), newCurve)
           quad(newCurve, RDF + 'type', U(':Curve'))
           quad(newCurve, U(':attr'), U(':strength'))
@@ -269,7 +258,6 @@
         addQuads: curveQuads.concat(pointQuads)
         }
       @graph.applyAndSendPatch(patch)
-      log('land', effect, dropTime, newNote)
       
 
 Polymer