Skip to content

Commit 4ed9285

Browse files
authored
Merge pull request #2279 from antgonza/moi.send
mv moi-ws to qiita_websocket
2 parents fb65ff1 + 0a9182f commit 4ed9285

File tree

8 files changed

+116
-53
lines changed

8 files changed

+116
-53
lines changed

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,3 @@ gg_13_8-*
5757

5858
# sphinx documentation
5959
qiita_pet/static/doc/
60-
61-
# moi static files
62-
qiita_pet/static/vendor/js/moi.js
63-
qiita_pet/static/vendor/js/moi_list.js

INSTALL.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ Set your `QIITA_CONFIG_FP` environment variable to point to that file (into `.ba
140140

141141
```bash
142142
echo "export QIITA_CONFIG_FP=$HOME/.qiita_config_test.cfg" >> ~/.bashrc
143-
echo "export MOI_CONFIG_FP=$HOME/.qiita_config_test.cfg" >> ~/.bashrc
144143
source ~/.bashrc
145144
# Re-enable conda environment for qiita
146145
source activate qiita

qiita_pet/static/js/qiita.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,100 @@ function change_artifact_name(portal_dir, artifact_id, new_name, on_success_func
240240
}
241241
});
242242
}
243+
244+
/**
245+
* Taken from https://goo.gl/KkQ1S4
246+
*
247+
* Original script information:
248+
* @author Daniel McDonald
249+
* @copyright Copyright 2014, biocore
250+
* @credits Daniel McDonald, Joshua Shorenstein, Jose Navas
251+
* @license BSD
252+
* @version 0.1.0-dev
253+
* @maintainer Daniel McDonald
254+
* @email mcdonadt@colorado.edu
255+
* @status Development
256+
*
257+
*
258+
* @name qiita_websocket
259+
*
260+
* @class manages WebSocket for job information
261+
*
262+
*/
263+
264+
var qiita_websocket = new function () {
265+
var
266+
/* the server end of the websocket */
267+
host = null,
268+
/* the websocket */
269+
ws = null,
270+
271+
/* registered callbacks */
272+
callbacks = {},
273+
274+
/* the encode and decode methods used for communication */
275+
encode = JSON.stringify,
276+
decode = JSON.parse;
277+
278+
/**
279+
*
280+
* Registers a callback method for a given action
281+
*
282+
* @param {action} The associated action verb, str.
283+
* @param {func} The associated function, function. This function must
284+
* accept an object. Any return is ignored.
285+
*
286+
*/
287+
this.add_callback = function(action, func) { callbacks[action] = func; };
288+
289+
/**
290+
*
291+
* Packages data into an object, and passes an encoded version of the
292+
* object to the websocket.
293+
*
294+
* @param {action} The associated action to send, str.
295+
* @param {data} The data to send, str or Array of str.
296+
*/
297+
this.send = function(action, data) {
298+
to_send = {};
299+
to_send[action] = data;
300+
ws.send(encode(to_send));
301+
};
302+
303+
/**
304+
*
305+
* Verify the browser supports websockets, and if so, initialize the
306+
* websocket. On construction, this method will send a message over the
307+
* socket to get all known job information associated with this client.
308+
*
309+
* @param {host} The URL for the websocket, minus the ws:// header, or null
310+
* to use the default qiita_websocket-ws.
311+
* @param {on_close} Optional function for action when websocket is closed.
312+
* @param {on_error} Optional function for action when websocket errors.
313+
*/
314+
this.init = function(host, on_close, on_error) {
315+
if (!("WebSocket" in window)) {
316+
alert("Your browser does not appear to support websockets!");
317+
return;
318+
}
319+
//check if we need regular or secure websocket
320+
socket = window.location.protocol == "https:" ? 'wss://' : 'ws://';
321+
ws = new WebSocket(socket + host);
322+
323+
// retrive all messages
324+
var on_open_message = [];
325+
326+
ws.onopen = function(){};
327+
ws.onclose = on_close;
328+
ws.onerror = on_error;
329+
330+
ws.onmessage = function(evt) {
331+
message = decode(evt.data);
332+
for(var action in message) {
333+
if(action in callbacks) {
334+
callbacks[action](message[action]);
335+
}
336+
}
337+
};
338+
};
339+
};

qiita_pet/templates/analysis_selected.html

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{% block head %}
33
{% from future.utils import viewitems %}
44
{% from itertools import chain %}
5-
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/moi.js"></script>
65
<script type="text/javascript">
76

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

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

@@ -27,7 +26,7 @@
2726

2827
function remove_proc_data(pid, sid) {
2928
if(confirm('Are you sure you want to remove all samples for this processed data?')) {
30-
moi.send('remove_pd', {'proc_data': pid, 'samples': [], 'sid': sid});
29+
qiita_websocket.send('remove_pd', {'proc_data': pid, 'samples': [], 'sid': sid});
3130
}
3231
}
3332

@@ -41,7 +40,7 @@
4140
check_empty();
4241
}
4342

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

