Changeset - 26fabcf3a0a8
[Not reviewed]
default
0 2 0
Drew Perttula - 9 years ago 2016-06-09 06:40:53
drewp@bigasterisk.com
relocate nextNumberedResource to SyncedGraph
Ignore-this: 16d6678d2b5f5ff34d9cd092ca2dcd46
2 files changed with 24 insertions and 23 deletions:
0 comments (0 inline, 0 general)
light9/web/graph.coffee
Show inline comments
 
@@ -269,7 +269,20 @@ class window.SyncedGraph
 
    return out
 

	
 
  contains: (s, p, o) ->
 
    @_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]       
 

	
light9/web/timeline/timeline.coffee
Show inline comments
 
@@ -218,44 +218,33 @@ Polymer
 
  ready: ->
 

	
 
  attached: ->
 
    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'))
 
        ]        
 
      pointQuads = []
 
      for i in [0...4]
 
@@ -266,13 +255,12 @@ Polymer
 
      
 
      patch = {
 
        delQuads: []
 
        addQuads: curveQuads.concat(pointQuads)
 
        }
 
      @graph.applyAndSendPatch(patch)
 
      log('land', effect, dropTime, newNote)
 
      
 

	
 
Polymer
 
  is: "light9-timeline-time-axis",
 
  # for now since it's just one line calling dia,
 
  # light9-timeline-editor does our drawing work.
0 comments (0 inline, 0 general)