Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the user an error message when no tables were extracted #425

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 30 additions & 21 deletions webapp/static/js/pdf_view.js
Expand Up @@ -293,23 +293,29 @@ Tabula.Query = Backbone.Model.extend({
success: _.bind(function(resp) {
this.set('data', resp);

// this only needs to happen on the first select, when we don't know what the extraction method is yet
// (because it's set by the heuristic on the server-side).
// TODO: only execute it when one of the list_of_coords has guess or undefined as its extraction_method
_(_.zip(this.get('list_of_coords'), resp)).each(function(stuff, i){
var coord_set = stuff[0];
var resp_item = stuff[1];
if (stashed_selections.get(coord_set.selection_id)){
stashed_selections.get(coord_set.selection_id).
set('extraction_method', resp_item["extraction_method"]);
if (resp.length > 0) {
// this only needs to happen on the first select, when we don't know what the extraction method is yet
// (because it's set by the heuristic on the server-side).
// TODO: only execute it when one of the list_of_coords has guess or undefined as its extraction_method
_(_.zip(this.get('list_of_coords'), resp)).each(function(stuff, i){
var coord_set = stuff[0];
var resp_item = stuff[1];
if (stashed_selections.get(coord_set.selection_id)){
stashed_selections.get(coord_set.selection_id).
set('extraction_method', resp_item["extraction_method"]);
}
coord_set["extraction_method"] = resp_item["extraction_method"];
});

this.trigger("tabula:query-success");

if (options !== undefined && _.isFunction(options.success)){
Tabula.pdf_view.options.success(resp);
}
coord_set["extraction_method"] = resp_item["extraction_method"];
});

this.trigger("tabula:query-success");

if (options !== undefined && _.isFunction(options.success)){
Tabula.pdf_view.options.success(resp);
} else {
// no tables were extracted
var error_message = "No tables were extracted. Please try selecting a different extraction method from the sidebar.";
this.triggerQueryError(error_message, options);
}

}, this),
Expand All @@ -324,14 +330,17 @@ Tabula.Query = Backbone.Model.extend({
var info = error_html.find('#info').text().trim();
error_text = [summary, meta, info].join("<br />");
}
var debugging_text = "Tabula API version: " + Tabula.api_version + "\nFilename: " + Tabula.pdf_view.pdf_document.get('original_filename') + "\n" + error_text
this.set('error_message', debugging_text);
this.trigger("tabula:query-error");
if (options !== undefined && _.isFunction(options.error))
options.error(resp);
this.triggerQueryError(error_text, options);
}, this),
});
},
triggerQueryError: function(error_text, options){
var debugging_text = "Tabula API version: " + Tabula.api_version + "\nFilename: " + Tabula.pdf_view.pdf_document.get('original_filename') + "\n" + error_text
this.set('error_message', debugging_text);
this.trigger("tabula:query-error");
if (options !== undefined && _.isFunction(options.error))
options.error(resp);
},
setExtractionMethod: function(extractionMethod){
_(this.get('list_of_coords')).each(function(coord_set){ coord_set['extraction_method'] = extractionMethod; });
},
Expand Down