Skip to content

mv moi-ws to qiita_websocket #2279

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 6 commits into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,3 @@ gg_13_8-*

# sphinx documentation
qiita_pet/static/doc/

# moi static files
qiita_pet/static/vendor/js/moi.js
qiita_pet/static/vendor/js/moi_list.js
1 change: 0 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ Set your `QIITA_CONFIG_FP` environment variable to point to that file (into `.ba

```bash
echo "export QIITA_CONFIG_FP=$HOME/.qiita_config_test.cfg" >> ~/.bashrc
echo "export MOI_CONFIG_FP=$HOME/.qiita_config_test.cfg" >> ~/.bashrc
source ~/.bashrc
# Re-enable conda environment for qiita
source activate qiita
Expand Down
97 changes: 97 additions & 0 deletions qiita_pet/static/js/qiita.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,100 @@ function change_artifact_name(portal_dir, artifact_id, new_name, on_success_func
}
});
}

/**
* Taken from https://goo.gl/KkQ1S4
*
* Original script information:
* @author Daniel McDonald
* @copyright Copyright 2014, biocore
* @credits Daniel McDonald, Joshua Shorenstein, Jose Navas
* @license BSD
* @version 0.1.0-dev
* @maintainer Daniel McDonald
* @email mcdonadt@colorado.edu
* @status Development
*
*
* @name qiita_websocket
*
* @class manages WebSocket for job information
*
*/

var qiita_websocket = new function () {
var
/* the server end of the websocket */
host = null,
/* the websocket */
ws = null,

/* registered callbacks */
callbacks = {},

/* the encode and decode methods used for communication */
encode = JSON.stringify,
decode = JSON.parse;

/**
*
* Registers a callback method for a given action
*
* @param {action} The associated action verb, str.
* @param {func} The associated function, function. This function must
* accept an object. Any return is ignored.
*
*/
this.add_callback = function(action, func) { callbacks[action] = func; };

/**
*
* Packages data into an object, and passes an encoded version of the
* object to the websocket.
*
* @param {action} The associated action to send, str.
* @param {data} The data to send, str or Array of str.
*/
this.send = function(action, data) {
to_send = {};
to_send[action] = data;
ws.send(encode(to_send));
};

/**
*
* Verify the browser supports websockets, and if so, initialize the
* websocket. On construction, this method will send a message over the
* socket to get all known job information associated with this client.
*
* @param {host} The URL for the websocket, minus the ws:// header, or null
* to use the default qiita_websocket-ws.
* @param {on_close} Optional function for action when websocket is closed.
* @param {on_error} Optional function for action when websocket errors.
*/
this.init = function(host, on_close, on_error) {
if (!("WebSocket" in window)) {
alert("Your browser does not appear to support websockets!");
return;
}
//check if we need regular or secure websocket
socket = window.location.protocol == "https:" ? 'wss://' : 'ws://';
ws = new WebSocket(socket + host);

// retrive all messages
var on_open_message = [];

ws.onopen = function(){};
ws.onclose = on_close;
ws.onerror = on_error;

ws.onmessage = function(evt) {
message = decode(evt.data);
for(var action in message) {
if(action in callbacks) {
callbacks[action](message[action]);
}
}
};
};
};
15 changes: 7 additions & 8 deletions qiita_pet/templates/analysis_selected.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{% block head %}
{% from future.utils import viewitems %}
{% from itertools import chain %}
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/moi.js"></script>
<script type="text/javascript">

function error(evt) { $('#ws-error').html("<b>Server communication error. Sample removal will not be recorded. Please try again later.</b>"); };
Expand All @@ -16,7 +15,7 @@

function clear() {
if(confirm('Are you sure you want to remove all samples?')) {
moi.send('clear', {'pids': {% raw [int(p) for p in chain.from_iterable(pid.keys() for sid, pid in viewitems(sel_data))] %} });
qiita_websocket.send('clear', {'pids': {% raw [int(p) for p in chain.from_iterable(pid.keys() for sid, pid in viewitems(sel_data))] %} });
}
}

Expand All @@ -27,7 +26,7 @@

function remove_proc_data(pid, sid) {
if(confirm('Are you sure you want to remove all samples for this processed data?')) {
moi.send('remove_pd', {'proc_data': pid, 'samples': [], 'sid': sid});
qiita_websocket.send('remove_pd', {'proc_data': pid, 'samples': [], 'sid': sid});
}
}

Expand All @@ -41,7 +40,7 @@
check_empty();
}

function remove_sample(sid, pid, sample) { moi.send('remove_sample', {'proc_data': pid, 'samples': [sample], 'sid': sid}); }
function remove_sample(sid, pid, sample) { qiita_websocket.send('remove_sample', {'proc_data': pid, 'samples': [sample], 'sid': sid}); }

