Skip to content

DataTables load using AJAX, Search by metadata on studies page #1006

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

Merged
merged 29 commits into from
Apr 1, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
616300f
add get_info to Studies object
squirrelo Mar 19, 2015
d595016
expand tests
squirrelo Mar 19, 2015
90313f7
use get_info in listing handler
squirrelo Mar 19, 2015
fb5eef3
condense view studies pages
squirrelo Mar 19, 2015
1ffd4bc
clean up naming, add form elements
squirrelo Mar 19, 2015
16257c4
load study tables through ajax
squirrelo Mar 19, 2015
9ccc098
add message for zero results
squirrelo Mar 19, 2015
abeb46f
add search and retrieve to page
squirrelo Mar 20, 2015
259bec2
fix bug in joins
squirrelo Mar 20, 2015
b8472a8
add full ajax search support
squirrelo Mar 20, 2015
cf6ca77
add error handling to datatables
squirrelo Mar 20, 2015
cd4f66e
alter/add tests for handlers to reflect changes
squirrelo Mar 20, 2015
ce4d334
fix tests
squirrelo Mar 20, 2015
58b28cd
implement Jess' suggestions
squirrelo Mar 21, 2015
1872555
Merge branch 'master' of https://github.com/biocore/qiita into cart
squirrelo Mar 22, 2015
4b7ffcf
remove unneeded format loop, format datatables better
squirrelo Mar 24, 2015
515f0f6
update tests
squirrelo Mar 24, 2015
21b17d6
Merge branch 'master' of https://github.com/biocore/qiita into cart
squirrelo Mar 24, 2015
04f87f4
specific ordering for PMIDs for testing
squirrelo Mar 24, 2015
ee4c9e2
flake8
squirrelo Mar 24, 2015
ef16d18
address issues
squirrelo Mar 26, 2015
fbe7c74
address comments
squirrelo Mar 26, 2015
e0f22d0
merge upstream/master
squirrelo Mar 27, 2015
0df6666
fix merge issues
squirrelo Mar 27, 2015
5085c35
more enhancements
squirrelo Mar 27, 2015
ea69fe8
address comments
squirrelo Mar 28, 2015
3a12f87
update tests
squirrelo Mar 28, 2015
25ae8f2
update schema and html files
squirrelo Mar 29, 2015
e01e224
fix search disabled and clearing table search
squirrelo Apr 1, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add error handling to datatables
  • Loading branch information
squirrelo committed Mar 20, 2015
commit cf6ca7799bf66e1ccf5325882e36f0bd6e53f1e7
27 changes: 26 additions & 1 deletion qiita_pet/handlers/study_handlers/listing_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

from tornado.web import authenticated, HTTPError
from tornado.gen import coroutine, Task
from pyparsing import ParseException

from qiita_core.exceptions import IncompetentQiitaDeveloperError
from qiita_db.user import User
from qiita_db.study import Study, StudyPerson
from qiita_db.search import QiitaStudySearch
from qiita_db.metadata_template import SampleTemplate
from qiita_db.exceptions import QiitaDBIncompatibleDatatypeError
from qiita_db.util import get_table_cols
from qiita_pet.handlers.base_handlers import BaseHandler
from qiita_pet.handlers.util import study_person_linkifier, pubmed_linkifier
Expand Down Expand Up @@ -176,7 +178,30 @@ def get(self, ignore):
if query != "":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if query

# Search for samples matching the query
search = QiitaStudySearch()
res, meta = search(query, User(user))
try:
res, meta = search(query, User(user))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use self.current_user (less objs instantiations)

except ParseException:
print ">>>>>>ParseException"
self.clear()
self.set_status(400)
self.write('Malformed search query. Please read "search help" '
'and try again.')
return
except QiitaDBIncompatibleDatatypeError as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under what types of situations would this arise? I didn't see a test case on it, so just curious

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

someone tries to search over both varchar and numeric on same column

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this should raise an error. Let's have 2 studies with column Ph, one has only float values (created as float) and the other one has a combination of float/str (created as str). If a user searches for Ph = 0.4 it should return the samples that match that criteria from both studies, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it has a combination of float/str, the entire column will be varchar and we can't do proper numeric comparisons vs a string. This is a known issue with the search engine that will get fixed during the refactor. Before this explicit error raising the search would just 500 error if you do this type of search.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

print ">>>>>>QiitaDBIncompatibleDatatypeError"
self.clear()
self.set_status(400)
searchmsg = 'BUUUUUTS'
self.write(searchmsg)
return
except:
print ">>>>>>GENERIC ERROR"
# catch any other error as generic server error
self.set_status(500)
self.write("Server error during search. Please try again "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this indicative of an actual problem that should be logged?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Wasn't logged in the code I copy-pasted to here but can add it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do 👍

"later")
if not res:
res = {}
info = _build_study_info(search_type, self.current_user,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this call only needs to be done once and can be done outside of the conditions if res is set to None in the else block

studies=res.keys())
else:
Expand Down
17 changes: 14 additions & 3 deletions qiita_pet/templates/list_studies.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
"sZeroRecords": "No studies found"
},
"ajax": {
"url": ajaxURL + "&type=standard&query="
}
"url": ajaxURL + "&type=standard&query=",
"error": function(jqXHR, textStatus, ex) {
$("#submit-button").prop("disabled",false);
$("#search-error").text(jqXHR.responseText);
}
}
});
$('#shared-studies-table').dataTable({
order: [[ 1, "asc" ]],
Expand All @@ -31,8 +35,13 @@
},
"ajax": {
"url": ajaxURL + "&type=shared&query=",
}
"error": function(jqXHR, textStatus, ex) {
$("#submit-button").prop("disabled",false);
$("#search-error").text(jqXHR.responseText);
}
}
});

$('#users_list').chosen({width: "100%"});
$('#users_list').on('change', function(evt, params) {
params['study_id'] = current_study;
Expand All @@ -47,6 +56,7 @@
$("#search-form").submit(function(event) {
event.preventDefault();
$("#submit-button").prop("disabled",true);
$("#search-error").text('');
query = $("#searchbox").val();
$("#user-studies-table").DataTable().ajax.url(ajaxURL + "&type=standard&query=" + query).load(function() {$("#submit-button").prop("disabled",false);}, true);
$("#shared-studies-table").DataTable().ajax.url(ajaxURL + "&type=shared&query=" + query).load(function() {$("#submit-button").prop("disabled",false);}, true);
Expand Down Expand Up @@ -85,6 +95,7 @@ <h1>Search</h1>
<input type="textbox" id="searchbox" name="searchbox" class="form-control" style="width:80%;white-space:nowrap;" />
<button type="submit" id="submit-button" class="btn btn-default">Submit</button>
</form>
<span id="search-error" style="color:red"></span>
</div>
<div class="col-sm-12" id="searchmsg" name="searchmsg"></div>
</div>
Expand Down