Supports slug parsing and slug URLs.
authordsc <dsc@wikimedia.org>
Wed, 7 Mar 2012 18:59:05 +0000 (10:59 -0800)
committerdsc <dsc@wikimedia.org>
Wed, 7 Mar 2012 18:59:05 +0000 (10:59 -0800)
docs/todo.md
lib/main.co
lib/server/server.co
lib/vis/vis-model.co
lib/vis/vis-view.co

index 135365f..0a54206 100644 (file)
@@ -3,13 +3,8 @@
 
 ## bugs
 
-- defaults should only be filtered out for toURL() and toJSON()
 - redraw button!
-- valueFormatter, axisLabelFormatter
 - (Safari) dygraph on safari has a bug parsing dates, bug http://code.google.com/p/dygraphs/issues/detail?id=287
-- (Chrome) When changing a checkbox, the graph doesn't seem to get updated. The model is updated though, and when a non-checkbox option is modified the checkbox-option is also updated in the view
-    - E.g. when setting showRoller=true , the input doesn't get displayed right away. Also, when resetting to showRoller=false it doesn't disappear 
-- huge issues coordinating subview insertion of HTML blocks -- need to add events and provide an abstraction
 
 
 ## ux
index 70da9c1..1cf6af4 100644 (file)
@@ -33,22 +33,18 @@ main = ->
         console.log 'StateChange!\n\n', String(root.location), '\n\n'
     
     
-    # If we got querystring args, apply them to the graph
     data = {}
-    if String(root.location).split '?' .1
+    
+    # Process URL
+    loc = String root.location
+    
+    # If we got querystring args, apply them to the graph
+    if loc.split '?' .1
         data = _.uncollapseObject _.fromKV that.replace('#', '%23')
-        
-        # # yarr, have to do options separately or everything goes to shit
-        # options = delete data.options
-        # graph.model.set data, {+silent}
-        # graph.chartOptions options, {+silent}
-        # # Flush all changes once the DOM settles
-        # _.delay do
-        #     ->
-        #         graph.change()
-        #         # graph.scaffold.invoke 'change'
-        #     50
     
+    # Extract slug from URL
+    if match = /\/graph\/(?!view)([^\/?]+)/i.exec loc
+        data.slug = match[1]
     
     vis   = root.vis   = new VisModel data
     graph = root.graph = new VisView do
index b4cf71c..44c8d93 100755 (executable)
@@ -132,7 +132,7 @@ app.get '/graph/:slug/?', (req, res, next) ->
     # console.log '  slug:  ', slug
     # console.log '  params:', req.params
     unless _.str.include slug, '.'
-        {pathname, search} = req.info
+        {pathname, search or ''} = req.info
         req.url = "#pathname/view#search"
         req.params.action = 'view'
     next()
index c534e1d..380bfc0 100644 (file)
@@ -89,8 +89,9 @@ VisModel = exports.VisModel = BaseModel.extend do # {{{
         json
     
     
-    toKVPairs: ->
+    toKVPairs: (keepSlug=false) ->
         kvo = @toJSON()
+        delete kvo.slug unless keepSlug
         # console.group 'toKVPairs'
         # console.log '[IN]', JSON.stringify kvo
         opts = kvo.options = _.clone kvo.options
@@ -105,6 +106,17 @@ VisModel = exports.VisModel = BaseModel.extend do # {{{
         # console.groupEnd()
         _.collapseObject kvo
     
+    toKV: (keepSlug=false) ->
+        _.toKV @toKVPairs keepSlug
+    
+    
+    /**
+     * @returns {String} URL identifying this model.
+     */
+    toURL: ->
+        slug = @get 'slug', ''
+        slug = "/#slug" if slug
+        "/graph#slug?#{@toKV(false)}"
     
     toString: -> "#{@ctorName}(id=#{@id})"
 
index 6b13eba..8e3e86c 100644 (file)
@@ -68,7 +68,7 @@ VisView = exports.VisView = BaseView.extend do # {{{
         @scaffold.collection.reset that if o.graph_spec
         
         @scaffold.on 'change', (scaffold, value, key, field) ~>
-            console.log "scaffold.change!", key, value, field
+            # console.log "scaffold.change!", key, value
             @model.setOption key, value, {+silent} #unless field.isDefault()
         
         options = @model.get 'options', {}