From: dsc Date: Thu, 1 Mar 2012 17:25:33 +0000 (-0800) Subject: Moves presets, fixes routes & views to point to right place X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=a8b3a0add8d900bf7f6b00af70e41b0bafc95d41;p=kraken-ui.git Moves presets, fixes routes & views to point to right place --- diff --git a/lib/graph/graph-view.co b/lib/graph/graph-view.co index e3446d5..c82539d 100644 --- a/lib/graph/graph-view.co +++ b/lib/graph/graph-view.co @@ -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 diff --git a/lib/main.co b/lib/main.co index a90bd2a..fc5a88c 100644 --- a/lib/main.co +++ b/lib/main.co @@ -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 diff --git a/lib/scaffold/scaffold-view.co b/lib/scaffold/scaffold-view.co index d3f4add..2f717d6 100644 --- a/lib/scaffold/scaffold-view.co +++ b/lib/scaffold/scaffold-view.co @@ -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 index 0000000..bc9925a --- /dev/null +++ b/lib/server/reqinfo.co @@ -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() + + + diff --git a/lib/server/server.co b/lib/server/server.co index c44887d..b4cf71c 100755 --- a/lib/server/server.co +++ b/lib/server/server.co @@ -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 index 27790ae..0000000 --- a/www/graph/root.yaml +++ /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 index 5033daa..0000000 --- a/www/graph/test.jade +++ /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 index e69de29..0000000 diff --git a/www/graph/view.jade b/www/graph/view.jade new file mode 100644 index 0000000..699cfb3 --- /dev/null +++ b/www/graph/view.jade @@ -0,0 +1 @@ +include edit \ No newline at end of file diff --git a/www/graph/presets/root.yaml b/www/presets/root.yaml similarity index 100% rename from www/graph/presets/root.yaml rename to www/presets/root.yaml