Commit 496bc15a authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Remove websockets

parent 0889faa7
......@@ -56,4 +56,4 @@ if [ "$LOCAL" == "True" ]; then
host="127.0.0.1"
fi
FLASK_DEBUG=${debug} FLASK_APP=${SCRIPTPATH}/../srv/main.py flask run --host=${host} --port=${PORT} --no-reload
FLASK_DEBUG=${debug} FLASK_APP=${SCRIPTPATH}/../srv/main.py flask run --host=${host} --port=${PORT}
......@@ -50,13 +50,15 @@ d3.boxplot.color_mixes = "#969696";
//Filter sizes:
d3.boxplot.min_sizes = [0, 0.01, 0.02, 0.03, 0.05, 1, 2];
d3.boxplot.init = function (id, from_file=false) {
dgenies.result.id_res = id;
d3.boxplot.init = function (id_res=null, from_file=false) {
if (id_res === null) {
id_res = dgenies.result.id_res;
}
$("#form-parameters")[0].reset();
$("form#select-zone")[0].reset();
if (!from_file) {
$.post("/get_graph",
{"id": id},
{"id": id_res},
function (data) {
if (data["success"]) {
d3.boxplot.launch(data);
......@@ -68,7 +70,7 @@ d3.boxplot.init = function (id, from_file=false) {
)
}
else {
$.get(id,
$.get(id_res,
{},
function (data) {
d3.boxplot.launch(data);
......
dgenies = {};
dgenies.loading = "#loading";
dgenies.login = null; // Username for websocket (anonymous)
dgenies.notify = function (text, type="warning", delay=5000) {
$.notify({
......
......@@ -17,7 +17,13 @@ dgenies.result.controls.launch_sort_contigs = function () {
$.post(`/sort/${dgenies.result.id_res}`,
{},
function (data) {
if (!data["success"]) {
if (data["success"]) {
dgenies.reset_loading_message();
window.setTimeout(() => {
d3.boxplot.launch(data, true);
}, 0);
}
else {
dgenies.hide_loading();
dgenies.notify("An error occurred! Please contact us to report the bug", "danger");
}
......
......@@ -7,36 +7,6 @@ dgenies.result = {};
dgenies.result.id_res = null;
dgenies.result.init = function(id_res) {
dgenies.result.socketio(id_res);
dgenies.result.id_res = id_res
d3.boxplot.init();
};
dgenies.result.socketio = function (id_res) {
// Connect to Websocket:
let socket = io.connect();
socket.on('connect', function() {
socket.emit('join', {room: "res_" + id_res});
});
socket.on("connected", function(data) {
console.log("Websocket connection established");
if ("username" in data) {
dgenies.login = data["username"];
}
});
/*
* Websocket events
*/
/**
* Update the dotplot
*/
socket.on('update_graph', function(data){
if ("success" in data && data["success"]) {
console.log("Update graph");
dgenies.show_loading();
window.setTimeout(() => {
d3.boxplot.launch(data, true);
}, 0);
}
});
};
\ No newline at end of file
flask==0.12.*
Flask-Mail==0.9.*
flask-socketio==2.9.*
gevent==1.2.*
gevent-websocket==0.10.*
Jinja2==2.9.*
pony==0.7.*
docopt==0.6.*
......
......@@ -5,10 +5,8 @@ import time
import datetime
import shutil
import re
import gevent
from flask import Flask, render_template, request, url_for, jsonify, session, Response, abort
from flask_mail import Mail
from flask_socketio import SocketIO, emit, join_room, leave_room
from lib.paf import Paf
from config_reader import AppConfigReader
from lib.job_manager import JobManager
......@@ -38,8 +36,6 @@ app = Flask(__name__, static_url_path='/static')
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['SECRET_KEY'] = 'dsqdsq-255sdA-fHfg52-25Asd5'
socketio = SocketIO(app, async_mode='gevent')
# Init mail:
mail = Mail(app)
......@@ -190,23 +186,18 @@ def get_graph():
return jsonify({"success": False, "message": paf.error})
def sort_paf(paf, id_res):
paf.sort()
res = {"success": False}
if paf.parsed:
res = paf.get_d3js_data()
res["success"] = True
emit_event("update_graph", res, "res_" + id_res)
@app.route('/sort/<id_res>', methods=['POST'])
def sort_graph(id_res):
paf = os.path.join(app_data, id_res, "map.paf")
idx1 = os.path.join(app_data, id_res, "query.idx")
idx2 = os.path.join(app_data, id_res, "target.idx")
paf = Paf(paf, idx1, idx2, False)
gevent.spawn(sort_paf, paf=paf, id_res=id_res)
return jsonify({"success": True})
paf.sort()
if paf.parsed:
res = paf.get_d3js_data()
res["success"] = True
return jsonify(res)
return jsonify({"success": False, "message": paf.error})
@app.route("/upload", methods=['POST'])
......@@ -244,23 +235,5 @@ def upload():
return jsonify({"files": [], "success": "ERR", "message": "Session not initialized. Please refresh the page."})
############
# SocketIO #
############
@socketio.on('join')
def on_join(data):
username = Functions.random_string(10)
room = data['room']
join_room(room)
emit("connected", {"username": username})
def emit_event(event, data, room=None):
socketio.emit(event, data, room=room)
socketio.sleep(0)
if __name__ == '__main__':
socketio.run(app)
\ No newline at end of file
app.run()
......@@ -12,10 +12,9 @@
<script src="{{ url_for('static', filename='js/d3.boxplot.zoom.js') }}" type="text/JavaScript"></script>
<script src="{{ url_for('static', filename='js/d3.boxplot.events.js') }}" type="text/JavaScript"></script>
<script src="{{ url_for('static', filename='js/d3.boxplot.mousetip.js') }}" type="text/JavaScript"></script>
<script src="{{ url_for('static', filename='js/socket.io.slim.js') }}" type="text/javascript"></script>
<link rel="stylesheet" href="{{ url_for('static', filename='css/chosen.min.css') }}" type="text/css">
{% endblock %}
{% block onload %}d3.boxplot.init('{{ id }}');dgenies.result.init('{{ id }}');{% endblock %}
{% block onload %}dgenies.result.init('{{ id }}');{% endblock %}
{% block content %}
{{ super() }}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment