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) ~>
@constructor.register this
@metrics = new MetricList @attributes.metrics
@on 'change:metrics', @onMetricChange, this
- @on 'load-success', @onLoadSuccess, this
+ @load()
canonicalize: (ds) ->
@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
onLoadError: (jqXHR, txtStatus, err) ->
@_errorLoading = true
console.error "#this Error loading data! -- #msg: #{err or ''}"
+ @trigger 'load-error', this, txtStatus, err
getData: ->
*/
Metric = exports.Metric = BaseModel.extend do # {{{
urlRoot : '/metrics'
+ ready : false
/**
* Data source of the Metric.
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
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.