Updates application to use a router to delegate to the various views.
authorDavid Schoonover <dsc@wikimedia.org>
Mon, 16 Jul 2012 20:56:00 +0000 (13:56 -0700)
committerDavid Schoonover <dsc@wikimedia.org>
Mon, 16 Jul 2012 20:56:00 +0000 (13:56 -0700)
12 files changed:
src/dashboard/dashboard-model.co
src/graph/graph-display-view.co
src/graph/graph-edit-view.co
src/graph/graph-view.co
src/limn.co [new file with mode: 0644]
www/css/graph.styl
www/dashboard/view.jade
www/graph/edit.jade
www/graph/index.jade
www/graph/view.jade
www/js/limn
www/modules.yaml

index bd969e7..780417d 100644 (file)
@@ -1,3 +1,5 @@
+Seq = require 'seq'
+
 { _, op,
 } = require 'limn/util'
 { BaseModel,
index ce745de..cc31151 100644 (file)
@@ -28,7 +28,7 @@ GraphDisplayView = exports.GraphDisplayView = GraphView.extend do # {{{
     
     
     constructor: function GraphDisplayView
-        BaseView ...
+        GraphView ...
     
     initialize : (o={}) ->
         @data = {}
index 2f9abc9..2d0d1d8 100644 (file)
@@ -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 ...
index 704ce86..52ea119 100644 (file)
@@ -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 (file)
index 0000000..b0c7880
--- /dev/null
@@ -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
+
index ed0d26d..5a240c5 100644 (file)
@@ -106,6 +106,8 @@ section.graph
         .help-block
             font-size 11px
             line-height 1.3
+        .graph-size-row input[type="text"]
+            display inline-block
     
     /* }}} */
     
index 8dbbe93..05ff780 100644 (file)
@@ -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)
index bfa7732..c525a23 100644 (file)
@@ -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)
index f8b87a6..bc02be3 100644 (file)
@@ -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)
index aa5fd68..49f2ba4 100644 (file)
@@ -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)
index 58677dd..929cb3d 120000 (symlink)
@@ -1 +1 @@
-../../lib
\ No newline at end of file
+../../src
\ No newline at end of file
index dcf3d6c..77a9946 100644 (file)
@@ -139,7 +139,7 @@ development:
                 - dashboard-model
                 - dashboard-view
                 - index
-            - app
+            - limn
 
 # -   suffix: .js
 #     paths: