Skip to content

Websockets on cart page #1058

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 21 commits into from
Apr 23, 2015

Conversation

squirrelo
Copy link
Contributor

~~Requires #1041 so merge that first.~~Merged
Depends on #1056 so merge that firstMerged

This adds websocket-based removal of samples and processed data on the selected samples cart page. It also moves the analysis creation to that page as well.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 78.96% when pulling a828daa on squirrelo:websockets-on-cart-page into c1fc3c8 on biocore:cart-branch.

@squirrelo
Copy link
Contributor Author

Ready for review

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 795c748 on squirrelo:websockets-on-cart-page into * on biocore:cart-branch*.

@ElDeveloper
Copy link
Contributor

argh, conflicts, can you pull from upstream master and upstream cart-branch.

@squirrelo
Copy link
Contributor Author

Done, tests running now.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 79.26% when pulling 05b3837 on squirrelo:websockets-on-cart-page into 2409338 on biocore:cart-branch.

@squirrelo
Copy link
Contributor Author

@biocore/qiita-dev Tests pass, ready for review!

@ElDeveloper
Copy link
Contributor

Ok, now I'm reviewing this one.

# parse into JSON
msginfo = loads(msg)
default = Analysis(self.current_user.default_analysis)
if 'samples' not in msginfo:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can simplify this if/else block by using msginfo.get('samples'), which would return a None when 'samples' is not part of the dictionary. And perhaps, this is the way both arguments should be retrieved such that in case nothing was sent remove_samples would raise an exception (QiitaIncompetentDeveloper, I think).

Copy link
Contributor

Choose a reason for hiding this comment

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

if the object sent over the line always includes samples then the message is consistent. In this branch, the message would just need to have samples associated with []

Copy link
Contributor

Choose a reason for hiding this comment

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

or None

@ElDeveloper
Copy link
Contributor

This looks great!! Such an awesome improvement overall, a few things:

  • If you (1) select samples for an analysis, then (2) go to "view selected samples", then (3) remove all the samples and (4) try to create the analysis. You'll get a 405 error. Similarly if no samples are selected and you click "view selected samples", you'll get the following traceback:
  File "/Users/yoshikivazquezbaeza/.virtualenvs/qiita/lib/python2.7/site-package
s/tornado/web.py", line 1141, in _when_complete
    callback()

  File "/Users/yoshikivazquezbaeza/.virtualenvs/qiita/lib/python2.7/site-package
s/tornado/web.py", line 1162, in _execute_method
    self._when_complete(method(*self.path_args, **self.path_kwargs),

  File "/Users/yoshikivazquezbaeza/.virtualenvs/qiita/lib/python2.7/site-package
s/tornado/web.py", line 2297, in wrapper
    return method(self, *args, **kwargs)

  File "/Users/yoshikivazquezbaeza/git_sw/qiita/qiita_pet/handlers/analysis_hand
lers.py", line 220, in get
    proc_info=proc_data_info)

  File "/Users/yoshikivazquezbaeza/.virtualenvs/qiita/lib/python2.7/site-packages/tornado/web.py", line 538, in render
    html = self.render_string(template_name, **kwargs)

  File "/Users/yoshikivazquezbaeza/.virtualenvs/qiita/lib/python2.7/site-packages/tornado/web.py", line 645, in render_string
    return t.generate(**namespace)

  File "/Users/yoshikivazquezbaeza/.virtualenvs/qiita/lib/python2.7/site-packages/tornado/template.py", line 273, in generate
    return execute()

  File "analysis_selected_html.generated.py", line 276, in _tt_execute
    for pid in proc_datas:  # analysis_selected.html:79 (via sitebase.html:192)

UnboundLocalError: local variable 'proc_datas' referenced before assignment

@@ -63,6 +72,10 @@
</div>
{% end %}

<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#create-analysis-modal-view">
Copy link
Contributor

Choose a reason for hiding this comment

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

This button would be better ( I think ) at the top.

Copy link
Contributor

Choose a reason for hiding this comment

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

And probably colored in "green"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have it at the bottom to force people to look at what they selected before hitting create. I can make it green though.

@ElDeveloper
Copy link
Contributor

When I select a few samples and try to create the analysis, I get a 405 error.

@ElDeveloper
Copy link
Contributor

Last thing, now that I've been able to list several studies under the "/selected/" handler, I think it would be better if the studies were presented inside a data table. And the table shouldn't use the full width of the window, it looks weird.

@@ -1,8 +1,15 @@
{% extends sitebase.html %}
{% block head %}
<script type="text/javascript">
var ws = new WebSocket('ws://' + window.location.host + '/analysis/selected/socket/');
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be really nice if it were possible to reuse the moi init here since it is already doing browser checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an init_websocket function for taking care of boilerplate code.

@josenavas
Copy link
Contributor

I've not gone over the code but I was testing this branch as @squirrelo suggested that this is the last PR on this branch.

One of the things that act weirdly is that I can select samples, go to the "View selected samples" page; and, when I go back to the study listing page, I have no feedback of which samples have been already selected. I would suggest that the checkbox should be checked if you've already chosen those samples. Alternatively, I would suggest changing the checkbox to a + sign (glyphicon); and use a - sign when that study has been already selected. Other options are using a color scheme, but I think this can look like a Christmas tree. Anyways, I think some kind of feedback is needed in the study selection page.

@josenavas
Copy link
Contributor

Also, I cannot create an analysis. I added a new study, completely processed it, I only choose it's samples. When I click create analysis on the modal that appears, nothing happens...

As a note, nothing in my terminal or javascript console, so no clue on what is going on.

@squirrelo
Copy link
Contributor Author

Fixed the issue with creation of new analyses, the modal was submitting to the wrong page.

As for previously selected samples, I agree that something needs to be done, but it's something that needs a lot of discussion and thought. For now, I think what we have will work, and it can be expanded upon when we come to a conclusion for how previously selected samples are shown. The big issue is that you aren't selecting by sample, but by processed data.

@josenavas
Copy link
Contributor

Thanks for the comments @squirrelo
However, I don't think that we should merge all this branch into master (it can go to it's own branch). Based on the new Contributing.md document, this functionality is not complete, and leaving the system in a somewhat inconsistent state (it can be really misleading to the user - it was for me...), so we should discuss this and being able to make it for the alpha 0.1 release...

@squirrelo
Copy link
Contributor Author

This is good to go as is for now though, since it's still on it's own branch. In light of that, can we get this a final review and merge?

@josenavas
Copy link
Contributor

As @ElDeveloper suggests, I will be more comfortable if @wasade can review this, as he has more experience with websockets and he already had some comments on this PR.

@squirrelo
Copy link
Contributor Author

This only changed a single number, so the tests will pass fine. It's good to review.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 79.26% when pulling 5b253ff on squirrelo:websockets-on-cart-page into 2409338 on biocore:cart-branch.

var ws = init_websocket(window.location.host + '/analysis/selected/socket/');
ws.onmessage = function(evt) { if(evt.data != 'true') {ws.close();} };
ws.onerror = function(evt) { $('#ws-error').html("<b>Server communication error. Sample removal will not be recorded. Please try again later.</b>"); };
ws.onclose = function(evt) { $('#ws-error').html("<b>Server communication error. Sample removal will not be recorded. Please try again later.</b>"); };
Copy link
Contributor

Choose a reason for hiding this comment

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

Closing a web socket should be a normal operation, right? Why is this considered an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

n this case, it should stay open until you leave the page in order to capture sample removals. If it closes prematurely that’s bad and should be treated as an error.

On Apr 22, 2015, at 7:20 AM, Daniel McDonald notifications@github.com wrote:

In qiita_pet/templates/analysis_selected.html #1058 (comment):

@@ -1,8 +1,15 @@
{% extends sitebase.html %}
{% block head %}

<script type="text/javascript"> +var ws = init_websocket(window.location.host + '/analysis/selected/socket/'); +ws.onmessage = function(evt) { if(evt.data != 'true') {ws.close();} }; +ws.onerror = function(evt) { $('#ws-error').html("Server communication error. Sample removal will not be recorded. Please try again later."); }; +ws.onclose = function(evt) { $('#ws-error').html("Server communication error. Sample removal will not be recorded. Please try again later."); }; Closing a web socket should be a normal operation, right? Why is this considered an error?


