finished basic refactoring of dashboard loading behavior. Still broken though
authorerosen <erosen@wikimedia.org>
Wed, 27 Jun 2012 23:37:52 +0000 (16:37 -0700)
committererosen <erosen@wikimedia.org>
Wed, 27 Jun 2012 23:37:52 +0000 (16:37 -0700)
lib/dashboard/dashboard-model.co
lib/dashboard/dashboard-view.co
lib/main-dashboard.co

index c6872a3..b625638 100644 (file)
@@ -24,8 +24,7 @@ Dashboard = exports.Dashboard = BaseModel.extend do # {{{
     
     initialize: ->
         BaseModel::initialize ...
-        @getGraphs null @trigger 'ready'
-    
+        @getGraphs null, ~> @triggerReady
     
     defaults: ->
         name : null
@@ -99,48 +98,20 @@ Dashboard = exports.Dashboard = BaseModel.extend do # {{{
     
 #    addGraph: (graph, tabName) ->
 #        ...
-        
     
-    getGraphIds : (cb, tabs) ->
-        console.log('[getGraphIds]\tentering')
-        tab_ids = _.keys(tabs)
-        tab_objs = _.values(tabs)
-        graph_ids = _.map tab_objs, (tab_obj) -> tab_obj.graph_ids
-        kvlists = _.zip(tab_ids, graph_ids)
-        # console.log(keys)
-        # console.log(values)
-        # console.log(kvlists)
-        cb null, kvlists
-
-    expand : (cb, kvlist) ->
-        console.log('[expand]\tentering')
-        # console.log(kvlist)
-        [key, vlist] = kvlist
-        # console.log('[expand]\tkey:')
-        # console.log(key)
-        # console.log('[expand]\tvlist:')
-        # console.log(vlist)
-        tmp = [[key, v] for v of vlist]
-        # console.log('[expand]\ttmp:')
-        # console.log(tmp)
-        cb null [[key, v] for v of vlist]
-
     nest : (cb, records) ->
         console.log('[nest]\tentering')
-        console.log('[nest]\torig:')
-        console.log(records)
-        tab_tree = d3.nest()
+        # console.log('[nest]\torig:')
+        # console.log(records)
+        graph_map = d3.nest()
             .key (graph_rec) ->
                 graph_rec[0]
-            .key (graph_rec) ->
-                graph_rec[1]
-            .rollup (arr) -> arr[0][2]
-            # .key (graph_rec) ->
-            #     graph_rec[2]
+            .rollup (arr) -> 
+                arr[0][1]
             .map(records)
-        console.log('[nest]\tnew:')
-        console.log(tab_tree)
-        cb null tab_tree
+        # console.log('[nest]\tnew:')
+        # console.log(graph_map)
+        cb null graph_map
     
     show : (cb, obj) ->
         console.log('[show]')
@@ -149,34 +120,33 @@ Dashboard = exports.Dashboard = BaseModel.extend do # {{{
     
     pushAsync : (cb, arr) ->
         (err, elem) ->
-            console.log('[appendInner]\tentering')
-            console.log('[appendInner]\tarr:')
-            console.log(arr)
             arr.push elem
             cb null
-    
-    
+
     getGraphs : (err, cb) ->
         console.log('[getGraphs]\tentering')
-        _this = this
-        Seq [@tabs]
-        .seq_ @getGraphIds
-        # .parEach_ @show
-        .flatten(false)
-        # .parEach_ @show
-        .parMap_ @expand # turn ['core', ['x','y','z']] into [['core','x'],['core','y'],['core','z']]
-        # .parEach_ @show  
-        .flatten(false)
-        .flatten(false)
-        # .parEach_ @show
-        .parEach_ (next, kv) ->
-            console.log('this:')
-            console.log(this)
-            Graph.lookup kv[1], _this.pushAsync next, kv
+        # consolidate graph_ids to one array
+        graph_ids = _(@tabs).chain().values().map((tab_obj) -> tab_obj.graph_ids).flatten().value()
+        
+        Seq [graph_ids]
+        .flatten()
+        .parMap_ (next, graph_id) ->
+            next null [graph_id]
+        .parEach_ (next, graph_id_arr) ~>
+            Graph.lookup graph_id_arr[0], @pushAsync next, graph_id_arr
+            # Graph.lookup graph_id_arr[0], (err, el) ->
+            #     graph_id_arr.push el
+            #     next null
         # .parEach_ @show
         .unflatten()
-        .seq_ @nest
-        .parEach_ @show
+        .seq_ (next, graph_tuples) ->
+            # console.log('[setter]\tgraph_tuples:')
+            # console.log(graph_tuples)
+            @graphs = _.generate graph_tuples
+            # console.log('[setter]\t@graphs:')
+            # console.log(@graphs)            
+            cb null
+        # .parEach_ @show
         
         
     
index 657668a..8a03440 100644 (file)
@@ -19,52 +19,6 @@ DashboardView = exports.DashboardView = BaseView.extend do # {{{
     className      : 'dashboard'
     template       : require 'kraken/template/dashboard/dashboard'
     
-    graph_ids : <[
-        unique_visitors
-        reach
-        pageviews
-        pageviews_mobile
-        pageviews_mobile_target
-        commons
-        articles
-        articles_per_day
-        edits
-        new_editors
-        active_editors
-        active_editors_target
-        very_active_editors
-    ]>
-    
-    core_tab :
-        graph_ids : <[
-        unique_visitors
-        pageviews
-        pageviews_mobile
-        pageviews_mobile_target
-        new_editors
-        active_editors
-        active_editors_target
-    ]>
-        name: ".core-graphs-pane"
-    
-    other_tab :
-        graph_ids : <[
-        reach
-        commons
-        articles
-        articles_per_day
-        edits
-        very_active_editors
-    ]>
-        name: ".other-graphs-pane"
-    
-    dev_tab :
-        graph_ids : <[
-        mobile_devices
-        mobile_devices_browsers
-        mobile_devices_applications
-    ]>
-        name: ".dev-graphs-pane"
     
     events:
         # Select the whole permalink URI text when it receives focus.
@@ -78,7 +32,8 @@ DashboardView = exports.DashboardView = BaseView.extend do # {{{
     ready    : false
     
     
-    constructor: function DashboardView
+    constructor: function DashboardView(options={})
+        @model = options.model
         @subviews = []
         @graphs   = new GraphList
         Backbone.View ...
@@ -88,7 +43,8 @@ DashboardView = exports.DashboardView = BaseView.extend do # {{{
         BaseView::initialize ...
         # @graphs.on 'add', @attachGraphs, this
         # @graphs.on 'add', @attachGraph, this
-        @load()
+        console.log('[dashboard-view::initialize]\tentering')
+        @model.on('ready', @load, this)
     
     
     # FIXME:
@@ -97,15 +53,14 @@ DashboardView = exports.DashboardView = BaseView.extend do # {{{
     # TODO:
     #   - only render graph when scrolling makes it visible
     load: ->
-        @addTab(@core_tab)
-        @addTab(@other_tab)
-        @addTab(@dev_tab)
+        console.log('[dashboard-view::load]\tentering')
+        _.map(@model.tabs, @addTab)
     
     addTab: (tab) ->
+        console.log('[dashboard-view::addTab]\tentering')
         self = this
-        Seq(tab.graph_ids)
-            .parMap (id) ->
-                Graph.lookup id, this
+        graphs = _(tab.graph_ids).map((graph_id) -> @model.graphs[graph_id])
+        Seq(graphs)
             .parMap (graph) ->
                 self.graphs.add graph
                 this null, new GraphDisplayView {model:graph}
@@ -116,7 +71,6 @@ DashboardView = exports.DashboardView = BaseView.extend do # {{{
                 self.subviews.push view
                 view.isAttached = true
     
-    
     ### Tabs {{{
     
     onTabShown: (e) ->
index 5bc8c8d..9f92800 100644 (file)
@@ -11,7 +11,7 @@ Backbone = require 'backbone'
 } = require 'kraken/chart'
 { Graph, GraphList, GraphDisplayView,
 } = require 'kraken/graph'
-{ DashboardView,
+{ DashboardView, Dashboard,
 } = require 'kraken/dashboard'
 
 
@@ -22,7 +22,8 @@ root = this
 main = ->
     # Instantiate model & view
     root.app = new AppView ->
-        @view  = root.dashboard  = new DashboardView {@model}
+        @model  = root.dashboard  = new Dashboard
+        @view  = root.view  = new DashboardView {@model}
 
 
 jQuery main