[#162,refactor][s]: backend is now string in 'normal' set of Dataset arguments.
This commit is contained in:
parent
5216e23f45
commit
3d6ad46cc5
@ -192,7 +192,8 @@ var ExplorerApp = Backbone.View.extend({
|
||||
}
|
||||
type = 'elasticsearch';
|
||||
}
|
||||
var dataset = new recline.Model.Dataset(datasetInfo, type);
|
||||
datasetInfo.backend = type;
|
||||
var dataset = new recline.Model.Dataset(datasetInfo);
|
||||
this.createExplorer(dataset);
|
||||
},
|
||||
|
||||
@ -203,13 +204,12 @@ var ExplorerApp = Backbone.View.extend({
|
||||
$('.modal.js-load-dialog-file').modal('hide');
|
||||
var $file = $form.find('input[type="file"]')[0];
|
||||
var dataset = new recline.Model.Dataset({
|
||||
file: $file.files[0],
|
||||
separator : $form.find('input[name="separator"]').val(),
|
||||
delimiter : $form.find('input[name="delimiter"]').val(),
|
||||
encoding : $form.find('input[name="encoding"]').val()
|
||||
},
|
||||
'csv'
|
||||
);
|
||||
file: $file.files[0],
|
||||
separator : $form.find('input[name="separator"]').val(),
|
||||
delimiter : $form.find('input[name="delimiter"]').val(),
|
||||
encoding : $form.find('input[name="encoding"]').val(),
|
||||
backend: 'csv'
|
||||
});
|
||||
dataset.fetch().done(function() {
|
||||
self.createExplorer(dataset)
|
||||
});
|
||||
|
||||
33
src/model.js
33
src/model.js
@ -9,28 +9,16 @@ my.Dataset = Backbone.Model.extend({
|
||||
__type__: 'Dataset',
|
||||
|
||||
// ### initialize
|
||||
//
|
||||
// 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) {
|
||||
initialize: function() {
|
||||
_.bindAll(this, 'query');
|
||||
this.backend = backend;
|
||||
if (typeof backend === 'undefined') {
|
||||
this.backend = null;
|
||||
if (this.get('backend')) {
|
||||
this.backend = this._backendFromString(this.get('backend'));
|
||||
} else { // try to guess backend ...
|
||||
if (this.get('records')) {
|
||||
this.backend = recline.Backend.Memory;
|
||||
}
|
||||
}
|
||||
if (typeof(backend) === 'string') {
|
||||
this.backend = this._backendFromString(backend);
|
||||
}
|
||||
this.fields = new my.FieldList();
|
||||
this.currentRecords = new my.RecordList();
|
||||
this._changes = {
|
||||
@ -43,6 +31,9 @@ my.Dataset = Backbone.Model.extend({
|
||||
this.queryState = new my.Query();
|
||||
this.queryState.bind('change', 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;
|
||||
if (this.backend == recline.Backend.Memory) {
|
||||
this.fetch();
|
||||
@ -298,13 +289,11 @@ my.Dataset.restore = function(state) {
|
||||
};
|
||||
} else {
|
||||
var datasetInfo = {
|
||||
url: state.url
|
||||
url: state.url,
|
||||
backend: state.backend
|
||||
};
|
||||
}
|
||||
dataset = new recline.Model.Dataset(
|
||||
datasetInfo,
|
||||
state.backend
|
||||
);
|
||||
dataset = new recline.Model.Dataset(datasetInfo);
|
||||
return dataset;
|
||||
};
|
||||
|
||||
|
||||
@ -25,10 +25,9 @@ test("parseCSV", function() {
|
||||
'"Xyz ""ABC"" O\'Brien", 11:35\n' +
|
||||
'"Other, AN", 12:35\n';
|
||||
var dataset = new recline.Model.Dataset({
|
||||
data: csv
|
||||
},
|
||||
'csv'
|
||||
);
|
||||
data: csv,
|
||||
backend: 'csv'
|
||||
});
|
||||
dataset.fetch();
|
||||
equal(dataset.currentRecords.length, 3);
|
||||
var row = dataset.currentRecords.models[0].toJSON();
|
||||
|
||||
@ -71,9 +71,9 @@ test('DataProxy Backend', function() {
|
||||
equal(backend.__type__, 'dataproxy');
|
||||
|
||||
var dataset = new recline.Model.Dataset({
|
||||
url: 'http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv'
|
||||
},
|
||||
'dataproxy'
|
||||
url: 'http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv',
|
||||
backend: 'dataproxy'
|
||||
}
|
||||
);
|
||||
|
||||
var stub = sinon.stub($, 'ajax', function(options) {
|
||||
|
||||
@ -250,10 +250,9 @@ module("Backend ElasticSearch - Recline");
|
||||
|
||||
test("query", function() {
|
||||
var dataset = new recline.Model.Dataset({
|
||||
url: 'https://localhost:9200/my-es-db/my-es-type'
|
||||
},
|
||||
'elasticsearch'
|
||||
);
|
||||
url: 'https://localhost:9200/my-es-db/my-es-type',
|
||||
backend: 'elasticsearch'
|
||||
});
|
||||
|
||||
var stub = sinon.stub($, 'ajax', function(options) {
|
||||
if (options.url.indexOf('_mapping') != -1) {
|
||||
@ -292,10 +291,9 @@ test("query", function() {
|
||||
|
||||
test("write", function() {
|
||||
var dataset = new recline.Model.Dataset({
|
||||
url: 'http://localhost:9200/recline-test/es-write'
|
||||
},
|
||||
'elasticsearch'
|
||||
);
|
||||
url: 'http://localhost:9200/recline-test/es-write',
|
||||
backend: 'elasticsearch'
|
||||
});
|
||||
|
||||
stop();
|
||||
|
||||
|
||||
@ -169,10 +169,9 @@ var sample_gdocs_spreadsheet_data = {
|
||||
|
||||
test("GDocs Backend", function() {
|
||||
var dataset = new recline.Model.Dataset({
|
||||
url: 'https://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values?alt=json'
|
||||
},
|
||||
'gdocs'
|
||||
);
|
||||
url: 'https://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values?alt=json',
|
||||
backend: 'gdocs'
|
||||
});
|
||||
|
||||
var stub = sinon.stub($, 'getJSON', function(options, cb) {
|
||||
var partialUrl = 'spreadsheets.google.com';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user