[backend/webstore][s]: remove webstore backend.

This commit is contained in:
Rufus Pollock 2012-03-15 00:27:53 +00:00
parent 35631f3713
commit 95a394bd13
3 changed files with 1 additions and 178 deletions

View File

@ -39,7 +39,7 @@
<select name="backend_type">
<option value="elasticsearch">ElasticSearch</option>
<option value="dataproxy">DataProxy</option>
<option value="webstore">Webstore</option>
<option value="gdocs">Google Spreadsheets</option>
</select>
</form>
</div>

View File

@ -1,61 +0,0 @@
this.recline = this.recline || {};
this.recline.Backend = this.recline.Backend || {};
(function($, my) {
// ## Webstore Backend
//
// Connecting to [Webstores](http://github.com/okfn/webstore)
//
// To use this backend ensure your Dataset has a webstore_url in its attributes.
my.Webstore = Backbone.Model.extend({
sync: function(method, model, options) {
if (method === "read") {
if (model.__type__ == 'Dataset') {
var base = model.get('webstore_url');
var schemaUrl = base + '/schema.json';
var jqxhr = $.ajax({
url: schemaUrl,
dataType: 'jsonp',
jsonp: '_callback'
});
var dfd = $.Deferred();
my.wrapInTimeout(jqxhr).done(function(schema) {
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);
})
.fail(function(arguments) {
dfd.reject(arguments);
});
return dfd.promise();
}
}
},
query: function(model, queryObj) {
var base = model.get('webstore_url');
var data = {
_limit: queryObj.size
, _offset: queryObj.from
};
var jqxhr = $.ajax({
url: base + '.json',
data: data,
dataType: 'jsonp',
jsonp: '_callback',
cache: true
});
var dfd = $.Deferred();
jqxhr.done(function(results) {
dfd.resolve(results.data);
});
return dfd.promise();
}
});
recline.Model.backends['webstore'] = new my.Webstore();
}(jQuery, this.recline.Backend));

View File

@ -90,122 +90,6 @@ test('Memory Backend: update and delete', function () {
});
});
// 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"
}
]
};
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({
id: 'my-id',
webstore_url: 'http://webstore.test.ckan.org/rufuspollock/demo/data'
},
'webstore'
);
var stub = sinon.stub($, 'ajax', function(options) {
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() {
}
}
}
});
dataset.fetch().done(function(dataset) {
deepEqual(['__id__', 'date', 'geometry', 'amount'], _.pluck(dataset.fields.toJSON(), 'id'));
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": [