function remove_sample_from_html(data) {
pid = data.proc_data;
Expand All @@ -58,10 +57,10 @@
check_empty();
}
$(document).ready(function() {
moi.init(null, window.location.host + '{% raw qiita_config.portal_dir %}/analysis/selected/socket/', function(){}, error, error);
moi.add_callback('remove_pd', remove_pd_from_html);
moi.add_callback('remove_sample', remove_sample_from_html);
moi.add_callback('clear', clear_from_html);
qiita_websocket.init(window.location.host + '{% raw qiita_config.portal_dir %}/analysis/selected/socket/', error, error);
qiita_websocket.add_callback('remove_pd', remove_pd_from_html);
qiita_websocket.add_callback('remove_sample', remove_sample_from_html);
qiita_websocket.add_callback('clear', clear_from_html);
$('#clear-button').on('click', clear);
{% if sel_data %}$('#no-selected').hide(){% end %}
});
Expand Down
2 changes: 0 additions & 2 deletions qiita_pet/templates/analysis_waiting.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{% extends sitebase.html%}

{%block head%}
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/moi.js"></script>
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/moi_list.js"></script>
<script type="text/javascript">
$(document).ready(function() {
moi_list.init("{{group_id}}", undefined, window.location.host + '{% raw qiita_config.portal_dir %}/moi-ws/');
Expand Down
8 changes: 8 additions & 0 deletions qiita_pet/templates/artifact_ajax/artifact_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@
function validate_new_name() {
$("#update-name-btn").prop('disabled', $("#new-artifact-name").val() === "");
}

$(document).ready(function() {
// Set the focus on the text input when the modal to change the artifact
// name is shown
$('#update-artifact-name').on('shown.bs.modal', function() {
$('#new-artifact-name').focus();
});
});
</script>
<div class='row'>
<div class='col-md-12'>
Expand Down
7 changes: 3 additions & 4 deletions qiita_pet/templates/list_studies.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<link rel="stylesheet" href="{% raw qiita_config.portal_dir %}/static/vendor/css/jquery.dataTables.min.css" type="text/css">
<link rel="stylesheet" href="{% raw qiita_config.portal_dir %}/static/vendor/css/select2.min.css" type="text/css">

<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/moi.js"></script>
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/select2.min.js"></script>
<script src="{% raw qiita_config.portal_dir %}/static/js/sharing.js"></script>
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/tag-it.min.js" type="text/javascript" charset="utf-8"></script>
Expand All @@ -21,7 +20,7 @@
$.get('/artifact/samples/', {ids:aids})
.done(function ( data ) {
if (data['status']=='success') {
moi.send('sel', data['data']);
qiita_websocket.send('sel', data['data']);
button.value = 'Added';
$(button).removeClass("btn-info");
} else {
Expand Down Expand Up @@ -80,8 +79,8 @@
});

$("#search-waiting").hide();
moi.init(null, window.location.host + '{% raw qiita_config.portal_dir %}/study/list/socket/', function(){}, error, error);
moi.add_callback('sel', show_alert);
qiita_websocket.init(window.location.host + '{% raw qiita_config.portal_dir %}/study/list/socket/', error, error);
qiita_websocket.add_callback('sel', show_alert);
function format_biom_rows(data, row) {
var proc_data_table = '<table class="table" cellpadding="0" cellspacing="0" border="0" style="padding-left:0px;width:95%">';
proc_data_table += '<tr>';
Expand Down
35 changes: 1 addition & 34 deletions scripts/qiita-env
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------

from sys import exit

import click

import qiita_db as qdb
Expand Down Expand Up @@ -89,44 +87,13 @@ def test(runner):
"""Test the environment

Check to make sure that basic services are up and working. These include
connectivity to postgres, redis, and the ability to submit jobs through
moi.
connectivity to postgres, and redis.

Tests are performed both on localhost and ipengines.
"""
_test(runner)


@env.command()
@click.option('--job', required=True, type=str, help='The job ID')
def job_details(job):
"""Pretty print moi job details"""
from json import loads
from redis.exceptions import ResponseError
from qiita_core.qiita_settings import r_client

try:
data = r_client.get(job)
except ResponseError:
click.echo("ID does not appear to be a job")
exit(1)

if data is None:
click.echo("Job cannot be found")
else:
data = loads(data)
for k in sorted(data):
value = data[k]

if k == 'result':
if isinstance(value, list):
value = ''.join(value)
else:
value = str(value)

click.echo("%s : %s" % (k, value))


@env.command(name="create-portal")
@click.argument('portal', required=True, type=str)
@click.argument('description', required=True, type=str)
Expand Down