From: David Schoonover Date: Mon, 16 Jul 2012 20:56:00 +0000 (-0700) Subject: Updates application to use a router to delegate to the various views. X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=d5ce6e0e5c04e256a0abd811c899f7dd3c3418c8;p=limn.git Updates application to use a router to delegate to the various views. --- diff --git a/src/dashboard/dashboard-model.co b/src/dashboard/dashboard-model.co index bd969e7..780417d 100644 --- a/src/dashboard/dashboard-model.co +++ b/src/dashboard/dashboard-model.co @@ -1,3 +1,5 @@ +Seq = require 'seq' + { _, op, } = require 'limn/util' { BaseModel, diff --git a/src/graph/graph-display-view.co b/src/graph/graph-display-view.co index ce745de..cc31151 100644 --- a/src/graph/graph-display-view.co +++ b/src/graph/graph-display-view.co @@ -28,7 +28,7 @@ GraphDisplayView = exports.GraphDisplayView = GraphView.extend do # {{{ constructor: function GraphDisplayView - BaseView ... + GraphView ... initialize : (o={}) -> @data = {} diff --git a/src/graph/graph-edit-view.co b/src/graph/graph-edit-view.co index 2f9abc9..2d0d1d8 100644 --- a/src/graph/graph-edit-view.co +++ b/src/graph/graph-edit-view.co @@ -41,12 +41,20 @@ GraphEditView = exports.GraphEditView = GraphView.extend do # {{{ 'submit form.chart-options' : 'onOptionsSubmit' 'change .chart-options input[type="checkbox"]' : 'onOptionsSubmit' + # TODO: actually apply this + routes: + 'graphs/:graph/edit/info' : 'showInfoPane' + 'graphs/:graph/edit/data/metric/:metric' : 'showDataPane' + 'graphs/:graph/edit/data' : 'showDataPane' + 'graphs/:graph/edit/options/:optionsFilter' : 'showOptionsPane' + 'graphs/:graph/edit/options' : 'showOptionsPane' + constructor: function GraphEditView - BaseView ... + GraphView ... initialize : (o={}) -> GraphEditView.__super__.initialize ... diff --git a/src/graph/graph-view.co b/src/graph/graph-view.co index 704ce86..52ea119 100644 --- a/src/graph/graph-view.co +++ b/src/graph/graph-view.co @@ -1,3 +1,4 @@ +Seq = require 'seq' moment = require 'moment' _ = require 'limn/util/underscore' diff --git a/src/limn.co b/src/limn.co new file mode 100644 index 0000000..b0c7880 --- /dev/null +++ b/src/limn.co @@ -0,0 +1,141 @@ +limn = exports + +Backbone = require 'backbone' + +{ _, op, root, +} = limn.util = require 'limn/util' +{ BaseView, BaseModel, BaseList, +} = limn.base = require 'limn/base' +{ ChartType, DygraphsChartType, +} = limn.chart = require 'limn/chart' +{ Graph, GraphList, GraphDisplayView, GraphEditView, GraphListView, +} = limn.graph = require 'limn/graph' +{ DashboardView, Dashboard, +} = limn.dashboard = require 'limn/dashboard' + + +/** + * @class Sets up root application, automatically attaching to an existing element + * found at `appSelector` and delegating to the appropriate view. + * @extends Backbone.Router + */ +LimnApp = limn.LimnApp = Backbone.Router.extend do # {{{ + appSelector : '#content .inner' + + routes: + 'graphs/(new|edit)' : 'newGraph' + 'graphs/:graphId/edit' : 'editGraph' + 'graphs/:graphId' : 'showGraph' + 'graphs' : 'listGraphs' + + 'dashboards/(new|edit)' : 'newDashboard' + 'dashboards/:dashId/edit' : 'editDashboard' + 'dashboards/:dashId' : 'showDashboard' + 'dashboards' : 'listDashboards' + + + + /** + * @constructor + */ + constructor: function LimnApp (@config={}) + @appSelector = that if config.appSelector + @el = config.el or= jQuery @appSelector .0 + @$el = jQuery @el + Backbone.Router.call this, config + this + + initialize: -> + jQuery ~> @setup() + this + + setup: -> + # Add / route for Homepage + @route /^(?:[\?].*)?$/, 'home' + # Start observing history changes + Backbone.history.start { +pushState, root:@config.mount } + + # Helper for setting up models + processData: (id, data={}) -> + unless id and _ <[ edit new ]> .contains id + data.id = data.slug = id + data + + + + /* * * * Routes * * * */ + + + home: -> + console.log "#this.home!" + @showDashboard 'reportcard' + + + ### Graphs + + createGraphModel: (id) -> + data = @processData id + graph = new Graph data, {+parse} + + newGraph: -> + @editGraph() + + editGraph: (id) -> + @model = @createGraphModel id + @view = new GraphEditView {@model} .attach @el + + showGraph: (id) -> + @model = @createGraphModel id + @view = new GraphDisplayView {@model} .attach @el + + listGraphs: -> + @collection = new GraphList() + @view = new GraphListView {@collection} .attach @el + + + ### Dashboards + + createDashboardModel: (id) -> + data = @processData id + dashboard = new Dashboard data, {+parse} + + newDashboard: -> + console.error 'newDashboard!?' + + editDashboard: (id) -> + console.error 'editDashboard!?' + + showDashboard: (id) -> + @model = @createDashboardModel id + @view = new DashboardView {@model} .attach @el + + listDashboards: -> + console.error 'listDashboards!?' + + + ### Misc + + getClassName: -> + "#{@..name or @..displayName}" + + toString: -> + "#{@getClassName()}()" +# }}} + + +### Static Methods +LimnApp import do + + findConfig : -> + # TODO: fill out inferred config + config = root.limn_config or {} + config.mount or= "/" + config + + main : function limnMain + config = limn.config or= LimnApp.findConfig() + limn.app or= new LimnApp config unless config.libOnly + + +jQuery LimnApp.main + diff --git a/www/css/graph.styl b/www/css/graph.styl index ed0d26d..5a240c5 100644 --- a/www/css/graph.styl +++ b/www/css/graph.styl @@ -106,6 +106,8 @@ section.graph .help-block font-size 11px line-height 1.3 + .graph-size-row input[type="text"] + display inline-block /* }}} */ diff --git a/www/dashboard/view.jade b/www/dashboard/view.jade index 8dbbe93..05ff780 100644 --- a/www/dashboard/view.jade +++ b/www/dashboard/view.jade @@ -14,4 +14,6 @@ append styles block main-scripts - script(src="/js/limn/main-dashboard.js?"+version) + script + var limn = require('limn/limn'); + //- script(src="/js/limn/main-dashboard.js?"+version) diff --git a/www/graph/edit.jade b/www/graph/edit.jade index bfa7732..c525a23 100644 --- a/www/graph/edit.jade +++ b/www/graph/edit.jade @@ -10,5 +10,8 @@ append styles mixin css('data.css') mixin css('isotope.css') + block main-scripts - script(src="/js/limn/main-edit.js?"+version) + script + var limn = require('limn/limn'); + //- script(src="/js/limn/main-edit.js?"+version) diff --git a/www/graph/index.jade b/www/graph/index.jade index f8b87a6..bc02be3 100644 --- a/www/graph/index.jade +++ b/www/graph/index.jade @@ -1,7 +1,9 @@ extends ../layout block title - title Graph | Limn + title Browse Graphs | Limn block main-scripts - script(src="/js/limn/main-graph-list.js?"+version) + script + var limn = require('limn/limn'); + //- script(src="/js/limn/main-graph-list.js?"+version) diff --git a/www/graph/view.jade b/www/graph/view.jade index aa5fd68..49f2ba4 100644 --- a/www/graph/view.jade +++ b/www/graph/view.jade @@ -7,4 +7,6 @@ append styles mixin css('graph-display.css') block main-scripts - script(src="/js/limn/main-display.js?"+version) + script + var limn = require('limn/limn'); + //- script(src="/js/limn/main-display.js?"+version) diff --git a/www/js/limn b/www/js/limn index 58677dd..929cb3d 120000 --- a/www/js/limn +++ b/www/js/limn @@ -1 +1 @@ -../../lib \ No newline at end of file +../../src \ No newline at end of file diff --git a/www/modules.yaml b/www/modules.yaml index dcf3d6c..77a9946 100644 --- a/www/modules.yaml +++ b/www/modules.yaml @@ -139,7 +139,7 @@ development: - dashboard-model - dashboard-view - index - - app + - limn # - suffix: .js # paths: