[#25,backend][s]: update backends to new fields setup.
This commit is contained in:
@@ -51,8 +51,8 @@ function demoDataset() {
|
|||||||
title: 'My Test Dataset'
|
title: 'My Test Dataset'
|
||||||
, name: '1-my-test-dataset'
|
, name: '1-my-test-dataset'
|
||||||
, id: datasetId
|
, id: datasetId
|
||||||
, fields: ['x', 'y', 'z']
|
|
||||||
},
|
},
|
||||||
|
fields: [{id: 'x'}, {id: 'y'}, {id: 'z'}],
|
||||||
documents: [
|
documents: [
|
||||||
{id: 0, x: 1, y: 2, z: 3}
|
{id: 0, x: 1, y: 2, z: 3}
|
||||||
, {id: 1, x: 2, y: 4, z: 6}
|
, {id: 1, x: 2, y: 4, z: 6}
|
||||||
|
|||||||
@@ -59,9 +59,9 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
// backend.addDataset({
|
// backend.addDataset({
|
||||||
// metadata: {
|
// metadata: {
|
||||||
// id: 'my-id',
|
// id: 'my-id',
|
||||||
// title: 'My Title',
|
// title: 'My Title'
|
||||||
// fields: ['x', 'y', 'z'],
|
|
||||||
// },
|
// },
|
||||||
|
// fields: [{id: 'x'}, {id: 'y'}, {id: 'z'}],
|
||||||
// documents: [
|
// documents: [
|
||||||
// {id: 0, x: 1, y: 2, z: 3},
|
// {id: 0, x: 1, y: 2, z: 3},
|
||||||
// {id: 1, x: 2, y: 4, z: 6}
|
// {id: 1, x: 2, y: 4, z: 6}
|
||||||
@@ -86,6 +86,7 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
if (model.__type__ == 'Dataset') {
|
if (model.__type__ == 'Dataset') {
|
||||||
var rawDataset = this.datasets[model.id];
|
var rawDataset = this.datasets[model.id];
|
||||||
model.set(rawDataset.metadata);
|
model.set(rawDataset.metadata);
|
||||||
|
model.fields.reset(rawDataset.fields);
|
||||||
model.docCount = rawDataset.documents.length;
|
model.docCount = rawDataset.documents.length;
|
||||||
dfd.resolve(model);
|
dfd.resolve(model);
|
||||||
}
|
}
|
||||||
@@ -153,12 +154,12 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
});
|
});
|
||||||
var dfd = $.Deferred();
|
var dfd = $.Deferred();
|
||||||
wrapInTimeout(jqxhr).done(function(schema) {
|
wrapInTimeout(jqxhr).done(function(schema) {
|
||||||
fields = _.map(schema.data, function(item) {
|
var fieldData = _.map(schema.data, function(item) {
|
||||||
return item.name;
|
item.id = item.name;
|
||||||
});
|
delete item.name;
|
||||||
model.set({
|
return item;
|
||||||
fields: fields
|
|
||||||
});
|
});
|
||||||
|
model.fields.reset(fieldData);
|
||||||
model.docCount = schema.count;
|
model.docCount = schema.count;
|
||||||
dfd.resolve(model, jqxhr);
|
dfd.resolve(model, jqxhr);
|
||||||
})
|
})
|
||||||
@@ -227,9 +228,10 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
});
|
});
|
||||||
var dfd = $.Deferred();
|
var dfd = $.Deferred();
|
||||||
wrapInTimeout(jqxhr).done(function(results) {
|
wrapInTimeout(jqxhr).done(function(results) {
|
||||||
model.set({
|
model.fields.reset(_.map(results.fields, function(fieldId) {
|
||||||
fields: results.fields
|
return {id: fieldId};
|
||||||
});
|
})
|
||||||
|
);
|
||||||
dfd.resolve(model, jqxhr);
|
dfd.resolve(model, jqxhr);
|
||||||
})
|
})
|
||||||
.fail(function(arguments) {
|
.fail(function(arguments) {
|
||||||
@@ -293,7 +295,10 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
|
|
||||||
$.getJSON(model.get('url'), function(d) {
|
$.getJSON(model.get('url'), function(d) {
|
||||||
result = self.gdocsToJavascript(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!)
|
// cache data onto dataset (we have loaded whole gdoc it seems!)
|
||||||
model._dataCache = result.data;
|
model._dataCache = result.data;
|
||||||
dfd.resolve(model);
|
dfd.resolve(model);
|
||||||
@@ -303,7 +308,7 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
|
|
||||||
query: function(dataset, queryObj) {
|
query: function(dataset, queryObj) {
|
||||||
var dfd = $.Deferred();
|
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
|
// zip the fields with the data rows to produce js objs
|
||||||
// TODO: factor this out as a common method with other backends
|
// TODO: factor this out as a common method with other backends
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ var memoryData = {
|
|||||||
title: 'My Test Dataset'
|
title: 'My Test Dataset'
|
||||||
, name: '1-my-test-dataset'
|
, name: '1-my-test-dataset'
|
||||||
, id: 'test-dataset'
|
, id: 'test-dataset'
|
||||||
, fields: ['x', 'y', 'z']
|
|
||||||
},
|
},
|
||||||
|
fields: [{id: 'x'}, {id: 'y'}, {id: 'z'}],
|
||||||
documents: [
|
documents: [
|
||||||
{id: 0, x: 1, y: 2, z: 3}
|
{id: 0, x: 1, y: 2, z: 3}
|
||||||
, {id: 1, x: 2, y: 4, z: 6}
|
, {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];
|
var data = dataset.backend.datasets[memoryData.metadata.id];
|
||||||
dataset.fetch().then(function(datasetAgain) {
|
dataset.fetch().then(function(datasetAgain) {
|
||||||
equal(dataset.get('name'), data.metadata.name);
|
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);
|
equal(dataset.docCount, 6);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -196,7 +196,7 @@ test('Webstore Backend', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
dataset.fetch().done(function(dataset) {
|
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)
|
equal(3, dataset.docCount)
|
||||||
dataset.query().done(function(docList) {
|
dataset.query().done(function(docList) {
|
||||||
equal(3, docList.length)
|
equal(3, docList.length)
|
||||||
@@ -295,7 +295,7 @@ test('DataProxy Backend', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
dataset.fetch().done(function(dataset) {
|
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)
|
equal(null, dataset.docCount)
|
||||||
dataset.query().done(function(docList) {
|
dataset.query().done(function(docList) {
|
||||||
equal(10, docList.length)
|
equal(10, docList.length)
|
||||||
@@ -490,8 +490,8 @@ test("GDoc Backend", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
dataset.fetch().then(function(dataset) {
|
dataset.fetch().then(function(dataset) {
|
||||||
console.log('inside dataset:', dataset, dataset.get('fields'), dataset.get('data'));
|
console.log('inside dataset:', dataset, dataset.fields, dataset.get('data'));
|
||||||
deepEqual(['column-2', 'column-1'], dataset.get('fields'));
|
deepEqual(['column-2', 'column-1'], _.pluck(dataset.fields.toJSON(), 'id'));
|
||||||
//equal(null, dataset.docCount)
|
//equal(null, dataset.docCount)
|
||||||
dataset.query().then(function(docList) {
|
dataset.query().then(function(docList) {
|
||||||
equal(3, docList.length);
|
equal(3, docList.length);
|
||||||
|
|||||||
Reference in New Issue
Block a user