[#110,app,load,ux][s]: refactor import/load menu to be called load, to support DataHub directly, and have better UX.
* List options to load from in dropdown menu rather than modal dialog * Provide some help info in load dialog * Support DataHub (including auto-guessing of Data API) - fixes #110.
This commit is contained in:
@@ -6,8 +6,9 @@ jQuery(function($) {
|
||||
|
||||
var ExplorerApp = Backbone.View.extend({
|
||||
events: {
|
||||
'submit form.js-import-url': '_onImportURL',
|
||||
'submit .js-import-dialog-file form': '_onImportFile'
|
||||
'click .nav .js-load-dialog-url': '_onLoadURLDialog',
|
||||
'submit form.js-load-url': '_onLoadURL',
|
||||
'submit .js-load-dialog-file form': '_onLoadFile'
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
@@ -153,33 +154,52 @@ var ExplorerApp = Backbone.View.extend({
|
||||
setupLoader: function(callback) {
|
||||
// pre-populate webstore load form with an example url
|
||||
var demoUrl = 'http://thedatahub.org/api/data/b9aae52b-b082-4159-b46f-7bb9c158d013';
|
||||
$('form.js-import-url input[name="source"]').val(demoUrl);
|
||||
$('form.js-load-url input[name="source"]').val(demoUrl);
|
||||
},
|
||||
|
||||
_onImportURL: function(e) {
|
||||
_onLoadURLDialog: function(e) {
|
||||
e.preventDefault();
|
||||
$('.modal.js-import-dialog-url').modal('hide');
|
||||
var $link = $(e.target);
|
||||
var $modal = $('.modal.js-load-dialog-url');
|
||||
$modal.find('h3').text($link.text());
|
||||
$modal.modal('show');
|
||||
$modal.find('input[name="source"]').val('');
|
||||
$modal.find('input[name="backend_type"]').val($link.attr('data-type'));
|
||||
$modal.find('.help-block').text($link.attr('data-help'));
|
||||
},
|
||||
|
||||
_onLoadURL: function(e) {
|
||||
e.preventDefault();
|
||||
$('.modal.js-load-dialog-url').modal('hide');
|
||||
var $form = $(e.target);
|
||||
var source = $form.find('input[name="source"]').val();
|
||||
var datasetInfo = {
|
||||
id: 'my-dataset',
|
||||
url: source,
|
||||
webstore_url: source
|
||||
url: source
|
||||
};
|
||||
var type = $form.find('select[name="backend_type"]').val();
|
||||
var type = $form.find('input[name="backend_type"]').val();
|
||||
if (type === 'csv' || type === 'excel') {
|
||||
datasetInfo.format = type;
|
||||
type = 'dataproxy';
|
||||
}
|
||||
if (type === 'datahub') {
|
||||
// have a full resource url so convert to data API
|
||||
if (source.indexOf('dataset') != -1) {
|
||||
var parts = source.split('/');
|
||||
datasetInfo.url = parts[0] + '/' + parts[1] + '/' + parts[2] + '/api/data/' + parts[parts.length-1];
|
||||
}
|
||||
type = 'elasticsearch';
|
||||
}
|
||||
console.log(datasetInfo.url);
|
||||
var dataset = new recline.Model.Dataset(datasetInfo, type);
|
||||
this.createExplorer(dataset);
|
||||
},
|
||||
|
||||
_onImportFile: function(e) {
|
||||
_onLoadFile: function(e) {
|
||||
var self = this;
|
||||
e.preventDefault();
|
||||
var $form = $(e.target);
|
||||
$('.modal.js-import-dialog-file').modal('hide');
|
||||
$('.modal.js-load-dialog-file').modal('hide');
|
||||
var $file = $form.find('input[type="file"]')[0];
|
||||
var file = $file.files[0];
|
||||
var options = {
|
||||
|
||||
Reference in New Issue
Block a user