Checkpoint on Data UI
authordsc <dsc@wikimedia.org>
Fri, 13 Apr 2012 15:52:15 +0000 (08:52 -0700)
committerdsc <dsc@wikimedia.org>
Fri, 13 Apr 2012 15:52:15 +0000 (08:52 -0700)
lib/dataset/data-view.co
lib/graph/graph-model.co

index 89d5be6..4685e5b 100644 (file)
@@ -13,7 +13,7 @@ Seq = require 'seq'
  * @class
  */
 DataView = exports.DataView = BaseView.extend do # {{{
-    __bind__       : <[ onReady ]>
+    __bind__       : <[ ]>
     tagName        : 'section'
     className      : 'data-ui'
     template       : require 'kraken/template/data'
@@ -28,46 +28,48 @@ DataView = exports.DataView = BaseView.extend do # {{{
     initialize: ->
         @graph_id = @options.graph_id
         BaseView::initialize ...
-        @on 'ready', @onReady
+        @on 'ready', @onReady, this
         @load()
     
     
     load: ->
+        @wait()
         $.getJSON '/datasources/all', (@datasources) ~>
-            @canonicalizeDataSources @datasources
+            _.each @datasources, @canonicalizeDataSource, this
             @ready = true
+            @unwait()
             @render()
             @trigger 'ready', this
     
     /**
      * Transform the `columns` field to ensure an Array of {label, type} objects.
      */
-    canonicalizeDataSources: (datasources) ->
-        _.each datasources, (ds) ->
-            ds.shortName    or= ds.name
-            ds.title        or= ds.name
-            ds.subtitle     or= ''
-            
-            cols = ds.columns
-            if _.isArray cols
-                ds.metrics = _.map cols, (col, idx) ->
-                    if _.isArray col
-                        [label, type] = col
-                        {idx, label, type or 'int'}
-                    else
-                        col
-            else
-                ds.metrics = _.map cols.labels, (label, idx) ->
-                    {idx, label, type:cols.types[idx] or 'int'}
-        datasources
+    canonicalizeDataSource: (ds) ->
+        ds.shortName    or= ds.name
+        ds.title        or= ds.name
+        ds.subtitle     or= ''
+        
+        cols = ds.columns
+        if _.isArray cols
+            ds.metrics = _.map cols, (col, idx) ->
+                if _.isArray col
+                    [label, type] = col
+                    {idx, label, type or 'int'}
+                else
+                    col
+        else
+            ds.metrics = _.map cols.labels, (label, idx) ->
+                {idx, label, type:cols.types[idx] or 'int'}
+        ds
     
     
     onReady: ->
-        @metric_edit_view = @addSubview new MetricEditView  {@graph_id, dataset:@model, @datasources}
+        dataset = @model
+        @metric_edit_view = @addSubview new MetricEditView  {@graph_id, dataset, @datasources}
         @metric_edit_view
             .on 'update',           @onUpdateMetric,      this
         
-        @dataset_view = @addSubview new DataSetView {@model, @graph_id, @dataset, @datasources}
+        @dataset_view = @addSubview new DataSetView {@model, @graph_id, dataset, @datasources}
         @dataset_view
             .on 'add-metric',       @onMetricsChanged,  this
             .on 'remove-metric',    @onMetricsChanged,  this
index aa92406..8e007ac 100644 (file)
@@ -91,7 +91,8 @@ Graph = exports.Graph = BaseModel.extend do # {{{
         @chartType = ChartType.lookup @get('chartType')
         
         # Insert submodels in place of JSON
-        @set 'data', new DataSet(@get('data') or @get('dataset')), {+silent}
+        # @get('dataset')
+        @set 'data', new DataSet(@get('data')), {+silent}
         
         @trigger 'init', this
         @load() if opts.autoload
@@ -204,9 +205,17 @@ Graph = exports.Graph = BaseModel.extend do # {{{
             @trigger "change:options", this, @get('options'), 'options', opts
         this
     
+    inheritOption: (key, opts={}) ->
+        old = @getOption(key)
+        @optionCascade.inherit(key)
+        unless @getOption(key) is old or opts.silent
+            @trigger "change:options.#key", this, void, key, opts
+            @trigger "change:options", this, @get('options'), 'options', opts
+        this
+    
     getOptions: (opts={}) ->
         opts = {+keepDefaults, +keepUnchanged} import opts
-        options = @optionCascade.toObject()
+        options = @optionCascade.collapse()
         for k, v in options
             delete options[k] if v is void or
                 (not opts.keepDefaults  and @isDefaultOption k) or