* @class
*/
DataView = exports.DataView = BaseView.extend do # {{{
- __bind__ : <[ onReady ]>
+ __bind__ : <[ ]>
tagName : 'section'
className : 'data-ui'
template : require 'kraken/template/data'
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
@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
@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