Reply to this email directly or view it on GitHub https://github.com/biocore/qiita/pull/1058/files#r28876200.

@wasade
Copy link
Contributor

wasade commented Apr 22, 2015

What is the reason for not reusing the moi client-side websocket code? It would require only a minor modification to moi.js (allow specifying an onerror method at construction, and the specific handler the websocket should use). This is an opportunity to reduce js code replication and centralize websocket handling client-side.

@squirrelo
Copy link
Contributor Author

The MOI.js is specific to what MOI is doing. I can make it generalizable, but then it’s no longe the same asr MOI.js in the MOI repo and the changes will need to get moved there as well. This is a fast solution that allows us to have qiita-specific websocket code and MOI specific web socket code coexist.

On Apr 22, 2015, at 7:38 AM, Daniel McDonald notifications@github.com wrote:

What is the reason for not reusing the moi client-side websocket code? It would require only a minor modification to moi.js (allow specifying an onerror method at construction, and the specific handler the websocket should use). This is an opportunity to reduce js code replication and centralize websocket handling client-side.


Reply to this email directly or view it on GitHub #1058 (comment).

@wasade
Copy link
Contributor

wasade commented Apr 22, 2015

It really isn't specific. Is a PR for the minor changes against moi not possible? It literally does the exact same thing, is just more flexible.

That argument is analogous to writing a custom fasta parser every time we need to parse a fasta file. It's quick, allows for special casing whatever random garbage is in the comment field, but hurts us in the long run.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 79.26% when pulling 05c24c0 on squirrelo:websockets-on-cart-page into 2409338 on biocore:cart-branch.

@squirrelo
Copy link
Contributor Author

Ok, broke out the web socket initialization and in the process may have fixed #993. If the MOI code looks good I’ll open a pull request to add it directly into MOI.

On Apr 22, 2015, at 8:26 AM, Daniel McDonald notifications@github.com wrote:

It really isn't specific. Is a PR for the minor changes against moi not possible? It literally does the exact same thing, is just more flexible.

That argument is analogous to writing a custom fasta parser every time we need to parse a fasta file. It's quick, allows for special casing whatever random garbage is in the comment field, but hurts us in the long run.


Reply to this email directly or view it on GitHub #1058 (comment).

@wasade
Copy link
Contributor

wasade commented Apr 22, 2015

Great, thank you
On Apr 22, 2015 9:46 AM, "Joshua Shorenstein" notifications@github.com
wrote:

Ok, broke out the web socket initialization and in the process may have
fixed #993. If the MOI code looks good I’ll open a pull request to add it
directly into MOI.

On Apr 22, 2015, at 8:26 AM, Daniel McDonald notifications@github.com
wrote:

It really isn't specific. Is a PR for the minor changes against moi not
possible? It literally does the exact same thing, is just more flexible.

That argument is analogous to writing a custom fasta parser every time
we need to parse a fasta file. It's quick, allows for special casing
whatever random garbage is in the comment field, but hurts us in the long
run.


Reply to this email directly or view it on GitHub <
https://github.com/biocore/qiita/pull/1058#issuecomment-95236350>.


Reply to this email directly or view it on GitHub
#1058 (comment).

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 79.26% when pulling a239792 on squirrelo:websockets-on-cart-page into 2409338 on biocore:cart-branch.

@squirrelo
Copy link
Contributor Author

This is now fully MOI-ified so it should be ready for merge. I will add the cart info stuff to the top corner in a subsequent pull request, since this one is already growing rather large.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 79.35% when pulling 0cc55c9 on squirrelo:websockets-on-cart-page into 2409338 on biocore:cart-branch.

@wasade
Copy link
Contributor

wasade commented Apr 23, 2015

👍

antgonza added a commit that referenced this pull request Apr 23, 2015
@antgonza antgonza merged commit 460df34 into qiita-spots:cart-branch Apr 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants