[#162,refactor][s]: backend is now string in 'normal' set of Dataset arguments.
This commit is contained in:
@@ -192,7 +192,8 @@ var ExplorerApp = Backbone.View.extend({
|
|||||||
}
|
}
|
||||||
type = 'elasticsearch';
|
type = 'elasticsearch';
|
||||||
}
|
}
|
||||||
var dataset = new recline.Model.Dataset(datasetInfo, type);
|
datasetInfo.backend = type;
|
||||||
|
var dataset = new recline.Model.Dataset(datasetInfo);
|
||||||
this.createExplorer(dataset);
|
this.createExplorer(dataset);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -203,13 +204,12 @@ var ExplorerApp = Backbone.View.extend({
|
|||||||
$('.modal.js-load-dialog-file').modal('hide');
|
$('.modal.js-load-dialog-file').modal('hide');
|
||||||
var $file = $form.find('input[type="file"]')[0];
|
var $file = $form.find('input[type="file"]')[0];
|
||||||
var dataset = new recline.Model.Dataset({
|
var dataset = new recline.Model.Dataset({
|
||||||
file: $file.files[0],
|
file: $file.files[0],
|
||||||
separator : $form.find('input[name="separator"]').val(),
|
separator : $form.find('input[name="separator"]').val(),
|
||||||
delimiter : $form.find('input[name="delimiter"]').val(),
|
delimiter : $form.find('input[name="delimiter"]').val(),
|
||||||
encoding : $form.find('input[name="encoding"]').val()
|
encoding : $form.find('input[name="encoding"]').val(),
|
||||||
},
|
backend: 'csv'
|
||||||
'csv'
|
});
|
||||||
);
|
|
||||||
dataset.fetch().done(function() {
|
dataset.fetch().done(function() {
|
||||||
self.createExplorer(dataset)
|
self.createExplorer(dataset)
|
||||||
});
|
});
|
||||||
|
|||||||
33
src/model.js
33
src/model.js
@@ -9,28 +9,16 @@ my.Dataset = Backbone.Model.extend({
|
|||||||
__type__: 'Dataset',
|
__type__: 'Dataset',
|
||||||
|
|
||||||
// ### initialize
|
// ### initialize
|
||||||
//
|
initialize: function() {
|
||||||
// Sets up instance properties (see above)
|
|
||||||
//
|
|
||||||
// @param {Object} model: standard set of model attributes passed to Backbone models
|
|
||||||
//
|
|
||||||
// @param {Object or String} backend: Backend instance (see
|
|
||||||
// `recline.Backend.Base`) or a string specifying that instance. The
|
|
||||||
// string specifying may be a full class path e.g.
|
|
||||||
// 'recline.Backend.ElasticSearch' or a simple name e.g.
|
|
||||||
// 'elasticsearch' or 'ElasticSearch' (in this case must be a Backend in
|
|
||||||
// recline.Backend module)
|
|
||||||
initialize: function(model, backend) {
|
|
||||||
_.bindAll(this, 'query');
|
_.bindAll(this, 'query');
|
||||||
this.backend = backend;
|
this.backend = null;
|
||||||
if (typeof backend === 'undefined') {
|
if (this.get('backend')) {
|
||||||
|
this.backend = this._backendFromString(this.get('backend'));
|
||||||
|
} else { // try to guess backend ...
|
||||||
if (this.get('records')) {
|
if (this.get('records')) {
|
||||||
this.backend = recline.Backend.Memory;
|
this.backend = recline.Backend.Memory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (typeof(backend) === 'string') {
|
|
||||||
this.backend = this._backendFromString(backend);
|
|
||||||
}
|
|
||||||
this.fields = new my.FieldList();
|
this.fields = new my.FieldList();
|
||||||
this.currentRecords = new my.RecordList();
|
this.currentRecords = new my.RecordList();
|
||||||
this._changes = {
|
this._changes = {
|
||||||
@@ -43,6 +31,9 @@ my.Dataset = Backbone.Model.extend({
|
|||||||
this.queryState = new my.Query();
|
this.queryState = new my.Query();
|
||||||
this.queryState.bind('change', this.query);
|
this.queryState.bind('change', this.query);
|
||||||
this.queryState.bind('facet:add', this.query);
|
this.queryState.bind('facet:add', this.query);
|
||||||
|
// store is what we query and save against
|
||||||
|
// store will either be the backend or be a memory store if Backend fetch
|
||||||
|
// tells us to use memory store
|
||||||
this._store = this.backend;
|
this._store = this.backend;
|
||||||
if (this.backend == recline.Backend.Memory) {
|
if (this.backend == recline.Backend.Memory) {
|
||||||
this.fetch();
|
this.fetch();
|
||||||
@@ -298,13 +289,11 @@ my.Dataset.restore = function(state) {
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
var datasetInfo = {
|
var datasetInfo = {
|
||||||
url: state.url
|
url: state.url,
|
||||||
|
backend: state.backend
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
dataset = new recline.Model.Dataset(
|
dataset = new recline.Model.Dataset(datasetInfo);
|
||||||
datasetInfo,
|
|
||||||
state.backend
|
|
||||||
);
|
|
||||||
return dataset;
|
return dataset;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -25,10 +25,9 @@ test("parseCSV", function() {
|
|||||||
'"Xyz ""ABC"" O\'Brien", 11:35\n' +
|
'"Xyz ""ABC"" O\'Brien", 11:35\n' +
|
||||||
'"Other, AN", 12:35\n';
|
'"Other, AN", 12:35\n';
|
||||||
var dataset = new recline.Model.Dataset({
|
var dataset = new recline.Model.Dataset({
|
||||||
data: csv
|
data: csv,
|
||||||
},
|
backend: 'csv'
|
||||||
'csv'
|
});
|
||||||
);
|
|
||||||
dataset.fetch();
|
dataset.fetch();
|
||||||
equal(dataset.currentRecords.length, 3);
|
equal(dataset.currentRecords.length, 3);
|
||||||
var row = dataset.currentRecords.models[0].toJSON();
|
var row = dataset.currentRecords.models[0].toJSON();
|
||||||
|
|||||||
@@ -71,9 +71,9 @@ test('DataProxy Backend', function() {
|
|||||||
equal(backend.__type__, 'dataproxy');
|
equal(backend.__type__, 'dataproxy');
|
||||||
|
|
||||||
var dataset = new recline.Model.Dataset({
|
var dataset = new recline.Model.Dataset({
|
||||||
url: 'http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv'
|
url: 'http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv',
|
||||||
},
|
backend: 'dataproxy'
|
||||||
'dataproxy'
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
var stub = sinon.stub($, 'ajax', function(options) {
|
var stub = sinon.stub($, 'ajax', function(options) {
|
||||||
|
|||||||
@@ -250,10 +250,9 @@ module("Backend ElasticSearch - Recline");
|
|||||||
|
|
||||||
test("query", function() {
|
test("query", function() {
|
||||||
var dataset = new recline.Model.Dataset({
|
var dataset = new recline.Model.Dataset({
|
||||||
url: 'https://localhost:9200/my-es-db/my-es-type'
|
url: 'https://localhost:9200/my-es-db/my-es-type',
|
||||||
},
|
backend: 'elasticsearch'
|
||||||
'elasticsearch'
|
});
|
||||||
);
|
|
||||||
|
|
||||||
var stub = sinon.stub($, 'ajax', function(options) {
|
var stub = sinon.stub($, 'ajax', function(options) {
|
||||||
if (options.url.indexOf('_mapping') != -1) {
|
if (options.url.indexOf('_mapping') != -1) {
|
||||||
@@ -292,10 +291,9 @@ test("query", function() {
|
|||||||
|
|
||||||
test("write", function() {
|
test("write", function() {
|
||||||
var dataset = new recline.Model.Dataset({
|
var dataset = new recline.Model.Dataset({
|
||||||
url: 'http://localhost:9200/recline-test/es-write'
|
url: 'http://localhost:9200/recline-test/es-write',
|
||||||
},
|
backend: 'elasticsearch'
|
||||||
'elasticsearch'
|
});
|
||||||
);
|
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
|
|||||||
@@ -169,10 +169,9 @@ var sample_gdocs_spreadsheet_data = {
|
|||||||
|
|
||||||
test("GDocs Backend", function() {
|
test("GDocs Backend", function() {
|
||||||
var dataset = new recline.Model.Dataset({
|
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',
|
||||||
},
|
backend: 'gdocs'
|
||||||
'gdocs'
|
});
|
||||||
);
|
|
||||||
|
|
||||||
var stub = sinon.stub($, 'getJSON', function(options, cb) {
|
var stub = sinon.stub($, 'getJSON', function(options, cb) {
|
||||||
var partialUrl = 'spreadsheets.google.com';
|
var partialUrl = 'spreadsheets.google.com';
|
||||||
|
|||||||
Reference in New Issue
Block a user