[#25,backend][s]: update backends to new fields setup.

This commit is contained in:
Rufus Pollock 2012-02-18 08:20:10 +00:00
parent a75e04701f
commit 25c0177097
3 changed files with 24 additions and 19 deletions

View File

@ -51,8 +51,8 @@ function demoDataset() {
title: 'My Test Dataset'
, name: '1-my-test-dataset'
, id: datasetId
, fields: ['x', 'y', 'z']
},
fields: [{id: 'x'}, {id: 'y'}, {id: 'z'}],
documents: [
{id: 0, x: 1, y: 2, z: 3}
, {id: 1, x: 2, y: 4, z: 6}

View File

@ -59,9 +59,9 @@ this.recline.Model = this.recline.Model || {};
// backend.addDataset({
// metadata: {
// id: 'my-id',
// title: 'My Title',
// fields: ['x', 'y', 'z'],
// title: 'My Title'
// },
// fields: [{id: 'x'}, {id: 'y'}, {id: 'z'}],
// documents: [
// {id: 0, x: 1, y: 2, z: 3},
// {id: 1, x: 2, y: 4, z: 6}
@ -86,6 +86,7 @@ this.recline.Model = this.recline.Model || {};
if (model.__type__ == 'Dataset') {
var rawDataset = this.datasets[model.id];
model.set(rawDataset.metadata);
model.fields.reset(rawDataset.fields);
model.docCount = rawDataset.documents.length;
dfd.resolve(model);
}
@ -153,12 +154,12 @@ this.recline.Model = this.recline.Model || {};
});
var dfd = $.Deferred();
wrapInTimeout(jqxhr).done(function(schema) {
fields = _.map(schema.data, function(item) {
return item.name;
});
model.set({
fields: fields
var fieldData = _.map(schema.data, function(item) {
item.id = item.name;
delete item.name;
return item;
});
model.fields.reset(fieldData);
model.docCount = schema.count;
dfd.resolve(model, jqxhr);
})
@ -227,9 +228,10 @@ this.recline.Model = this.recline.Model || {};
});
var dfd = $.Deferred();
wrapInTimeout(jqxhr).done(function(results) {
model.set({
fields: results.fields
});
model.fields.reset(_.map(results.fields, function(fieldId) {
return {id: fieldId};
})
);
dfd.resolve(model, jqxhr);
})
.fail(function(arguments) {
@ -293,7 +295,10 @@ this.recline.Model = this.recline.Model || {};
$.getJSON(model.get('url'), function(d) {
result = self.gdocsToJavascript(d);
model.set({'fields': result.field});
model.fields.reset(_.map(result.field, function(fieldId) {
return {id: fieldId};
})
);
// cache data onto dataset (we have loaded whole gdoc it seems!)
model._dataCache = result.data;
dfd.resolve(model);
@ -303,7 +308,7 @@ this.recline.Model = this.recline.Model || {};
query: function(dataset, queryObj) {
var dfd = $.Deferred();
var fields = dataset.get('fields');
var fields = _.pluck(dataset.fields.toJSON(), 'id');
// zip the fields with the data rows to produce js objs
// TODO: factor this out as a common method with other backends

View File

@ -6,8 +6,8 @@ var memoryData = {
title: 'My Test Dataset'
, name: '1-my-test-dataset'
, id: 'test-dataset'
, fields: ['x', 'y', 'z']
},
fields: [{id: 'x'}, {id: 'y'}, {id: 'z'}],
documents: [
{id: 0, x: 1, y: 2, z: 3}
, {id: 1, x: 2, y: 4, z: 6}
@ -32,7 +32,7 @@ test('Memory Backend: basics', function () {
var data = dataset.backend.datasets[memoryData.metadata.id];
dataset.fetch().then(function(datasetAgain) {
equal(dataset.get('name'), data.metadata.name);
deepEqual(dataset.get('fields'), data.metadata.fields);
deepEqual(_.pluck(dataset.fields.toJSON(), 'id'), _.pluck(data.fields, 'id'));
equal(dataset.docCount, 6);
});
});
@ -196,7 +196,7 @@ test('Webstore Backend', function() {
});
dataset.fetch().done(function(dataset) {
deepEqual(['__id__', 'date', 'geometry', 'amount'], dataset.get('fields'));
deepEqual(['__id__', 'date', 'geometry', 'amount'], _.pluck(dataset.fields.toJSON(), 'id'));
equal(3, dataset.docCount)
dataset.query().done(function(docList) {
equal(3, docList.length)
@ -295,7 +295,7 @@ test('DataProxy Backend', function() {
});
dataset.fetch().done(function(dataset) {
deepEqual(['__id__', 'date', 'price'], dataset.get('fields'));
deepEqual(['__id__', 'date', 'price'], _.pluck(dataset.fields.toJSON(), 'id'));
equal(null, dataset.docCount)
dataset.query().done(function(docList) {
equal(10, docList.length)
@ -490,8 +490,8 @@ test("GDoc Backend", function() {
});
dataset.fetch().then(function(dataset) {
console.log('inside dataset:', dataset, dataset.get('fields'), dataset.get('data'));
deepEqual(['column-2', 'column-1'], dataset.get('fields'));
console.log('inside dataset:', dataset, dataset.fields, dataset.get('data'));
deepEqual(['column-2', 'column-1'], _.pluck(dataset.fields.toJSON(), 'id'));
//equal(null, dataset.docCount)
dataset.query().then(function(docList) {
equal(3, docList.length);