From ec064880d69a549a80ba1c445b3d152496fe7d76 Mon Sep 17 00:00:00 2001 From: dsc Date: Fri, 13 Apr 2012 08:52:15 -0700 Subject: [PATCH] Checkpoint on Data UI --- lib/dataset/data-view.co | 48 +++++++++++++++++++++++---------------------- lib/graph/graph-model.co | 13 ++++++++++- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/lib/dataset/data-view.co b/lib/dataset/data-view.co index 89d5be6..4685e5b 100644 --- a/lib/dataset/data-view.co +++ b/lib/dataset/data-view.co @@ -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 diff --git a/lib/graph/graph-model.co b/lib/graph/graph-model.co index aa92406..8e007ac 100644 --- a/lib/graph/graph-model.co +++ b/lib/graph/graph-model.co @@ -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 -- 1.7.0.4