Checkpoint on Data UI.
authordsc <dsc@wikimedia.org>
Tue, 17 Apr 2012 18:12:38 +0000 (11:12 -0700)
committerdsc <dsc@wikimedia.org>
Tue, 17 Apr 2012 18:12:38 +0000 (11:12 -0700)
lib/dataset/dataset-model.co
lib/dataset/datasource-model.co
lib/dataset/metric-model.co

index 0cef0ad..47ae0e8 100644 (file)
@@ -50,7 +50,7 @@ DataSet = exports.DataSet = BaseModel.extend do # {{{
         return this if @ready and not opts.force
         @wait()
         @trigger 'load', this
-        Seq @metrics.pluck 'source_id'
+        Seq _.unique @metrics.pluck 'source_id'
             .parMap_ (next, source_id) ->
                 DataSource.lookup source_id, next
             .seqEach_ (next, source) ~>
index e06d0d5..57fed50 100644 (file)
@@ -59,7 +59,7 @@ DataSource = exports.DataSource = BaseModel.extend do # {{{
         @constructor.register this
         @metrics = new MetricList @attributes.metrics
         @on 'change:metrics', @onMetricChange, this
-        @on 'load-success', @onLoadSuccess, this
+        @load()
     
     
     canonicalize: (ds) ->
@@ -91,31 +91,28 @@ DataSource = exports.DataSource = BaseModel.extend do # {{{
             @loadCSV url
         default
             console.error "#this.load() Unknown Data Format!"
-            @trigger 'load-error', this, 'Unknown Data Format!'
+            @onLoadError null, 'Unknown Data Format!', new Error 'Unknown Data Format!'
         this
     
     loadJSON: (url) ->
         $.ajax do
             url      : url
             dataType : 'json'
-            success : (@data) ->
-                @trigger 'load-success', this
-            error : (jqXHR, txtStatus, err) ->
-                @trigger 'load-error', this, txtStatus, err
+            success  : @onLoadSuccess
+            error    : @onLoadError
         this
     
     loadCSV: (url) ->
         $.ajax do
             url      : url
             dataType : 'text'
-            success : (data) ->
-                @data = new CSVData data
-                @trigger 'load-success', this
-            error : (jqXHR, txtStatus, err) ->
-                @trigger 'load-error', this, txtStatus, err
+            success  : (data) ~> @onLoadSuccess new CSVData data
+            error    : @onLoadError
         this
     
-    onLoadSuccess: ->
+    onLoadSuccess: (@data) ->
+        console.log "#this.onLoadSuccess #{@data}"
+        @trigger 'load-success', this
         return if @ready
         @ready = true
         @trigger 'ready', this
@@ -123,6 +120,7 @@ DataSource = exports.DataSource = BaseModel.extend do # {{{
     onLoadError: (jqXHR, txtStatus, err) ->
         @_errorLoading = true
         console.error "#this Error loading data! -- #msg: #{err or ''}"
+        @trigger 'load-error', this, txtStatus, err
     
     
     getData: ->
index b953a20..72e95de 100644 (file)
@@ -9,6 +9,7 @@ DataSource = DataSourceList = null
  */
 Metric = exports.Metric = BaseModel.extend do # {{{
     urlRoot  : '/metrics'
+    ready : false
     
     /**
      * Data source of the Metric.
@@ -43,13 +44,15 @@ Metric = exports.Metric = BaseModel.extend do # {{{
     
     initialize : ->
         BaseModel::initialize ...
-        @on 'change:source_id', @onUpdateSource, this
-        @onUpdateSource()
+        @on 'change:source_id',  @lookupSource,         this
+        @on 'change:source_col', @onUpdateSourceCol,    this
+        @lookupSource()
     
     
-    onUpdateSource: ->
+    lookupSource: ->
         if source_id = @get 'source_id'
             @wait()
+            @updateId()
             DataSource.lookup source_id, @onSourceReady, this
         this
     
@@ -60,12 +63,23 @@ Metric = exports.Metric = BaseModel.extend do # {{{
             console.error "#this Error loading DataSource! #err"
         else
             @source = source
+            @updateId()
             unless @ready
                 @ready = true
                 @trigger 'ready', this
         this
     
     
+    onUpdateSourceCol: ->
+        @updateId()
+        this
+    
+    updateId: ->
+        if (source_id = @get('source_id')) and (source_col = @get('source_col'))
+            @id = "#source_id[#source_col]"
+        this
+    
+    
     /**
      * Check whether the metric has aiight-looking values so we don't
      * attempt to graph unconfigured crap.