Moves presets, fixes routes & views to point to right place
authordsc <dsc@less.ly>
Thu, 1 Mar 2012 17:25:33 +0000 (09:25 -0800)
committerdsc <dsc@less.ly>
Thu, 1 Mar 2012 17:25:54 +0000 (09:25 -0800)
lib/graph/graph-view.co
lib/main.co
lib/scaffold/scaffold-view.co
lib/server/reqinfo.co [new file with mode: 0644]
lib/server/server.co
www/graph/root.yaml [deleted file]
www/graph/test.jade [deleted file]
www/graph/view.co [deleted file]
www/graph/view.jade [new file with mode: 0644]
www/presets/root.yaml [moved from www/graph/presets/root.yaml with 100% similarity]

index e3446d5..c82539d 100644 (file)
@@ -61,7 +61,7 @@ GraphOptionsScaffold = exports.GraphOptionsScaffold = Scaffold.extend do # {{{
     template       : require 'kraken/template/graph-scaffold'
     collectionType : GraphOptionList
     subviewType    : GraphOptionView
-    $fields        : '.fields'
+    fields        : '.fields'
     
     # GraphView will set this
     ready          : false
@@ -76,7 +76,8 @@ GraphOptionsScaffold = exports.GraphOptionsScaffold = Scaffold.extend do # {{{
         # console.log "#this.render() -> .isotope()"
         # @__super__.render ...
         return this unless @ready
-        @$el.find '.options.control-group' .isotope do
+        container = if @fields then @$el.find @fields else @$el
+        container.isotope do
             itemSelector    : '.field.option'
             layoutMode      : 'masonry'
             masonry         : columnWidth : 10
index a90bd2a..fc5a88c 100644 (file)
@@ -56,7 +56,7 @@ main = ->
 
 # Load data files
 Seq([   <[ CHART_OPTIONS_SPEC /graph/dygraph-options.json ]>,
-        <[ ROOT_VIS_DATA /graph/root ]>
+        <[ ROOT_VIS_DATA /presets/root.json ]>
 ])
 .parEach_ (next, [key, url]) ->
     jQuery.ajax do
index d3f4add..2f717d6 100644 (file)
@@ -85,8 +85,8 @@ Scaffold = exports.Scaffold = BaseView.extend do # {{{
         SubviewType = @subviewType
         view = new SubviewType model:field
         @subviews.push view
-        el = if @$fields then @$el.find @$fields else @$el
-        el.append view.render().el unless field.get 'ignore'
+        container = if @fields then @$el.find @fields else @$el
+        container.append view.render().el unless field.get 'ignore'
         view.on 'update', @change.bind(this, field)
         
         @render()
diff --git a/lib/server/reqinfo.co b/lib/server/reqinfo.co
new file mode 100644 (file)
index 0000000..bc9925a
--- /dev/null
@@ -0,0 +1,20 @@
+_   = require 'underscore'
+url = require 'url'
+
+module.exports = exports = (options) ->
+    mw = new ReqInfoMiddleware options
+    mw.respond
+
+class exports.ReqInfoMiddleware
+    
+    (@options={}) ->
+        _.bindAll this, 'respond'
+    
+    parse : url.parse
+    
+    respond : function reqinfo(req, res, next)
+        req.info = @parse req.url
+        next()
+    
+
+
index c44887d..b4cf71c 100755 (executable)
@@ -2,10 +2,14 @@
 
 fs       = require 'fs'
 path     = require 'path'
+{parse}  = require 'url'
 {existsSync:exists} = path
 {exec, spawn} = require 'child_process'
 
 _        = require 'underscore'
+_.str    = require 'underscore.string'
+_.mixin _.str.exports()
+
 Seq      = require 'seq'
 yaml     = require 'js-yaml'
 mime     = require 'mime'
@@ -60,6 +64,9 @@ app.configure ->
     
     app.use express.logger() if LOG_LEVEL is 'DEBUG'
     
+    # Parse URL, fiddle
+    app.use require('./reqinfo')({})
+    
     # Parse form submits into req.params
     app.use express.bodyParser()
     
@@ -109,18 +116,42 @@ app.configure ->
         showStack      : true
 
 
-### Routes
+/* * * *  Routes  * * * {{{ */
 
 app.get '/', (req, res) ->
     res.render 'dashboard'
 
-app.get '/graph/:id', (req, res, next) ->
-    {id} = req.params
-    # console.log req.url
-    if exists("#WWW/graph/#id.yaml") or exists("#WWW/graph/#id.json")
+app.get '/preset/:slug', (req, res, next) ->
+    if exists("#WWW/presets/#slug.yaml") or exists("#WWW/presets/#slug.json")
         req.url += '.json'
     next()
 
+app.get '/graph/:slug/?', (req, res, next) ->
+    {slug} = req.params
+    # console.log '/graph/:slug/?'
+    # console.log '  slug:  ', slug
+    # console.log '  params:', req.params
+    unless _.str.include slug, '.'
+        {pathname, search} = req.info
+        req.url = "#pathname/view#search"
+        req.params.action = 'view'
+    next()
+
+app.get '/graph/:slug/:action/?', (req, res) ->
+    {slug, action} = req.params
+    res.render "graph/#action"
+
+app.get '/:type/:action/?', (req, res, next) ->
+    {type, action} = req.params
+    if path.existsSync "#WWW/#type/#action.jade"
+        res.render "#type/#action"
+    else
+        next()
+
+
+
+# }}}
+/* * * *  Data Source Oracle  * * * {{{ */
 
 YAML_EXT_PAT = /\.ya?ml$/i
 
@@ -175,17 +206,7 @@ app.get '/data/all', (req, res, next) ->
             console.error that if err.stack
             res.send { error:String(err), partial_data:data }
 
-
-app.get '/:type/:action', (req, res, next) ->
-    {type, action} = req.params
-    if path.existsSync "#WWW/#type/#action.jade"
-        res.render "#type/#action"
-    else
-        next()
-
-
-
-
+# }}}
 
 /**
  * Handle webhook notification to pull from origin.
diff --git a/www/graph/root.yaml b/www/graph/root.yaml
deleted file mode 100644 (file)
index 27790ae..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-# The root graph, holding defaults inherited by all graphs.
-
-dataset : '/data/non_mobile_pageviews_by.timestamp.language.csv'
-width   : 'auto'
-height  : 400
-options : 
-    # visibility                   : true
-    # stackedGraph                 : false
-    # fillGraph                    : false
-    colors                         : [ "#FF0097", "#EF8158", "#83BB32", "#182B53", "#4596FF", "#553DC9", "#AD3238", "#00FFBC", "#F1D950" ]
-    # colorSaturation              : 1.0
-    # colorValue                   : 0.5
-    rightGap                       : 20
-    animatedZooms                  : true
-    # labels                       : Array
-    labelsSeparateLines            : true
-    xlabel                         : Date
-    # logscale                     : false
-    axisLineColor                  : '#333333'
-    # axisTickSize                 : 3.0
-    axisLabelColor                 : black
-    # axisLabelFontSize            : 14
-    # labelsKMB                    : false
-    # labelsKMG2                   : false
-    digitsAfterDecimal             : 2
-    maxNumberWidth                 : 6
-    sigFigs                        : 3
-    # valueFormatter               : function(num or millis, opts, dygraph)
-    # showRoller                   : false
-    # rollPeriod                   : 1
-    # sigma                        : 2.0
-    # wilsonInterval               : true
-    # fillAlpha                    : 0.15
-    # customBars                   : false
-    # errorBars                    : false
-    # fractions                    : false
-    # delimiter                    : ','
-    # xValueParser                 : function(str) -> number
-    # drawXGrid                    : true
-    # drawYGrid                    : true
-    gridLineColor                  : '#eeeeee'
-    # gridLineWidth                : 0.3
-    # showRangeSelector            : false
-    # rangeSelectorHeight          : 40
-    # rangeSelectorPlotFillColor   : '#A7B1C4'
-    # rangeSelectorPlotStrokeColor : '#808FAB'
-    displayAnnotations             : true
diff --git a/www/graph/test.jade b/www/graph/test.jade
deleted file mode 100644 (file)
index 5033daa..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-extends ../layout
-
-block title
-    title Kraken: Graph Test Page
-
-append styles
-    mixin css('forms.css')
-    mixin css('graph.css')
-    mixin css('isotope.css')
-
diff --git a/www/graph/view.co b/www/graph/view.co
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/www/graph/view.jade b/www/graph/view.jade
new file mode 100644 (file)
index 0000000..699cfb3
--- /dev/null
@@ -0,0 +1 @@
+include edit
\ No newline at end of file