[#162,refactor][s]: backend fetch method dataset argument is simple JS object not backbone Dataset.
* Helps make Backends simpler and more independent of Model
This commit is contained in:
@@ -12,9 +12,9 @@ this.recline.Backend.DataProxy = this.recline.Backend.DataProxy || {};
|
|||||||
// Load data from a URL via the [DataProxy](http://github.com/okfn/dataproxy).
|
// Load data from a URL via the [DataProxy](http://github.com/okfn/dataproxy).
|
||||||
my.fetch = function(dataset) {
|
my.fetch = function(dataset) {
|
||||||
var data = {
|
var data = {
|
||||||
url: dataset.get('url'),
|
url: dataset.url,
|
||||||
'max-results': dataset.get('size') || dataset.get('rows') || 1000,
|
'max-results': dataset.size || dataset.rows || 1000,
|
||||||
type: dataset.get('format') || ''
|
type: dataset.format || ''
|
||||||
};
|
};
|
||||||
var jqxhr = $.ajax({
|
var jqxhr = $.ajax({
|
||||||
url: my.dataproxy_url,
|
url: my.dataproxy_url,
|
||||||
|
|||||||
@@ -3,11 +3,14 @@ this.recline.Backend = this.recline.Backend || {};
|
|||||||
this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {};
|
this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {};
|
||||||
|
|
||||||
(function($, my) {
|
(function($, my) {
|
||||||
|
my.fetch = function(dataset) {
|
||||||
|
};
|
||||||
|
|
||||||
// ## ElasticSearch Wrapper
|
// ## ElasticSearch Wrapper
|
||||||
//
|
//
|
||||||
// Connecting to [ElasticSearch](http://www.elasticsearch.org/) endpoints.
|
// Connecting to [ElasticSearch](http://www.elasticsearch.org/) endpoints.
|
||||||
// @param {String} endpoint: url for ElasticSearch type/table, e.g. for ES running
|
// @param {String} endpoint: url for ElasticSearch type/table, e.g. for ES running
|
||||||
// on localhost:9200 with index // twitter and type tweet it would be:
|
// on http://localhost:9200 with index twitter and type tweet it would be:
|
||||||
//
|
//
|
||||||
// <pre>http://localhost:9200/twitter/tweet</pre>
|
// <pre>http://localhost:9200/twitter/tweet</pre>
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ this.recline.Backend.GDocs = this.recline.Backend.GDocs || {};
|
|||||||
// Dataset must have a url attribute pointing to the Gdocs or its JSON feed e.g.
|
// Dataset must have a url attribute pointing to the Gdocs or its JSON feed e.g.
|
||||||
// <pre>
|
// <pre>
|
||||||
// var dataset = new recline.Model.Dataset({
|
// var dataset = new recline.Model.Dataset({
|
||||||
|
// url: 'https://docs.google.com/spreadsheet/ccc?key=0Aon3JiuouxLUdGlQVDJnbjZRSU1tUUJWOUZXRG53VkE#gid=0'
|
||||||
|
// },
|
||||||
|
// 'gdocs'
|
||||||
|
// );
|
||||||
|
//
|
||||||
|
// var dataset = new recline.Model.Dataset({
|
||||||
// url: 'https://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values?alt=json'
|
// url: 'https://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values?alt=json'
|
||||||
// },
|
// },
|
||||||
// 'gdocs'
|
// 'gdocs'
|
||||||
@@ -22,10 +28,9 @@ this.recline.Backend.GDocs = this.recline.Backend.GDocs || {};
|
|||||||
//
|
//
|
||||||
// * fields: array of Field objects
|
// * fields: array of Field objects
|
||||||
// * records: array of objects for each row
|
// * records: array of objects for each row
|
||||||
//
|
|
||||||
my.fetch = function(dataset) {
|
my.fetch = function(dataset) {
|
||||||
var dfd = $.Deferred();
|
var dfd = $.Deferred();
|
||||||
var url = my.getSpreadsheetAPIUrl(dataset.get('url'));
|
var url = my.getSpreadsheetAPIUrl(dataset.url);
|
||||||
$.getJSON(url, function(d) {
|
$.getJSON(url, function(d) {
|
||||||
result = my.parseData(d);
|
result = my.parseData(d);
|
||||||
var fields = _.map(result.fields, function(fieldId) {
|
var fields = _.map(result.fields, function(fieldId) {
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ my.Dataset = Backbone.Model.extend({
|
|||||||
var dfd = $.Deferred();
|
var dfd = $.Deferred();
|
||||||
// TODO: fail case;
|
// TODO: fail case;
|
||||||
if (this.backend !== recline.Backend.Memory) {
|
if (this.backend !== recline.Backend.Memory) {
|
||||||
this.backend.fetch(this).then(handleResults)
|
this.backend.fetch(this.toJSON()).then(handleResults)
|
||||||
} else {
|
} else {
|
||||||
// special case where we have been given data directly
|
// special case where we have been given data directly
|
||||||
handleResults({
|
handleResults({
|
||||||
|
|||||||
Reference in New Issue
Block a user