Fixes saving bug.
authordsc <dsc@wikimedia.org>
Wed, 4 Apr 2012 20:36:30 +0000 (13:36 -0700)
committerdsc <dsc@wikimedia.org>
Wed, 4 Apr 2012 20:36:30 +0000 (13:36 -0700)
lib/graph/graph-edit-view.co
lib/main.co
lib/server/controllers/graph.co

index c95a6e8..92d2ff7 100644 (file)
@@ -114,7 +114,7 @@ GraphEditView = exports.GraphEditView = BaseView.extend do # {{{
     
     save: ->
         console.log "#this.save!"
-        id = @model.id or @model.get('slug')
+        id = @model.get('slug') or @model.id
         @model.save {id}, {+wait}
         false
     
@@ -326,7 +326,7 @@ GraphEditView = exports.GraphEditView = BaseView.extend do # {{{
         changes = @model.changedAttributes()
         options = @model.getOptions()
         # console.log "Graph.changed( options ) ->\n\tchanges: #{JSON.stringify changes}\n\toptions: #{JSON.stringify options}" #"\n\t^opts: #{JSON.stringify _.intersection _.keys(changes), _.keys(options)}"
-        @chart.updateOptions file:that if changes?.dataset
+        @chart?.updateOptions file:that if changes?.dataset
         @chartOptions options, {+silent} if changes?.options
     
     onScaffoldChange: (scaffold, value, key, field) ->
index dffeb9e..61d2da9 100644 (file)
@@ -45,7 +45,7 @@ main = ->
             (v, k) -> [ k, dyglib.parseOption(k,v) ]
     
     # Extract id from URL
-    if match = /\/graph\/(?!view)([^\/?]+)/i.exec loc
+    if match = /\/graphs\/([^\/?]+)/i.exec loc
         data.id = data.slug = match[1]
     
     # _.dump _.clone(data.options), 'data.options'
index 8017081..d557f74 100644 (file)
@@ -32,6 +32,8 @@ class GraphController extends Controller
             parser = yaml.load
         
         err, data <- fs.readFile file, 'utf8'
+        if 'ENOENT' is err?.code
+            return cb null, {}
         if err
             console.error "GraphController.autoload(#id, #{typeof cb}) -->\nerr"
             return cb err
@@ -47,11 +49,17 @@ class GraphController extends Controller
     
     # GET /graphs/:graph
     show: (req, res) ->
-        res.send req.graph
+        if req.format is 'json'
+            res.send req.graph
+        else
+            res.render 'graph/view'
     
     # GET /graphs/:graph/edit
     edit: (req, res) ->
-        res.send req.graph
+        if req.format is 'json'
+            res.send req.graph
+        else
+            res.render 'graph/edit'
     
     # GET /graphs/new
     new: (req, res) ->