[whitespace][xs]: correct indentation issues introduced in b3a71e82cc.
This commit is contained in:
@@ -69,59 +69,59 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
// };
|
// };
|
||||||
// </pre>
|
// </pre>
|
||||||
my.BackendMemory = Backbone.Model.extend({
|
my.BackendMemory = Backbone.Model.extend({
|
||||||
sync: function(method, model, options) {
|
sync: function(method, model, options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (method === "read") {
|
if (method === "read") {
|
||||||
var dfd = $.Deferred();
|
|
||||||
if (model.__type__ == 'Dataset') {
|
|
||||||
var dataset = model;
|
|
||||||
dataset.set({
|
|
||||||
headers: dataset.backendConfig.data.headers
|
|
||||||
});
|
|
||||||
dataset.docCount = dataset.backendConfig.data.rows.length;
|
|
||||||
dfd.resolve(dataset);
|
|
||||||
}
|
|
||||||
return dfd.promise();
|
|
||||||
} else if (method === 'update') {
|
|
||||||
var dfd = $.Deferred();
|
|
||||||
if (model.__type__ == 'Document') {
|
|
||||||
_.each(model.backendConfig.data.rows, function(row, idx) {
|
|
||||||
if(row.id === model.id) {
|
|
||||||
model.backendConfig.data.rows[idx] = model.toJSON();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
dfd.resolve(model);
|
|
||||||
}
|
|
||||||
return dfd.promise();
|
|
||||||
} else if (method === 'delete') {
|
|
||||||
var dfd = $.Deferred();
|
|
||||||
if (model.__type__ == 'Document') {
|
|
||||||
model.backendConfig.data.rows = _.reject(model.backendConfig.data.rows, function(row) {
|
|
||||||
return (row.id === model.id);
|
|
||||||
});
|
|
||||||
dfd.resolve(model);
|
|
||||||
}
|
|
||||||
return dfd.promise();
|
|
||||||
} else {
|
|
||||||
alert('Not supported: sync on BackendMemory with method ' + method + ' and model ' + model);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
query: function(model, queryObj) {
|
|
||||||
var numRows = queryObj.size;
|
|
||||||
var start = queryObj.offset;
|
|
||||||
var dfd = $.Deferred();
|
var dfd = $.Deferred();
|
||||||
results = model.backendConfig.data.rows;
|
if (model.__type__ == 'Dataset') {
|
||||||
// not complete sorting!
|
var dataset = model;
|
||||||
_.each(queryObj.sort, function(item) {
|
dataset.set({
|
||||||
results = _.sortBy(results, function(row) {
|
headers: dataset.backendConfig.data.headers
|
||||||
var _out = row[item[0]];
|
|
||||||
return (item[1] == 'asc') ? _out : -1*_out;
|
|
||||||
});
|
});
|
||||||
});
|
dataset.docCount = dataset.backendConfig.data.rows.length;
|
||||||
var results = results.slice(start, start+numRows);
|
dfd.resolve(dataset);
|
||||||
dfd.resolve(results);
|
}
|
||||||
return dfd.promise();
|
return dfd.promise();
|
||||||
|
} else if (method === 'update') {
|
||||||
|
var dfd = $.Deferred();
|
||||||
|
if (model.__type__ == 'Document') {
|
||||||
|
_.each(model.backendConfig.data.rows, function(row, idx) {
|
||||||
|
if(row.id === model.id) {
|
||||||
|
model.backendConfig.data.rows[idx] = model.toJSON();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dfd.resolve(model);
|
||||||
|
}
|
||||||
|
return dfd.promise();
|
||||||
|
} else if (method === 'delete') {
|
||||||
|
var dfd = $.Deferred();
|
||||||
|
if (model.__type__ == 'Document') {
|
||||||
|
model.backendConfig.data.rows = _.reject(model.backendConfig.data.rows, function(row) {
|
||||||
|
return (row.id === model.id);
|
||||||
|
});
|
||||||
|
dfd.resolve(model);
|
||||||
|
}
|
||||||
|
return dfd.promise();
|
||||||
|
} else {
|
||||||
|
alert('Not supported: sync on BackendMemory with method ' + method + ' and model ' + model);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
query: function(model, queryObj) {
|
||||||
|
var numRows = queryObj.size;
|
||||||
|
var start = queryObj.offset;
|
||||||
|
var dfd = $.Deferred();
|
||||||
|
results = model.backendConfig.data.rows;
|
||||||
|
// not complete sorting!
|
||||||
|
_.each(queryObj.sort, function(item) {
|
||||||
|
results = _.sortBy(results, function(row) {
|
||||||
|
var _out = row[item[0]];
|
||||||
|
return (item[1] == 'asc') ? _out : -1*_out;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
var results = results.slice(start, start+numRows);
|
||||||
|
dfd.resolve(results);
|
||||||
|
return dfd.promise();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
my.backends['memory'] = new my.BackendMemory();
|
my.backends['memory'] = new my.BackendMemory();
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
my.Dataset = Backbone.Model.extend({
|
my.Dataset = Backbone.Model.extend({
|
||||||
__type__: 'Dataset',
|
__type__: 'Dataset',
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
|
console.log(options);
|
||||||
this.currentDocuments = new my.DocumentList();
|
this.currentDocuments = new my.DocumentList();
|
||||||
this.docCount = null;
|
this.docCount = null;
|
||||||
this.backend = null;
|
this.backend = null;
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
(function ($) {
|
(function ($) {
|
||||||
|
module("Dataset");
|
||||||
|
|
||||||
module("Dataset");
|
test('new Dataset', function () {
|
||||||
|
var datasetId = 'test-dataset';
|
||||||
test('new Dataset', function () {
|
var metadata = {
|
||||||
var datasetId = 'test-dataset';
|
title: 'My Test Dataset'
|
||||||
var metadata = {
|
|
||||||
title: 'My Test Dataset'
|
|
||||||
, name: '1-my-test-dataset'
|
, name: '1-my-test-dataset'
|
||||||
, id: datasetId
|
, id: datasetId
|
||||||
};
|
};
|
||||||
var indata = {
|
var indata = {
|
||||||
headers: ['x', 'y', 'z']
|
headers: ['x', 'y', 'z']
|
||||||
, rows: [
|
, rows: [
|
||||||
{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}
|
||||||
@@ -19,476 +18,469 @@
|
|||||||
, {id: 4, x: 5, y: 10, z: 15}
|
, {id: 4, x: 5, y: 10, z: 15}
|
||||||
, {id: 5, x: 6, y: 12, z: 18}
|
, {id: 5, x: 6, y: 12, z: 18}
|
||||||
]
|
]
|
||||||
};
|
|
||||||
var dataset = new recline.Model.Dataset(metadata);
|
|
||||||
dataset.backendConfig = {
|
|
||||||
type: 'memory'
|
|
||||||
// deep copy so we do not touch original data ...
|
|
||||||
, data: $.extend(true, {}, indata)
|
|
||||||
};
|
|
||||||
expect(10);
|
|
||||||
dataset.fetch().then(function(dataset) {
|
|
||||||
equal(dataset.get('name'), metadata.name);
|
|
||||||
deepEqual(dataset.get('headers'), indata.headers);
|
|
||||||
equal(dataset.docCount, 6);
|
|
||||||
var queryObj = {
|
|
||||||
size: 4
|
|
||||||
, offset: 2
|
|
||||||
};
|
|
||||||
dataset.query(queryObj).then(function(documentList) {
|
|
||||||
deepEqual(indata.rows[2], documentList.models[0].toJSON());
|
|
||||||
});
|
|
||||||
var queryObj = {
|
|
||||||
sort: [
|
|
||||||
['y', 'desc']
|
|
||||||
]
|
|
||||||
};
|
|
||||||
dataset.query(queryObj).then(function(docs) {
|
|
||||||
var doc0 = dataset.currentDocuments.models[0].toJSON();
|
|
||||||
equal(doc0.x, 6);
|
|
||||||
});
|
|
||||||
dataset.query().then(function(docList) {
|
|
||||||
equal(docList.length, Math.min(100, indata.rows.length));
|
|
||||||
var doc1 = docList.models[0];
|
|
||||||
deepEqual(doc1.toJSON(), indata.rows[0]);
|
|
||||||
|
|
||||||
// Test UPDATE
|
|
||||||
var newVal = 10;
|
|
||||||
doc1.set({x: newVal});
|
|
||||||
doc1.save().then(function() {
|
|
||||||
equal(dataset.backendConfig.data.rows[0].x, newVal);
|
|
||||||
})
|
|
||||||
|
|
||||||
// Test Delete
|
|
||||||
doc1.destroy().then(function() {
|
|
||||||
equal(dataset.backendConfig.data.rows.length, 5);
|
|
||||||
equal(dataset.backendConfig.data.rows[0].x, indata.rows[1].x);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: move to fixtures
|
|
||||||
var webstoreSchema = {
|
|
||||||
"count": 3,
|
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"name": "__id__",
|
|
||||||
"type": "integer",
|
|
||||||
"values_url": "/rufuspollock/demo/data/distinct/__id__"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "date",
|
|
||||||
"type": "text",
|
|
||||||
"values_url": "/rufuspollock/demo/data/distinct/date"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "geometry",
|
|
||||||
"type": "text",
|
|
||||||
"values_url": "/rufuspollock/demo/data/distinct/geometry"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "amount",
|
|
||||||
"type": "text",
|
|
||||||
"values_url": "/rufuspollock/demo/data/distinct/amount"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"name": "type"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "name"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "values_url"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
var dataset = new recline.Model.Dataset(metadata);
|
||||||
webstoreData = {
|
dataset.backendConfig = {
|
||||||
"count": null,
|
type: 'memory'
|
||||||
"data": [
|
// deep copy so we do not touch original data ...
|
||||||
{
|
, data: $.extend(true, {}, indata)
|
||||||
"__id__": 1,
|
|
||||||
"amount": "100",
|
|
||||||
"date": "2009-01-01",
|
|
||||||
"geometry": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"__id__": 2,
|
|
||||||
"amount": "200",
|
|
||||||
"date": "2010-01-01",
|
|
||||||
"geometry": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"__id__": 3,
|
|
||||||
"amount": "300",
|
|
||||||
"date": "2011-01-01",
|
|
||||||
"geometry": null
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"name": "__id__"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "date"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "geometry"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "amount"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
expect(10);
|
||||||
test('Webstore Backend', function() {
|
dataset.fetch().then(function(dataset) {
|
||||||
var dataset = new recline.Model.Dataset();
|
equal(dataset.get('name'), metadata.name);
|
||||||
dataset.backendConfig = {
|
deepEqual(dataset.get('headers'), indata.headers);
|
||||||
type: 'webstore',
|
equal(dataset.docCount, 6);
|
||||||
url: 'http://webstore.test.ckan.org/rufuspollock/demo/data'
|
var queryObj = {
|
||||||
|
size: 4
|
||||||
|
, offset: 2
|
||||||
};
|
};
|
||||||
|
dataset.query(queryObj).then(function(documentList) {
|
||||||
var stub = sinon.stub($, 'ajax', function(options) {
|
deepEqual(indata.rows[2], documentList.models[0].toJSON());
|
||||||
if (options.url.indexOf('schema.json') != -1) {
|
|
||||||
return {
|
|
||||||
done: function(callback) {
|
|
||||||
callback(webstoreSchema);
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
fail: function() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
done: function(callback) {
|
|
||||||
callback(webstoreData);
|
|
||||||
},
|
|
||||||
fail: function() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
var queryObj = {
|
||||||
dataset.fetch().done(function(dataset) {
|
sort: [
|
||||||
deepEqual(['__id__', 'date', 'geometry', 'amount'], dataset.get('headers'));
|
['y', 'desc']
|
||||||
equal(3, dataset.docCount)
|
|
||||||
// dataset.query().done(function(docList) {
|
|
||||||
// equal(3, docList.length)
|
|
||||||
// equal("2009-01-01", docList.models[0].get('date'));
|
|
||||||
// });
|
|
||||||
});
|
|
||||||
$.ajax.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
var dataProxyData = {
|
|
||||||
"data": [
|
|
||||||
[
|
|
||||||
"1",
|
|
||||||
"1950-01",
|
|
||||||
"34.73"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"2",
|
|
||||||
"1950-02",
|
|
||||||
"34.73"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"3",
|
|
||||||
"1950-03",
|
|
||||||
"34.73"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"4",
|
|
||||||
"1950-04",
|
|
||||||
"34.73"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"5",
|
|
||||||
"1950-05",
|
|
||||||
"34.73"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"6",
|
|
||||||
"1950-06",
|
|
||||||
"34.73"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"7",
|
|
||||||
"1950-07",
|
|
||||||
"34.73"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"8",
|
|
||||||
"1950-08",
|
|
||||||
"34.73"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"9",
|
|
||||||
"1950-09",
|
|
||||||
"34.73"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"10",
|
|
||||||
"1950-10",
|
|
||||||
"34.73"
|
|
||||||
]
|
]
|
||||||
],
|
};
|
||||||
|
dataset.query(queryObj).then(function(docs) {
|
||||||
|
var doc0 = dataset.currentDocuments.models[0].toJSON();
|
||||||
|
equal(doc0.x, 6);
|
||||||
|
});
|
||||||
|
dataset.query().then(function(docList) {
|
||||||
|
equal(docList.length, Math.min(100, indata.rows.length));
|
||||||
|
var doc1 = docList.models[0];
|
||||||
|
deepEqual(doc1.toJSON(), indata.rows[0]);
|
||||||
|
|
||||||
|
// Test UPDATE
|
||||||
|
var newVal = 10;
|
||||||
|
doc1.set({x: newVal});
|
||||||
|
doc1.save().then(function() {
|
||||||
|
equal(dataset.backendConfig.data.rows[0].x, newVal);
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test Delete
|
||||||
|
doc1.destroy().then(function() {
|
||||||
|
equal(dataset.backendConfig.data.rows.length, 5);
|
||||||
|
equal(dataset.backendConfig.data.rows[0].x, indata.rows[1].x);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: move to fixtures
|
||||||
|
var webstoreSchema = {
|
||||||
|
"count": 3,
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"name": "__id__",
|
||||||
|
"type": "integer",
|
||||||
|
"values_url": "/rufuspollock/demo/data/distinct/__id__"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "date",
|
||||||
|
"type": "text",
|
||||||
|
"values_url": "/rufuspollock/demo/data/distinct/date"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "geometry",
|
||||||
|
"type": "text",
|
||||||
|
"values_url": "/rufuspollock/demo/data/distinct/geometry"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "amount",
|
||||||
|
"type": "text",
|
||||||
|
"values_url": "/rufuspollock/demo/data/distinct/amount"
|
||||||
|
}
|
||||||
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
"__id__",
|
{
|
||||||
"date",
|
"name": "type"
|
||||||
"price"
|
},
|
||||||
],
|
{
|
||||||
"length": null,
|
"name": "name"
|
||||||
"max_results": 10,
|
},
|
||||||
"url": "http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv"
|
{
|
||||||
|
"name": "values_url"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
webstoreData = {
|
||||||
|
"count": null,
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"__id__": 1,
|
||||||
|
"amount": "100",
|
||||||
|
"date": "2009-01-01",
|
||||||
|
"geometry": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 2,
|
||||||
|
"amount": "200",
|
||||||
|
"date": "2010-01-01",
|
||||||
|
"geometry": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 3,
|
||||||
|
"amount": "300",
|
||||||
|
"date": "2011-01-01",
|
||||||
|
"geometry": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "__id__"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "date"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "geometry"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "amount"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
test('Webstore Backend', function() {
|
||||||
|
var dataset = new recline.Model.Dataset();
|
||||||
|
dataset.backendConfig = {
|
||||||
|
type: 'webstore',
|
||||||
|
url: 'http://webstore.test.ckan.org/rufuspollock/demo/data'
|
||||||
};
|
};
|
||||||
|
|
||||||
test('DataProxy Backend', function() {
|
var stub = sinon.stub($, 'ajax', function(options) {
|
||||||
// needed only if not stubbing
|
if (options.url.indexOf('schema.json') != -1) {
|
||||||
// stop();
|
return {
|
||||||
var dataset = new recline.Model.Dataset();
|
done: function(callback) {
|
||||||
dataset.backendConfig = {
|
callback(webstoreSchema);
|
||||||
type: 'dataproxy',
|
return this;
|
||||||
url: 'http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv'
|
},
|
||||||
};
|
fail: function() {
|
||||||
|
return this;
|
||||||
var stub = sinon.stub($, 'ajax', function(options) {
|
|
||||||
var partialUrl = 'jsonpdataproxy.appspot.com';
|
|
||||||
if (options.url.indexOf(partialUrl) != -1) {
|
|
||||||
return {
|
|
||||||
done: function(callback) {
|
|
||||||
callback(dataProxyData);
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
fail: function() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
return {
|
||||||
dataset.fetch().done(function(dataset) {
|
done: function(callback) {
|
||||||
deepEqual(['__id__', 'date', 'price'], dataset.get('headers'));
|
callback(webstoreData);
|
||||||
equal(null, dataset.docCount)
|
},
|
||||||
dataset.query().done(function(docList) {
|
fail: function() {
|
||||||
equal(10, docList.length)
|
}
|
||||||
equal("1950-01", docList.models[0].get('date'));
|
}
|
||||||
// needed only if not stubbing
|
}
|
||||||
start();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
$.ajax.restore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dataset.fetch().done(function(dataset) {
|
||||||
|
deepEqual(['__id__', 'date', 'geometry', 'amount'], dataset.get('headers'));
|
||||||
|
equal(3, dataset.docCount)
|
||||||
|
// dataset.query().done(function(docList) {
|
||||||
|
// equal(3, docList.length)
|
||||||
|
// equal("2009-01-01", docList.models[0].get('date'));
|
||||||
|
// });
|
||||||
|
});
|
||||||
|
$.ajax.restore();
|
||||||
|
});
|
||||||
|
|
||||||
var sample_gdocs_spreadsheet_data = {
|
|
||||||
"feed": {
|
var dataProxyData = {
|
||||||
"category": [
|
"data": [
|
||||||
|
[
|
||||||
|
"1",
|
||||||
|
"1950-01",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"2",
|
||||||
|
"1950-02",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"3",
|
||||||
|
"1950-03",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"4",
|
||||||
|
"1950-04",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"5",
|
||||||
|
"1950-05",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"6",
|
||||||
|
"1950-06",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"7",
|
||||||
|
"1950-07",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"8",
|
||||||
|
"1950-08",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"9",
|
||||||
|
"1950-09",
|
||||||
|
"34.73"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"10",
|
||||||
|
"1950-10",
|
||||||
|
"34.73"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
"__id__",
|
||||||
|
"date",
|
||||||
|
"price"
|
||||||
|
],
|
||||||
|
"length": null,
|
||||||
|
"max_results": 10,
|
||||||
|
"url": "http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv"
|
||||||
|
};
|
||||||
|
|
||||||
|
test('DataProxy Backend', function() {
|
||||||
|
// needed only if not stubbing
|
||||||
|
// stop();
|
||||||
|
var dataset = new recline.Model.Dataset();
|
||||||
|
dataset.backendConfig = {
|
||||||
|
type: 'dataproxy',
|
||||||
|
url: 'http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv'
|
||||||
|
};
|
||||||
|
|
||||||
|
var stub = sinon.stub($, 'ajax', function(options) {
|
||||||
|
var partialUrl = 'jsonpdataproxy.appspot.com';
|
||||||
|
if (options.url.indexOf(partialUrl) != -1) {
|
||||||
|
return {
|
||||||
|
done: function(callback) {
|
||||||
|
callback(dataProxyData);
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
fail: function() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dataset.fetch().done(function(dataset) {
|
||||||
|
deepEqual(['__id__', 'date', 'price'], dataset.get('headers'));
|
||||||
|
equal(null, dataset.docCount)
|
||||||
|
dataset.query().done(function(docList) {
|
||||||
|
equal(10, docList.length)
|
||||||
|
equal("1950-01", docList.models[0].get('date'));
|
||||||
|
// needed only if not stubbing
|
||||||
|
start();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$.ajax.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var sample_gdocs_spreadsheet_data = {
|
||||||
|
"feed": {
|
||||||
|
"category": [
|
||||||
|
{
|
||||||
|
"term": "http://schemas.google.com/spreadsheets/2006#list",
|
||||||
|
"scheme": "http://schemas.google.com/spreadsheets/2006"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"updated": {
|
||||||
|
"$t": "2010-07-12T18:32:16.200Z"
|
||||||
|
},
|
||||||
|
"xmlns": "http://www.w3.org/2005/Atom",
|
||||||
|
"xmlns$gsx": "http://schemas.google.com/spreadsheets/2006/extended",
|
||||||
|
"title": {
|
||||||
|
"$t": "Sheet1",
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"author": [
|
||||||
{
|
{
|
||||||
"term": "http://schemas.google.com/spreadsheets/2006#list",
|
"name": {
|
||||||
"scheme": "http://schemas.google.com/spreadsheets/2006"
|
"$t": "okfn.rufus.pollock"
|
||||||
|
},
|
||||||
|
"email": {
|
||||||
|
"$t": "okfn.rufus.pollock@gmail.com"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"updated": {
|
"openSearch$startIndex": {
|
||||||
"$t": "2010-07-12T18:32:16.200Z"
|
"$t": "1"
|
||||||
},
|
},
|
||||||
"xmlns": "http://www.w3.org/2005/Atom",
|
"link": [
|
||||||
"xmlns$gsx": "http://schemas.google.com/spreadsheets/2006/extended",
|
{
|
||||||
"title": {
|
"href": "http://spreadsheets.google.com/pub?key=0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc",
|
||||||
"$t": "Sheet1",
|
"type": "text/html",
|
||||||
"type": "text"
|
"rel": "alternate"
|
||||||
},
|
},
|
||||||
"author": [
|
{
|
||||||
|
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values",
|
||||||
|
"type": "application/atom+xml",
|
||||||
|
"rel": "http://schemas.google.com/g/2005#feed"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values?alt=json-in-script",
|
||||||
|
"type": "application/atom+xml",
|
||||||
|
"rel": "self"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"xmlns$openSearch": "http://a9.com/-/spec/opensearchrss/1.0/",
|
||||||
|
"entry": [
|
||||||
|
{
|
||||||
|
"category": [
|
||||||
{
|
{
|
||||||
"name": {
|
"term": "http://schemas.google.com/spreadsheets/2006#list",
|
||||||
"$t": "okfn.rufus.pollock"
|
"scheme": "http://schemas.google.com/spreadsheets/2006"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"updated": {
|
||||||
|
"$t": "2010-07-12T18:32:16.200Z"
|
||||||
},
|
},
|
||||||
"email": {
|
"gsx$column-2": {
|
||||||
"$t": "okfn.rufus.pollock@gmail.com"
|
"$t": "1"
|
||||||
}
|
},
|
||||||
}
|
"gsx$column-1": {
|
||||||
],
|
"$t": "A"
|
||||||
"openSearch$startIndex": {
|
},
|
||||||
"$t": "1"
|
"title": {
|
||||||
},
|
"$t": "A",
|
||||||
"link": [
|
"type": "text"
|
||||||
{
|
},
|
||||||
"href": "http://spreadsheets.google.com/pub?key=0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc",
|
"content": {
|
||||||
"type": "text/html",
|
"$t": "column-2: 1",
|
||||||
"rel": "alternate"
|
"type": "text"
|
||||||
},
|
},
|
||||||
{
|
"link": [
|
||||||
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values",
|
|
||||||
"type": "application/atom+xml",
|
|
||||||
"rel": "http://schemas.google.com/g/2005#feed"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values?alt=json-in-script",
|
|
||||||
"type": "application/atom+xml",
|
|
||||||
"rel": "self"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"xmlns$openSearch": "http://a9.com/-/spec/opensearchrss/1.0/",
|
|
||||||
"entry": [
|
|
||||||
{
|
|
||||||
"category": [
|
|
||||||
{
|
{
|
||||||
"term": "http://schemas.google.com/spreadsheets/2006#list",
|
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cokwr",
|
||||||
"scheme": "http://schemas.google.com/spreadsheets/2006"
|
"type": "application/atom+xml",
|
||||||
|
"rel": "self"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"updated": {
|
"id": {
|
||||||
"$t": "2010-07-12T18:32:16.200Z"
|
"$t": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cokwr"
|
||||||
},
|
}
|
||||||
"gsx$column-2": {
|
},
|
||||||
"$t": "1"
|
{
|
||||||
},
|
"category": [
|
||||||
"gsx$column-1": {
|
|
||||||
"$t": "A"
|
|
||||||
},
|
|
||||||
"title": {
|
|
||||||
"$t": "A",
|
|
||||||
"type": "text"
|
|
||||||
},
|
|
||||||
"content": {
|
|
||||||
"$t": "column-2: 1",
|
|
||||||
"type": "text"
|
|
||||||
},
|
|
||||||
"link": [
|
|
||||||
{
|
|
||||||
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cokwr",
|
|
||||||
"type": "application/atom+xml",
|
|
||||||
"rel": "self"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"id": {
|
|
||||||
"$t": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cokwr"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"category": [
|
"term": "http://schemas.google.com/spreadsheets/2006#list",
|
||||||
|
"scheme": "http://schemas.google.com/spreadsheets/2006"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"updated": {
|
||||||
|
"$t": "2010-07-12T18:32:16.200Z"
|
||||||
|
},
|
||||||
|
"gsx$column-2": {
|
||||||
|
"$t": "2"
|
||||||
|
},
|
||||||
|
"gsx$column-1": {
|
||||||
|
"$t": "b"
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
"$t": "b",
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
"$t": "column-2: 2",
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"link": [
|
||||||
{
|
{
|
||||||
"term": "http://schemas.google.com/spreadsheets/2006#list",
|
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cpzh4",
|
||||||
"scheme": "http://schemas.google.com/spreadsheets/2006"
|
"type": "application/atom+xml",
|
||||||
|
"rel": "self"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"updated": {
|
"id": {
|
||||||
"$t": "2010-07-12T18:32:16.200Z"
|
"$t": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cpzh4"
|
||||||
},
|
}
|
||||||
"gsx$column-2": {
|
},
|
||||||
"$t": "2"
|
{
|
||||||
},
|
"category": [
|
||||||
"gsx$column-1": {
|
|
||||||
"$t": "b"
|
|
||||||
},
|
|
||||||
"title": {
|
|
||||||
"$t": "b",
|
|
||||||
"type": "text"
|
|
||||||
},
|
|
||||||
"content": {
|
|
||||||
"$t": "column-2: 2",
|
|
||||||
"type": "text"
|
|
||||||
},
|
|
||||||
"link": [
|
|
||||||
{
|
|
||||||
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cpzh4",
|
|
||||||
"type": "application/atom+xml",
|
|
||||||
"rel": "self"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"id": {
|
|
||||||
"$t": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cpzh4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"category": [
|
"term": "http://schemas.google.com/spreadsheets/2006#list",
|
||||||
|
"scheme": "http://schemas.google.com/spreadsheets/2006"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"updated": {
|
||||||
|
"$t": "2010-07-12T18:32:16.200Z"
|
||||||
|
},
|
||||||
|
"gsx$column-2": {
|
||||||
|
"$t": "3"
|
||||||
|
},
|
||||||
|
"gsx$column-1": {
|
||||||
|
"$t": "c"
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
"$t": "c",
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
"$t": "column-2: 3",
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"link": [
|
||||||
{
|
{
|
||||||
"term": "http://schemas.google.com/spreadsheets/2006#list",
|
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cre1l",
|
||||||
"scheme": "http://schemas.google.com/spreadsheets/2006"
|
"type": "application/atom+xml",
|
||||||
|
"rel": "self"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": {
|
||||||
|
"$t": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cre1l"
|
||||||
}
|
}
|
||||||
],
|
|
||||||
"updated": {
|
|
||||||
"$t": "2010-07-12T18:32:16.200Z"
|
|
||||||
},
|
|
||||||
"gsx$column-2": {
|
|
||||||
"$t": "3"
|
|
||||||
},
|
|
||||||
"gsx$column-1": {
|
|
||||||
"$t": "c"
|
|
||||||
},
|
|
||||||
"title": {
|
|
||||||
"$t": "c",
|
|
||||||
"type": "text"
|
|
||||||
},
|
|
||||||
"content": {
|
|
||||||
"$t": "column-2: 3",
|
|
||||||
"type": "text"
|
|
||||||
},
|
|
||||||
"link": [
|
|
||||||
{
|
|
||||||
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cre1l",
|
|
||||||
"type": "application/atom+xml",
|
|
||||||
"rel": "self"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"id": {
|
|
||||||
"$t": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cre1l"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"openSearch$totalResults": {
|
|
||||||
"$t": "3"
|
|
||||||
},
|
|
||||||
"id": {
|
|
||||||
"$t": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"version": "1.0",
|
|
||||||
"encoding": "UTF-8"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test("GDoc Backend", function() {
|
|
||||||
var dataset = new recline.Model.Dataset();
|
|
||||||
dataset.backendConfig = {
|
|
||||||
type: 'gdocs',
|
|
||||||
url: 'https://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values?alt=json'
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log('got gdoc dataset', dataset);
|
|
||||||
|
|
||||||
var stub = sinon.stub($, 'getJSON', function(options, cb) {
|
|
||||||
console.log('options are', options, cb);
|
|
||||||
var partialUrl = 'spreadsheets.google.com';
|
|
||||||
if (options.indexOf(partialUrl) != -1) {
|
|
||||||
cb(sample_gdocs_spreadsheet_data)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
],
|
||||||
|
"openSearch$totalResults": {
|
||||||
|
"$t": "3"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"$t": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"version": "1.0",
|
||||||
|
"encoding": "UTF-8"
|
||||||
|
}
|
||||||
|
|
||||||
dataset.fetch().then(function(dataset) {
|
test("GDoc Backend", function() {
|
||||||
console.log('inside dataset:', dataset, dataset.get('headers'), dataset.get('data'));
|
var dataset = new recline.Model.Dataset();
|
||||||
deepEqual(['column-2', 'column-1'], dataset.get('headers'));
|
dataset.backendConfig = {
|
||||||
//equal(null, dataset.docCount)
|
type: 'gdocs',
|
||||||
dataset.query().then(function(docList) {
|
url: 'https://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values?alt=json'
|
||||||
equal(3, docList.length);
|
};
|
||||||
console.log(docList.models[0]);
|
|
||||||
equal("A", docList.models[0].get('column-1'));
|
|
||||||
// needed only if not stubbing
|
|
||||||
start();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
$.getJSON.restore();
|
|
||||||
|
|
||||||
|
console.log('got gdoc dataset', dataset);
|
||||||
|
|
||||||
|
var stub = sinon.stub($, 'getJSON', function(options, cb) {
|
||||||
|
console.log('options are', options, cb);
|
||||||
|
var partialUrl = 'spreadsheets.google.com';
|
||||||
|
if (options.indexOf(partialUrl) != -1) {
|
||||||
|
cb(sample_gdocs_spreadsheet_data)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dataset.fetch().then(function(dataset) {
|
||||||
|
console.log('inside dataset:', dataset, dataset.get('headers'), dataset.get('data'));
|
||||||
|
deepEqual(['column-2', 'column-1'], dataset.get('headers'));
|
||||||
|
//equal(null, dataset.docCount)
|
||||||
|
dataset.query().then(function(docList) {
|
||||||
|
equal(3, docList.length);
|
||||||
|
console.log(docList.models[0]);
|
||||||
|
equal("A", docList.models[0].get('column-1'));
|
||||||
|
// needed only if not stubbing
|
||||||
|
start();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$.getJSON.restore();
|
||||||
|
});
|
||||||
|
|
||||||
})(this.jQuery);
|
})(this.jQuery);
|
||||||
|
|||||||
Reference in New Issue
Block a user