Skip to content

Commit

Permalink
Make callbacks consistent for dataset methods. #672.
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxfish committed May 3, 2012
1 parent 19071ae commit 6dd722c
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 59 deletions.
46 changes: 26 additions & 20 deletions client/static/js/models/datasets.js
Expand Up @@ -156,7 +156,7 @@ PANDA.models.Dataset = Backbone.Model.extend({
error = JSON.parse(xhr.responseText);

if (error_callback) {
error_callback(error);
error_callback(this, error);
}
}
});
Expand Down Expand Up @@ -190,7 +190,7 @@ PANDA.models.Dataset = Backbone.Model.extend({
error = JSON.parse(xhr.responseText);

if (error_callback) {
error_callback(error);
error_callback(this, error);
}
}
});
Expand Down Expand Up @@ -222,7 +222,7 @@ PANDA.models.Dataset = Backbone.Model.extend({
var error = JSON.parse(xhr.responseText);

if (error_callback) {
error_callback(error);
error_callback(this, error);
}
}
});
Expand All @@ -248,7 +248,7 @@ PANDA.models.Dataset = Backbone.Model.extend({
this.set(response);

if (success_callback) {
success_callback(response);
success_callback(this);
}
}, this),
error: _.bind(function(xhr, status, error) {
Expand Down Expand Up @@ -292,7 +292,7 @@ PANDA.models.Dataset = Backbone.Model.extend({
var error = JSON.parse(xhr.responseText);

if (error_callback) {
error_callback(this, xhr.responseText);
error_callback(this, error);
}
}
});
Expand Down Expand Up @@ -368,7 +368,7 @@ PANDA.collections.Datasets = Backbone.Collection.extend({
var error = JSON.parse(xhr.responseText);

if (error_callback) {
error_callback(error);
error_callback(this, error);
}
}
});
Expand Down Expand Up @@ -427,29 +427,35 @@ PANDA.collections.Datasets = Backbone.Collection.extend({
dataType: "json",
data: data,
success: _.bind(function(response) {
var objs = this.parse(response);

datasets = _.map(objs, function(obj) {
d = new PANDA.models.Dataset();
d.set(d.parse(obj));

return d;
});

this.reset(datasets);
this.process_search_meta_results(response);

if (success_callback) {
success_callback(this, response);
success_callback(this);
}
}, this),
error: _.bind(function(xhr, status, error) {
error: function(xhr, textStatus) {
var error = JSON.parse(xhr.responseText);

if (error_callback) {
error_callback(this, xhr.responseText);
error_callback(this, error);
}
}, this)
}
});
},

process_search_meta_results: function(response) {
var objs = this.parse(response);

datasets = _.map(objs, function(obj) {
d = new PANDA.models.Dataset();
d.set(d.parse(obj));

return d;
});

this.reset(datasets);
},