4645
function remove_sample_from_html(data) {
4746
pid = data.proc_data;
@@ -58,10 +57,10 @@
5857
check_empty();
5958
}
6059
$(document).ready(function() {
61-
moi.init(null, window.location.host + '{% raw qiita_config.portal_dir %}/analysis/selected/socket/', function(){}, error, error);
62-
moi.add_callback('remove_pd', remove_pd_from_html);
63-
moi.add_callback('remove_sample', remove_sample_from_html);
64-
moi.add_callback('clear', clear_from_html);
60+
qiita_websocket.init(window.location.host + '{% raw qiita_config.portal_dir %}/analysis/selected/socket/', error, error);
61+
qiita_websocket.add_callback('remove_pd', remove_pd_from_html);
62+
qiita_websocket.add_callback('remove_sample', remove_sample_from_html);
63+
qiita_websocket.add_callback('clear', clear_from_html);
6564
$('#clear-button').on('click', clear);
6665
{% if sel_data %}$('#no-selected').hide(){% end %}
6766
});

qiita_pet/templates/analysis_waiting.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{% extends sitebase.html%}
22

33
{%block head%}
4-
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/moi.js"></script>
5-
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/moi_list.js"></script>
64
<script type="text/javascript">
75
$(document).ready(function() {
86
moi_list.init("{{group_id}}", undefined, window.location.host + '{% raw qiita_config.portal_dir %}/moi-ws/');

qiita_pet/templates/artifact_ajax/artifact_summary.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@
8989
function validate_new_name() {
9090
$("#update-name-btn").prop('disabled', $("#new-artifact-name").val() === "");
9191
}
92+
93+
$(document).ready(function() {
94+
// Set the focus on the text input when the modal to change the artifact
95+
// name is shown
96+
$('#update-artifact-name').on('shown.bs.modal', function() {
97+
$('#new-artifact-name').focus();
98+
});
99+
});
92100
</script>
93101
<div class='row'>
94102
<div class='col-md-12'>

qiita_pet/templates/list_studies.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<link rel="stylesheet" href="{% raw qiita_config.portal_dir %}/static/vendor/css/jquery.dataTables.min.css" type="text/css">
55
<link rel="stylesheet" href="{% raw qiita_config.portal_dir %}/static/vendor/css/select2.min.css" type="text/css">
66

7-
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/moi.js"></script>
87
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/select2.min.js"></script>
98
<script src="{% raw qiita_config.portal_dir %}/static/js/sharing.js"></script>
109
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/tag-it.min.js" type="text/javascript" charset="utf-8"></script>
@@ -21,7 +20,7 @@
2120
$.get('/artifact/samples/', {ids:aids})
2221
.done(function ( data ) {
2322
if (data['status']=='success') {
24-
moi.send('sel', data['data']);
23+
qiita_websocket.send('sel', data['data']);
2524
button.value = 'Added';
2625
$(button).removeClass("btn-info");
2726
} else {
@@ -80,8 +79,8 @@
8079
});
8180

8281
$("#search-waiting").hide();
83-
moi.init(null, window.location.host + '{% raw qiita_config.portal_dir %}/study/list/socket/', function(){}, error, error);
84-
moi.add_callback('sel', show_alert);
82+
qiita_websocket.init(window.location.host + '{% raw qiita_config.portal_dir %}/study/list/socket/', error, error);
83+
qiita_websocket.add_callback('sel', show_alert);
8584
function format_biom_rows(data, row) {
8685
var proc_data_table = '<table class="table" cellpadding="0" cellspacing="0" border="0" style="padding-left:0px;width:95%">';
8786
proc_data_table += '<tr>';

scripts/qiita-env

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
# The full license is in the file LICENSE, distributed with this software.
99
# -----------------------------------------------------------------------------
1010

11-
from sys import exit
12-
1311
import click
1412

1513
import qiita_db as qdb
@@ -89,44 +87,13 @@ def test(runner):
8987
"""Test the environment
9088
9189
Check to make sure that basic services are up and working. These include
92-
connectivity to postgres, redis, and the ability to submit jobs through
93-
moi.
90+
connectivity to postgres, and redis.
9491
9592
Tests are performed both on localhost and ipengines.
9693
"""
9794
_test(runner)
9895

9996

100-
@env.command()
101-
@click.option('--job', required=True, type=str, help='The job ID')
102-
def job_details(job):
103-
"""Pretty print moi job details"""
104-
from json import loads
105-
from redis.exceptions import ResponseError
106-
from qiita_core.qiita_settings import r_client
107-
108-
try:
109-
data = r_client.get(job)
110-
except ResponseError:
111-
click.echo("ID does not appear to be a job")
112-
exit(1)
113-
114-
if data is None:
115-
click.echo("Job cannot be found")
116-
else:
117-
data = loads(data)
118-
for k in sorted(data):
119-
value = data[k]
120-
121-
if k == 'result':
122-
if isinstance(value, list):
123-
value = ''.join(value)
124-
else:
125-
value = str(value)
126-
127-
click.echo("%s : %s" % (k, value))
128-
129-
13097
@env.command(name="create-portal")
13198
@click.argument('portal', required=True, type=str)
13299
@click.argument('description', required=True, type=str)

0 commit comments

Comments
 (0)