results: function() {
/*
* Grab the current data in a simplified data structure appropriate
Expand Down
3 changes: 3 additions & 0 deletions client/static/js/models/users.js
Expand Up @@ -17,6 +17,8 @@ PANDA.models.User = Backbone.Model.extend({
refresh_notifications: function(success_callback) {
/*
* Refresh notifications list from the server.
*
* TODO: error callback
*/
this.notifications.fetch({
data: "read_at__isnull=True",
Expand All @@ -29,6 +31,7 @@ PANDA.models.User = Backbone.Model.extend({
* Mark all notifications as read.
*
* TODO: bulk update
* TODO: error callback
*/
var now = moment().format("YYYY-MM-DDTHH:mm:ss");

Expand Down
8 changes: 4 additions & 4 deletions client/static/js/views/data_upload.js
Expand Up @@ -260,10 +260,10 @@ PANDA.views.DataUpload = Backbone.View.extend({
// Begin import, runs synchronously so errors may be caught immediately
this.dataset.import_data(
this.upload.get("id"),
_.bind(function() {
Redd.goto_dataset_view(this.dataset.get("slug"));
}, this),
_.bind(function(error) {
function(dataset) {
Redd.goto_dataset_view(dataset.get("slug"));
},
_.bind(function(dataset, error) {
// Preemptive import errors (mismatched columns, etc.)
this.upload.destroy()
this.step_three_error_message(error.error_message);
Expand Down
11 changes: 6 additions & 5 deletions client/static/js/views/dataset_edit.js
Expand Up @@ -76,20 +76,21 @@ PANDA.views.DatasetEdit = Backbone.View.extend({
}, this));

this.dataset.patch(s,
_.bind(function(response) {
function(dataset) {
$("#modal-edit-dataset").modal("hide");
Redd.goto_dataset_view(this.dataset.get("slug"));
Redd.goto_dataset_view(dataset.get("slug"));
Redd.refresh_categories();
}, this),
function(model, response) {
},
function(dataset, response) {
try {
errors = $.parseJSON(response);
} catch(e) {
errors = { "__all__": "Unknown error" };
}

$("#edit-dataset-form").show_errors(errors, "Save failed!");
});
}
);

return false;
}
Expand Down
10 changes: 6 additions & 4 deletions client/static/js/views/dataset_search.js
Expand Up @@ -134,6 +134,11 @@ PANDA.views.DatasetSearch = Backbone.View.extend({
},

search: function(query, limit, page) {
/*
* Execute a search.
*
* TODO: error handler
*/
this.decode_query_string(query);

this.render();
Expand All @@ -143,10 +148,7 @@ PANDA.views.DatasetSearch = Backbone.View.extend({
page,
_.bind(function(dataset) {
this.results.render();
}, this),
function() {
// TODO: error handler
}
}, this)
);
},

Expand Down
29 changes: 17 additions & 12 deletions client/static/js/views/dataset_view.js
Expand Up @@ -200,15 +200,16 @@ PANDA.views.DatasetView = Backbone.View.extend({
this.dataset.reindex_data(
typed_columns,
column_types,
_.bind(function() {
function(dataset) {
bootbox.alert(
"Your data indexing task has been successfully queued. You wil receive an email when it is complete.",
_.bind(function() {
Redd.goto_dataset_view(this.dataset.get("slug"));
function() {
Redd.goto_dataset_view(dataset.get("slug"));
window.scrollTo(0, 0);
}, this));
}, this),
function(error) {
}
);
},
function(dataset, error) {
bootbox.alert("<p>Your data indexing task failed to start!</p><p>Error:</p><code>" + error.traceback + "</code>");
});
},
Expand All @@ -219,10 +220,10 @@ PANDA.views.DatasetView = Backbone.View.extend({
*/
this.dataset.export_data(
null,
function() {
function(dataset) {
bootbox.alert("Your export has been successfully queued. When it is complete you will be emailed a link to download the file.");
},
function(error) {
function(dataset, error) {
bootbox.alert("<p>Your export failed to start!</p><p>Error:</p><code>" + error.traceback + "</code>");
}
);
Expand All @@ -231,12 +232,16 @@ PANDA.views.DatasetView = Backbone.View.extend({
destroy: function() {
/*
* Destroy this dataset.
*
* TODO: error handler
*/
this.dataset.destroy({ success: _.bind(function() {
this.dataset = null;
this.dataset.destroy({
success: _.bind(function() {
this.dataset = null;

Redd.goto_search();
}, this)});
Redd.goto_search();
}, this)
});
}
});

1 change: 0 additions & 1 deletion client/static/js/views/datasets_results.js
Expand Up @@ -3,7 +3,6 @@ PANDA.views.DatasetsResults = Backbone.View.extend({
_.bindAll(this);

this.search = options.search;
this.search.datasets.bind("reset", this.render);
},

render: function() {
Expand Down
24 changes: 15 additions & 9 deletions client/static/js/views/datasets_search.js
Expand Up @@ -17,19 +17,25 @@ PANDA.views.DatasetsSearch = Backbone.View.extend({
},

reset: function(category, query, limit, page) {
/*
* Execute the search.
*
* TODO: error handler
*/
this.category = category;
this.query = query;

this.render();

// Bypass search if there are no query terms
if (category == "all" && !query) {
this.datasets.search_meta(null, query, limit, page);
} else if (category != "all") {
this.datasets.search_meta(category, query, limit, page);
} else {
this.datasets.search_meta(null, query, limit, page);
}

this.datasets.search_meta(
(this.category == "all") ? null : this.category,
this.query,
limit,
page,
_.bind(function(datasets) {
this.results.render();
}, this)
);
},

render: function() {
Expand Down
10 changes: 6 additions & 4 deletions client/static/js/views/search.js
Expand Up @@ -46,6 +46,11 @@ PANDA.views.Search = Backbone.View.extend({
},

search: function(query, limit, page) {
/*
* Execute cross-dataset search.
*
* TODO: error handler
*/
this.query = query;

if (this.query) {
Expand All @@ -55,10 +60,7 @@ PANDA.views.Search = Backbone.View.extend({
page,
_.bind(function(datasets) {
this.results.render();
}, this),
function() {
// TODO: error handler
}
}, this)
);
} else {
this.render();
Expand Down

0 comments on commit 6dd722c

Please sign in to comment.